| 1 |
/* Time Base Facility API. API implementation. |
| 2 |
* |
| 3 |
* Copyright IBM Corp. 2014 |
| 4 |
* |
| 5 |
* The MIT License (MIT) |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
* of this software and associated documentation files (the "Software"), to deal |
| 9 |
* in the Software without restriction, including without limitation the rights |
| 10 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 |
* copies of the Software, and to permit persons to whom the Software is |
| 12 |
* furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included in |
| 15 |
* all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 |
* THE SOFTWARE. |
| 24 |
* |
| 25 |
* Contributors: |
| 26 |
* IBM Corporation, Adhemerval Zanella - Initial implementation. |
| 27 |
* IBM Corporation, Rajalakshmi S - Initial implementation. |
| 28 |
*/ |
| 29 |
#ifndef _PAF_TB_H |
| 30 |
#define _PAF_TB_H |
| 31 |
|
| 32 |
#include <stdint.h> |
| 33 |
|
| 34 |
/* We use 64bit values for the times. */ |
| 35 |
typedef uint64_t timing; |
| 36 |
|
| 37 |
static inline timing |
| 38 |
paf_timing_now () |
| 39 |
{ |
| 40 |
/* Read the Time Base Register. */ |
| 41 |
#ifdef __powerpc64__ |
| 42 |
timing val; |
| 43 |
__asm__ __volatile__ ("mfspr %0, 268":"=r" (val)); |
| 44 |
return val; |
| 45 |
#else |
| 46 |
timing hi, lo, tmp; |
| 47 |
__asm__ __volatile__ ("1: mfspr %0,269;" |
| 48 |
" mfspr %1,268;" |
| 49 |
" mfspr %2,269;" |
| 50 |
" cmpw %0,%2;" |
| 51 |
" bne 1b;" |
| 52 |
: "=&r" (hi), "=&r" (lo), "=&r" (tmp)); |
| 53 |
return (((uint64_t) hi << 32) | lo); |
| 54 |
#endif |
| 55 |
} |
| 56 |
|
| 57 |
static inline void |
| 58 |
paf_timing_accum (timing * sum, timing diff) |
| 59 |
{ |
| 60 |
*sum += diff; |
| 61 |
} |
| 62 |
|
| 63 |
static inline timing |
| 64 |
paf_timing_diff (timing start, timing end) |
| 65 |
{ |
| 66 |
timing diff; |
| 67 |
diff = end - start; |
| 68 |
return diff; |
| 69 |
} |
| 70 |
|
| 71 |
#endif |