hw3 should be done
This commit is contained in:
parent
c6c8c95690
commit
883dedd64e
2 changed files with 32 additions and 21 deletions
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"ratio": "c"
|
||||||
|
}
|
||||||
|
}
|
|
@ -169,8 +169,6 @@ thread_start (void)
|
||||||
sema_down (&idle_started);
|
sema_down (&idle_started);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tick_count = 0;
|
|
||||||
|
|
||||||
/* Called by the timer interrupt handler at each timer tick.
|
/* Called by the timer interrupt handler at each timer tick.
|
||||||
Thus, this function runs in an external interrupt context. */
|
Thus, this function runs in an external interrupt context. */
|
||||||
void
|
void
|
||||||
|
@ -189,19 +187,19 @@ thread_tick (void)
|
||||||
kernel_ticks++;
|
kernel_ticks++;
|
||||||
|
|
||||||
++thread_ticks;
|
++thread_ticks;
|
||||||
++tick_count;
|
|
||||||
|
|
||||||
if (thread_mlfqs) {
|
if (thread_mlfqs) {
|
||||||
if (thread_ticks % 4 == 0) {
|
if (timer_ticks() % 4 == 0) {
|
||||||
compute_mlfqs_priority(t);
|
compute_mlfqs_priority(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (thread_current() != idle_thread) {
|
||||||
t->recent_cpu = FPR_ADD_INT(t->recent_cpu, 1);
|
t->recent_cpu = FPR_ADD_INT(t->recent_cpu, 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (tick_count >= TIMER_FREQ) { // this is true every second
|
if (timer_ticks() % TIMER_FREQ == 0) { // this is true every second
|
||||||
tick_count = 0;
|
int a = t != idle_thread && (t->status == THREAD_RUNNING || t->status == THREAD_READY) ? 1 : 0;
|
||||||
|
int thr_running = list_size(&ready_list) + a;
|
||||||
int thr_running = thread_current() == idle_thread ? 0 : 1;
|
|
||||||
thr_running += list_size(&ready_list);
|
|
||||||
|
|
||||||
load_avg = FPR_ADD_FPR(
|
load_avg = FPR_ADD_FPR(
|
||||||
FPR_MUL_FPR(INT_DIV_INT(59, 60), load_avg),
|
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);
|
FPReal dag = FPR_MUL_INT(load_avg, 2);
|
||||||
|
|
||||||
t->recent_cpu = FPR_MUL_FPR(t->recent_cpu,
|
struct list_elem* e;
|
||||||
FPR_DIV_FPR(dag, FPR_ADD_INT(dag, 1))) + INT_TO_FPR(t->nice);
|
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)) {
|
i->recent_cpu = FPR_MUL_FPR(i->recent_cpu,
|
||||||
t->recent_cpu = INT_TO_FPR(100);
|
FPR_DIV_FPR(dag, FPR_ADD_INT(dag, 1))) + INT_TO_FPR(i->nice);
|
||||||
} else if (t->recent_cpu < INT_TO_FPR(0)) {
|
|
||||||
t->recent_cpu = INT_TO_FPR(0);
|
//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
|
int
|
||||||
thread_get_nice (void)
|
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
|
void
|
||||||
|
@ -250,13 +250,19 @@ thread_set_nice (int nice)
|
||||||
int
|
int
|
||||||
thread_get_recent_cpu (void)
|
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
|
int
|
||||||
thread_get_load_avg (void)
|
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. */
|
/* Prints thread statistics. */
|
||||||
|
|
Reference in a new issue