Added the null syscall and a userapp that exploits it.
authorKevin Klues <klueska@cs.berkeley.edu>
Tue, 5 May 2009 06:24:44 +0000 (23:24 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 6 May 2009 18:29:42 +0000 (11:29 -0700)
Still need to make an async version of the null syscall and change
init.c to run it correctly.  I made the changes locally, but didn't want
to push the changes in init.c to the global tree.

inc/lib.h
inc/syscall.h
kern/Makefrag
kern/syscall.c
lib/syscall.c
user/null.c [new file with mode: 0644]

index a47c61d..ea29bb4 100644 (file)
--- a/inc/lib.h
+++ b/inc/lib.h
@@ -34,8 +34,9 @@ void  exit(void);
 char*  readline(const char *buf);
 
 // syscall.c
-void   sys_cputs(const char *string, size_t len);
-void   sys_cputs_async(const char *string, size_t len);
+void sys_null();
+void sys_cputs(const char *string, size_t len);
+void sys_cputs_async(const char *string, size_t len);
 int    sys_cgetc(void);
 envid_t        sys_getenvid(void);
 int    sys_env_destroy(envid_t);
index 5435a6a..b8ea258 100644 (file)
@@ -7,12 +7,13 @@
 /* system call numbers */
 enum
 {
-       SYS_cputs = 0,
+       SYS_null = 1,
+       SYS_cputs,
        SYS_cgetc,
        SYS_getenvid,
        SYS_env_destroy,
-       NSYSCALLS
 };
+#define NSYSCALLS (SYS_env_destroy)
 
 #define NUM_SYS_ARGS 6
 typedef struct SyscallRequest {
index 239220c..497bbba 100644 (file)
@@ -40,18 +40,19 @@ KERN_SRCFILES :=    kern/entry.S \
 # Only build files if they exist.
 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
 
-KERN_BINFILES :=       user/hello \
-                       user/buggyhello \
-                       user/evilhello \
-                       user/testbss \
-                       user/divzero \
-                       user/breakpoint \
-                       user/softint \
-                       user/badsegment \
-                       user/faultread \
-                       user/faultreadkernel \
-                       user/faultwrite \
-                       user/faultwritekernel
+KERN_BINFILES :=       user/null \
+                                       user/hello \
+                                       user/buggyhello \
+                                       user/evilhello \
+                                       user/testbss \
+                                       user/divzero \
+                                       user/breakpoint \
+                                       user/softint \
+                                       user/badsegment \
+                                       user/faultread \
+                                       user/faultreadkernel \
+                                       user/faultwrite \
+                                       user/faultwritekernel
 
 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
 KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
index 255bbff..b96fe82 100644 (file)
 #include <kern/syscall.h>
 #include <kern/console.h>
 
+//Do absolutely nothing.  Used for profiling.  
+static void sys_null() 
+{
+       return;
+}
+
 // Print a string to the system console.
 // The string is exactly 'len' characters long.
 // Destroys the environment on memory errors.
@@ -82,6 +88,9 @@ syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
                return -E_INVAL;
        
        switch (syscallno) {
+               case SYS_null:
+                       sys_null();
+                       return 0;
                case SYS_cputs:
                        sys_cputs((char *DANGEROUS)a1, (size_t)a2);
                        return 0;
index 0c18445..b050c0d 100644 (file)
@@ -54,6 +54,11 @@ void sys_cputs_async(const char *s, size_t len)
        async_syscall(&syscall);
 }
 
+void sys_null()
+{
+       syscall(SYS_null,0,0,0,0,0);
+}
+
 void
 sys_cputs(const char *s, size_t len)
 {
diff --git a/user/null.c b/user/null.c
new file mode 100644 (file)
index 0000000..f22ac63
--- /dev/null
@@ -0,0 +1,33 @@
+// null app
+#include <inc/lib.h>
+#include <inc/types.h>
+#include <inc/syscall.h>
+
+uint64_t avg(uint32_t (COUNT(length) array)[], int length) 
+{
+       uint64_t sum = 0;
+       for(int i=0; i<length; i++) {
+               sum+=array[i];
+       }
+       return (length > 0) ? sum/((uint64_t)length) : 0;
+}
+
+void umain(void)
+{
+       //Get the measurements a bunch of times to make sure its accurate
+       #define NUM_ITERATIONS  500
+       uint32_t times[NUM_ITERATIONS];
+       for(int i=0; i<NUM_ITERATIONS; i++) {
+               //times[i] = get_time();
+               sys_null();
+               //times[i] = get_time() - times[i];
+       }
+       
+       //Compute the average and print it
+       uint64_t a = avg(times, NUM_ITERATIONS);
+       cprintf_async("Average latency: %ld", a);
+       //cprintf("Standard Deviation: %d", stddev);
+
+       //Spin to make sure we don't have any resources dealocated before done
+       while(1);
+}