event_t *scheduler_add_callback(uint64_t clock, call_t *c, callback_t callback, void *arg) { event_t *event; if ((scheduler_get_end()) && (clock > scheduler_get_end())) { return NULL; } if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { fprintf(stderr, "scheduler.c: add callback node %d : ERROR when allocating event\n", c->node); return NULL; } event->clock = clock; event->u.cb.call.entity = c->entity; event->u.cb.call.node = c->node; event->u.cb.call.from = c->from; event->u.cb.callback = callback; event->u.cb.arg = arg; event->priority = PRIORITY_CALLBACK; scheduler_add_event(event); /* if worldsens mode save this event as rdv */ if (ws_count) worldsens_add_rdv(clock, PRIORITY_CALLBACK); return event; }
void scheduler_add_mobility(uint64_t clock) { event_t *event; if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { return; } event->clock = clock; event->priority = PRIORITY_MOBILITY; scheduler_add_event(event); }
/* ************************************************** */ void scheduler_add_birth(uint64_t clock, nodeid_t id) { event_t *event; if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { return; } event->clock = clock; event->priority = PRIORITY_BIRTH; event->u.nodeid = id; scheduler_add_event(event); }
void scheduler_add_milestone(uint64_t clock) { event_t *event; if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { return; } event->clock = clock; event->priority = PRIORITY_MILESTONE; scheduler_add_event(event); /* if worldsens mode save this event as rdv */ if (ws_count) worldsens_add_rdv(clock, PRIORITY_MILESTONE); }
void scheduler_add_tx_end(uint64_t clock, call_t *c, packet_t *packet) { event_t *event; if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { return; } event->clock = clock; event->u.rx.packet = packet; event->u.rx.call.node = c->node; event->u.rx.call.entity = c->entity; event->u.rx.call.from = c->from; event->priority = PRIORITY_TX_END; scheduler_add_event(event); return; }
void scheduler_add_rx_end(uint64_t clock, call_t *c, packet_t *packet) { event_t *event; if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { return; } event->clock = clock; event->u.rx.packet = packet; event->u.rx.call.entity = c->entity; event->u.rx.call.node = c->node; event->u.rx.call.from = c->from; event->priority = PRIORITY_RX_END; scheduler_add_event(event); /* if worldsens mode save this event as rdv */ if (ws_count) worldsens_add_rdv(clock, PRIORITY_RX_END); return; }
int main (int argc, char ** argv) { int ret, status, i = 0; pid_t rt_child; timer_t tid; struct sigaction sa; struct sigevent sigev; struct itimerspec new_tmr; struct sched_param s_param; cpu_set_t mask; scheduler_check_arguments(argc, argv); //--------------------------------PAPI initilization------------------------------// init_papi(); scheduler_init_papi(); set_option(); scheduler_set_option(); add_events(); scheduler_add_event(); //---------------------------Timer initialization and sigaction----------------------// sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = timer_handler; sigemptyset(&sa.sa_mask); if(sigaction(SIGRTMIN, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } if(sigaction(SIGCONT, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGRTMIN; sigev.sigev_value.sival_ptr = &tid; if(timer_create(CLOCK_REALTIME, &sigev, &tid) != -1){ new_tmr.it_value.tv_sec = 0; new_tmr.it_value.tv_nsec = 25000000; new_tmr.it_interval.tv_sec = 0; new_tmr.it_interval.tv_nsec = 25000000; } /**********************************************************************************************/ //Launch the attackers printf("Launching %d attackers\n", atoi(argv[2])); for(i=0; i < atoi(argv[2]); i++){ if((pid_attacker[nb_attackers++] = fork()) == 0){ CPU_ZERO(&mask); CPU_SET(i+2, &mask); printf("Core %d\n", i+2); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } char c[2]; sprintf(c, "%d", i+2); if(execl("/usr/bin/xterm", "xterm", "-hold", "-e", "./bin/attack_task", "1", c, NULL) == -1){ exit(17); } exit(0); } } sleep(10); /**********************************************************************************************/ /**********************************************************************************************/ //Child executes the RT task in one core if((rt_child = fork())==0){ int stdin_fd = -1; //Setting the affinity of the child //Using only one CPU with max priority CPU_ZERO(&mask); CPU_SET(1, &mask); stdin_fd = open("/dev/null", O_RDONLY); if(stdin_fd == -1) exit(127); dup2(stdin_fd, 1); dup2(stdin_fd, 2); close(stdin_fd); s_param.sched_priority = sched_get_priority_max(SCHED_FIFO); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } if(sched_setscheduler(getpid(), SCHED_FIFO, &s_param)){ fprintf(stderr, "Sched error: sched_setscheduler\n"); exit(17); } if(execl(argv[1], "RT task", NB_RT_ITERATION, NULL) == -1){ fprintf(stderr, "Execl error: Couldn't launch RT exec\n"); exit(17); } exit(0); }else if(rt_child == -1){ fprintf(stderr, "Fork: couldn't create the RT child.\n"); exit(16); /**********************************************************************************************/ //The scheduler }else{ sleep(1); //<= Waiting for stationnary period if(timer_settime(tid, 0, &new_tmr, NULL) == -1){ perror("Timer_settime"); exit(3); } // Launch the counters and the timer if((ret = PAPI_start(PAPI_EventSet)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } if((ret = PAPI_start(scheduler_eventset)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } struct timeval tv1, tv2; gettimeofday(&tv1, NULL); // Wait for RT child to finish, then kill attackers ret = -1; while(ret != rt_child){ ret = waitpid(rt_child, &status, 0); } if (!WIFEXITED(status)) { fprintf(stderr, "scheduler: Child exited with wrong status\n"); exit(16); } for(i=0; i<nb_attackers; i++){ fprintf(stderr, "\nScheduler (%d) > Sending signal to %d\n", getpid(), pid_attacker[i]); kill(pid_attacker[i], SIGKILL); } gettimeofday(&tv2, NULL); char time_to_char[20]; printf ("\nTotal time = %f seconds\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); sprintf(time_to_char, "%f\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); // Stopping and reading for Gnuplot if((ret = PAPI_stop(PAPI_EventSet, papi_values))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_stop(scheduler_eventset, &scheduler_value))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_read(PAPI_EventSet, papi_values)) != PAPI_OK){ fprintf(stderr, "PAPI error : Couldn't read the values %s\n", PAPI_strerror(ret)); exit(18); } // Printing and writting for Gnuplot print_counters(papi_values); write_miss_values(1, nb_attackers, papi_values); // Writting the time for Gnuplot int fic_time; char fic_name[50]; switch(atoi(argv[2])){ case 0: strcpy(fic_name, "plot/mesures_execution_0_scheduler.data"); break; case 1: strcpy(fic_name, "plot/mesures_execution_1_scheduler.data"); break; case 2: strcpy(fic_name, "plot/mesures_execution_2_scheduler.data"); break; default: strcpy(fic_name, "plot/mesures_execution.data"); break; } if ((fic_time = open(fic_name, O_RDWR | O_APPEND))==-1){ perror("Open error on fic_time\n"); exit(19); } if (write(fic_time, time_to_char, strlen(time_to_char))==0){ fprintf(stderr, "Write exec_time error\n"); exit(20); } // Cleaning event sets if((ret=PAPI_cleanup_eventset(PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_cleanup_eventset(scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_destroy_eventset(&PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } if((ret=PAPI_destroy_eventset(&scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } } return EXIT_SUCCESS; }