@@ -444,7 +444,16 @@ Record running and enabled time for read events (:S)
Sets the clock id to use for the various time fields in the perf_event_type
records. See clock_gettime(). In particular CLOCK_MONOTONIC and
CLOCK_MONOTONIC_RAW are supported, some events might also allow
-CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI.
+CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. In addition, the kernel might
+support CLOCK_PERF_HW_CLOCK to select an architecture dependent hardware
+clock, for which the unit of time is ticks not nanoseconds. On x86,
+CLOCK_PERF_HW_CLOCK is provided by the rdtsc instruction, and is not
+paravirtualized. There is also CLOCK_PERF_HW_CLOCK_NS which is the same as
+CLOCK_PERF_HW_CLOCK, but converted to nanoseconds. Note support of
+CLOCK_PERF_HW_CLOCK_NS does not necessarily imply support of
+CLOCK_PERF_HW_CLOCK or vice versa. Be warned, CLOCK_PERF_HW_CLOCK and
+CLOCK_PERF_HW_CLOCK_NS may not be stable or well-behaved in any way,
+including varying across different CPUs. That warning can also apply to TSC.
-S::
--snapshot::
@@ -1973,7 +1973,7 @@ static int record__init_clock(struct record *rec)
struct timeval ref_tod;
u64 ref;
- if (!rec->opts.use_clockid)
+ if (!rec->opts.use_clockid || rec->opts.clockid >= CLOCK_PERF_HW_CLOCK)
return 0;
if (rec->opts.use_clockid && rec->opts.clockid_res_ns)
@@ -49,6 +49,9 @@ static const struct clockid_map clockids[] = {
CLOCKID_MAP("real", CLOCK_REALTIME),
CLOCKID_MAP("boot", CLOCK_BOOTTIME),
+ CLOCKID_MAP("perf_hw_clock", CLOCK_PERF_HW_CLOCK),
+ CLOCKID_MAP("perf_hw_clock_ns", CLOCK_PERF_HW_CLOCK_NS),
+
CLOCKID_END,
};
@@ -57,6 +60,8 @@ static int get_clockid_res(clockid_t clk_id, u64 *res_ns)
struct timespec res;
*res_ns = 0;
+ if (clk_id >= CLOCK_PERF_HW_CLOCK)
+ return 0;
if (!clock_getres(clk_id, &res))
*res_ns = res.tv_nsec + res.tv_sec * NSEC_PER_SEC;
else
@@ -8,4 +8,12 @@ int parse_clockid(const struct option *opt, const char *str, int unset);
const char *clockid_name(clockid_t clk_id);
+#ifndef CLOCK_PERF_HW_CLOCK
+#define CLOCK_PERF_HW_CLOCK 0x10000000
+#endif
+
+#ifndef CLOCK_PERF_HW_CLOCK_NS
+#define CLOCK_PERF_HW_CLOCK_NS 0x10000001
+#endif
+
#endif
Add support for new clock IDs CLOCK_PERF_HW_CLOCK and CLOCK_PERF_HW_CLOCK_NS. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> --- tools/perf/Documentation/perf-record.txt | 11 ++++++++++- tools/perf/builtin-record.c | 2 +- tools/perf/util/clockid.c | 5 +++++ tools/perf/util/clockid.h | 8 ++++++++ 4 files changed, 24 insertions(+), 2 deletions(-)