]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
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>. | |
715f6251 | 6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
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. | |
715f6251 | 15 | * |
716154c5 | 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 | 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 | |
716154c5 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
23 | ***************************************************************************** | |
24 | * Solaris Porting LAyer Tests (SPLAT) Time Tests. | |
25 | \*****************************************************************************/ | |
715f6251 | 26 | |
df870a69 | 27 | #include <sys/time.h> |
52479ecf | 28 | #include <linux/mm_compat.h> |
79a7ab25 | 29 | #include <linux/slab.h> |
7c50328b | 30 | #include "splat-internal.h" |
f1ca4da6 | 31 | |
7c50328b | 32 | #define SPLAT_TIME_NAME "time" |
33 | #define SPLAT_TIME_DESC "Kernel Time Tests" | |
f1ca4da6 | 34 | |
7c50328b | 35 | #define SPLAT_TIME_TEST1_ID 0x0801 |
36 | #define SPLAT_TIME_TEST1_NAME "time1" | |
37 | #define SPLAT_TIME_TEST1_DESC "HZ Test" | |
f1ca4da6 | 38 | |
7c50328b | 39 | #define SPLAT_TIME_TEST2_ID 0x0802 |
40 | #define SPLAT_TIME_TEST2_NAME "time2" | |
41 | #define SPLAT_TIME_TEST2_DESC "Monotonic Test" | |
f1ca4da6 | 42 | |
43 | static int | |
7c50328b | 44 | splat_time_test1(struct file *file, void *arg) |
f1ca4da6 | 45 | { |
46 | int myhz = hz; | |
7c50328b | 47 | splat_vprint(file, SPLAT_TIME_TEST1_NAME, "hz is %d\n", myhz); |
f1ca4da6 | 48 | return 0; |
49 | } | |
50 | ||
51 | static int | |
7c50328b | 52 | splat_time_test2(struct file *file, void *arg) |
f1ca4da6 | 53 | { |
54 | hrtime_t tm1, tm2; | |
55 | int i; | |
56 | ||
57 | tm1 = gethrtime(); | |
7c50328b | 58 | splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm1); |
f1ca4da6 | 59 | |
60 | for(i = 0; i < 100; i++) { | |
61 | tm2 = gethrtime(); | |
7c50328b | 62 | splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm2); |
f1ca4da6 | 63 | |
64 | if(tm1 > tm2) { | |
7c50328b | 65 | splat_print(file, "%s: gethrtime() is not giving " |
66 | "monotonically increasing values\n", | |
67 | SPLAT_TIME_TEST2_NAME); | |
f1ca4da6 | 68 | return 1; |
69 | } | |
70 | tm1 = tm2; | |
71 | ||
72 | set_current_state(TASK_INTERRUPTIBLE); | |
73 | schedule_timeout(10); | |
74 | } | |
75 | ||
76 | return 0; | |
77 | } | |
78 | ||
7c50328b | 79 | splat_subsystem_t * |
80 | splat_time_init(void) | |
f1ca4da6 | 81 | { |
7c50328b | 82 | splat_subsystem_t *sub; |
f1ca4da6 | 83 | |
84 | sub = kmalloc(sizeof(*sub), GFP_KERNEL); | |
85 | if (sub == NULL) | |
86 | return NULL; | |
87 | ||
88 | memset(sub, 0, sizeof(*sub)); | |
7c50328b | 89 | strncpy(sub->desc.name, SPLAT_TIME_NAME, SPLAT_NAME_SIZE); |
90 | strncpy(sub->desc.desc, SPLAT_TIME_DESC, SPLAT_DESC_SIZE); | |
f1ca4da6 | 91 | INIT_LIST_HEAD(&sub->subsystem_list); |
92 | INIT_LIST_HEAD(&sub->test_list); | |
93 | spin_lock_init(&sub->test_lock); | |
7c50328b | 94 | sub->desc.id = SPLAT_SUBSYSTEM_TIME; |
f1ca4da6 | 95 | |
9c9ad845 | 96 | splat_test_init(sub, SPLAT_TIME_TEST1_NAME, SPLAT_TIME_TEST1_DESC, |
7c50328b | 97 | SPLAT_TIME_TEST1_ID, splat_time_test1); |
9c9ad845 | 98 | splat_test_init(sub, SPLAT_TIME_TEST2_NAME, SPLAT_TIME_TEST2_DESC, |
7c50328b | 99 | SPLAT_TIME_TEST2_ID, splat_time_test2); |
f1ca4da6 | 100 | |
101 | return sub; | |
102 | } | |
103 | ||
104 | void | |
7c50328b | 105 | splat_time_fini(splat_subsystem_t *sub) |
f1ca4da6 | 106 | { |
107 | ASSERT(sub); | |
108 | ||
9c9ad845 CC |
109 | splat_test_fini(sub, SPLAT_TIME_TEST2_ID); |
110 | splat_test_fini(sub, SPLAT_TIME_TEST1_ID); | |
f1ca4da6 | 111 | |
112 | kfree(sub); | |
113 | } | |
114 | ||
115 | int | |
7c50328b | 116 | splat_time_id(void) |
f1ca4da6 | 117 | { |
7c50328b | 118 | return SPLAT_SUBSYSTEM_TIME; |
f1ca4da6 | 119 | } |