示例#1
0
文件: graphics.c 项目: glipari/ptask
/* s = scheduler, p = task's priority , tipo_test={0:SCHED,1:PART,2:PROT} */
void draw_system_info (int s, int part, int prot, int act_mode, int p, int tipo_test, bool verbose) {

	int 	len_stringProt_Part = MAX_STR_PROT + MAX_STR_PART + 1;
	int 	x, nc;
	int 	col_prot ,col_sched, col_part, col_act_flag; //colors of various modes
	int 	col_selected = 14; 							//selected color = YELLOW
	col_prot = col_sched = col_part = FGC;

	clear_to_color(screen, BGC);

	/*rectangle for animation*/
	rect(screen, XMIN-L-1, BASE-1, XMAX+L+1, TOP+L+1, FGC);

	/*rectangle for tasks informations*/
	rect(screen, XMIN-L-1, BASE1-1, XMAX+L+1, TOP1+L+10+1, FGC);

	if(tipo_test == SCHED)
			col_sched = col_selected;
	else if (tipo_test == PART)
			col_part = col_selected;
	else if (tipo_test == PROT)
			col_prot = col_selected;
	else if (tipo_test == TASK_FUN) {
			col_act_flag = col_selected;
			textprintf_ex(screen, font, 2 + 50, 25, col_act_flag, BGC, "%s", string_act_mode[act_mode]);
	}

	/*draw system information  ( protocol - partitioning)*/
	textprintf_ex(screen, font, 2, 10, col_prot, BGC, "%s", string_prot[prot]);

	textprintf_ex(screen, font, 2 + PIXEL_CHAR * MAX_STR_PROT, 10, col_part, BGC, "%s", string_part[part]);

	x = len_stringProt_Part * PIXEL_CHAR;
	textout_ex(screen, font, string_sched[s], x, 10, col_sched, 0);

	nc = ptask_getnumcores();
	textprintf_ex(screen, font, 2, 25, FGC, BGC, " NumCores = %d", nc);

	textout_ex(screen, font, string_prior[p], x, 25, FGC, 0);

	textout_ex(screen, font, "ACTIVATION  SEQUENCE = ", XMIN, BASE1+10, FGC, 0);
	if ( verbose ){
		textout_ex(screen, font, "            PRIORITY = ", XMIN, BASE1+20, FGC, 0);
		textout_ex(screen, font, "TERMINATION SEQUENCE = ", XMIN, BASE1+30, FGC, 0);
	}

	textout_ex(screen, font, "KEY [1-9] to activate tasks (mod != MOD_DEF_OFFSET)", 5, YWIN-20, 10, 0);
	textout_ex(screen, font, "ESC exit", XWIN-70, YWIN-20, 12, 0);
}
示例#2
0
文件: testProt.c 项目: glipari/ptask
int main(void) {

    int ret = 0, nc;
    int c;
    int key = 0;
    int part = PARTITIONED; // PARTITIONED, GLOBAL
    int sched = SCHED_FIFO;

    get_data();
    init();
    ret = select_prot();
    if (ret == -1) {
        allegro_exit();
        return 0;
    }

    print_grid(ret);
    ptask_init(sched, part, ret);
    t_start = ptask_gettime(MILLI);
    set_sem_sezC(ret);

    nc = ptask_getnumcores();
    textprintf_ex(screen, font, 480, 10, 7, BGC, "(NumCores = %d)", nc);

    int gen_id = ptask_create_prio(gen, 100, 30, NOW);
    if (gen_id < 0) {
        printf("Could not create task gen\n");
        exit(-1);
    }

    while (key != KEY_ESC) {

        if (keypressed()) {
            c = readkey();
            key = c >> 8;
        }
    }

    pmux_destroy(&mx_sezNorm);
    pmux_destroy(&mx_sezA);
    pmux_destroy(&mx_sezB);

    allegro_exit();
    return 0;
}
示例#3
0
文件: ball.c 项目: glipari/ptask
int main(void) {
    int c;                              /* character from keyboard	*/
    int i, j, k;                        /* number of tasks created	*/
    double a;                           /* temporary variable           */
    int h;                              /* temporary variable           */
    int ntasks = 0;                     /* total number of created tasks*/
    int last_proc = 0;                  /* last assigned processor      */
    int max_proc = ptask_getnumcores(); /* max number of procs  */

    init();

    a = 2. * G * (float)TOP;
    for (i = 0; i < MAX_TASKS; i++)
        v0[i] = sqrt(a);

    i = 0;
    do {
        k = 0;
        if (keypressed()) {
            c = readkey();
            k = c >> 8;
        }

        if ((ntasks == 0) && (k == KEY_SPACE)) {
            clear_to_color(screen, BGC);
            rect(screen, XMIN - L - 1, BASE - 1, XMAX + L + 1,
                 TOP + BASE + L + 1, 14);
        }

        if ((ntasks < MAX_TASKS) && (k == KEY_SPACE)) {
            tpars params = TASK_SPEC_DFL;
            params.period = tspec_from(PER, MILLI);
            params.rdline = tspec_from(DREL, MILLI);
            params.priority = PRIO - i;
            params.measure_flag = 1;
            params.act_flag = NOW;
            /* a round robin assignment */
            params.processor = last_proc++;
            if (last_proc >= max_proc)
                last_proc = 0;

            /** i = task_create(palla, PER, DREL, PRIO-i, NOW); */
            i = ptask_create_param(palla, &params);
            if (i != -1) {
                printf("Task %d created and activated\n", i);
                ntasks++;
            } else {
                allegro_exit();
                printf("Error in creating task!\n");
                exit(-1);
            }
        }

        if ((k >= KEY_0) && (k <= KEY_9)) {
            a = 2. * G * (float)TOP;
            pthread_mutex_lock(&mxv);
            v0[k - KEY_0] = sqrt(a);
            pthread_mutex_unlock(&mxv);
        }

        if ((k == KEY_O) && (ntasks > 9)) {
            for (j = 10; j < ntasks; j++) {
                h = rand() % (TOP - BASE);
                a = 2. * G * (float)h;
                pthread_mutex_lock(&mxv);
                v0[j] = sqrt(a);
                pthread_mutex_unlock(&mxv);
            }
        }

        if (k == KEY_A) {
            for (j = 0; j < ntasks; j++) {
                h = rand() % (TOP - BASE);
                a = 2. * G * (float)h;
                pthread_mutex_lock(&mxv);
                v0[j] = sqrt(a);
                pthread_mutex_unlock(&mxv);
            }
        }

        /*
          Printing deadline misses
          TO BE DONE
          for (j=0; j<ntasks; j++) {
          sprintf(s, "%d", task_dmiss(j));
          textout_ex(screen, font, s, 50+j*48, 450, 7, 0);
          }
        */

    } while (k != KEY_ESC);

    printf("Now printing the stats\n");
    for (j = 0; j < ntasks; j++) {
        tspec wcet = ptask_get_wcet(j);
        tspec acet = ptask_get_avg(j);

        printf("TASK %d: WCET = %ld\t ACET = %ld\t NINST=%d\n", j,
               tspec_to(&wcet, MICRO), tspec_to(&acet, MICRO),
               ptask_get_numinstances(j));
    }

    printf("End of statistics\n");
    allegro_exit();
    return 0;
}
示例#4
0
int main()
{
  printf("Number of system cores: %d\n", ptask_getnumcores());
  return 0;
}
示例#5
0
文件: graphics.c 项目: glipari/ptask
/* s = scheduler, p = task's priority , tipo_test={0:SCHED,1:PART,2:PROT,
 * 3:PARAM_TEST, 5:MODE_TEST}*/
