]> git.proxmox.com Git - mirror_spl.git/blob - src/splat/splat-time.c
Initial commit. All spl source written up to this point wrapped
[mirror_spl.git] / src / splat / splat-time.c
1 #include <sys/zfs_context.h>
2 #include <sys/splat-ctl.h>
3
4 #define KZT_SUBSYSTEM_TIME 0x0800
5 #define KZT_TIME_NAME "time"
6 #define KZT_TIME_DESC "Kernel Time Tests"
7
8 #define KZT_TIME_TEST1_ID 0x0801
9 #define KZT_TIME_TEST1_NAME "time1"
10 #define KZT_TIME_TEST1_DESC "HZ Test"
11
12 #define KZT_TIME_TEST2_ID 0x0802
13 #define KZT_TIME_TEST2_NAME "time2"
14 #define KZT_TIME_TEST2_DESC "Monotonic Test"
15
16 static int
17 kzt_time_test1(struct file *file, void *arg)
18 {
19 int myhz = hz;
20 kzt_vprint(file, KZT_TIME_TEST1_NAME, "hz is %d\n", myhz);
21 return 0;
22 }
23
24 static int
25 kzt_time_test2(struct file *file, void *arg)
26 {
27 hrtime_t tm1, tm2;
28 int i;
29
30 tm1 = gethrtime();
31 kzt_vprint(file, KZT_TIME_TEST2_NAME, "time is %lld\n", tm1);
32
33 for(i = 0; i < 100; i++) {
34 tm2 = gethrtime();
35 kzt_vprint(file, KZT_TIME_TEST2_NAME, "time is %lld\n", tm2);
36
37 if(tm1 > tm2) {
38 kzt_print(file, "%s: gethrtime() is not giving monotonically increasing values\n", KZT_TIME_TEST2_NAME);
39 return 1;
40 }
41 tm1 = tm2;
42
43 set_current_state(TASK_INTERRUPTIBLE);
44 schedule_timeout(10);
45 }
46
47 return 0;
48 }
49
50 kzt_subsystem_t *
51 kzt_time_init(void)
52 {
53 kzt_subsystem_t *sub;
54
55 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
56 if (sub == NULL)
57 return NULL;
58
59 memset(sub, 0, sizeof(*sub));
60 strncpy(sub->desc.name, KZT_TIME_NAME, KZT_NAME_SIZE);
61 strncpy(sub->desc.desc, KZT_TIME_DESC, KZT_DESC_SIZE);
62 INIT_LIST_HEAD(&sub->subsystem_list);
63 INIT_LIST_HEAD(&sub->test_list);
64 spin_lock_init(&sub->test_lock);
65 sub->desc.id = KZT_SUBSYSTEM_TIME;
66
67 KZT_TEST_INIT(sub, KZT_TIME_TEST1_NAME, KZT_TIME_TEST1_DESC,
68 KZT_TIME_TEST1_ID, kzt_time_test1);
69 KZT_TEST_INIT(sub, KZT_TIME_TEST2_NAME, KZT_TIME_TEST2_DESC,
70 KZT_TIME_TEST2_ID, kzt_time_test2);
71
72 return sub;
73 }
74
75 void
76 kzt_time_fini(kzt_subsystem_t *sub)
77 {
78 ASSERT(sub);
79
80 KZT_TEST_FINI(sub, KZT_TIME_TEST2_ID);
81 KZT_TEST_FINI(sub, KZT_TIME_TEST1_ID);
82
83 kfree(sub);
84 }
85
86 int
87 kzt_time_id(void)
88 {
89 return KZT_SUBSYSTEM_TIME;
90 }