aboutsummaryrefslogtreecommitdiffstats
path: root/modules/splat/splat-time.c
blob: 1aa13e52010519071dfd2da03098bd4199ab13a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 *  This file is part of the SPL: Solaris Porting Layer.
 *
 *  Copyright (c) 2008 Lawrence Livermore National Security, LLC.
 *  Produced at Lawrence Livermore National Laboratory
 *  Written by:
 *          Brian Behlendorf <behlendorf1@llnl.gov>,
 *          Herb Wartens <wartens2@llnl.gov>,
 *          Jim Garlick <garlick@llnl.gov>
 *  UCRL-CODE-235197
 *
 *  This is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This is distributed in the hope that it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
 */

#include "splat-internal.h"

#define SPLAT_SUBSYSTEM_TIME		0x0800
#define SPLAT_TIME_NAME			"time"
#define SPLAT_TIME_DESC			"Kernel Time Tests"

#define SPLAT_TIME_TEST1_ID		0x0801
#define SPLAT_TIME_TEST1_NAME		"time1"
#define SPLAT_TIME_TEST1_DESC		"HZ Test"

#define SPLAT_TIME_TEST2_ID		0x0802
#define SPLAT_TIME_TEST2_NAME		"time2"
#define SPLAT_TIME_TEST2_DESC		"Monotonic Test"

static int
splat_time_test1(struct file *file, void *arg)
{
	int myhz = hz;
	splat_vprint(file, SPLAT_TIME_TEST1_NAME, "hz is %d\n", myhz);
        return 0;
}

static int
splat_time_test2(struct file *file, void *arg)
{
        hrtime_t tm1, tm2;
	int i;

        tm1 = gethrtime();
        splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm1);

        for(i = 0; i < 100; i++) {
                tm2 = gethrtime();
                splat_vprint(file, SPLAT_TIME_TEST2_NAME, "time is %lld\n", tm2);

                if(tm1 > tm2) {
                        splat_print(file, "%s: gethrtime() is not giving "
				    "monotonically increasing values\n",
				    SPLAT_TIME_TEST2_NAME);
                        return 1;
                }
                tm1 = tm2;

                set_current_state(TASK_INTERRUPTIBLE);
                schedule_timeout(10);
        }

        return 0;
}

splat_subsystem_t *
splat_time_init(void)
{
        splat_subsystem_t *sub;

        sub = kmalloc(sizeof(*sub), GFP_KERNEL);
        if (sub == NULL)
                return NULL;

        memset(sub, 0, sizeof(*sub));
        strncpy(sub->desc.name, SPLAT_TIME_NAME, SPLAT_NAME_SIZE);
	strncpy(sub->desc.desc, SPLAT_TIME_DESC, SPLAT_DESC_SIZE);
        INIT_LIST_HEAD(&sub->subsystem_list);
	INIT_LIST_HEAD(&sub->test_list);
        spin_lock_init(&sub->test_lock);
        sub->desc.id = SPLAT_SUBSYSTEM_TIME;

        SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST1_NAME, SPLAT_TIME_TEST1_DESC,
	              SPLAT_TIME_TEST1_ID, splat_time_test1);
        SPLAT_TEST_INIT(sub, SPLAT_TIME_TEST2_NAME, SPLAT_TIME_TEST2_DESC,
	              SPLAT_TIME_TEST2_ID, splat_time_test2);

        return sub;
}

void
splat_time_fini(splat_subsystem_t *sub)
{
        ASSERT(sub);

        SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST2_ID);
        SPLAT_TEST_FINI(sub, SPLAT_TIME_TEST1_ID);

        kfree(sub);
}

int
splat_time_id(void)
{
        return SPLAT_SUBSYSTEM_TIME;
}