Log In | Get Help   
Home My Page Projects Code Snippets Project Openings UPC Operations Microbenchmarking Suite
Summary Activity Tracker Lists Docs News SCM Files
[uoms] View of /trunk/uoms/src/timers/timers.c
[uoms] / trunk / uoms / src / timers / timers.c Repository:
ViewVC logotype

View of /trunk/uoms/src/timers/timers.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (download) (annotate)
Mon Nov 29 18:07:07 2010 UTC (13 years, 6 months ago) by dalvarez
File size: 4974 byte(s)
V1.1
/******************************************************************************/
/*                                                                            */
/*  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 <http://www.gnu.org/licenses/>.             */
/*                                                                            */
/******************************************************************************/

/******************************************************************************/
/*                                                                            */
/*    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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/* Get clock ticks */
uint64_t getTicks() {
#ifdef __ia64
	#ifdef __INTEL_COMPILER
		#include <ia64intrin.h>
		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 <errno.h>
	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
}

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge