hw3 should be done

This commit is contained in:
Claudio Maggioni 2020-04-14 16:20:38 +02:00
parent c6c8c95690
commit 883dedd64e
2 changed files with 32 additions and 21 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"ratio": "c"
}
}

View File

@ -169,8 +169,6 @@ thread_start (void)
sema_down (&idle_started);
}
static int tick_count = 0;
/* Called by the timer interrupt handler at each timer tick.
Thus, this function runs in an external interrupt context. */
void
@ -189,19 +187,19 @@ thread_tick (void)
kernel_ticks++;
++thread_ticks;
++tick_count;
if (thread_mlfqs) {
if (thread_ticks % 4 == 0) {
if (timer_ticks() % 4 == 0) {
compute_mlfqs_priority(t);
}
t->recent_cpu = FPR_ADD_INT(t->recent_cpu, 1);
if (tick_count >= TIMER_FREQ) { // this is true every second
tick_count = 0;
if (thread_current() != idle_thread) {
t->recent_cpu = FPR_ADD_INT(t->recent_cpu, 1);
}
int thr_running = thread_current() == idle_thread ? 0 : 1;
thr_running += list_size(&ready_list);
if (timer_ticks() % TIMER_FREQ == 0) { // this is true every second
int a = t != idle_thread && (t->status == THREAD_RUNNING || t->status == THREAD_READY) ? 1 : 0;
int thr_running = list_size(&ready_list) + a;
load_avg = FPR_ADD_FPR(
FPR_MUL_FPR(INT_DIV_INT(59, 60), load_avg),
@ -209,17 +207,16 @@ thread_tick (void)
FPReal dag = FPR_MUL_INT(load_avg, 2);
t->recent_cpu = FPR_MUL_FPR(t->recent_cpu,
FPR_DIV_FPR(dag, FPR_ADD_INT(dag, 1))) + INT_TO_FPR(t->nice);
struct list_elem* e;
for (e = list_begin(&all_list); e != list_end(&all_list);) {
struct thread* i = list_entry(e, struct thread, allelem);
if (t->recent_cpu > INT_TO_FPR(100)) {
t->recent_cpu = INT_TO_FPR(100);
} else if (t->recent_cpu < INT_TO_FPR(0)) {
t->recent_cpu = INT_TO_FPR(0);
i->recent_cpu = FPR_MUL_FPR(i->recent_cpu,
FPR_DIV_FPR(dag, FPR_ADD_INT(dag, 1))) + INT_TO_FPR(i->nice);
//printf("\nmalusa recent_cpu: %d, running: %d b %d\n", FPR_TO_INT(t->recent_cpu), thr_running, a);
e = list_next(e);
}
printf("recent_cpu: %d\n", t->recent_cpu);
//printf("load_avg: %d - threads_ready: %d\n", load_avg, thr_running);
}
}
@ -231,7 +228,10 @@ thread_tick (void)
int
thread_get_nice (void)
{
return thread_current()->nice;
enum intr_level old_level = intr_disable();
int r = thread_current()->nice;
intr_set_level(old_level);
return r;
}
void
@ -250,13 +250,19 @@ thread_set_nice (int nice)
int
thread_get_recent_cpu (void)
{
return FPR_TO_INT(FPR_MUL_INT(thread_current()->recent_cpu, 100));
enum intr_level old_level = intr_disable();
int r = FPR_TO_INT(FPR_MUL_INT(thread_current()->recent_cpu, 100));
intr_set_level(old_level);
return r;
}
int
thread_get_load_avg (void)
{
return FPR_TO_INT(FPR_MUL_INT(load_avg, 100));
enum intr_level old_level = intr_disable();
int r = FPR_TO_INT(FPR_MUL_INT(load_avg, 100));
intr_set_level(old_level);
return r;
}
/* Prints thread statistics. */