]> wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-cache-off.c

wirehaze git hosting

add ppos/
[ppos.git] / ppos / test / pingpong-cache-off.c
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
4
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
7
8 // Teste das operações de acesso ao disco com uma única tarefa,
9 // que lê e escreve/altera blocos do disco SEM CACHE.
10
11 #include <assert.h>
12 #include "lib/libc.h"
13 #include "ppos.h"
14
15 // corpo da tarefa principal
16 void user_main(void *arg)
17 {
18 int status;
19 unsigned char *buffer;
20 int num_blk; // numero de blocos no disco
21 int blk_size; // tamanho de cada bloco (bytes)
22 int time_start;
23 int blk_inicio, blk_final;
24
25 printf("%5d ms: user: inicio\n", systime());
26
27 // busca geometria do disco
28 num_blk = block_blocks();
29 assert(num_blk);
30 blk_size = block_size();
31 assert(blk_size);
32
33 printf("%5d ms: disco contem %d blocos de %d bytes cada\n",
34 systime(), num_blk, blk_size);
35
36 // aloca o buffer para ler blocos do disco
37 buffer = mem_alloc(blk_size);
38 assert(buffer);
39
40 time_start = systime();
41
42 // escreve blocos
43 blk_inicio = 0;
44 blk_final = num_blk / 4;
45 for (int i = blk_inicio; i < blk_final; i++)
46 {
47 printf("%5d ms: escreve bloco %d\n", systime(), i);
48 status = block_write(i, buffer);
49 if (status)
50 printf("Erro ao escrever bloco %d!\n", i);
51 }
52
53 // lê blocos
54 blk_inicio += num_blk / 8;
55 blk_final += num_blk / 8;
56 for (int i = blk_inicio; i < blk_final; i++)
57 {
58 printf("%5d ms: lendo bloco %d\n", systime(), i);
59 status = block_read(i, buffer);
60 if (status)
61 printf("Erro ao ler bloco %d!\n", i);
62 }
63
64 // lê blocos
65 blk_inicio += num_blk / 8;
66 blk_final += num_blk / 8;
67 for (int i = blk_inicio; i < blk_final; i++)
68 {
69 printf("%5d ms: lendo bloco %d\n", systime(), i);
70 status = block_read(i, buffer);
71 if (status)
72 printf("Erro ao ler bloco %d!\n", i);
73 }
74
75 printf("As operações SEM CACHE demoraram %d ms\n", systime() - time_start);
76
77 // libera o buffer de blocos do disco
78 mem_free(buffer);
79
80 printf("%5d ms: user fim\n", systime());
81
82 task_exit(0);
83 }
84