]> git.proxmox.com Git - mirror_spl.git/blob - module/splat/splat-time.c
cd513c93f91f1a966d1ec4f4e40c4a3f3dc077c0
[mirror_spl.git] / module / splat / splat-time.c
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting LAyer Tests (SPLAT) Time Tests.
25 \*****************************************************************************/
26
27 #include <sys/time.h>
28 #include <linux/slab.h>
29 #include "splat-internal.h"
30
31 #define SPLAT_TIME_NAME "time"
32 #define SPLAT_TIME_DESC "Kernel Time Tests"
33
34 #define SPLAT_TIME_TEST1_ID 0x0801
35 #define SPLAT_TIME_TEST1_NAME "time1"
36 #define SPLAT_TIME_TEST1_DESC "HZ Test"
37
38 #define SPLAT_TIME_TEST2_ID 0x0802
39 #define SPLAT_TIME_TEST2_NAME "time2"
40 #define SPLAT_TIME_TEST2_DESC "Monotonic Test"
41
42 static int
43 splat_time_test1(struct file *file, void *arg)
44 {
45 int myhz = hz;
46 splat_vprint(file, SPLAT_TIME_TEST1_NAME, "hz is %d\n", myhz);
47 return 0;
48 }
49
50 static int
51 splat_time_test2(struct file *file, void *arg)
52 {
53 hrtime_t tm1, tm2;
54 int i;
55
56 tm1 = gethrtime();
57 splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm1);
58
59 for(i = 0; i < 100; i++) {
60 tm2 = gethrtime();
61 splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm2);
62
63 if(tm1 > tm2) {
64 splat_print(file, "%s: gethrtime() is not giving "
65 "monotonically increasing values\n",
66 SPLAT_TIME_TEST2_NAME);
67 return 1;
68 }
69 tm1 = tm2;
70
71 set_current_state(TASK_INTERRUPTIBLE);
72 schedule_timeout(10);
73 }
74
75 return 0;
76 }
77
78 splat_subsystem_t *
79 splat_time_init(void)
80 {
81 splat_subsystem_t *sub;
82
83 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
84 if (sub == NULL)
85 return NULL;
86
87 memset(sub, 0, sizeof(*sub));
88 strncpy(sub->desc.name, SPLAT_TIME_NAME, SPLAT_NAME_SIZE);
89 strncpy(sub->desc.desc, SPLAT_TIME_DESC, SPLAT_DESC_SIZE);
90 INIT_LIST_HEAD(&sub->subsystem_list);
91 INIT_LIST_HEAD(&sub->test_list);
92 spin_lock_init(&sub->test_lock);
93 sub->desc.id = SPLAT_SUBSYSTEM_TIME;
94
95 SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST1_NAME, SPLAT_TIME_TEST1_DESC,
96 SPLAT_TIME_TEST1_ID, splat_time_test1);
97 SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST2_NAME, SPLAT_TIME_TEST2_DESC,
98 SPLAT_TIME_TEST2_ID, splat_time_test2);
99
100 return sub;
101 }
102
103 void
104 splat_time_fini(splat_subsystem_t *sub)
105 {
106 ASSERT(sub);
107
108 SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST2_ID);
109 SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST1_ID);
110
111 kfree(sub);
112 }
113
114 int
115 splat_time_id(void)
116 {
117 return SPLAT_SUBSYSTEM_TIME;
118 }