Théoriquement RR bon, mais le temps de compilation est très long
This commit is contained in:
parent
fb90cbf14a
commit
dfab397122
@ -1,10 +1,10 @@
|
|||||||
1,10,0
|
1,10,0,0
|
||||||
2,40,0
|
2,40,0,0
|
||||||
3,50,30
|
3,50,30,0
|
||||||
4,30,20
|
4,30,20,0
|
||||||
5,40,10
|
5,40,10,0
|
||||||
6,50,30
|
6,50,30,0
|
||||||
7,90,40
|
7,90,40,0
|
||||||
8,90,60
|
8,90,60,0
|
||||||
9,50,40
|
9,50,40,0
|
||||||
10,90,30
|
10,90,30,0
|
||||||
|
|
148
simulator.c
148
simulator.c
@ -16,6 +16,7 @@ struct pinfo {
|
|||||||
int arrival_time;
|
int arrival_time;
|
||||||
int execution_time;
|
int execution_time;
|
||||||
int priority;
|
int priority;
|
||||||
|
int nb_time_pre_empted;
|
||||||
|
|
||||||
int wait_time;
|
int wait_time;
|
||||||
int turnaround_time;
|
int turnaround_time;
|
||||||
@ -153,8 +154,8 @@ void free_processes(struct pinfo * next) {
|
|||||||
|
|
||||||
void write_file(struct pinfo * process, struct perf_info * perf) {
|
void write_file(struct pinfo * process, struct perf_info * perf) {
|
||||||
|
|
||||||
FILE *myStream_execution = fopen("execution2.csv", "w");
|
FILE *myStream_execution = fopen("executionRR.csv", "w");
|
||||||
FILE *myStream_performance = fopen("performance2.csv", "w");
|
FILE *myStream_performance = fopen("performanceRR.csv", "w");
|
||||||
|
|
||||||
|
|
||||||
if (myStream_execution == NULL || myStream_performance == NULL) {
|
if (myStream_execution == NULL || myStream_performance == NULL) {
|
||||||
@ -163,96 +164,109 @@ void write_file(struct pinfo * process, struct perf_info * perf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (process != NULL) {
|
while (process != NULL) {
|
||||||
fprintf(myStream_execution, "%d,%d,%d,%d\n", // Ajout de la colonne des préemptions
|
fprintf(myStream_execution, "%d,%d,%d,%d\n",
|
||||||
process->id,
|
process->id,
|
||||||
process->turnaround_time,
|
process->turnaround_time,
|
||||||
process->wait_time,
|
process->wait_time,
|
||||||
process->execution_time - process->remaining_time); // Nombre de préemptions
|
process->nb_time_pre_empted);
|
||||||
process = process->next_pinfo;
|
process = process->next_pinfo;
|
||||||
}
|
}
|
||||||
fclose(myStream_execution);
|
fclose(myStream_execution);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fprintf(myStream_performance, "%d,%d,%d\n",
|
fprintf(myStream_performance, "%d,%d,%d\n",
|
||||||
perf->total_time,
|
perf->total_time,
|
||||||
perf->total_nr_ctxt_switch,
|
perf->total_nr_ctxt_switch,
|
||||||
perf->total_time_ctxt_switch);
|
perf->total_time_ctxt_switch);
|
||||||
|
|
||||||
|
|
||||||
fclose(myStream_performance);
|
fclose(myStream_performance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pinfo *enqueue(struct pinfo *queue, struct pinfo *process) {
|
||||||
|
if (queue == NULL) {
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
struct pinfo *temp = queue;
|
||||||
|
while (temp->next_pinfo != NULL) {
|
||||||
|
temp = temp->next_pinfo;
|
||||||
|
}
|
||||||
|
temp->next_pinfo = process;
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pinfo *dequeue(struct pinfo **queue) {
|
||||||
|
if (*queue == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
struct pinfo *process = *queue;
|
||||||
|
*queue = (*queue)->next_pinfo;
|
||||||
|
process->next_pinfo = NULL;
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct perf_info schedule_RR(struct pinfo *processes) {
|
struct perf_info schedule_RR(struct pinfo *processes) {
|
||||||
int current_time = 0; // Temps actuel
|
|
||||||
int context_switches = 0; // Nombre de changements de contexte
|
|
||||||
struct perf_info perf = {0, 0, 0};
|
struct perf_info perf = {0, 0, 0};
|
||||||
|
int current_time = 0;
|
||||||
|
struct pinfo *queue = NULL;
|
||||||
|
struct pinfo *current_process = NULL;
|
||||||
|
int remaining_quantum = RR_QUANTUM;
|
||||||
|
|
||||||
struct pinfo * queue = processes; // File d'attente de processus
|
while (processes != NULL || queue != NULL || current_process != NULL) {
|
||||||
struct pinfo * temp; // Variable temporaire pour itérer
|
// Ajouter les nouveaux processus arrivés à la file d'attente
|
||||||
|
while (processes != NULL && processes->arrival_time <= current_time) {
|
||||||
while (1) {
|
processes->state = READY;
|
||||||
int all_done = 1; // Vérifier si tous les processus sont terminés
|
queue = enqueue(queue, processes);
|
||||||
|
printf("Processus %d ajouté à la file d'attente à l'heure %d\n", processes->id, current_time);
|
||||||
// Itérer sur les processus dans la queue
|
processes = processes->next_pinfo;
|
||||||
temp = queue;
|
|
||||||
while (temp != NULL) {
|
|
||||||
// Vérifiez si le processus a encore du temps restant
|
|
||||||
if (temp->remaining_time > 0) {
|
|
||||||
all_done = 0; // Il y a au moins un processus qui n'est pas terminé
|
|
||||||
|
|
||||||
// Si le temps actuel est inférieur au temps d'arrivée
|
|
||||||
if (current_time < temp->arrival_time) {
|
|
||||||
current_time = temp->arrival_time; // Mettez à jour le temps
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exécutez le processus pendant le quantum
|
// Si aucun processus en cours, prendre le suivant dans la file d'attente
|
||||||
if (temp->remaining_time > RR_QUANTUM) {
|
if (current_process == NULL && queue != NULL) {
|
||||||
current_time += RR_QUANTUM; // Ajoute le quantum au temps
|
current_process = dequeue(&queue);
|
||||||
temp->remaining_time -= RR_QUANTUM; // Diminue le temps restant
|
current_process->nb_time_pre_empted++;
|
||||||
context_switches++; // Compter le changement de contexte
|
remaining_quantum = RR_QUANTUM; // Réinitialiser le quantum
|
||||||
|
printf("Processus %d pris de la file d'attente pour exécution à l'heure %d\n", current_process->id, current_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exécuter le processus courant
|
||||||
|
if (current_process != NULL) {
|
||||||
|
current_process->remaining_time--;
|
||||||
|
current_process->turnaround_time++;
|
||||||
|
remaining_quantum--;
|
||||||
|
printf("Processus %d exécuté à l'heure %d, temps restant: %d, quantum restant: %d\n", current_process->id, current_time, current_process->remaining_time, remaining_quantum);
|
||||||
|
current_time++;
|
||||||
|
|
||||||
|
// Vérifier si le processus est terminé
|
||||||
|
if (current_process->remaining_time == 0) {
|
||||||
|
current_process->state = FINISHED;
|
||||||
|
printf("Processus %d terminé à l'heure %d\n", current_process->id, current_time);
|
||||||
|
current_process = NULL;
|
||||||
|
} else if (remaining_quantum == 0) {
|
||||||
|
// Si le quantum RR est atteint, remettre le processus en file d'attente
|
||||||
|
current_process->state = WAITING;
|
||||||
|
queue = enqueue(queue, current_process);
|
||||||
|
printf("Processus %d préempté et remis en file d'attente à l'heure %d\n", current_process->id, current_time);
|
||||||
|
current_process = NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Le processus se termine ici
|
// Si aucun processus à exécuter, avancer le temps
|
||||||
current_time += temp->remaining_time; // Ajoutez le temps restant à current_time
|
printf("Aucun processus à exécuter à l'heure %d, avancer le temps\n", current_time);
|
||||||
temp->turnaround_time = current_time - temp->arrival_time; // Calculer le TAT
|
current_time++;
|
||||||
temp->wait_time += (temp->turnaround_time - temp->execution_time); // Calculer le WT
|
|
||||||
temp->remaining_time = 0; // Le processus est terminé
|
|
||||||
temp->state = FINISHED; // Marquez comme terminé
|
|
||||||
}
|
|
||||||
}
|
|
||||||
temp = temp->next_pinfo; // Passer au processus suivant
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Réinitialiser la file d'attente
|
// Mise à jour des performances
|
||||||
temp = processes; // Revenir au début de la liste
|
perf.total_time = current_time;
|
||||||
struct pinfo * last = NULL; // Pour maintenir la fin de la queue
|
perf.total_nr_ctxt_switch++;
|
||||||
|
perf.total_time_ctxt_switch += CNTXT_SWITCH;
|
||||||
// Créer une nouvelle file d'attente
|
|
||||||
while (temp != NULL) {
|
|
||||||
// Ne pas ajouter les processus terminés à la nouvelle queue
|
|
||||||
if (temp->remaining_time > 0) {
|
|
||||||
if (last == NULL) {
|
|
||||||
queue = temp; // Premier processus dans la nouvelle queue
|
|
||||||
} else {
|
|
||||||
last->next_pinfo = temp; // Ajouter à la fin
|
|
||||||
}
|
|
||||||
last = temp; // Mettre à jour le dernier élément de la queue
|
|
||||||
}
|
|
||||||
temp = temp->next_pinfo; // Passer au processus suivant
|
|
||||||
}
|
|
||||||
if (last != NULL) {
|
|
||||||
last->next_pinfo = NULL; // Terminer la liste
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si tous les processus sont terminés, sortez de la boucle
|
printf("Planification RR terminée\n");
|
||||||
if (all_done) {
|
return perf;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour des statistiques de performance
|
|
||||||
perf.total_time = current_time; // Total du temps écoulé
|
|
||||||
perf.total_nr_ctxt_switch = context_switches; // Total des changements de contexte
|
|
||||||
perf.total_time_ctxt_switch = context_switches * CNTXT_SWITCH; // Temps total pour les changements de contexte
|
|
||||||
|
|
||||||
return perf; // Retournez les performances
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user