import cbaos v0.1
[cbaos.git] / test / benchmark.c
blobba0f6d071db8db58163d69d746d2890e69a23a8c
1 /* Author: Domen Puncer <domen@cba.si>. License: WTFPL, see file LICENSE */
2 #include <stdio.h>
4 #include <sched.h>
5 #include <lock.h>
6 #include <compiler.h>
9 static int bench0_count;
10 static int bench1_count;
12 static void bench0(u32 arg)
14 while (1) {
15 bench0_count++;
16 sched_yield();
20 static void bench1(u32 arg)
22 while (1) {
23 bench1_count++;
24 sched_yield();
28 /* hmm... context switch here takes >5us, on chibios it's 1.2us, improve when bored */
29 static void bench_print(u32 arg)
31 while (1) {
32 struct lock l;
33 lock(&l);
34 printf("context switches 0:%i, 1:%i\n", bench0_count, bench1_count);
35 unlock(&l);
36 msleep(1000);
41 #ifdef ARCH_UNIX
42 #define STACK 2048
43 #else
44 #define STACK 128
45 #endif
46 static u32 s1[STACK];
47 static u32 s2[STACK];
48 static u32 s3[STACK];
49 static struct task t1, t2, t3;
51 void benchmark()
53 t1 = (struct task) {
54 .name = "t1",
55 .stack = s1,
56 .stack_len = ALEN(s1),
59 t2 = (struct task) {
60 .name = "t2",
61 .stack = s2,
62 .stack_len = ALEN(s2),
65 t3 = (struct task) {
66 .name = "t3",
67 .stack = s3,
68 .stack_len = ALEN(s3),
71 sched_init();
73 task_new(&t1, bench0, 0, 0);
74 task_new(&t2, bench1, 0, 0);
75 task_new(&t3, bench_print, 0, 0);
77 sched_start();