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