devtime.c (1068:6330fe678283) devtime.c (2665:a124942bacb8)
1/*
2 * Copyright (c) 2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1/*
2 * Copyright (c) 2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
27 */
28
29#include <linux/module.h>
30#include <linux/config.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h>
33#include <linux/fs.h>
34#include <asm/uaccess.h>
35#include <linux/kernel.h>
36#include <asm/io.h>
37#include <asm/page.h>
38#include <linux/netdevice.h>
39
40#ifdef __i386__
41#include <asm/processor.h>
42#include <asm/msr.h>
43#endif
44
45#define DRIVER_AUTHOR "Ali Saidi"
46#define DRIVER_DESC "Interface to time uncacachable read and writes to device registers"
47#define DRIVER_VER "0.1"
48
49static char *dataAddr = NULL;
50static int count = 0;
51#ifdef __alpha__
52static int memTest = 0;
53#endif
54
55static inline uint32_t cycleCounter(uint32_t dep);
56
57static int __init devtime_start(void)
58{
59 uint64_t addr;
60 uint32_t t1, t2;
61 uint32_t trash;
62 int x;
63 uint32_t *times;
64 uint32_t num = 0;
65 struct net_device *dev;
66
67 printk("Devtime Driver Version %s Loaded...\n", DRIVER_VER);
68
69#ifdef __alpha__
70 if (memTest) {
71 addr = 0xfffffc0000000000;
72// addr += 16*1024*1024;
73
74 printk("Preparing memory test.\n");
75
76 t1 = cycleCounter(trash);
77 for (x = 0; x < count; x++) {
78 trash = readl(addr);
79 t2 = cycleCounter(trash);
80 times[num++] = t2 - t1;
81 t1 = t2;
82 addr += 4096;
83 }
84
85 printk("Measurements:\n");
86 for (x = 0; x < count; x++) {
87 printk("%d ", times[x]);
88 if (((x + 1) % 10) == 0)
89 printk("\n");
90 }
91 printk("\nDone.\n");
92 } else
93#endif
94 if (dataAddr != 0 && count != 0) {
95 addr = simple_strtoull(dataAddr, NULL, 0);
96
97 addr = ioremap(addr, PAGE_SIZE);
98 /**
99 * Make sure that the remapping actually worked. On alpha we have
100 * linear addressing, so its not a problem. But it can fail in x86
101 * if physical memory is mapped to this address.
102 */
103 times = kmalloc(sizeof(uint32_t) * count, GFP_USER);
104 if (!times) {
105 printk("Could not allocate memory... Try again later.\n");
106 return -1;
107 }
108
109 if (addr) {
110 printk("Preparing to read %#llx %d times.\n", addr, count);
111
112 t1 = cycleCounter(trash);
113 for (x = 0; x < count; x++) {
114 trash = readl(addr);
115 t2 = cycleCounter(trash);
116 times[num++] = t2 - t1;
117 t1 = t2;
118 }
119
120 /**
121 * Unmap the address.
122 */
123 iounmap(addr);
124
125 printk("Measurements:\n");
126 for (x = 0; x < count; x++) {
127 printk("%d ", times[x]);
128 if (((x + 1) % 10) == 0)
129 printk("\n");
130 }
131 printk("\nDone.\n");
132 } else {
133 printk("Unable to remap address. Please try again later.\n");
134 }
135 } else {
136 dev = dev_get_by_name("eth0");
137 if (dev) {
138 printk("Eth0: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
139 dev->mem_start, dev->mem_end, dev->base_addr);
140 dev_put(dev);
141 }
142 dev = 0;
143 dev = dev_get_by_name("eth1");
144 if (dev) {
145 printk("Eth1: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
146 dev->mem_start, dev->mem_end, dev->base_addr);
147 dev_put(dev);
148 }
149
150 printk("Required information not supplied.\n");
151 }
152
153 return 0;
154}
155
156#ifdef __i386__
157
158static inline uint32_t cycleCounter(uint32_t dep)
159{
160 uint32_t time;
161 cpuid_eax(0);
162 rdtscl(time);
163 cpuid_eax(0);
164 return time;
165}
166
167#elif __alpha__
168
169inline uint32_t cycleCounter(uint32_t dep)
170{
171 uint32_t res;
172 asm volatile ("rpcc %0, %1" : "=r"(res) : "r" (dep) : "memory");
173 return res;
174}
175#else
176#error Architecture NOT SUPPORTED
177#endif
178
179static void __exit devtime_end(void)
180{
181 printk("Devtime Driver Version %s Unloaded...\n", DRIVER_VER);
182}
183
184
185module_init(devtime_start);
186module_exit(devtime_end);
187
188MODULE_LICENSE("Dual BSD/GPL");
189MODULE_AUTHOR(DRIVER_AUTHOR);
190MODULE_DESCRIPTION(DRIVER_DESC);
191module_param(dataAddr, charp, 0);
192module_param(count, int, 0);
193#ifdef __alpha__
194module_param(memTest, int, 0);
195#endif
29 */
30
31#include <linux/module.h>
32#include <linux/config.h>
33#include <linux/moduleparam.h>
34#include <linux/init.h>
35#include <linux/fs.h>
36#include <asm/uaccess.h>
37#include <linux/kernel.h>
38#include <asm/io.h>
39#include <asm/page.h>
40#include <linux/netdevice.h>
41
42#ifdef __i386__
43#include <asm/processor.h>
44#include <asm/msr.h>
45#endif
46
47#define DRIVER_AUTHOR "Ali Saidi"
48#define DRIVER_DESC "Interface to time uncacachable read and writes to device registers"
49#define DRIVER_VER "0.1"
50
51static char *dataAddr = NULL;
52static int count = 0;
53#ifdef __alpha__
54static int memTest = 0;
55#endif
56
57static inline uint32_t cycleCounter(uint32_t dep);
58
59static int __init devtime_start(void)
60{
61 uint64_t addr;
62 uint32_t t1, t2;
63 uint32_t trash;
64 int x;
65 uint32_t *times;
66 uint32_t num = 0;
67 struct net_device *dev;
68
69 printk("Devtime Driver Version %s Loaded...\n", DRIVER_VER);
70
71#ifdef __alpha__
72 if (memTest) {
73 addr = 0xfffffc0000000000;
74// addr += 16*1024*1024;
75
76 printk("Preparing memory test.\n");
77
78 t1 = cycleCounter(trash);
79 for (x = 0; x < count; x++) {
80 trash = readl(addr);
81 t2 = cycleCounter(trash);
82 times[num++] = t2 - t1;
83 t1 = t2;
84 addr += 4096;
85 }
86
87 printk("Measurements:\n");
88 for (x = 0; x < count; x++) {
89 printk("%d ", times[x]);
90 if (((x + 1) % 10) == 0)
91 printk("\n");
92 }
93 printk("\nDone.\n");
94 } else
95#endif
96 if (dataAddr != 0 && count != 0) {
97 addr = simple_strtoull(dataAddr, NULL, 0);
98
99 addr = ioremap(addr, PAGE_SIZE);
100 /**
101 * Make sure that the remapping actually worked. On alpha we have
102 * linear addressing, so its not a problem. But it can fail in x86
103 * if physical memory is mapped to this address.
104 */
105 times = kmalloc(sizeof(uint32_t) * count, GFP_USER);
106 if (!times) {
107 printk("Could not allocate memory... Try again later.\n");
108 return -1;
109 }
110
111 if (addr) {
112 printk("Preparing to read %#llx %d times.\n", addr, count);
113
114 t1 = cycleCounter(trash);
115 for (x = 0; x < count; x++) {
116 trash = readl(addr);
117 t2 = cycleCounter(trash);
118 times[num++] = t2 - t1;
119 t1 = t2;
120 }
121
122 /**
123 * Unmap the address.
124 */
125 iounmap(addr);
126
127 printk("Measurements:\n");
128 for (x = 0; x < count; x++) {
129 printk("%d ", times[x]);
130 if (((x + 1) % 10) == 0)
131 printk("\n");
132 }
133 printk("\nDone.\n");
134 } else {
135 printk("Unable to remap address. Please try again later.\n");
136 }
137 } else {
138 dev = dev_get_by_name("eth0");
139 if (dev) {
140 printk("Eth0: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
141 dev->mem_start, dev->mem_end, dev->base_addr);
142 dev_put(dev);
143 }
144 dev = 0;
145 dev = dev_get_by_name("eth1");
146 if (dev) {
147 printk("Eth1: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
148 dev->mem_start, dev->mem_end, dev->base_addr);
149 dev_put(dev);
150 }
151
152 printk("Required information not supplied.\n");
153 }
154
155 return 0;
156}
157
158#ifdef __i386__
159
160static inline uint32_t cycleCounter(uint32_t dep)
161{
162 uint32_t time;
163 cpuid_eax(0);
164 rdtscl(time);
165 cpuid_eax(0);
166 return time;
167}
168
169#elif __alpha__
170
171inline uint32_t cycleCounter(uint32_t dep)
172{
173 uint32_t res;
174 asm volatile ("rpcc %0, %1" : "=r"(res) : "r" (dep) : "memory");
175 return res;
176}
177#else
178#error Architecture NOT SUPPORTED
179#endif
180
181static void __exit devtime_end(void)
182{
183 printk("Devtime Driver Version %s Unloaded...\n", DRIVER_VER);
184}
185
186
187module_init(devtime_start);
188module_exit(devtime_end);
189
190MODULE_LICENSE("Dual BSD/GPL");
191MODULE_AUTHOR(DRIVER_AUTHOR);
192MODULE_DESCRIPTION(DRIVER_DESC);
193module_param(dataAddr, charp, 0);
194module_param(count, int, 0);
195#ifdef __alpha__
196module_param(memTest, int, 0);
197#endif