From: Mathieu Desnoyers Date: Mon, 28 Sep 2015 15:44:49 +0000 (-0400) Subject: Cleanup: move generic caa_get_cycles to arch/generic.h X-Git-Tag: v0.9.0~20 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f8c43f458c80566d298d539ec518a8be8c7cc861;p=userspace-rcu.git Cleanup: move generic caa_get_cycles to arch/generic.h Eliminate some code duplication. It also implements a "generic" caa_get_cycles() on architectures where its support is not implemented. Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu/arch/aarch64.h b/urcu/arch/aarch64.h index 946e1c6..a68813d 100644 --- a/urcu/arch/aarch64.h +++ b/urcu/arch/aarch64.h @@ -33,19 +33,6 @@ extern "C" { #include #include -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - cycles_t thetime; - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return 0; - thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); - return (cycles_t)thetime; -} - /* * Define the membarrier system call number if not yet available in the * system headers. aarch64 implements asm-generic/unistd.h system call diff --git a/urcu/arch/alpha.h b/urcu/arch/alpha.h index f4ef3d7..e61f82c 100644 --- a/urcu/arch/alpha.h +++ b/urcu/arch/alpha.h @@ -33,13 +33,6 @@ extern "C" { #define cmm_wmb() __asm__ __volatile__ ("wmb":::"memory") #define cmm_read_barrier_depends() __asm__ __volatile__ ("mb":::"memory") -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - return 0; /* not supported */ -} - #ifdef __cplusplus } #endif diff --git a/urcu/arch/arm.h b/urcu/arch/arm.h index 1457166..9483bab 100644 --- a/urcu/arch/arm.h +++ b/urcu/arch/arm.h @@ -39,19 +39,6 @@ extern "C" { #include #include -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - cycles_t thetime; - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return 0; - thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); - return (cycles_t)thetime; -} - /* * Define the membarrier system call number if not yet available in the * system headers. diff --git a/urcu/arch/gcc.h b/urcu/arch/gcc.h index 5638f36..8684a16 100644 --- a/urcu/arch/gcc.h +++ b/urcu/arch/gcc.h @@ -33,19 +33,6 @@ extern "C" { #include #include -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - cycles_t thetime; - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return 0; - thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); - return (cycles_t)thetime; -} - #ifdef __cplusplus } #endif diff --git a/urcu/arch/generic.h b/urcu/arch/generic.h index 3f7521e..a80b3d6 100644 --- a/urcu/arch/generic.h +++ b/urcu/arch/generic.h @@ -150,6 +150,22 @@ extern "C" { #define caa_cpu_relax() cmm_barrier() #endif +#ifndef HAS_CAA_GET_CYCLES +#define HAS_CAA_GET_CYCLES +typedef unsigned long long cycles_t; + +static inline cycles_t caa_get_cycles (void) +{ + cycles_t thetime; + struct timeval tv; + + if (gettimeofday(&tv, NULL) != 0) + return 0; + thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); + return (cycles_t)thetime; +} +#endif /* HAS_CAA_GET_CYCLES */ + #ifdef __cplusplus } #endif diff --git a/urcu/arch/hppa.h b/urcu/arch/hppa.h index 61e8283..82d2a42 100644 --- a/urcu/arch/hppa.h +++ b/urcu/arch/hppa.h @@ -1,6 +1,26 @@ #ifndef _URCU_ARCH_HPPA_H #define _URCU_ARCH_HPPA_H +/* + * arch/hppa.h: definitions for hppa architecture + * + * Copyright (c) 2014 Helge Deller + * + * This library 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 2.1 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include #include #include @@ -12,6 +32,7 @@ extern "C" { #include #include +#define HAS_CAA_GET_CYCLES typedef unsigned long cycles_t; static inline cycles_t caa_get_cycles(void) diff --git a/urcu/arch/ia64.h b/urcu/arch/ia64.h index 7957685..12834f3 100644 --- a/urcu/arch/ia64.h +++ b/urcu/arch/ia64.h @@ -33,19 +33,6 @@ extern "C" { #include #include -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - cycles_t thetime; - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return 0; - thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); - return (cycles_t)thetime; -} - /* * Define the membarrier system call number if not yet available in the * system headers. diff --git a/urcu/arch/mips.h b/urcu/arch/mips.h index 4ecdc37..ea5b7e9 100644 --- a/urcu/arch/mips.h +++ b/urcu/arch/mips.h @@ -36,13 +36,6 @@ extern "C" { " .set mips0 \n" \ :::"memory") -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles(void) -{ - return 0; /* not supported */ -} - #ifdef __cplusplus } #endif diff --git a/urcu/arch/ppc.h b/urcu/arch/ppc.h index 1784ccd..0bef952 100644 --- a/urcu/arch/ppc.h +++ b/urcu/arch/ppc.h @@ -82,6 +82,8 @@ extern "C" { rval; \ }) +#define HAS_CAA_GET_CYCLES + typedef unsigned long long cycles_t; #ifdef __powerpc64__ diff --git a/urcu/arch/s390.h b/urcu/arch/s390.h index 6dc09a3..86a0a36 100644 --- a/urcu/arch/s390.h +++ b/urcu/arch/s390.h @@ -40,6 +40,8 @@ extern "C" { #define cmm_mb() __asm__ __volatile__("bcr 15,0" : : : "memory") +#define HAS_CAA_GET_CYCLES + typedef unsigned long long cycles_t; static inline cycles_t caa_get_cycles (void) diff --git a/urcu/arch/sparc64.h b/urcu/arch/sparc64.h index 2ccb86f..fb99450 100644 --- a/urcu/arch/sparc64.h +++ b/urcu/arch/sparc64.h @@ -45,13 +45,6 @@ __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \ #define cmm_rmb() membar_safe("#LoadLoad") #define cmm_wmb() membar_safe("#StoreStore") -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - return 0; /* unimplemented */ -} - #ifdef __cplusplus } #endif diff --git a/urcu/arch/tile.h b/urcu/arch/tile.h index 2787ac7..94dad40 100644 --- a/urcu/arch/tile.h +++ b/urcu/arch/tile.h @@ -33,19 +33,6 @@ extern "C" { #include #include -typedef unsigned long long cycles_t; - -static inline cycles_t caa_get_cycles (void) -{ - cycles_t thetime; - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return 0; - thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec); - return (cycles_t)thetime; -} - /* * Define the membarrier system call number if not yet available in the * system headers. tile implements asm-generic/unistd.h system call diff --git a/urcu/arch/x86.h b/urcu/arch/x86.h index ecc4b2d..afbf4fa 100644 --- a/urcu/arch/x86.h +++ b/urcu/arch/x86.h @@ -69,6 +69,8 @@ extern "C" { #define caa_cpu_relax() __asm__ __volatile__ ("rep; nop" : : : "memory") +#define HAS_CAA_GET_CYCLES + #define rdtscll(val) \ do { \ unsigned int __a, __d; \