aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/perf_event.c
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2010-02-08 10:06:01 -0500
committerIngo Molnar <mingo@elte.hu>2010-02-26 04:56:53 -0500
commitd76a0812ac4139ceb54daab3cc70e1bd8bd9d43a (patch)
tree81413e2271b310a698bec191a8f0ded5cdcfa2de /arch/x86/kernel/cpu/perf_event.c
parent3a0304e90aa5a2c0c308a05d28f7d109a48d8539 (diff)
perf_events: Add new start/stop PMU callbacks
In certain situations, the kernel may need to stop and start the same event rapidly. The current PMU callbacks do not distinguish between stop and release (i.e., stop + free the resource). Thus, a counter may be released, then it will be immediately re-acquired. Event scheduling will again take place with no guarantee to assign the same counter. On some processors, this may event yield to failure to assign the event back due to competion between cores. This patch is adding a new pair of callback to stop and restart a counter without actually release the underlying counter resource. On stop, the counter is stopped, its values saved and that's it. On start, the value is reloaded and counter is restarted (on x86, actual restart is delayed until perf_enable()). Signed-off-by: Stephane Eranian <eranian@google.com> [ added fallback to ->enable/->disable for all other PMUs fixed x86_pmu_start() to call x86_pmu.enable() merged __x86_pmu_disable into x86_pmu_stop() ] Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <4b703875.0a04d00a.7896.ffffb824@mx.google.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/cpu/perf_event.c')
-rw-r--r--arch/x86/kernel/cpu/perf_event.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index a920f173a220..9173ea95f918 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1495,7 +1495,7 @@ static inline int match_prev_assignment(struct hw_perf_event *hwc,
1495 hwc->last_tag == cpuc->tags[i]; 1495 hwc->last_tag == cpuc->tags[i];
1496} 1496}
1497 1497
1498static void __x86_pmu_disable(struct perf_event *event, struct cpu_hw_events *cpuc); 1498static void x86_pmu_stop(struct perf_event *event);
1499 1499
1500void hw_perf_enable(void) 1500void hw_perf_enable(void)
1501{ 1501{
@@ -1533,7 +1533,7 @@ void hw_perf_enable(void)
1533 match_prev_assignment(hwc, cpuc, i)) 1533 match_prev_assignment(hwc, cpuc, i))
1534 continue; 1534 continue;
1535 1535
1536 __x86_pmu_disable(event, cpuc); 1536 x86_pmu_stop(event);
1537 1537
1538 hwc->idx = -1; 1538 hwc->idx = -1;
1539 } 1539 }
@@ -1801,6 +1801,19 @@ static int x86_pmu_enable(struct perf_event *event)
1801 return 0; 1801 return 0;
1802} 1802}
1803 1803
1804static int x86_pmu_start(struct perf_event *event)
1805{
1806 struct hw_perf_event *hwc = &event->hw;
1807
1808 if (hwc->idx == -1)
1809 return -EAGAIN;
1810
1811 x86_perf_event_set_period(event, hwc, hwc->idx);
1812 x86_pmu.enable(hwc, hwc->idx);
1813
1814 return 0;
1815}
1816
1804static void x86_pmu_unthrottle(struct perf_event *event) 1817static void x86_pmu_unthrottle(struct perf_event *event)
1805{ 1818{
1806 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 1819 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
@@ -1924,8 +1937,9 @@ static void intel_pmu_drain_bts_buffer(struct cpu_hw_events *cpuc)
1924 event->pending_kill = POLL_IN; 1937 event->pending_kill = POLL_IN;
1925} 1938}
1926 1939
1927static void __x86_pmu_disable(struct perf_event *event, struct cpu_hw_events *cpuc) 1940static void x86_pmu_stop(struct perf_event *event)
1928{ 1941{
1942 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1929 struct hw_perf_event *hwc = &event->hw; 1943 struct hw_perf_event *hwc = &event->hw;
1930 int idx = hwc->idx; 1944 int idx = hwc->idx;
1931 1945
@@ -1954,7 +1968,7 @@ static void x86_pmu_disable(struct perf_event *event)
1954 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 1968 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
1955 int i; 1969 int i;
1956 1970
1957 __x86_pmu_disable(event, cpuc); 1971 x86_pmu_stop(event);
1958 1972
1959 for (i = 0; i < cpuc->n_events; i++) { 1973 for (i = 0; i < cpuc->n_events; i++) {
1960 if (event == cpuc->event_list[i]) { 1974 if (event == cpuc->event_list[i]) {
@@ -2667,6 +2681,8 @@ static inline void x86_pmu_read(struct perf_event *event)
2667static const struct pmu pmu = { 2681static const struct pmu pmu = {
2668 .enable = x86_pmu_enable, 2682 .enable = x86_pmu_enable,
2669 .disable = x86_pmu_disable, 2683 .disable = x86_pmu_disable,
2684 .start = x86_pmu_start,
2685 .stop = x86_pmu_stop,
2670 .read = x86_pmu_read, 2686 .read = x86_pmu_read,
2671 .unthrottle = x86_pmu_unthrottle, 2687 .unthrottle = x86_pmu_unthrottle,
2672}; 2688};