#include #include #include #include "cyclic_scheduler.h" /* * init */ void cyclic_init(void * sched_data) { printf("cyclic_scheduler: init\n"); // initialize scheduler structures cyclic_schr_data_t *schr_data = (cyclic_schr_data_t *)sched_data; schr_data->num_threads = 0; schr_data->current_slice = -1; } /* * new_thread */ void cyclic_new_thread(void * sched_data, pthread_t thread, posix_appsched_actions_t * actions) { cyclic_sched_params_t cyclic_params; size_t paramsize; // Get thread CYCLIC scheduling parameters CHK (pthread_getappschedparam (thread, &cyclic_params, ¶msize)); report("cyclic_new_thread", cyclic_params.id); // set scheduler structures cyclic_schr_data_t *schr_data = (cyclic_schr_data_t *)sched_data; schr_data->slices[schr_data->num_threads] = cyclic_params.slice; schr_data->thread_ids[schr_data->num_threads] = thread; // scheduling actions: // alcanzado número máximo de threads? if (schr_data->num_threads < CYCLIC_MX_NUM_THREADS) { // accept thread // posix_appsched_actions_addaccept(...) schr_data->num_threads++; // si es el primer thread que se une, le activa if (schr_data->num_threads == 1) { // activate thread with high urgency // posix_appsched_actions_addactivateurg(...) schr_data->current_slice = 0; // program notification for the end of the slice //posix_appsched_actions_addthreadnotification(...); } } else { // reject thread //posix_appsched_actions_addreject(...) } } /* * cyclic_notification_for_thread */ void cyclic_notification_for_thread(void * sched_data, pthread_t thread, posix_appsched_actions_t * actions) { printf("cyclic_scheduler: notification_for_thread\n"); // baja urgencia del thread que acaba // sube la urgencia del siguiente thread // programa una notificación para el fin de su rodaja } /* * Show a message with the elapsed time * Auxiliary function. It is NOT a primitive operation of the * scheduler */ void report (char * message, int id) { struct timespec now; clock_gettime(CLOCK_MONOTONIC,&now); printf("%3.3f: %s: %d\n",(double) now.tv_sec+ now.tv_nsec/1.0e9, message, id); }