]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/splat/splat-time.c
More cleanup.
[mirror_spl-debian.git] / modules / splat / splat-time.c
CommitLineData
7c50328b 1#include "splat-internal.h"
f1ca4da6 2
7c50328b 3#define SPLAT_SUBSYSTEM_TIME 0x0800
4#define SPLAT_TIME_NAME "time"
5#define SPLAT_TIME_DESC "Kernel Time Tests"
f1ca4da6 6
7c50328b 7#define SPLAT_TIME_TEST1_ID 0x0801
8#define SPLAT_TIME_TEST1_NAME "time1"
9#define SPLAT_TIME_TEST1_DESC "HZ Test"
f1ca4da6 10
7c50328b 11#define SPLAT_TIME_TEST2_ID 0x0802
12#define SPLAT_TIME_TEST2_NAME "time2"
13#define SPLAT_TIME_TEST2_DESC "Monotonic Test"
f1ca4da6 14
15static int
7c50328b 16splat_time_test1(struct file *file, void *arg)
f1ca4da6 17{
18 int myhz = hz;
7c50328b 19 splat_vprint(file, SPLAT_TIME_TEST1_NAME, "hz is %d\n", myhz);
f1ca4da6 20 return 0;
21}
22
23static int
7c50328b 24splat_time_test2(struct file *file, void *arg)
f1ca4da6 25{
26 hrtime_t tm1, tm2;
27 int i;
28
29 tm1 = gethrtime();
7c50328b 30 splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm1);
f1ca4da6 31
32 for(i = 0; i < 100; i++) {
33 tm2 = gethrtime();
7c50328b 34 splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm2);
f1ca4da6 35
36 if(tm1 > tm2) {
7c50328b 37 splat_print(file, "%s: gethrtime() is not giving "
38 "monotonically increasing values\n",
39 SPLAT_TIME_TEST2_NAME);
f1ca4da6 40 return 1;
41 }
42 tm1 = tm2;
43
44 set_current_state(TASK_INTERRUPTIBLE);
45 schedule_timeout(10);
46 }
47
48 return 0;
49}
50
7c50328b 51splat_subsystem_t *
52splat_time_init(void)
f1ca4da6 53{
7c50328b 54 splat_subsystem_t *sub;
f1ca4da6 55
56 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
57 if (sub == NULL)
58 return NULL;
59
60 memset(sub, 0, sizeof(*sub));
7c50328b 61 strncpy(sub->desc.name, SPLAT_TIME_NAME, SPLAT_NAME_SIZE);
62 strncpy(sub->desc.desc, SPLAT_TIME_DESC, SPLAT_DESC_SIZE);
f1ca4da6 63 INIT_LIST_HEAD(&sub->subsystem_list);
64 INIT_LIST_HEAD(&sub->test_list);
65 spin_lock_init(&sub->test_lock);
7c50328b 66 sub->desc.id = SPLAT_SUBSYSTEM_TIME;
f1ca4da6 67
7c50328b 68 SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST1_NAME, SPLAT_TIME_TEST1_DESC,
69 SPLAT_TIME_TEST1_ID, splat_time_test1);
70 SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST2_NAME, SPLAT_TIME_TEST2_DESC,
71 SPLAT_TIME_TEST2_ID, splat_time_test2);
f1ca4da6 72
73 return sub;
74}
75
76void
7c50328b 77splat_time_fini(splat_subsystem_t *sub)
f1ca4da6 78{
79 ASSERT(sub);
80
7c50328b 81 SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST2_ID);
82 SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST1_ID);
f1ca4da6 83
84 kfree(sub);
85}
86
87int
7c50328b 88splat_time_id(void)
f1ca4da6 89{
7c50328b 90 return SPLAT_SUBSYSTEM_TIME;
f1ca4da6 91}