Skip to contentSkip to conversation

sched_clock: Make it NMI safe

tip:perfcounters/core tip-bot for Peter Zijlstra 1 participant 1 message Sep 18, 2009

lore
Share & tools
lore
#0 lore raw
Commit-ID:  def0a9b2573e00ab0b486cb5382625203ab4c4a6
Gitweb:     http://git.kernel.org/tip/def0a9b2573e00ab0b486cb5382625203ab4c4a6
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Fri, 18 Sep 2009 20:14:01 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 18 Sep 2009 20:47:30 +0200

sched_clock: Make it NMI safe

Arjan complained about the suckyness of TSC on modern machines, and asked if we could do something about that for PERF_SAMPLE_TIME.

Make cpu_clock() NMI safe by removing the spinlock and using cmpxchg. This also makes it smaller and more robust.

Affects architectures that use HAVE_UNSTABLE_SCHED_CLOCK, i.e. IA64 and x86.

LKML-Reference: <new-submission>

---
 kernel/perf_counter.c |    9 +--
 kernel/sched_clock.c  |  122 +++++++++++++++++++++---------------------------
 2 files changed, 56 insertions(+), 75 deletions(-)
kernel/perf_counter.c +3 -6
index 6944bd5..06d233a 100644
@@ -2955,10 +2955,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 	}
 
 	if (sample_type & PERF_SAMPLE_TIME) {
-		/*
-		 * Maybe do better on x86 and provide cpu_clock_nmi()
-		 */
-		data->time = sched_clock();
+		data->time = perf_clock();
 
 		header->size += sizeof(data->time);
 	}
@@ -3488,7 +3485,7 @@ static void perf_log_throttle(struct perf_counter *counter, int enable)
 			.misc = 0,
 			.size = sizeof(throttle_event),
 		},
-		.time		= sched_clock(),
+		.time		= perf_clock(),
 		.id		= primary_counter_id(counter),
 		.stream_id	= counter->id,
 	};
@@ -3540,7 +3537,7 @@ static int __perf_counter_overflow(struct perf_counter *counter, int nmi,
 	}
 
 	if (counter->attr.freq) {
-		u64 now = sched_clock();
+		u64 now = perf_clock();
 		s64 delta = now - hwc->freq_stamp;
 
 		hwc->freq_stamp = now;
kernel/sched_clock.c +53 -69

182 lines not on this page · raw message