Finished sparc port merge, fixed symlink cleaning
[akaros.git] / kern / src / testing.c
1 #ifdef __DEPUTY__
2 #pragma nodeputy
3 #endif
4
5 #include <arch/mmu.h>
6 #include <arch/arch.h>
7 #include <smp.h>
8
9 #include <ros/memlayout.h>
10
11 #include <atomic.h>
12 #include <stdio.h>
13 #include <assert.h>
14 #include <string.h>
15 #include <testing.h>
16 #include <trap.h>
17 #include <env.h>
18 #include <syscall.h>
19
20 #define test_vector 0xeb
21
22 #if 0
23
24 void test_ipi_sending(void)
25 {
26         extern handler_t interrupt_handlers[];
27         int8_t state = 0;
28
29         register_interrupt_handler(interrupt_handlers, test_vector,
30                                    test_hello_world_handler, 0);
31         enable_irqsave(&state);
32         cprintf("\nCORE 0 sending broadcast\n");
33         send_broadcast_ipi(test_vector);
34         udelay(3000000);
35         cprintf("\nCORE 0 sending all others\n");
36         send_all_others_ipi(test_vector);
37         udelay(3000000);
38         cprintf("\nCORE 0 sending self\n");
39         send_self_ipi(test_vector);
40         udelay(3000000);
41         cprintf("\nCORE 0 sending ipi to physical 1\n");
42         send_ipi(0x01, 0, test_vector);
43         udelay(3000000);
44         cprintf("\nCORE 0 sending ipi to physical 2\n");
45         send_ipi(0x02, 0, test_vector);
46         udelay(3000000);
47         cprintf("\nCORE 0 sending ipi to physical 3\n");
48         send_ipi(0x03, 0, test_vector);
49         udelay(3000000);
50         cprintf("\nCORE 0 sending ipi to physical 15\n");
51         send_ipi(0x0f, 0, test_vector);
52         udelay(3000000);
53         cprintf("\nCORE 0 sending ipi to logical 2\n");
54         send_ipi(0x02, 1, test_vector);
55         udelay(3000000);
56         cprintf("\nCORE 0 sending ipi to logical 1\n");
57         send_ipi(0x01, 1, test_vector);
58         udelay(3000000);
59         cprintf("\nDone!\n");
60         disable_irqsave(&state);
61 }
62
63 // Note this never returns and will muck with any other timer work
64 void test_pic_reception(void)
65 {
66         register_interrupt_handler(interrupt_handlers, 0x20, test_hello_world_handler, 0);
67         pit_set_timer(100,TIMER_RATEGEN); // totally arbitrary time
68         pic_unmask_irq(0);
69         cprintf("PIC1 Mask = 0x%04x\n", inb(PIC1_DATA));
70         cprintf("PIC2 Mask = 0x%04x\n", inb(PIC2_DATA));
71         unmask_lapic_lvt(LAPIC_LVT_LINT0);
72         cprintf("Core %d's LINT0: 0x%08x\n", core_id(), read_mmreg32(LAPIC_LVT_LINT0));
73         enable_irq();
74         while(1);
75 }
76
77 #endif
78
79 void test_print_info(void)
80 {
81         cprintf("\nCORE 0 asking all cores to print info:\n");
82         smp_call_function_all(test_print_info_handler, 0, 0);
83         cprintf("\nDone!\n");
84 }
85
86
87 extern uint8_t num_cpus;
88 barrier_t test_cpu_array;
89
90 void test_barrier(void)
91 {
92         cprintf("Core 0 initializing barrier\n");
93         init_barrier(&test_cpu_array, num_cpus);
94         cprintf("Core 0 asking all cores to print ids, barrier, rinse, repeat\n");
95         smp_call_function_all(test_barrier_handler, 0, 0);
96 }
97
98 void test_interrupts_irqsave(void)
99 {
100         int8_t state = 0;
101         printd("Testing Nesting Enabling first, turning ints off:\n");
102         disable_irq();
103         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
104         assert(!irq_is_enabled());
105         printd("Enabling IRQSave\n");
106         enable_irqsave(&state);
107         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
108         assert(irq_is_enabled());
109         printd("Enabling IRQSave Again\n");
110         enable_irqsave(&state);
111         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
112         assert(irq_is_enabled());
113         printd("Disabling IRQSave Once\n");
114         disable_irqsave(&state);
115         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
116         assert(irq_is_enabled());
117         printd("Disabling IRQSave Again\n");
118         disable_irqsave(&state);
119         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
120         assert(!irq_is_enabled());
121         printd("Done.  Should have been 0, 200, 200, 200, 0\n");
122
123         printd("Testing Nesting Disabling first, turning ints on:\n");
124         state = 0;
125         enable_irq();
126         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
127         assert(irq_is_enabled());
128         printd("Disabling IRQSave Once\n");
129         disable_irqsave(&state);
130         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
131         assert(!irq_is_enabled());
132         printd("Disabling IRQSave Again\n");
133         disable_irqsave(&state);
134         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
135         assert(!irq_is_enabled());
136         printd("Enabling IRQSave Once\n");
137         enable_irqsave(&state);
138         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
139         assert(!irq_is_enabled());
140         printd("Enabling IRQSave Again\n");
141         enable_irqsave(&state);
142         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
143         assert(irq_is_enabled());
144         printd("Done.  Should have been 200, 0, 0, 0, 200 \n");
145
146         state = 0;
147         disable_irq();
148         printd("Ints are off, enabling then disabling.\n");
149         enable_irqsave(&state);
150         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
151         assert(irq_is_enabled());
152         disable_irqsave(&state);
153         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
154         assert(!irq_is_enabled());
155         printd("Done.  Should have been 200, 0\n");
156
157         state = 0;
158         enable_irq();
159         printd("Ints are on, enabling then disabling.\n");
160         enable_irqsave(&state);
161         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
162         assert(irq_is_enabled());
163         disable_irqsave(&state);
164         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
165         assert(irq_is_enabled());
166         printd("Done.  Should have been 200, 200\n");
167
168         state = 0;
169         disable_irq();
170         printd("Ints are off, disabling then enabling.\n");
171         disable_irqsave(&state);
172         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
173         assert(!irq_is_enabled());
174         enable_irqsave(&state);
175         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
176         assert(!irq_is_enabled());
177         printd("Done.  Should have been 0, 0\n");
178
179         state = 0;
180         enable_irq();
181         printd("Ints are on, disabling then enabling.\n");
182         disable_irqsave(&state);
183         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
184         assert(!irq_is_enabled());
185         enable_irqsave(&state);
186         printd("Interrupts are: %x\n", read_eflags() & FL_IF);
187         assert(irq_is_enabled());
188         printd("Done.  Should have been 0, 200\n");
189
190         disable_irq();
191         cprintf("Passed enable_irqsave tests\n");
192 }
193
194 void test_bitmasks(void)
195 {
196 #define masksize 67
197         DECL_BITMASK(mask, masksize);
198         printk("size of mask %d\n", sizeof(mask));
199         CLR_BITMASK(mask, masksize);
200         PRINT_BITMASK(mask, masksize);
201         printk("cleared\n");
202         SET_BITMASK_BIT(mask, 0);
203         SET_BITMASK_BIT(mask, 11);
204         SET_BITMASK_BIT(mask, 17);
205         SET_BITMASK_BIT(mask, masksize-1);
206         printk("bits set\n");
207         PRINT_BITMASK(mask, masksize);
208         DECL_BITMASK(mask2, masksize);
209         COPY_BITMASK(mask2, mask, masksize);
210         printk("copy of original mask, should be the same as the prev\n");
211         PRINT_BITMASK(mask2, masksize);
212         CLR_BITMASK_BIT(mask, 11);
213         printk("11 cleared\n");
214         PRINT_BITMASK(mask, masksize);
215         printk("bit 17 is %d (should be 1)\n", GET_BITMASK_BIT(mask, 17));
216         printk("bit 11 is %d (should be 0)\n", GET_BITMASK_BIT(mask, 11));
217         FILL_BITMASK(mask, masksize);
218         PRINT_BITMASK(mask, masksize);
219         printk("should be all 1's, except for a few at the end\n");
220         printk("Is Clear?: %d (should be 0)\n", BITMASK_IS_CLEAR(mask,masksize));
221         CLR_BITMASK(mask, masksize);
222         PRINT_BITMASK(mask, masksize);
223         printk("Is Clear?: %d (should be 1)\n", BITMASK_IS_CLEAR(mask,masksize));
224         printk("should be cleared\n");
225 }
226
227 checklist_t* the_global_list;
228
229 void test_checklist_handler(trapframe_t *tf, void* data)
230 {
231         for (int i = 0; i < SMP_BOOT_TIMEOUT; i++);
232         for (int i = 0; i < SMP_BOOT_TIMEOUT; i++);
233         cprintf("down_checklist(%x,%d)\n",the_global_list,core_id());
234         down_checklist(the_global_list);
235 }
236
237 extern uint8_t num_cpus;
238
239 void test_checklists(void)
240 {
241         INIT_CHECKLIST(a_list, MAX_NUM_CPUS);
242         the_global_list = &a_list;
243         printk("Checklist Build, mask size: %d\n", sizeof(a_list.mask.bits));
244         printk("mask\n");
245         PRINT_BITMASK(a_list.mask.bits, a_list.mask.size);
246         SET_BITMASK_BIT(a_list.mask.bits, 11);
247         printk("Set bit 11\n");
248         PRINT_BITMASK(a_list.mask.bits, a_list.mask.size);
249
250         CLR_BITMASK(a_list.mask.bits, a_list.mask.size);
251         INIT_CHECKLIST_MASK(a_mask, MAX_NUM_CPUS);
252         FILL_BITMASK(a_mask.bits, num_cpus);
253         //CLR_BITMASK_BIT(a_mask.bits, core_id());
254         //SET_BITMASK_BIT(a_mask.bits, 1);
255         //printk("New mask (1, 17, 25):\n");
256         printk("Created new mask, filled up to num_cpus\n");
257         PRINT_BITMASK(a_mask.bits, a_mask.size);
258         printk("committing new mask\n");
259         commit_checklist_wait(&a_list, &a_mask);
260         printk("Old mask (copied onto):\n");
261         PRINT_BITMASK(a_list.mask.bits, a_list.mask.size);
262         //smp_call_function_single(1, test_checklist_handler, 0, 0);
263
264         smp_call_function_all(test_checklist_handler, 0, 0);
265
266         printk("Waiting on checklist\n");
267         waiton_checklist(&a_list);
268         printk("Done Waiting!\n");
269
270 }
271
272 atomic_t a = atomic_init(0), b = atomic_init(0), c = atomic_init(0);
273
274 void test_incrementer_handler(trapframe_t *tf, void* data)
275 {
276         assert(data);
277         atomic_inc((atomic_t*)data);
278 }
279
280 void test_null_handler(trapframe_t *tf, void* data)
281 {
282         asm volatile("nop");
283 }
284
285 void test_smp_call_functions(void)
286 {
287         int i;
288         handler_wrapper_t *waiter0 = 0, *waiter1 = 0, *waiter2 = 0, *waiter3 = 0,
289                           *waiter4 = 0, *waiter5 = 0;
290         uint8_t me = core_id();
291         printk("\nCore %d: SMP Call Self (nowait):\n", me);
292         printk("---------------------\n");
293         smp_call_function_self(test_hello_world_handler, 0, 0);
294         printk("\nCore %d: SMP Call Self (wait):\n", me);
295         printk("---------------------\n");
296         smp_call_function_self(test_hello_world_handler, 0, &waiter0);
297         smp_call_wait(waiter0);
298         printk("\nCore %d: SMP Call All (nowait):\n", me);
299         printk("---------------------\n");
300         smp_call_function_all(test_hello_world_handler, 0, 0);
301         printk("\nCore %d: SMP Call All (wait):\n", me);
302         printk("---------------------\n");
303         smp_call_function_all(test_hello_world_handler, 0, &waiter0);
304         smp_call_wait(waiter0);
305         printk("\nCore %d: SMP Call All-Else Individually, in order (nowait):\n", me);
306         printk("---------------------\n");
307         for(i = 1; i < num_cpus; i++)
308                 smp_call_function_single(i, test_hello_world_handler, 0, 0);
309         printk("\nCore %d: SMP Call Self (wait):\n", me);
310         printk("---------------------\n");
311         smp_call_function_self(test_hello_world_handler, 0, &waiter0);
312         smp_call_wait(waiter0);
313         printk("\nCore %d: SMP Call All-Else Individually, in order (wait):\n", me);
314         printk("---------------------\n");
315         for(i = 1; i < num_cpus; i++)
316         {
317                 smp_call_function_single(i, test_hello_world_handler, 0, &waiter0);
318                 smp_call_wait(waiter0);
319         }
320         printk("\nTesting to see if any IPI-functions are dropped when not waiting:\n");
321         printk("A: %d, B: %d, C: %d (should be 0,0,0)\n", atomic_read(&a), atomic_read(&b), atomic_read(&c));
322         smp_call_function_all(test_incrementer_handler, &a, 0);
323         smp_call_function_all(test_incrementer_handler, &b, 0);
324         smp_call_function_all(test_incrementer_handler, &c, 0);
325         // if i can clobber a previous IPI, the interleaving might do it
326         smp_call_function_single(1 % num_cpus, test_incrementer_handler, &a, 0);
327         smp_call_function_single(2 % num_cpus, test_incrementer_handler, &b, 0);
328         smp_call_function_single(3 % num_cpus, test_incrementer_handler, &c, 0);
329         smp_call_function_single(4 % num_cpus, test_incrementer_handler, &a, 0);
330         smp_call_function_single(5 % num_cpus, test_incrementer_handler, &b, 0);
331         smp_call_function_single(6 % num_cpus, test_incrementer_handler, &c, 0);
332         smp_call_function_all(test_incrementer_handler, &a, 0);
333         smp_call_function_single(3 % num_cpus, test_incrementer_handler, &c, 0);
334         smp_call_function_all(test_incrementer_handler, &b, 0);
335         smp_call_function_single(1 % num_cpus, test_incrementer_handler, &a, 0);
336         smp_call_function_all(test_incrementer_handler, &c, 0);
337         smp_call_function_single(2 % num_cpus, test_incrementer_handler, &b, 0);
338         // wait, so we're sure the others finish before printing.
339         // without this, we could (and did) get 19,18,19, since the B_inc
340         // handler didn't finish yet
341         smp_call_function_self(test_null_handler, 0, &waiter0);
342         // need to grab all 5 handlers (max), since the code moves to the next free.
343         smp_call_function_self(test_null_handler, 0, &waiter1);
344         smp_call_function_self(test_null_handler, 0, &waiter2);
345         smp_call_function_self(test_null_handler, 0, &waiter3);
346         smp_call_function_self(test_null_handler, 0, &waiter4);
347         smp_call_wait(waiter0);
348         smp_call_wait(waiter1);
349         smp_call_wait(waiter2);
350         smp_call_wait(waiter3);
351         smp_call_wait(waiter4);
352         printk("A: %d, B: %d, C: %d (should be 19,19,19)\n", atomic_read(&a), atomic_read(&b), atomic_read(&c));
353         printk("Attempting to deadlock by smp_calling with an outstanding wait:\n");
354         smp_call_function_self(test_null_handler, 0, &waiter0);
355         printk("Sent one\n");
356         smp_call_function_self(test_null_handler, 0, &waiter1);
357         printk("Sent two\n");
358         smp_call_wait(waiter0);
359         printk("Wait one\n");
360         smp_call_wait(waiter1);
361         printk("Wait two\n");
362         printk("\tMade it through!\n");
363         printk("Attempting to deadlock by smp_calling more than are available:\n");
364         printk("\tShould see an Insufficient message and a kernel warning.\n");
365         if (smp_call_function_self(test_null_handler, 0, &waiter0))
366                 printk("\tInsufficient handlers to call function (0)\n");
367         if (smp_call_function_self(test_null_handler, 0, &waiter1))
368                 printk("\tInsufficient handlers to call function (1)\n");
369         if (smp_call_function_self(test_null_handler, 0, &waiter2))
370                 printk("\tInsufficient handlers to call function (2)\n");
371         if (smp_call_function_self(test_null_handler, 0, &waiter3))
372                 printk("\tInsufficient handlers to call function (3)\n");
373         if (smp_call_function_self(test_null_handler, 0, &waiter4))
374                 printk("\tInsufficient handlers to call function (4)\n");
375         if (smp_call_function_self(test_null_handler, 0, &waiter5))
376                 printk("\tInsufficient handlers to call function (5)\n");
377         smp_call_wait(waiter0);
378         smp_call_wait(waiter1);
379         smp_call_wait(waiter2);
380         smp_call_wait(waiter3);
381         smp_call_wait(waiter4);
382         smp_call_wait(waiter5);
383         printk("\tMade it through!\n");
384
385         printk("Done\n");
386 }
387
388 #if 0
389 void test_lapic_status_bit(void)
390 {
391         register_interrupt_handler(interrupt_handlers, test_vector,
392                                    test_incrementer_handler, &a);
393         #define NUM_IPI 100000
394         atomic_set(&a,0);
395         printk("IPIs received (should be 0): %d\n", a);
396         for(int i = 0; i < NUM_IPI; i++) {
397                 send_ipi(7, 0, test_vector);
398                 lapic_wait_to_send();
399         }
400         // need to wait a bit to let those IPIs get there
401         udelay(5000000);
402         printk("IPIs received (should be %d): %d\n", a, NUM_IPI);
403         // hopefully that handler never fires again.  leaving it registered for now.
404 }
405 #endif
406
407 /******************************************************************************/
408 /*            Test Measurements: Couples with measurement.c                   */
409 // All user processes can R/W the UGDATA page
410 barrier_t* bar = (barrier_t*)UGDATA;
411 uint32_t* job_to_run = (uint32_t*)(UGDATA + sizeof(barrier_t));
412 env_t* env_batch[64]; // Fairly arbitrary, just the max I plan to use.
413
414 /* Helpers for test_run_measurements */
415 static void wait_for_all_envs_to_die(void)
416 {
417         while (atomic_read(&num_envs))
418                 cpu_relax();
419 }
420
421 #if 0
422
423 // this never returns.
424 static void sync_tests(int start_core, int num_threads, int job_num)
425 {
426         assert(start_core + num_threads <= num_cpus);
427         wait_for_all_envs_to_die();
428         for (int i = start_core; i < start_core + num_threads; i++)
429                 env_batch[i] = ENV_CREATE(roslib_measurements);
430         init_barrier(bar, num_threads);
431         *job_to_run = job_num;
432         for (int i = start_core; i < start_core + num_threads; i++)
433                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
434         process_workqueue();
435         // we want to fake a run, to reenter manager for the next case
436         env_t *env = ENV_CREATE(roslib_null);
437         smp_call_function_single(0, run_env_handler, env, 0);
438         process_workqueue();
439         panic("whoops!\n");
440 }
441
442 static void async_tests(int start_core, int num_threads, int job_num)
443 {
444         int count;
445
446         assert(start_core + num_threads <= num_cpus);
447         wait_for_all_envs_to_die();
448         for (int i = start_core; i < start_core + num_threads; i++)
449                 env_batch[i] = ENV_CREATE(roslib_measurements);
450         init_barrier(bar, num_threads);
451         *job_to_run = job_num;
452         for (int i = start_core; i < start_core + num_threads; i++)
453                 smp_call_function_single(i, run_env_handler, env_batch[i], 0);
454         count = 0;
455         while (count > -num_threads) {
456                 count = 0;
457                 for (int i = start_core; i < start_core + num_threads; i++) {
458                         count += process_generic_syscalls(env_batch[i], 1);
459                 }
460                 cpu_relax();
461         }
462         // we want to fake a run, to reenter manager for the next case
463         env_t *env = ENV_CREATE(roslib_null);
464         smp_call_function_single(0, run_env_handler, env, 0);
465         process_workqueue();
466         // this all never returns
467         panic("whoops!\n");
468 }
469
470 void test_run_measurements(uint32_t job_num)
471 {
472         switch (job_num) {
473                 case 0: // Nulls
474                         printk("Case 0:\n");
475                         async_tests(2, 1, job_num);  // start core 2, 1 core total
476                         break;
477                 case 1: // Sync
478                         printk("Case 1:\n");
479                         sync_tests(2, 1, job_num);
480                         break;
481                 case 2:
482                         printk("Case 2:\n");
483                         sync_tests(2, 2, job_num);
484                         break;
485                 case 3:
486                         printk("Case 3:\n");
487                         sync_tests(0, 3, job_num);
488                         break;
489                 case 4:
490                         printk("Case 4:\n");
491                         sync_tests(0, 4, job_num);
492                         break;
493                 case 5:
494                         printk("Case 5:\n");
495                         sync_tests(0, 5, job_num);
496                         break;
497                 case 6:
498                         printk("Case 6:\n");
499                         sync_tests(0, 6, job_num);
500                         break;
501                 case 7:
502                         printk("Case 7:\n");
503                         sync_tests(0, 7, job_num);
504                         break;
505                 case 8:
506                         printk("Case 8:\n");
507                         sync_tests(0, 8, job_num);
508                         break;
509                 case 9:
510                         printk("Case 9:\n");
511                         async_tests(2, 1, job_num);
512                         break;
513                 case 10:
514                         printk("Case 10:\n");
515                         async_tests(2, 2, job_num);
516                         break;
517                 case 11:
518                         printk("Case 11:\n");
519                         async_tests(2, 3, job_num);
520                         break;
521                 case 12:
522                         printk("Case 12:\n");
523                         async_tests(2, 4, job_num);
524                         break;
525                 case 13:
526                         printk("Case 13:\n");
527                         async_tests(2, 5, job_num);
528                         break;
529                 case 14:
530                         printk("Case 14:\n");
531                         async_tests(2, 6, job_num);
532                         break;
533                 default:
534                         warn("Invalid test number!!");
535         }
536         panic("Error in test setup!!");
537 }
538
539 #endif
540
541 /************************************************************/
542 /* ISR Handler Functions */
543
544 void test_hello_world_handler(trapframe_t *tf, void* data)
545 {
546         int trapno;
547         #if defined(__i386__)
548         trapno = tf->tf_trapno;
549         #elif defined(__sparc_v8__)
550         trapno = (tf->tbr >> 4) & 0xFF;
551         #else
552         trapno = 0;
553         #endif
554
555         cprintf("Incoming IRQ, ISR: %d on core %d with tf at 0x%08x\n",
556                 trapno, core_id(), tf);
557 }
558
559 uint32_t print_info_lock = 0;
560
561 void test_print_info_handler(trapframe_t *tf, void* data)
562 {
563         spin_lock_irqsave(&print_info_lock);
564         cprintf("----------------------------\n");
565         cprintf("This is Core %d\n", core_id());
566 #if 0
567         cprintf("MTRR_DEF_TYPE = 0x%08x\n", read_msr(IA32_MTRR_DEF_TYPE));
568         cprintf("MTRR Phys0 Base = 0x%016llx, Mask = 0x%016llx\n",
569                 read_msr(0x200), read_msr(0x201));
570         cprintf("MTRR Phys1 Base = 0x%016llx, Mask = 0x%016llx\n",
571                 read_msr(0x202), read_msr(0x203));
572         cprintf("MTRR Phys2 Base = 0x%016llx, Mask = 0x%016llx\n",
573                 read_msr(0x204), read_msr(0x205));
574         cprintf("MTRR Phys3 Base = 0x%016llx, Mask = 0x%016llx\n",
575                 read_msr(0x206), read_msr(0x207));
576         cprintf("MTRR Phys4 Base = 0x%016llx, Mask = 0x%016llx\n",
577                 read_msr(0x208), read_msr(0x209));
578         cprintf("MTRR Phys5 Base = 0x%016llx, Mask = 0x%016llx\n",
579                 read_msr(0x20a), read_msr(0x20b));
580         cprintf("MTRR Phys6 Base = 0x%016llx, Mask = 0x%016llx\n",
581                 read_msr(0x20c), read_msr(0x20d));
582         cprintf("MTRR Phys7 Base = 0x%016llx, Mask = 0x%016llx\n",
583                 read_msr(0x20e), read_msr(0x20f));
584 #endif
585         cprintf("----------------------------\n");
586         spin_unlock_irqsave(&print_info_lock);
587 }
588
589 void test_barrier_handler(trapframe_t *tf, void* data)
590 {
591         cprintf("Round 1: Core %d\n", core_id());
592         waiton_barrier(&test_cpu_array);
593         waiton_barrier(&test_cpu_array);
594         waiton_barrier(&test_cpu_array);
595         waiton_barrier(&test_cpu_array);
596         waiton_barrier(&test_cpu_array);
597         waiton_barrier(&test_cpu_array);
598         cprintf("Round 2: Core %d\n", core_id());
599         waiton_barrier(&test_cpu_array);
600         cprintf("Round 3: Core %d\n", core_id());
601         // uncomment to see it fucked up
602         //cprintf("Round 4: Core %d\n", core_id());
603 }
604
605 static void test_waiting_handler(trapframe_t *tf, void* data)
606 {
607         {HANDLER_ATOMIC atomic_dec((atomic_t*)data);}
608 }
609
610 #if 0
611 void test_pit(void)
612 {
613         cprintf("Starting test for PIT now (10s)\n");
614         udelay_pit(10000000);
615         cprintf("End now\n");
616         cprintf("Starting test for TSC (if stable) now (10s)\n");
617         udelay(10000000);
618         cprintf("End now\n");
619
620         cprintf("Starting test for LAPIC (if stable) now (10s)\n");
621         enable_irq();
622         lapic_set_timer(10000000, FALSE);
623
624         atomic_t waiting = atomic_init(1);
625         register_interrupt_handler(interrupt_handlers, test_vector,
626                                    test_waiting_handler, &waiting);
627         while(atomic_read(&waiting))
628                 cpu_relax();
629         cprintf("End now\n");
630 }
631 #endif