Browse files

uptime() sys call for benchmarking

increase PHYSTOP
  • Loading branch information...
1 parent 83d2db9 commit 789b508d538e6faf635e49f268a4f1f9e9b65f05 Robert Morris committed Aug 11, 2010
Showing with 47 additions and 9 deletions.
  1. +1 −1 defs.h
  2. +0 −4 kalloc.c
  3. +2 −0 syscall.c
  4. +1 −0 syscall.h
  5. +15 −1 sysproc.c
  6. +1 −1 trap.c
  7. +23 −1 usertests.c
  8. +1 −0 usys.S
  9. +3 −1 vm.c
View
2 defs.h
@@ -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
4 kalloc.c
@@ -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
2 syscall.c
@@ -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
1 syscall.h
@@ -19,3 +19,4 @@
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sleep 20
+#define SYS_uptime 21
View
16 sysproc.c
@@ -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;
+}
View
2 trap.c
@@ -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
24 usertests.c
@@ -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");
}
View
1 usys.S
@@ -28,3 +28,4 @@ SYSCALL(dup)
SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
+SYSCALL(uptime)
View
4 vm.c
@@ -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)
{

0 comments on commit 789b508

Please sign in to comment.