Re: [RFC] perf: need to expose sched_clock to correlate user sampleswith kernel samples

From: David Ahern
Date: Mon Feb 18 2013 - 13:59:32 EST

On 2/18/13 8:16 AM, Stephane Eranian wrote:

I think the advantage of the ioctl() is that is reuses existing infrastructure.
The downside is that to get the timestamp you need at a minimum:

uint64_t get_perf_timestamp(void)
struct perf_event_attr attr;
uint64_t ts = 0;
int fd;

memset(&attr, 0, sizeof(attr));

/* pick a dummy SW event (no PMU HW resource allocated), keep it disabled */
attr.config = PERF_COUNT_SW_CPU_CLOCK; /* dummy event */
attr.disabled = 1;

/* attach to self in per-thread mode */
fd = perf_event_open(&attr, 0, -1, -1, 0);
if (fd == -1)
return 0;

ioctl(fd, PERF_EVENT_IOC_GET_TIME, &ts);

return ts;

That's the approach I took with an update to my perf_clock to time-of-day series. Specific patch:

and series:

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at