Skip to content

Commit

Permalink
uptime() sys call for benchmarking
Browse files Browse the repository at this point in the history
increase PHYSTOP
  • Loading branch information
Robert Morris committed Aug 11, 2010
1 parent 83d2db9 commit 789b508
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sleep 20
#define SYS_uptime 21
16 changes: 15 additions & 1 deletion sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 changes: 1 addition & 1 deletion trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion usertests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -1233,6 +1235,7 @@ void
sbrktest(void)
{
int pid;
char *oldbrk = sbrk(0);

printf(stdout, "sbrk test\n");

Expand Down Expand Up @@ -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");
}

Expand Down
1 change: 1 addition & 0 deletions usys.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ SYSCALL(dup)
SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
SYSCALL(uptime)
4 changes: 3 additions & 1 deletion vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 789b508

Please sign in to comment.