uptime() sys call for benchmarking

increase PHYSTOP
This commit is contained in:
Robert Morris 2010-08-11 14:34:45 -04:00
parent 83d2db91f7
commit 789b508d53
9 changed files with 47 additions and 9 deletions

2
defs.h
View file

@ -142,7 +142,7 @@ void timerinit(void);
// trap.c
void idtinit(void);
extern int ticks;
extern uint ticks;
void tvinit(void);
extern struct spinlock tickslock;

View file

@ -23,14 +23,10 @@ struct {
int nfreemem;
// Initialize free list of physical pages.
// This code cheats by just considering one megabyte of
// pages after end. Real systems would determine the
// amount of memory available in the system and use it all.
void
kinit(char *p, uint len)
{
initlock(&kmem.lock, "kmem");
cprintf("end 0x%x free = %d(0x%x)\n", p, len);
nfreemem = 0;
kfree(p, len);
}

View file

@ -100,6 +100,7 @@ extern int sys_sleep(void);
extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
extern int sys_uptime(void);
static int (*syscalls[])(void) = {
[SYS_chdir] sys_chdir,
@ -122,6 +123,7 @@ static int (*syscalls[])(void) = {
[SYS_unlink] sys_unlink,
[SYS_wait] sys_wait,
[SYS_write] sys_write,
[SYS_uptime] sys_uptime,
};
void

View file

@ -19,3 +19,4 @@
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sleep 20
#define SYS_uptime 21

View file

@ -57,7 +57,8 @@ sys_sbrk(void)
int
sys_sleep(void)
{
int n, ticks0;
int n;
uint ticks0;
if(argint(0, &n) < 0)
return -1;
@ -73,3 +74,16 @@ sys_sleep(void)
release(&tickslock);
return 0;
}
// return how many clock tick interrupts have occurred
// since boot.
int
sys_uptime(void)
{
uint xticks;
acquire(&tickslock);
xticks = ticks;
release(&tickslock);
return xticks;
}

2
trap.c
View file

@ -11,7 +11,7 @@
struct gatedesc idt[256];
extern uint vectors[]; // in vectors.S: array of 256 entry pointers
struct spinlock tickslock;
int ticks;
uint ticks;
void
tvinit(void)

View file

@ -322,8 +322,9 @@ void
mem(void)
{
void *m1, *m2;
int pid;
int pid, ppid;
ppid = getpid();
if((pid = fork()) == 0){
m1 = 0;
while((m2 = malloc(10001)) != 0) {
@ -338,6 +339,7 @@ mem(void)
m1 = malloc(1024*20);
if(m1 == 0) {
printf(1, "couldn't allocate mem?!!\n");
kill(ppid);
exit();
}
free(m1);
@ -1233,6 +1235,7 @@ void
sbrktest(void)
{
int pid;
char *oldbrk = sbrk(0);
printf(stdout, "sbrk test\n");
@ -1313,6 +1316,25 @@ sbrktest(void)
exit();
}
// can we read the kernel's memory?
for(a = (char*)(640*1024); a < (char *)2000000; a += 50000){
int ppid = getpid();
int pid = fork();
if(pid < 0){
printf(stdout, "fork failed\n");
exit();
}
if(pid == 0){
printf(stdout, "oops could read %x = %x\n", a, *a);
kill(ppid);
exit();
}
wait();
}
if(sbrk(0) > oldbrk)
sbrk(-(sbrk(0) - oldbrk));
printf(stdout, "sbrk test OK\n");
}

1
usys.S
View file

@ -28,3 +28,4 @@ SYSCALL(dup)
SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
SYSCALL(uptime)

4
vm.c
View file

@ -29,7 +29,7 @@
// (both in physical memory and in the kernel's virtual address
// space).
#define PHYSTOP 0x300000
#define PHYSTOP 0x1000000
#define USERTOP 0xA0000
static uint kerntext; // Linker starts kernel at 1MB
@ -336,6 +336,8 @@ copyuvm(pde_t *pgdir, uint sz)
// Gather information about physical memory layout.
// Called once during boot.
// Really should find out how much physical memory
// there is rather than assuming PHYSTOP.
void
pminit(void)
{