sysinfo pass, make grade 40/40
This commit is contained in:
parent
8c9d916c76
commit
72d69e8d33
1
Makefile
1
Makefile
@ -189,6 +189,7 @@ UPROGS=\
|
|||||||
$U/_wc\
|
$U/_wc\
|
||||||
$U/_zombie\
|
$U/_zombie\
|
||||||
$U/_trace\
|
$U/_trace\
|
||||||
|
$U/_sysinfotest\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,7 @@ void ramdiskrw(struct buf*);
|
|||||||
void* kalloc(void);
|
void* kalloc(void);
|
||||||
void kfree(void *);
|
void kfree(void *);
|
||||||
void kinit(void);
|
void kinit(void);
|
||||||
|
int size_of_freemem(void);
|
||||||
|
|
||||||
// log.c
|
// log.c
|
||||||
void initlog(int, struct superblock*);
|
void initlog(int, struct superblock*);
|
||||||
@ -106,6 +107,7 @@ void yield(void);
|
|||||||
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
||||||
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
||||||
void procdump(void);
|
void procdump(void);
|
||||||
|
int number_of_process(void);
|
||||||
|
|
||||||
// swtch.S
|
// swtch.S
|
||||||
void swtch(struct context*, struct context*);
|
void swtch(struct context*, struct context*);
|
||||||
|
|||||||
@ -80,3 +80,18 @@ kalloc(void)
|
|||||||
memset((char*)r, 5, PGSIZE); // fill with junk
|
memset((char*)r, 5, PGSIZE); // fill with junk
|
||||||
return (void*)r;
|
return (void*)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
size_of_freemem(void)
|
||||||
|
{
|
||||||
|
struct run *r;
|
||||||
|
int count = 0;
|
||||||
|
acquire(&kmem.lock);
|
||||||
|
r = kmem.freelist;
|
||||||
|
while (r) {
|
||||||
|
count ++;
|
||||||
|
r = r->next;
|
||||||
|
}
|
||||||
|
release(&kmem.lock);
|
||||||
|
return count * PGSIZE;
|
||||||
|
}
|
||||||
@ -681,3 +681,14 @@ procdump(void)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
number_of_process(void)
|
||||||
|
{
|
||||||
|
struct proc *p;
|
||||||
|
int count = 0;
|
||||||
|
for (p = proc; p < &proc[NPROC]; p ++) {
|
||||||
|
if (p->state != UNUSED) count ++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
@ -102,6 +102,7 @@ extern uint64 sys_link(void);
|
|||||||
extern uint64 sys_mkdir(void);
|
extern uint64 sys_mkdir(void);
|
||||||
extern uint64 sys_close(void);
|
extern uint64 sys_close(void);
|
||||||
extern uint64 sys_trace(void);
|
extern uint64 sys_trace(void);
|
||||||
|
extern uint64 sys_sysinfo(void);
|
||||||
|
|
||||||
// An array mapping syscall numbers from syscall.h
|
// An array mapping syscall numbers from syscall.h
|
||||||
// to the function that handles the system call.
|
// to the function that handles the system call.
|
||||||
@ -128,6 +129,7 @@ static uint64 (*syscalls[])(void) = {
|
|||||||
[SYS_mkdir] sys_mkdir,
|
[SYS_mkdir] sys_mkdir,
|
||||||
[SYS_close] sys_close,
|
[SYS_close] sys_close,
|
||||||
[SYS_trace] sys_trace,
|
[SYS_trace] sys_trace,
|
||||||
|
[SYS_sysinfo] sys_sysinfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
char syscall_name[][8] = {
|
char syscall_name[][8] = {
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include "memlayout.h"
|
#include "memlayout.h"
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
|
#include "sysinfo.h"
|
||||||
|
|
||||||
uint64
|
uint64
|
||||||
sys_exit(void)
|
sys_exit(void)
|
||||||
@ -102,3 +103,20 @@ sys_trace(void)
|
|||||||
release(&myproc()->lock);
|
release(&myproc()->lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64
|
||||||
|
sys_sysinfo(void)
|
||||||
|
{
|
||||||
|
struct sysinfo info;
|
||||||
|
uint64 addr;
|
||||||
|
argaddr(0, &addr);
|
||||||
|
info.nproc = number_of_process();
|
||||||
|
info.freemem = size_of_freemem();
|
||||||
|
acquire(&myproc()->lock);
|
||||||
|
if(copyout(myproc()->pagetable, addr, (char *)&info, sizeof(info)) < 0){
|
||||||
|
release(&myproc()->lock);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
release(&myproc()->lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
struct stat;
|
struct stat;
|
||||||
|
struct sysinfo;
|
||||||
|
|
||||||
// system calls
|
// system calls
|
||||||
int fork(void);
|
int fork(void);
|
||||||
@ -23,6 +24,7 @@ char* sbrk(int);
|
|||||||
int sleep(int);
|
int sleep(int);
|
||||||
int uptime(void);
|
int uptime(void);
|
||||||
int trace(int);
|
int trace(int);
|
||||||
|
int sysinfo(struct sysinfo*);
|
||||||
|
|
||||||
// ulib.c
|
// ulib.c
|
||||||
int stat(const char*, struct stat*);
|
int stat(const char*, struct stat*);
|
||||||
|
|||||||
@ -37,3 +37,4 @@ entry("sbrk");
|
|||||||
entry("sleep");
|
entry("sleep");
|
||||||
entry("uptime");
|
entry("uptime");
|
||||||
entry("trace");
|
entry("trace");
|
||||||
|
entry("sysinfo");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user