/*****************************************************************************/
/* */
/* Copyright (c) 2008, 2009, 2010 */
/* Computer Architecture Group (CAG) */
/* University of A Coruña, Spain */
/* (http://gac.des.udc.es) */
/* Galicia Supercomputing Center (CESGA) */
/* (http://www.cesga.es) */
/* Hewlett-Packard Spain (HP) */
/* (http://www.hp.es) */
/* */
/* This file is part of UPC Operations Microbenchmarking Suite (UOMS). */
/* */
/* UOMS is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public License as published */
/* by the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* UOMS 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 Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with UOMS. If not, see . */
/* */
/*****************************************************************************/
/*****************************************************************************/
/* */
/* FUNDING: This development has been funded by Hewlett-Packard Spain */
/* */
/* Project Name: */
/* UPCHACO (2008-2011) */
/* Subproject: */
/* Improving UPC Usability and Performance in Constellation Systems: */
/* Implementation/Extensions of UPC Libraries. */
/* (UPCPUProject -> UPC Performance and Usability Project) */
/* */
/*****************************************************************************/
/*****************************************************************************
For further documentation, see
[1] Files under doc/
******************************************************************************/
#include
#include
#include
#include
/* Get clock ticks */
uint64_t getTicks() {
#ifdef __ia64
#ifdef __INTEL_COMPILER
#include
return (uint64_t)__getReg(_IA64_REG_AR_ITC);
#else
uint64_t ret = 0;
__asm__ __volatile__("mov %0=ar.itc" : "=r"(ret) );
return ret;
#endif
#else
#ifdef __HP_UPC_VER
return hpupc_ticks_now();
#elif __BERKELEY_UPC__
return bupc_ticks_now();
#else
uint64_t tstamp;
struct timeval tv;
if (gettimeofday(&tv, NULL)) {
perror("gettimeofday");
abort();
}
tstamp = (((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec)*1000;
return tstamp;
#endif
#endif
}
/* Ticks to nanoseconds */
uint64_t ticksToNS(uint64_t ticks) {
#ifdef __ia64
#include
double tick_rate_ns = 0;
errno = 0;
FILE *fp = fopen("/proc/cpuinfo","r");
if (errno != 0){
perror("*** Error opening /proc/cpuinfo: ");
exit(-1);
}
char input[255];
while (!feof(fp) && fgets(input, 255, fp)) {
if (strstr(input,"itc MHz")) {
char *p = strchr(input,':');
double MHz = 0.0;
if (p) MHz = atof(p+1);
if(!(MHz > 1 && MHz < 100000)) /* ensure it looks reasonable */
fprintf(stderr, "*** Warning: ITC frequency unreasonable: %f MHz\n*** Expect unexpected results\n",MHz);
tick_rate_ns = 1000. / MHz;
break;
}
}
fclose(fp);
return (ticks * tick_rate_ns);
#else
#ifdef __HP_UPC_VER
return hpupc_ticks_to_ns(ticks);
#elif __BERKELEY_UPC__
return bupc_ticks_to_ns(ticks);
#else // if gettimeofday is used
return ticks;
#endif
#endif
}