Skip to content

Commit 6c0246a

Browse files
Peter Zijlstrawilldeacon
authored andcommitted
perf: Add perf_event_mmap_page::cap_user_time_short ABI
In order to support short clock counters, provide an ABI extension. As a whole: u64 time, delta, cyc = read_cycle_counter(); + if (cap_user_time_short) + cyc = time_cycle + ((cyc - time_cycle) & time_mask); delta = mul_u64_u32_shr(cyc, time_mult, time_shift); if (cap_user_time_zero) time = time_zero + delta; delta += time_offset; Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Leo Yan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 279a811 commit 6c0246a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

include/uapi/linux/perf_event.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,10 @@ struct perf_event_mmap_page {
532532
cap_bit0_is_deprecated : 1, /* Always 1, signals that bit 0 is zero */
533533

534534
cap_user_rdpmc : 1, /* The RDPMC instruction can be used to read counts */
535-
cap_user_time : 1, /* The time_* fields are used */
535+
cap_user_time : 1, /* The time_{shift,mult,offset} fields are used */
536536
cap_user_time_zero : 1, /* The time_zero field is used */
537-
cap_____res : 59;
537+
cap_user_time_short : 1, /* the time_{cycle,mask} fields are used */
538+
cap_____res : 58;
538539
};
539540
};
540541

@@ -593,13 +594,29 @@ struct perf_event_mmap_page {
593594
* ((rem * time_mult) >> time_shift);
594595
*/
595596
__u64 time_zero;
597+
596598
__u32 size; /* Header size up to __reserved[] fields. */
599+
__u32 __reserved_1;
600+
601+
/*
602+
* If cap_usr_time_short, the hardware clock is less than 64bit wide
603+
* and we must compute the 'cyc' value, as used by cap_usr_time, as:
604+
*
605+
* cyc = time_cycles + ((cyc - time_cycles) & time_mask)
606+
*
607+
* NOTE: this form is explicitly chosen such that cap_usr_time_short
608+
* is a correction on top of cap_usr_time, and code that doesn't
609+
* know about cap_usr_time_short still works under the assumption
610+
* the counter doesn't wrap.
611+
*/
612+
__u64 time_cycles;
613+
__u64 time_mask;
597614

598615
/*
599616
* Hole for extension of the self monitor capabilities
600617
*/
601618

602-
__u8 __reserved[118*8+4]; /* align to 1k. */
619+
__u8 __reserved[116*8]; /* align to 1k. */
603620

604621
/*
605622
* Control data for the mmap() data buffer.

0 commit comments

Comments
 (0)