void draw_system_info(int s, int part, int prot, int p, int tipo_test,
                      bool verbose) {

    int len_stringProt_Part = MAX_STR_PROT + MAX_STR_PART + 1;
    int x, nc;
    int col_prot, col_sched, col_part; // colors of various modes
    int col_selected = 14;             // selected color = YELLOW
    col_prot = col_sched = col_part = FGC;

    if (tipo_test == SCHED)
        col_sched = col_selected;
    else if (tipo_test == PART)
        col_part = col_selected;
    else if (tipo_test == PROT)
        col_prot = col_selected;
    else
        col_prot = 15;

    clear_to_color(screen, BGC);

    /*rectangle for animation*/
    rect(screen, XMIN - L - 1, BASE - 1, XMAX + L + 1, TOP + L + 1, FGC);

    /*rectangle for tasks informations*/
    rect(screen, XMIN - L - 1, BASE1 - 1, XMAX + L + 1, TOP1 + L + 10 + 1, FGC);

    /*draw system information  ( protocol - partitioning - scheduler )*/
    textprintf_ex(screen, font, 2, 10, col_prot, BGC, "%s", string_prot[prot]);

    textprintf_ex(screen, font, 2 + PIXEL_CHAR * MAX_STR_PROT, 10, col_part,
                  BGC, "%s", string_part[part]);

    x = len_stringProt_Part * PIXEL_CHAR;
    textout_ex(screen, font, string_sched[s], x, 10, col_sched, 0);

    nc = ptask_getnumcores();
    textprintf_ex(screen, font, 2, 25, FGC, BGC, " NumCores = %d", nc);

    textout_ex(screen, font, string_prior[p], x, 25, FGC, 0);

    if (tipo_test <= PROT)
        textout_ex(screen, font, "ACTIVATION  SEQUENCE = ", XMIN, BASE1 + 10,
                   FGC, 0);
    else if (tipo_test == 3) {
        textout_ex(screen, font, "  id Task  ", XMIN, BASE1 + 10, FGC, 0);
        textout_ex(screen, font, "  period  ", XMIN + 112, BASE1 + 10, FGC, 0);
        textout_ex(screen, font, "  deadline  ", XMIN + 112 * 2, BASE1 + 10,
                   FGC, 0);
        textout_ex(screen, font, "  cpu id  ", XMIN + 112 * 3, BASE1 + 10, FGC,
                   0);
        textout_ex(screen, font, "  priority  ", XMIN + 112 * 4, BASE1 + 10,
                   FGC, 0);
    } else
        textout_ex(screen, font, " --->  MODE  ACTIVE  = ", XMIN, BASE1 + 10,
                   FGC, 0);

    if (verbose) {
        textout_ex(screen, font, "            PRIORITY = ", XMIN, BASE1 + 20,
                   FGC, 0);
        textout_ex(screen, font, "TERMINATION SEQUENCE = ", XMIN, BASE1 + 30,
                   FGC, 0);
    }

    if (tipo_test == 5) { // checking for modeTest
        textout_ex(screen, font, "KEY [ Z ] to active DEFAULT mode", 5,
                   YWIN - 40, 10, 0);
        textout_ex(screen, font, "KEY [ X ] to active MODE_A", 5, YWIN - 30, 10,
                   0);
        textout_ex(screen, font, "KEY [ C ] to active MODE_B", 5, YWIN - 20, 10,
                   0);
    } else if (tipo_test == 3) {
        textout_ex(screen, font,
                   "KEY [ A ] to activate tasks whit act_flag = 0", 5,
                   YWIN - 20, 10, 0);
        textout_ex(screen, font,
                   "KEY [ M ] to terminate tasks and show measure ", 5,
                   YWIN - 30, 10, 0);

    } else
        textout_ex(screen, font, "KEY [1-9] to activate tasks", 5, YWIN - 20,
                   10, 0);

    textout_ex(screen, font, "ESC exit", XWIN - 70, YWIN - 20, 12, 0);
}