| 1 |
// timestamp tapset -- gettimeofday variants |
| 2 |
// Copyright (C) 2005-2009 Red Hat Inc. |
| 3 |
// Copyright (C) 2006 Intel Corporation. |
| 4 |
// Copyright (C) 2019 Red Hat Inc. |
| 5 |
// |
| 6 |
// This file is part of systemtap, and is free software. You can |
| 7 |
// redistribute it and/or modify it under the terms of the GNU General |
| 8 |
// Public License (GPL); either version 2, or (at your option) any |
| 9 |
// later version. |
| 10 |
|
| 11 |
global __gtod_offset = 0 /* offset of (gettimeofday_ns() - ktime_get_ns()) */ |
| 12 |
|
| 13 |
/** |
| 14 |
* Description: This function returns the result of system's gettimeofday_ns(). |
| 15 |
* It is only callable from systemtap's user-space bpf interpreter |
| 16 |
* which has a function backing up this particular call number. |
| 17 |
* Its only purpose is to provide information to compute __gtod_offset |
| 18 |
* so the built-in ktime_get_ns() can be converted for gettimeofday_*(). |
| 19 |
*/ |
| 20 |
function __gtod_get_ns:long () |
| 21 |
%{ /* bpf */ /* pure */ /* unprivileged */ /* userspace */ |
| 22 |
0x85, 0, 0, 0, -4; /* call BPF_FUNC_gtod_get_ns */ |
| 23 |
0xbf, $$, 0, 0, 0 /* movx $$, r0 */ |
| 24 |
%} |
| 25 |
|
| 26 |
probe init |
| 27 |
{ |
| 28 |
/* compute an offset so ktime_get_ns() can be converted into gettimeofday_*() */ |
| 29 |
__gtod_offset = __gtod_get_ns() - ktime_get_ns(); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* sfunction gettimeofday_ns - Number of nanoseconds since UNIX epoch |
| 34 |
* |
| 35 |
* Description: This function returns the number of nanoseconds |
| 36 |
* since the UNIX epoch. |
| 37 |
*/ |
| 38 |
function gettimeofday_ns:long () |
| 39 |
{ /* pure */ /* unprivileged */ |
| 40 |
return (ktime_get_ns() + __gtod_offset) |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* sfunction gettimeofday_us - Number of microseconds since UNIX epoch |
| 45 |
* |
| 46 |
* Description: This function returns the number of microseconds |
| 47 |
* since the UNIX epoch. |
| 48 |
*/ |
| 49 |
function gettimeofday_us:long () { |
| 50 |
return gettimeofday_ns() / 1000; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* sfunction gettimeofday_ms - Number of milliseconds since UNIX epoch |
| 55 |
* |
| 56 |
* Description: This function returns the number of milliseconds |
| 57 |
* since the UNIX epoch. |
| 58 |
*/ |
| 59 |
function gettimeofday_ms:long () { |
| 60 |
return gettimeofday_ns() / 1000000; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* sfunction gettimeofday_s - Number of seconds since UNIX epoch |
| 65 |
* |
| 66 |
* Description: This function returns the number of seconds since |
| 67 |
* the UNIX epoch. |
| 68 |
*/ |
| 69 |
function gettimeofday_s:long () { |
| 70 |
return gettimeofday_ns() / 1000000000; |
| 71 |
} |