|
2 | 2 | #include <linux/bitops.h>
|
3 | 3 | #include <linux/types.h>
|
4 | 4 | #include <linux/slab.h>
|
| 5 | +#include <linux/sched/clock.h> |
5 | 6 |
|
6 | 7 | #include <asm/cpu_entry_area.h>
|
7 | 8 | #include <asm/perf_event.h>
|
8 | 9 | #include <asm/tlbflush.h>
|
9 | 10 | #include <asm/insn.h>
|
10 | 11 | #include <asm/io.h>
|
| 12 | +#include <asm/timer.h> |
11 | 13 |
|
12 | 14 | #include "../perf_event.h"
|
13 | 15 |
|
@@ -1568,6 +1570,27 @@ static u64 get_data_src(struct perf_event *event, u64 aux)
|
1568 | 1570 | return val;
|
1569 | 1571 | }
|
1570 | 1572 |
|
| 1573 | +static void setup_pebs_time(struct perf_event *event, |
| 1574 | + struct perf_sample_data *data, |
| 1575 | + u64 tsc) |
| 1576 | +{ |
| 1577 | + /* Converting to a user-defined clock is not supported yet. */ |
| 1578 | + if (event->attr.use_clockid != 0) |
| 1579 | + return; |
| 1580 | + |
| 1581 | + /* |
| 1582 | + * Doesn't support the conversion when the TSC is unstable. |
| 1583 | + * The TSC unstable case is a corner case and very unlikely to |
| 1584 | + * happen. If it happens, the TSC in a PEBS record will be |
| 1585 | + * dropped and fall back to perf_event_clock(). |
| 1586 | + */ |
| 1587 | + if (!using_native_sched_clock() || !sched_clock_stable()) |
| 1588 | + return; |
| 1589 | + |
| 1590 | + data->time = native_sched_clock_from_tsc(tsc) + __sched_clock_offset; |
| 1591 | + data->sample_flags |= PERF_SAMPLE_TIME; |
| 1592 | +} |
| 1593 | + |
1571 | 1594 | #define PERF_SAMPLE_ADDR_TYPE (PERF_SAMPLE_ADDR | \
|
1572 | 1595 | PERF_SAMPLE_PHYS_ADDR | \
|
1573 | 1596 | PERF_SAMPLE_DATA_PAGE_SIZE)
|
@@ -1715,11 +1738,8 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,
|
1715 | 1738 | *
|
1716 | 1739 | * We can only do this for the default trace clock.
|
1717 | 1740 | */
|
1718 |
| - if (x86_pmu.intel_cap.pebs_format >= 3 && |
1719 |
| - event->attr.use_clockid == 0) { |
1720 |
| - data->time = native_sched_clock_from_tsc(pebs->tsc); |
1721 |
| - data->sample_flags |= PERF_SAMPLE_TIME; |
1722 |
| - } |
| 1741 | + if (x86_pmu.intel_cap.pebs_format >= 3) |
| 1742 | + setup_pebs_time(event, data, pebs->tsc); |
1723 | 1743 |
|
1724 | 1744 | if (has_branch_stack(event))
|
1725 | 1745 | perf_sample_save_brstack(data, event, &cpuc->lbr_stack);
|
@@ -1781,10 +1801,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,
|
1781 | 1801 | perf_sample_data_init(data, 0, event->hw.last_period);
|
1782 | 1802 | data->period = event->hw.last_period;
|
1783 | 1803 |
|
1784 |
| - if (event->attr.use_clockid == 0) { |
1785 |
| - data->time = native_sched_clock_from_tsc(basic->tsc); |
1786 |
| - data->sample_flags |= PERF_SAMPLE_TIME; |
1787 |
| - } |
| 1804 | + setup_pebs_time(event, data, basic->tsc); |
1788 | 1805 |
|
1789 | 1806 | /*
|
1790 | 1807 | * We must however always use iregs for the unwinder to stay sane; the
|
|
0 commit comments