optinal finished
This commit is contained in:
@ -108,8 +108,7 @@ int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
||||
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
||||
void procdump(void);
|
||||
int proc_size(void);
|
||||
int get_current_load(void);
|
||||
void update_load_avg(void);
|
||||
int update_load(void);
|
||||
|
||||
// swtch.S
|
||||
void swtch(struct context *, struct context *);
|
||||
|
||||
@ -5,8 +5,9 @@
|
||||
#include "spinlock.h"
|
||||
#include "proc.h"
|
||||
#include "defs.h"
|
||||
#include "sysinfo.h"
|
||||
|
||||
uint64 load_avg = 0;
|
||||
uint64 current_load = 0;
|
||||
|
||||
struct cpu cpus[NCPU];
|
||||
|
||||
@ -453,6 +454,7 @@ scheduler(void)
|
||||
{
|
||||
struct proc *p;
|
||||
struct cpu *c = mycpu();
|
||||
/*update_load_avg();*/
|
||||
|
||||
c->proc = 0;
|
||||
for(;;){
|
||||
@ -469,6 +471,7 @@ scheduler(void)
|
||||
// before jumping back to us.
|
||||
p->state = RUNNING;
|
||||
c->proc = p;
|
||||
current_load += 1;
|
||||
swtch(&c->context, &p->context);
|
||||
|
||||
// Process is done running for now.
|
||||
@ -705,21 +708,6 @@ proc_size()
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
update_load() {
|
||||
return current_load;
|
||||
}
|
||||
|
||||
void
|
||||
update_load_avg() {
|
||||
int current_load = get_current_load();
|
||||
load_avg = (load_avg * ALPHA) + (current_load * (1 - ALPHA));
|
||||
}
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
#include "defs.h"
|
||||
#define ALPHA 0.9
|
||||
|
||||
extern uint64 load_avg;
|
||||
|
||||
// Saved registers for kernel context switches.
|
||||
struct context {
|
||||
|
||||
@ -110,12 +110,11 @@ sys_sysinfo(void)
|
||||
uint64 addr;
|
||||
argaddr(0, &addr);
|
||||
if (addr < 0) return -1;
|
||||
/*update_load_avg();*/
|
||||
struct proc* p = myproc();
|
||||
info.nproc = proc_size();
|
||||
info.freemem = freemem();
|
||||
info.unused_proc_num = NPROC - info.nproc;
|
||||
info.load_avg = load_avg;
|
||||
info.load_avg = update_load() * 100 / sys_uptime();
|
||||
if (copyout(p->pagetable, addr, (char*)&info, sizeof(info)) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
@ -15,7 +15,7 @@ int main() {
|
||||
printf(" Free Memory: %d bytes\n", info.freemem);
|
||||
printf(" Number of Processes: %d\n", info.nproc);
|
||||
printf(" Unused Process Slots: %d\n", info.unused_proc_num);
|
||||
printf(" Load Average: %d\n", info.load_avg);
|
||||
printf(" Load Average: %d / 100 \n", info.load_avg);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user