optinal load_avg to fix
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "proc.h"
|
||||
#include "defs.h"
|
||||
|
||||
uint64 load_avg = 0;
|
||||
|
||||
struct cpu cpus[NCPU];
|
||||
|
||||
struct proc proc[NPROC];
|
||||
@@ -701,3 +703,23 @@ proc_size()
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
get_current_load() {
|
||||
struct proc *p;
|
||||
int current_load = 0;
|
||||
|
||||
for (p = proc; p < &proc[NPROC]; p++) {
|
||||
if (p->state == RUNNING || p->state == RUNNABLE) {
|
||||
current_load++;
|
||||
}
|
||||
}
|
||||
|
||||
return current_load;
|
||||
}
|
||||
|
||||
void
|
||||
update_load_avg() {
|
||||
int current_load = get_current_load();
|
||||
load_avg = (load_avg * ALPHA) + (current_load * (1 - ALPHA));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user