]> wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-contab-prio.c

wirehaze git hosting

tasks implementation (ongoing)
[ppos.git] / ppos / test / pingpong-contab-prio.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 da contabilização com tarefas de prioridades distintas
9
10 #include <assert.h>
11 #include "lib/libc.h"
12 #include "ppos.h"
13
14 #define WORKLOAD 40000
15
16 static struct task_t *pang, *peng, *ping, *pong, *pung;
17
18 // simula um processamento pesado
19 int hardwork(int n)
20 {
21 int soma = 0;
22
23 for (int i = 0; i < n; i++)
24 for (int j = 0; j < n; j++)
25 soma += j;
26 return (soma);
27 }
28
29 // corpo das tarefas
30 void body(void *arg)
31 {
32 printf("%5d ms: %s inicia (prio: %d)\n", systime(),
33 (char *)arg, sched_getprio(NULL));
34 hardwork(WORKLOAD);
35 printf("%5d ms: %s termina\n", systime(), (char *)arg);
36 task_exit(0);
37 }
38
39 // corpo da tarefa principal
40 void user_main(void *arg)
41 {
42 printf("user: inicio\n");
43
44 // cria tarefas
45 pang = task_create("pang", body, "\tPang");
46 assert(pang);
47 peng = task_create("peng", body, "\t\tPeng");
48 assert(peng);
49 ping = task_create("ping", body, "\t\t\tPing");
50 assert(ping);
51 pong = task_create("pong", body, "\t\t\t\tPong");
52 assert(pong);
53 pung = task_create("pung", body, "\t\t\t\t\tPung");
54 assert(pung);
55
56 // ajusta prioridades
57 sched_setprio(pang, 0);
58 sched_setprio(peng, -2);
59 sched_setprio(ping, -4);
60 sched_setprio(pong, -6);
61 sched_setprio(pung, -8);
62
63 printf("user: fim\n");
64
65 task_exit(0);
66 }