More 'objective' definitions

This commit is contained in:
Adrien Bourmault 2021-06-14 18:33:13 +02:00
parent 02c42045c2
commit 9248f8176b
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
6 changed files with 47 additions and 42 deletions

View File

@ -54,11 +54,12 @@ struct {
int nmaxThread; int nmaxThread;
int nmaxCycles; int nmaxCycles;
pthread_t *id; pthread_t *id;
} typedef SchedulerParams_t; bool stopped;
} typedef Scheduler_t;
struct { struct {
pthread_t *id; pthread_t *id;
} typedef WorkerParams_t; } typedef Worker_t;
// //
// Local threads // Local threads

View File

@ -26,7 +26,7 @@
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Worker init function // // Worker init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
pthread_t *WorkerInit(SchedulerParams_t *parameters); pthread_t *WorkerInit(Worker_t *parameters);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Worker destructor function // // Worker destructor function //

View File

@ -26,7 +26,7 @@
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler init function // // Scheduler init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
pthread_t *SchedInit(SchedulerParams_t *parameters); pthread_t *SchedInit(Scheduler_t *parameters);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler destructor function // // Scheduler destructor function //

View File

@ -28,7 +28,7 @@ static void *LittleWorker(void *parameters);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler init function // // Scheduler init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
pthread_t *WorkerInit(SchedulerParams_t *parameters) pthread_t *WorkerInit(Scheduler_t *parameters)
{ {
parameters->id = (pthread_t*) malloc(sizeof(pthread_t)); parameters->id = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(parameters->id, NULL, LittleWorker, parameters); pthread_create(parameters->id, NULL, LittleWorker, parameters);
@ -40,7 +40,7 @@ pthread_t *WorkerInit(SchedulerParams_t *parameters)
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
static void *LittleWorker(void *params) static void *LittleWorker(void *params)
{ {
WorkerParams_t *parameters = (WorkerParams_t*) params; Worker_t *parameters = (Worker_t*) params;
int a = 4; int a = 4;
for (int i = 0; i < 45000; i++) { for (int i = 0; i < 45000; i++) {

View File

@ -33,14 +33,14 @@ void SchedulerCrashTest(void)
{ {
const int maxthread = 16; const int maxthread = 16;
SchedulerParams_t *parameters = Scheduler_t *scheduler0 =
(SchedulerParams_t*) calloc(1, sizeof(SchedulerParams_t)); (Scheduler_t*) calloc(1, sizeof(Scheduler_t));
pthread_t **schedThread = pthread_t **schedThread =
(pthread_t**) malloc(sizeof(pthread_t*) * maxthread); (pthread_t**) malloc(sizeof(pthread_t*) * maxthread);
for (int i=0; i < maxthread; i++) { for (int i=0; i < maxthread; i++) {
schedThread[i] = SchedInit(parameters); schedThread[i] = SchedInit(scheduler0);
} }
for (int i=0; i < maxthread; i++) { for (int i=0; i < maxthread; i++) {
@ -48,61 +48,65 @@ void SchedulerCrashTest(void)
SchedDestroy(schedThread[i]); SchedDestroy(schedThread[i]);
} }
free(parameters); free(scheduler0);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
time_t t;
Scheduler_t *scheduler0;
// Go!
printLog("Starting gem-graph-server...\n"); printLog("Starting gem-graph-server...\n");
time_t t = time(&t); //
// random generator
//
t = time(&t);
srand((unsigned) t); srand((unsigned) t);
// //
// Creating parameters structure for the Scheduler // Creating structure for the Scheduler
// //
SchedulerParams_t *parameters = scheduler0 = (Scheduler_t*) malloc(sizeof(Scheduler_t));
(SchedulerParams_t*) malloc(sizeof(SchedulerParams_t));
parameters->globalPreemptionSpace = scheduler0->globalPreemptionSpace =
(BoolArray_t*) malloc(sizeof(BoolArray_t)); (BoolArray_t*) malloc(sizeof(BoolArray_t));
parameters->globalPreemptionSpace->space = scheduler0->globalPreemptionSpace->space =
(bool*) malloc(sizeof(bool)*SPACE_SIZE); (bool*) malloc(sizeof(bool)*SPACE_SIZE);
parameters->globalPreemptionSpace->size = SPACE_SIZE; scheduler0->globalPreemptionSpace->size = SPACE_SIZE;
parameters->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t)); scheduler0->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t));
parameters->globalDrawingSpace->space = scheduler0->globalDrawingSpace->space =
(int*) malloc(sizeof(int)*SPACE_SIZE); (int*) malloc(sizeof(int)*SPACE_SIZE);
parameters->globalDrawingSpace->size = SPACE_SIZE; scheduler0->globalDrawingSpace->size = SPACE_SIZE;
parameters->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t)); scheduler0->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t));
parameters->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER); scheduler0->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
parameters->arrowList->size = ARROW_NUMBER; scheduler0->arrowList->size = ARROW_NUMBER;
parameters->nmaxThread = MAX_THREAD; scheduler0->nmaxThread = MAX_THREAD;
parameters->nmaxCycles = MAX_CYCLES; scheduler0->nmaxCycles = MAX_CYCLES;
// //
// Creating the Scheduler thread // Creating the Scheduler thread
// //
pthread_t *schedThread = SchedInit(parameters); SchedInit(scheduler0);
SchedWait(schedThread); SchedWait(scheduler0->id);
SchedDestroy(schedThread); SchedDestroy(scheduler0->id);
free(parameters->globalDrawingSpace->space); free(scheduler0->globalDrawingSpace->space);
free(parameters->globalDrawingSpace); free(scheduler0->globalDrawingSpace);
free(parameters->globalPreemptionSpace->space); free(scheduler0->globalPreemptionSpace->space);
free(parameters->globalPreemptionSpace); free(scheduler0->globalPreemptionSpace);
free(parameters->arrowList->space); free(scheduler0->arrowList->space);
free(parameters->arrowList); free(scheduler0->arrowList);
free(parameters); free(scheduler0);
//SchedulerCrashTest();
return 0; return 0;
} }

