For modern CPUs, perf clock is directly related to TSC. TSC can be calculated from perf clock and vice versa using a simple calculation. Two of the three componenets of that calculation are already exported in struct perf_event_mmap_page. This patch exports the third.
Showing the changes to include/uapi/linux (1 of 4 files). Show all
Unified · Split
| @@ -378,7 +378,8 @@ struct perf_event_mmap_page { · 377 unmodified lines | |||
| 378 | struct { | 378 | struct { |
| 379 | __u64 cap_usr_time : 1, | 379 | __u64 cap_usr_time : 1, |
| 380 | cap_usr_rdpmc : 1, | 380 | cap_usr_rdpmc : 1, |
| 381 | cap_____res : 62; | 381 | cap_usr_time_zero : 1, |
| 382 | cap_____res : 61; | ||
| 382 | }; | 383 | }; |
| 383 | }; | 384 | }; |
| 384 | 385 | ||
| @@ -420,12 +421,29 @@ struct perf_event_mmap_page { · 35 unmodified lines | |||
| 420 | __u16 time_shift; | 421 | __u16 time_shift; |
| 421 | __u32 time_mult; | 422 | __u32 time_mult; |
| 422 | __u64 time_offset; | 423 | __u64 time_offset; |
| 424 | /* | ||
| 425 | * If cap_usr_time_zero, the hardware clock (e.g. TSC) can be calculated | ||
| 426 | * from sample timestamps. | ||
| 427 | * | ||
| 428 | * time = timestamp - time_zero; | ||
| 429 | * quot = time / time_mult; | ||
| 430 | * rem = time % time_mult; | ||
| 431 | * cyc = (quot << time_shift) + (rem << time_shift) / time_mult; | ||
| 432 | * | ||
| 433 | * And vice versa: | ||
| 434 | * | ||
| 435 | * quot = cyc >> time_shift; | ||
| 436 | * rem = cyc & ((1 << time_shift) - 1); | ||
| 437 | * timestamp = time_zero + quot * time_mult + | ||
| 438 | * ((rem * time_mult) >> time_shift); | ||
| 439 | */ | ||
| 440 | __u64 time_zero; | ||
| 423 | 441 | ||
| 424 | /* | 442 | /* |
| 425 | * Hole for extension of the self monitor capabilities | 443 | * Hole for extension of the self monitor capabilities |
| 426 | */ | 444 | */ |
| 427 | 445 | ||
| 428 | __u64 __reserved[120]; /* align to 1k */ | 446 | __u64 __reserved[119]; /* align to 1k */ |
| 429 | 447 | ||
| 430 | /* | 448 | /* |
| 431 | * Control data for the mmap() data buffer. | 449 | * Control data for the mmap() data buffer. |