/* * Copyright (c) 2005 Mellanox Technologies Ltd., * (c) 2005 Harald Welte . All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * $Id$ */ #include #include #include "get_clock.h" #if defined(__PPC64__) double get_cpu_mhz(void) { FILE *f; char buf[256]; double mhz = 0.0; f = fopen("/proc/cpuinfo","r"); if (!f) return 0.0; while (fgets(buf, sizeof(buf), f)) { unsigned long timebase; int rc; rc = sscanf(buf, "timebase : %lu", &timebase); if (rc != 1) continue; mhz = timebase / 1000000; break; } return mhz; } #elif defined(__PPC__) #define CLOCK_TICK_RATE 1193180 double get_cpu_mhz(void) { double mhz = CLOCK_TICK_RATE; mhz = mhz / 1000000; return mhz; } #else double get_cpu_mhz(void) { FILE* f; char buf[256]; double mhz = 0.0; f = fopen("/proc/cpuinfo","r"); if (!f) return 0.0; while(fgets(buf, sizeof(buf), f)) { double m; int rc; #if defined(__sparc__) unsigned long long um = 0; rc = sscanf(buf, "Cpu0ClkTck : %llx", &um); m = um; #else rc = sscanf(buf, "cpu MHz : %lf", &m); #endif if (rc != 1) continue; if (mhz == 0.0) { #if defined(__sparc__) mhz = m / 1000000; #else mhz = m; #endif continue; } if (mhz != m) { fprintf(stderr,"Conflicting CPU frequency values" " detected: %lf != %lf\n", mhz, m); return 0.0; } } fclose(f); return mhz; } #endif /* cycle count initialization */ int cycles_init(void) { return 0; }