devtime.c revision 963
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 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 <linux/netdevice.h> 38 39#ifdef __i386__ 40#include <asm/processor.h> 41#include <asm/msr.h> 42#endif 43 44#define DRIVER_AUTHOR "Ali Saidi" 45#define DRIVER_DESC "Interface to time uncacachable read and writes to device registers" 46#define DRIVER_VER "0.1" 47 48static unsigned long devCnt, devSum, devSsq; 49static char *dataAddr = NULL; 50static int count = 0; 51 52static inline uint32_t cycleCounter(uint32_t dep); 53 54static int __init devtime_start(void) 55{ 56 uint64_t addr; 57 uint32_t t1, t2; 58 uint32_t trash; 59 int x; 60 61 struct net_device *dev; 62 63 64 printk("Devtime Driver Version %s Loaded...\n", DRIVER_VER); 65 66 if ((dataAddr != 0) && (count != 0)) 67 { 68 addr = simple_strtoull(dataAddr, NULL, 0); 69 70 devSum = 0; 71 devCnt = count; 72 73 printk("Preparing to read %#llx %d times.\n", addr, count); 74 75 t1 = cycleCounter(trash); 76 for (x=0; x < count; x++) 77 { 78 trash = readl(addr); 79 t2 = cycleCounter(trash); 80 devSum += t2 - t1; 81 t1 = t2; 82 } 83 84 printk("Read Address %#llx %ld times. Average latency %ld.\n", addr, devCnt, devSum/devCnt); 85 } else { 86 dev = dev_get_by_name("eth0"); 87 if (dev) 88 { 89 printk("Eth0: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n", dev->mem_start, 90 dev->mem_end, dev->base_addr); 91 dev_put(dev); 92 } 93 dev = dev_get_by_name("eth1"); 94 if (dev) 95 { 96 printk("Eth1: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n", dev->mem_start, 97 dev->mem_end, dev->base_addr); 98 dev_put(dev); 99 } 100 101 102 printk("Required information not supplied.\n"); 103 } 104 105 return 0; 106} 107 108#ifdef __i386__ 109 110static inline uint32_t cycleCounter(uint32_t dep) 111{ 112 uint32_t time; 113 cpuid_eax(0); 114 rdtscl(time); 115 cpuid_eax(0); 116 return time; 117} 118 119#elif __alpha__ 120 121inline uint32_t cycleCounter(uint32_t dep) 122{ 123 uint32_t res; 124 asm volatile ("rpcc %0, %1" : "=r"(res) : "r" (dep) : "memory"); 125 return res; 126} 127#else 128#error Architecture NOT SUPPORTE 129#endif 130 131static void __exit devtime_end(void) { 132 printk("Devtime Driver Version %s Unloaded...\n", DRIVER_VER); 133} 134 135 136module_init(devtime_start); 137module_exit(devtime_end); 138 139MODULE_LICENSE("BSD"); 140MODULE_AUTHOR(DRIVER_AUTHOR); 141MODULE_DESCRIPTION(DRIVER_DESC); 142module_param(dataAddr, charp, 0); 143module_param(count, int, 0); 144