View File

@ -31,7 +31,7 @@ static void *GreatScheduler(void *parameters);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler init function // // Scheduler init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
pthread_t *SchedInit(SchedulerParams_t *parameters) pthread_t *SchedInit(Scheduler_t *parameters)
{ {
parameters->id = (pthread_t*) malloc(sizeof(pthread_t)); parameters->id = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(parameters->id, NULL, GreatScheduler, parameters); pthread_create(parameters->id, NULL, GreatScheduler, parameters);
@ -74,7 +74,7 @@ static inline void centerRemove(Center_t *oldCenter)
} }
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler thread main function // // Scheduler area finder function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t spaceSize) static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t spaceSize)
{ {
@ -102,8 +102,8 @@ static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t space
static void *GreatScheduler(void *params) static void *GreatScheduler(void *params)
{ {
// récupération des paramètres et annonce // récupération des paramètres et annonce
SchedulerParams_t *parameters = (SchedulerParams_t*) params; Scheduler_t *args = (Scheduler_t*) params;
printLog("Scheduler id %lu: Bonjour I'm the boss !\n", *(parameters->id)); printLog("Scheduler id %lu: Bonjour I'm the boss !\n", *(args->id));
int ncpu = get_nprocs(); int ncpu = get_nprocs();
printLog("%d CPUs available.\n", ncpu); printLog("%d CPUs available.\n", ncpu);
@ -116,7 +116,7 @@ static void *GreatScheduler(void *params)
Center_t *workArea; Center_t *workArea;
int i = 0; int i = 0;
while (1) { while (!args->stopped) {
while ((workArea = findWorkArea(centersList, 4, 30))) { while ((workArea = findWorkArea(centersList, 4, 30))) {
i++; i++;
centerAdd(centersList, workArea); centerAdd(centersList, workArea);