bug fixes for timer and timer training.
authorDavid Zhu <yuzhu@cs.berkeley.edu>
Tue, 26 May 2009 00:50:01 +0000 (17:50 -0700)
committerDavid Zhu <yuzhu@cs.berkeley.edu>
Tue, 26 May 2009 00:50:01 +0000 (17:50 -0700)
several bugs fixed.
Serialized read tsc was clobbering register values.
We were getting negative reading for trained timer overhead.
Fixed pool implementation so we can iterate through allocated pool
buffers.

inc/pool.h
inc/syscall.h
inc/timer.h
inc/x86.h
kern/init.c
lib/libmain.c
lib/timer.c
user/null.c

index 36607ec..7852c5a 100644 (file)
@@ -25,13 +25,12 @@ typedef struct struct_##p {
                (p)->queue[i] = &((p)->pool[i]);                                       \
        }                                                                          \
 })
-
+// removed unnecessary (p)->queue[(p)->index] = NULL;
 #define POOL_GET(p)                                            \
 ({                                                             \
        void* rval = NULL;                                         \
        if((p)->free) {                                            \
                rval = (p)->queue[(p)->index];                         \
-               (p)->queue[(p)->index] = NULL;                         \
                (p)->free--;                                           \
                (p)->index++;                                          \
                if((p)->index == (p)->size) {                          \
@@ -50,7 +49,7 @@ typedef struct struct_##p {
                emptyIndex -= (p)->size;                                        \
        }                                                                   \
        for(int _i = emptyIndex;  _i < (p)->index; _i++){                       \
-               func((p)->queue[_i]);                                                                   \
+               func((p)->queue[_i]);                                                           \
        }                                                                                                                       \
 })                                                                                                                             \
 
index fb8deb6..9a62440 100644 (file)
@@ -44,4 +44,7 @@ struct syscall_desc {
 };
 LIST_HEAD(syscall_desc_list_t, syscall_desc_t);
 
+static uint32_t
+syscall_sysenter(int num, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5);
+
 #endif /* !ROS_INC_SYSCALL_H */
index 363486c..305a2aa 100644 (file)
@@ -42,6 +42,7 @@ typedef struct Timer{
        char label[TIMER_TAG_SIZE];
 } timer_t;
 
+//TODO: ifdef measurement? error check when pool runs low
 #define TAGGED_TIMING_BEGIN(tag)                    \
        static timer_t* _timer_##tag = NULL;            \
        if (_timer_##tag == NULL) {                     \
@@ -50,7 +51,6 @@ typedef struct Timer{
                _timer_##tag->aggr_run = 0;                 \
        }                                               \
        _timer_##tag->curr_run = start_timing();
-
 #define TAGGED_TIMING_END(tag)                                              \
 ({                                                                          \
        _timer_##tag->curr_run = stop_timing(_timer_##tag->curr_run);           \
index c57faba..88e4560 100644 (file)
--- a/inc/x86.h
+++ b/inc/x86.h
@@ -322,7 +322,8 @@ static __inline uint64_t
 read_tsc_serialized(void)
 {
     uint64_t tsc;
-    __asm __volatile("cpuid; rdtsc" : "=A" (tsc));
+       cpuid(0, 0, 0, 0, 0);
+       tsc = read_tsc();
        return tsc;
 }
 
index 132d07d..c7e8a60 100644 (file)
@@ -81,12 +81,12 @@ void kernel_init(multiboot_info_t *mboot_info)
        //ENV_CREATE(user_divzero);
        //ENV_CREATE(user_buggyhello);
        //ENV_CREATE(user_evilhello);
-       ENV_CREATE(user_hello);
-       ENV_CREATE(user_hello);
        //ENV_CREATE(user_hello);
        //ENV_CREATE(user_hello);
-       //ENV_CREATE(user_null);
-       //ENV_CREATE(user_null);
+       //ENV_CREATE(user_hello);
+       //ENV_CREATE(user_hello);
+       ENV_CREATE(user_null);
+       ENV_CREATE(user_null);
        env_run(&envs[0]);
        env_run(&envs[1]);
        panic("Don't Panic");
index e0ce63e..0eb448d 100644 (file)
@@ -31,7 +31,9 @@ libmain(int argc, char **argv)
        POOL_INIT(&async_desc_pool, MAX_ASYNCCALLS);
 
        // Setup the timer pool 
+       // TODO: ifdef measurement?
        POOL_INIT(&timer_pool, MAX_TIMERS);
+       train_timing();
 
        // save the name of the program so that panic() can use it
        if (argc > 0)
index ccd3c73..d57e21c 100644 (file)
@@ -29,7 +29,10 @@ uint64_t start_timing() __attribute__((noinline))
  */
 uint64_t stop_timing(uint64_t val) __attribute__((noinline))
 {
-    return (read_tsc_serialized() - val - timing_overhead);
+    uint64_t diff = (read_tsc_serialized() - val - timing_overhead);
+       if ((int64_t) diff < 0) 
+               return 1;
+       return diff;
 }
 
 /* train_timing()
@@ -40,7 +43,8 @@ uint64_t stop_timing(uint64_t val) __attribute__((noinline))
 void train_timing() 
 {
        int i;
-       register uint64_t cum_overhead = 0;
+       // set training overhead to be something large
+       register uint64_t training_overhead = 0xffffffff;
        register uint64_t time, diff;
 
        //Do this 3 times outside the loop to warm up cpuid
@@ -50,7 +54,6 @@ void train_timing()
        diff = stop_timing(time);
        time = start_timing();
        diff = stop_timing(time);
-
        for(i=0; i<10000; i++) {
                time = start_timing();
                diff = stop_timing(time);
@@ -59,8 +62,8 @@ void train_timing()
                 * to the cumulative error, otherwise, just diff itself
                 */
                if((int64_t)diff < 0)
-                       diff = (uint64_t)(~0) - diff + 1; 
-               cum_overhead += diff;
+                       diff = (uint64_t)(~0) - diff + 1;
+               training_overhead = MIN(training_overhead, diff);
        }
-       timing_overhead = (cum_overhead/i);
+       timing_overhead = training_overhead;
 }
index 46e2499..1219636 100644 (file)
@@ -24,11 +24,18 @@ uint64_t total(uint64_t (COUNT(length) array)[], int length)
        //return (length > 0) ? sum/((uint64_t)length) : 0;
 }
 
+void print_timer(timer_t* timer)
+{
+       cprintf("%s, %llu, %llu\n", timer->label, timer->curr_run, timer->aggr_run);
+}
+
 void umain(void)
 {
-       TAGGED_TIMING_BEGIN(tst);
+       extern uint64_t timing_overhead;
        async_desc_t *desc1, *desc2;
        async_rsp_t rsp1, rsp2;
+       cprintf ("training result %llu\n", timing_overhead);
+       /*      
        cache_buster_async(&desc1, 20, 0xdeadbeef);
        cache_buster_async(&desc2, 10, 0xcafebabe);
        waiton_async_call(desc1, &rsp1);
@@ -41,8 +48,12 @@ void umain(void)
        // Note this won't actually do 100 inner runs (first parameter).  will stop
        // making calls beyond the ring size and won't wait on any extra calls.
        measure_async_call(null_async(&desc), desc, 100, 100, "Async Null");
-       
-    TAGGED_TIMING_END(tst);
+       */
+       for (int i=0; i<100;i++){
+               TAGGED_TIMING_BEGIN(umain);
+               TAGGED_TIMING_END(umain);
+       }
+       POOL_FOR_EACH(&timer_pool, print_timer);
        // Spin to make sure we don't have any resources deallocated before done
        while(1);
 }