optinal load_avg to fix

This commit is contained in:
2025-03-26 09:32:27 +08:00
parent e66ab82e63
commit 2001e8e478
11 changed files with 68 additions and 20 deletions

View File

@@ -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));
}