summaryrefslogtreecommitdiffstats
path: root/core/test/run-timer.c
blob: 159e007acd7ccebfca376cf70c0bba7da88b49aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

#define __TEST__
#include <timer.h>
#include <skiboot.h>

#define mftb()	(stamp)
#define sync()
#define smt_lowest()
#define smt_medium()

enum proc_gen proc_gen = proc_gen_p9;

static uint64_t stamp, last;
struct lock;
static inline void lock_caller(struct lock *l, const char *caller)
{
	(void)caller;
	(void)l;
}
static inline void unlock(struct lock *l) { (void)l; }

unsigned long tb_hz = 512000000;

#include "../timer.c"

#define NUM_TIMERS	100

static struct timer timers[NUM_TIMERS];
static unsigned int rand_shift, count;

static void init_rand(void)
{
	unsigned long max = RAND_MAX;

	/* Get something reasonably small */
	while(max > 0x10000) {
		rand_shift++;
		max >>= 1;
	}
}

static void expiry(struct timer *t, void *data, uint64_t now)
{
	(void)data;
	(void)now;
	assert(t->target >= last);
	count--;
}

void p8_sbe_update_timer_expiry(uint64_t new_target)
{
	(void)new_target;
	/* FIXME: do intersting SLW timer sim */
}

void p9_sbe_update_timer_expiry(uint64_t new_target)
{
	(void)new_target;
}

int main(void)
{
	unsigned int i;

	init_rand();
	for (i = 0; i < NUM_TIMERS; i++) {
		init_timer(&timers[i], expiry, NULL);
		schedule_timer(&timers[i], random() >> rand_shift);
	}
	count = NUM_TIMERS;
	while(count) {
		check_timers(false);
		stamp++;
	}
	return 0;
}
OpenPOWER on IntegriCloud