lapic_wait_to_send tests
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 21 Apr 2009 21:43:04 +0000 (14:43 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 6 May 2009 18:42:18 +0000 (11:42 -0700)
Initial work, just blasts IPIs, can adjust to not wait, etc.

inc/x86.h
kern/init.c
kern/testing.c
kern/testing.h

index 48a60d0..23c768f 100644 (file)
--- a/inc/x86.h
+++ b/inc/x86.h
@@ -392,7 +392,9 @@ disable_irqsave(int8_t* state)
 static __inline void
 cpu_relax(void)
 {
-       asm volatile("pause");
+       // in case the compiler doesn't serialize for pause, the "m" will make sure
+       // no memory is reordered around this instruction.
+       asm volatile("pause" : : : "memory");
 }
 
 static __inline void
index 071ac1b..7d699f6 100644 (file)
@@ -67,6 +67,7 @@ void kernel_init(multiboot_info_t *mboot_info)
        test_checklists();
        test_barrier();
        test_print_info();
+       test_lapic_status_bit();
        test_ipi_sending();
        test_pit();
        */
index d33977a..6008879 100644 (file)
 #include <kern/atomic.h>
 #include <kern/smp.h>
 
+#define test_vector 0xeb
+
 void test_ipi_sending(void)
 {
-       #define test_vector 0xeb
        extern handler_t interrupt_handlers[];
        int8_t state = 0;
        
@@ -384,6 +385,23 @@ void test_smp_call_functions(void)
        printk("Done\n");
 }
 
+void test_lapic_status_bit(void)
+{
+       register_interrupt_handler(interrupt_handlers, test_vector,
+                                  test_incrementer_handler, &a);
+       #define NUM_IPI 100000
+       a = 0;
+       printk("IPIs received (should be 0): %d\n", a);
+       for(int i = 0; i < NUM_IPI; i++) {
+               send_ipi(7, 0, test_vector);
+               lapic_wait_to_send();
+       }
+       // need to wait a bit to let those IPIs get there
+       udelay(5000000);
+       printk("IPIs received (should be %d): %d\n", a, NUM_IPI);
+       // hopefully that handler never fires again.  leaving it registered for now.
+}
+
 /* Helper Functions */
 
 void test_hello_world_handler(trapframe_t *tf, void* data)
@@ -436,28 +454,28 @@ void test_barrier_handler(trapframe_t *tf, void* data)
        //cprintf("Round 4: Core %d\n", lapic_get_id());
 }
 
-volatile uint32_t waiting = 1;
-static void futurecall(trapframe_t *tf)
+static void test_waiting_handler(trapframe_t *tf, void* data)
 {
-       {HANDLER_ATOMIC atomic_dec(&waiting);}
+       {HANDLER_ATOMIC atomic_dec((uint32_t*)data);}
 }
+
 void test_pit(void)
 {
-       cprintf("starting test for pit now (10s) \n");
+       cprintf("Starting test for PIT now (10s)\n");
        udelay(10000000);
-       cprintf("end now \n");
-       cprintf("starting test for tsc (if stable) now (10s)\n");
+       cprintf("End now\n");
+       cprintf("Starting test for TSC (if stable) now (10s)\n");
        udelay(10000000);
-       cprintf("end now \n");
+       cprintf("End now\n");
        
-       cprintf("starting test for lapic (if stable) now (10s)\n");
+       cprintf("Starting test for LAPIC (if stable) now (10s)\n");
        enable_irq();
-       lapic_set_timer(10* bus_freq/128,0xeb,TRUE);
-       
-       register_interrupt_handler(interrupt_handlers, 0xeb, futurecall, 0);
+       lapic_set_timer(10* bus_freq/128, test_vector, TRUE);
        
+       uint32_t waiting = 1;
+       register_interrupt_handler(interrupt_handlers, test_vector,
+                                  test_waiting_handler, &waiting);
        while(waiting)
                cpu_relax();
-       cprintf("end now");
-
+       cprintf("End now\n");
 }
index 9d5740c..bc4407b 100644 (file)
@@ -19,6 +19,7 @@ void test_bitmasks(void);
 void test_checklists(void);
 void test_pit(void);
 void test_smp_call_functions(void);
+void test_lapic_status_bit(void);
 
 void test_hello_world_handler(trapframe_t *tf, void* data);
 void test_print_info_handler(trapframe_t *tf, void* data);