8 #include <linux/kernel.h>
9 #include <linux/sched.h>
13 #include <linux/slab.h>
37 static volatile int running;
41 while (get_tb() < mark)
42 tbsync->race_result =
add;
58 while (!tbsync->handshake)
69 while (tbsync->handshake)
72 set_tb(tb >> 32, tb & 0xfffffffful);
73 enter_contest(tbsync->mark, -1);
87 for (i = -3; i < num; ) {
90 tbsync->mark = mark = tb + 400;
94 tbsync->handshake = 1;
98 while (get_tb() <= tb)
100 tbsync->handshake = 0;
101 enter_contest(mark, 1);
107 score += tbsync->race_result;
115 int i, score, score2, old,
min=0,
max=5000, offset=1000;
117 pr_debug(
"Software timebase sync\n");
120 tbsync = kzalloc(
sizeof(*tbsync),
GFP_KERNEL );
130 for (old = -1; old !=
offset ; offset = (min+
max) / 2) {
133 pr_debug(
"score %d, offset %d\n", score, offset );
144 pr_debug(
"Min %d (score %d), Max %d (score %d)\n",
145 min, score,
max, score2);
147 score2 =
abs(score2);
148 offset = (score < score2) ? min :
max;
151 for (i = 0; i < 10; i++) {
156 if (score2 <= score || score2 < 20)
164 tbsync->handshake = 1;
167 tbsync->handshake = 0;