ppos

Usermode educational operating system.
Log | Files | Refs

pingpong-contab-stress.c (1189B)


      1 // PingPongOS - PingPong Operating System
      2 // © Prof. Carlos A. Maziero, DINF UFPR
      3 // Versão 2.1 -- 06/2026
      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 muitas tarefas (stress)
      9 
     10 #include <assert.h>
     11 #include "lib/pplibc.h"
     12 #include "syscall.h"
     13 
     14 #define WORKLOAD 5000
     15 #define NUMTASKS 512
     16 
     17 struct task_t *task[NUMTASKS];
     18 
     19 // simula um processamento pesado
     20 int hardwork(int n)
     21 {
     22     int soma = 0;
     23 
     24     for (int i = 0; i < n; i++)
     25         for (int j = 0; j < n; j++)
     26             soma += j;
     27     return (soma);
     28 }
     29 
     30 // corpo das tarefas
     31 void body()
     32 {
     33     for (int i = 0; i < 3; i++)
     34         hardwork(WORKLOAD);
     35     task_exit(NOERROR);
     36 }
     37 
     38 // corpo da tarefa principal
     39 void user_main(void *arg)
     40 {
     41     int id;
     42     char *name;
     43 
     44     name = task_name(NULL);
     45     id   = task_id(NULL);
     46     printk("%5u ms: %s (id %d): inicio\n", time(), name, id);
     47 
     48     // cria tarefas
     49     printk("Creating %d tasks\n", NUMTASKS);
     50     for (int i = 0; i < NUMTASKS; i++)
     51     {
     52         task[i] = task_create(NULL, body, NULL);
     53         assert(task[i]);
     54     }
     55 
     56     printk("%5u ms: %s fim\n", time(), name);
     57 
     58     task_exit(NOERROR);
     59 }