public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf: introduce is_sampling_event()
@ 2010-11-23 15:21 Franck Bui-Huu
  2010-11-23 15:21 ` [PATCH 2/3] perf: Limit event refresh to sampling event Franck Bui-Huu
  2010-11-26 15:03 ` [tip:perf/core] perf: Introduce is_sampling_event() tip-bot for Franck Bui-Huu
  0 siblings, 2 replies; 6+ messages in thread
From: Franck Bui-Huu @ 2010-11-23 15:21 UTC (permalink / raw)
  To: a.p.zijlstra; +Cc: linux-kernel

From: Franck Bui-Huu <fbuihuu@gmail.com>

and use it when appropriate.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/x86/kernel/cpu/perf_event.c |    2 +-
 include/linux/perf_event.h       |    5 +++++
 kernel/perf_event.c              |   10 +++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index ed63101..89aa0f8 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -437,7 +437,7 @@ static int x86_setup_perfctr(struct perf_event *event)
 	struct hw_perf_event *hwc = &event->hw;
 	u64 config;
 
-	if (!hwc->sample_period) {
+	if (!is_sampling_event(event)) {
 		hwc->sample_period = x86_pmu.max_period;
 		hwc->last_period = hwc->sample_period;
 		local64_set(&hwc->period_left, hwc->sample_period);
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 40150f3..bb1884c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -982,6 +982,11 @@ extern int perf_event_overflow(struct perf_event *event, int nmi,
 				 struct perf_sample_data *data,
 				 struct pt_regs *regs);
 
+static inline bool is_sampling_event(struct perf_event *event)
+{
+	return event->attr.sample_period != 0;
+}
+
 /*
  * Return 1 for a software event, 0 for a hardware event
  */
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index cb6c0d2..df7869f 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -2482,7 +2482,7 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg)
 	int ret = 0;
 	u64 value;
 
-	if (!event->attr.sample_period)
+	if (!is_sampling_event(event))
 		return -EINVAL;
 
 	if (copy_from_user(&value, arg, sizeof(value)))
@@ -4353,7 +4353,7 @@ static void perf_swevent_event(struct perf_event *event, u64 nr,
 	if (!regs)
 		return;
 
-	if (!hwc->sample_period)
+	if (!is_sampling_event(event))
 		return;
 
 	if (nr == 1 && hwc->sample_period == 1 && !event->attr.freq)
@@ -4516,7 +4516,7 @@ static int perf_swevent_add(struct perf_event *event, int flags)
 	struct hw_perf_event *hwc = &event->hw;
 	struct hlist_head *head;
 
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		hwc->last_period = hwc->sample_period;
 		perf_swevent_set_period(event);
 	}
@@ -4897,7 +4897,7 @@ static void perf_swevent_start_hrtimer(struct perf_event *event)
 
 	hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	hwc->hrtimer.function = perf_swevent_hrtimer;
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		s64 period = local64_read(&hwc->period_left);
 
 		if (period) {
@@ -4918,7 +4918,7 @@ static void perf_swevent_cancel_hrtimer(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
 
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		ktime_t remaining = hrtimer_get_remaining(&hwc->hrtimer);
 		local64_set(&hwc->period_left, ktime_to_ns(remaining));
 
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] perf: Limit event refresh to sampling event
  2010-11-23 15:21 [PATCH 1/3] perf: introduce is_sampling_event() Franck Bui-Huu
@ 2010-11-23 15:21 ` Franck Bui-Huu
  2010-11-23 15:21   ` [PATCH 3/3] perf: don't bother to init the hrtimer for no SW sampling counters Franck Bui-Huu
  2010-11-26 15:04   ` [tip:perf/core] perf: Limit event refresh to sampling event tip-bot for Franck Bui-Huu
  2010-11-26 15:03 ` [tip:perf/core] perf: Introduce is_sampling_event() tip-bot for Franck Bui-Huu
  1 sibling, 2 replies; 6+ messages in thread
From: Franck Bui-Huu @ 2010-11-23 15:21 UTC (permalink / raw)
  To: a.p.zijlstra; +Cc: linux-kernel

From: Franck Bui-Huu <fbuihuu@gmail.com>

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 kernel/perf_event.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index df7869f..813b09e 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -1072,7 +1072,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
 	/*
 	 * not supported on inherited events
 	 */
-	if (event->attr.inherit)
+	if (event->attr.inherit || !is_sampling_event(event))
 		return -EINVAL;
 
 	atomic_add(refresh, &event->event_limit);
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] perf: don't bother to init the hrtimer for no SW sampling counters
  2010-11-23 15:21 ` [PATCH 2/3] perf: Limit event refresh to sampling event Franck Bui-Huu
@ 2010-11-23 15:21   ` Franck Bui-Huu
  2010-11-26 15:04     ` [tip:perf/core] perf: Don't " tip-bot for Franck Bui-Huu
  2010-11-26 15:04   ` [tip:perf/core] perf: Limit event refresh to sampling event tip-bot for Franck Bui-Huu
  1 sibling, 1 reply; 6+ messages in thread
From: Franck Bui-Huu @ 2010-11-23 15:21 UTC (permalink / raw)
  To: a.p.zijlstra; +Cc: linux-kernel

From: Franck Bui-Huu <fbuihuu@gmail.com>

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 kernel/perf_event.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 813b09e..31515200 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -4894,24 +4894,26 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer)
 static void perf_swevent_start_hrtimer(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
+	s64 period;
+
+	if (!is_sampling_event(event))
+		return;
 
 	hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	hwc->hrtimer.function = perf_swevent_hrtimer;
-	if (is_sampling_event(event)) {
-		s64 period = local64_read(&hwc->period_left);
 
-		if (period) {
-			if (period < 0)
-				period = 10000;
+	period = local64_read(&hwc->period_left);
+	if (period) {
+		if (period < 0)
+			period = 10000;
 
-			local64_set(&hwc->period_left, 0);
-		} else {
-			period = max_t(u64, 10000, hwc->sample_period);
-		}
-		__hrtimer_start_range_ns(&hwc->hrtimer,
+		local64_set(&hwc->period_left, 0);
+	} else {
+		period = max_t(u64, 10000, hwc->sample_period);
+	}
+	__hrtimer_start_range_ns(&hwc->hrtimer,
 				ns_to_ktime(period), 0,
 				HRTIMER_MODE_REL_PINNED, 0);
-	}
 }
 
 static void perf_swevent_cancel_hrtimer(struct perf_event *event)
-- 
1.7.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [tip:perf/core] perf: Introduce is_sampling_event()
  2010-11-23 15:21 [PATCH 1/3] perf: introduce is_sampling_event() Franck Bui-Huu
  2010-11-23 15:21 ` [PATCH 2/3] perf: Limit event refresh to sampling event Franck Bui-Huu
@ 2010-11-26 15:03 ` tip-bot for Franck Bui-Huu
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2010-11-26 15:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, fbuihuu, tglx, mingo

Commit-ID:  6c7e550f13f8ad82efb6a5653ae628c2543c1768
Gitweb:     http://git.kernel.org/tip/6c7e550f13f8ad82efb6a5653ae628c2543c1768
Author:     Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Tue, 23 Nov 2010 16:21:43 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 26 Nov 2010 15:14:54 +0100

perf: Introduce is_sampling_event()

and use it when appropriate.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1290525705-6265-1-git-send-email-fbuihuu@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/cpu/perf_event.c |    2 +-
 include/linux/perf_event.h       |    5 +++++
 kernel/perf_event.c              |   10 +++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 7c1a4c3..c01dfec 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -442,7 +442,7 @@ static int x86_setup_perfctr(struct perf_event *event)
 	struct hw_perf_event *hwc = &event->hw;
 	u64 config;
 
-	if (!hwc->sample_period) {
+	if (!is_sampling_event(event)) {
 		hwc->sample_period = x86_pmu.max_period;
 		hwc->last_period = hwc->sample_period;
 		local64_set(&hwc->period_left, hwc->sample_period);
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index de2c417..cbf04cc 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -969,6 +969,11 @@ extern int perf_event_overflow(struct perf_event *event, int nmi,
 				 struct perf_sample_data *data,
 				 struct pt_regs *regs);
 
+static inline bool is_sampling_event(struct perf_event *event)
+{
+	return event->attr.sample_period != 0;
+}
+
 /*
  * Return 1 for a software event, 0 for a hardware event
  */
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 43f757c..8806984 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -2514,7 +2514,7 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg)
 	int ret = 0;
 	u64 value;
 
-	if (!event->attr.sample_period)
+	if (!is_sampling_event(event))
 		return -EINVAL;
 
 	if (copy_from_user(&value, arg, sizeof(value)))
@@ -4385,7 +4385,7 @@ static void perf_swevent_event(struct perf_event *event, u64 nr,
 	if (!regs)
 		return;
 
-	if (!hwc->sample_period)
+	if (!is_sampling_event(event))
 		return;
 
 	if (nr == 1 && hwc->sample_period == 1 && !event->attr.freq)
@@ -4548,7 +4548,7 @@ static int perf_swevent_add(struct perf_event *event, int flags)
 	struct hw_perf_event *hwc = &event->hw;
 	struct hlist_head *head;
 
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		hwc->last_period = hwc->sample_period;
 		perf_swevent_set_period(event);
 	}
@@ -4920,7 +4920,7 @@ static void perf_swevent_start_hrtimer(struct perf_event *event)
 
 	hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	hwc->hrtimer.function = perf_swevent_hrtimer;
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		s64 period = local64_read(&hwc->period_left);
 
 		if (period) {
@@ -4941,7 +4941,7 @@ static void perf_swevent_cancel_hrtimer(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
 
-	if (hwc->sample_period) {
+	if (is_sampling_event(event)) {
 		ktime_t remaining = hrtimer_get_remaining(&hwc->hrtimer);
 		local64_set(&hwc->period_left, ktime_to_ns(remaining));
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [tip:perf/core] perf: Limit event refresh to sampling event
  2010-11-23 15:21 ` [PATCH 2/3] perf: Limit event refresh to sampling event Franck Bui-Huu
  2010-11-23 15:21   ` [PATCH 3/3] perf: don't bother to init the hrtimer for no SW sampling counters Franck Bui-Huu
@ 2010-11-26 15:04   ` tip-bot for Franck Bui-Huu
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2010-11-26 15:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, fbuihuu, tglx, mingo

Commit-ID:  2e939d1da9b5628642314c1e68b4319e61263c94
Gitweb:     http://git.kernel.org/tip/2e939d1da9b5628642314c1e68b4319e61263c94
Author:     Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Tue, 23 Nov 2010 16:21:44 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 26 Nov 2010 15:14:55 +0100

perf: Limit event refresh to sampling event

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1290525705-6265-2-git-send-email-fbuihuu@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/perf_event.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 8806984..027c4d3 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -1073,7 +1073,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
 	/*
 	 * not supported on inherited events
 	 */
-	if (event->attr.inherit)
+	if (event->attr.inherit || !is_sampling_event(event))
 		return -EINVAL;
 
 	atomic_add(refresh, &event->event_limit);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [tip:perf/core] perf: Don't bother to init the hrtimer for no SW sampling counters
  2010-11-23 15:21   ` [PATCH 3/3] perf: don't bother to init the hrtimer for no SW sampling counters Franck Bui-Huu
@ 2010-11-26 15:04     ` tip-bot for Franck Bui-Huu
  0 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2010-11-26 15:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, fbuihuu, tglx, mingo

Commit-ID:  5d508e820a23d9b6e8a149dfaa8ba5cbedf3d95c
Gitweb:     http://git.kernel.org/tip/5d508e820a23d9b6e8a149dfaa8ba5cbedf3d95c
Author:     Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Tue, 23 Nov 2010 16:21:45 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 26 Nov 2010 15:14:55 +0100

perf: Don't bother to init the hrtimer for no SW sampling counters

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1290525705-6265-3-git-send-email-fbuihuu@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/perf_event.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 027c4d3..98c5549 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -4917,24 +4917,26 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer)
 static void perf_swevent_start_hrtimer(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
+	s64 period;
+
+	if (!is_sampling_event(event))
+		return;
 
 	hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	hwc->hrtimer.function = perf_swevent_hrtimer;
-	if (is_sampling_event(event)) {
-		s64 period = local64_read(&hwc->period_left);
 
-		if (period) {
-			if (period < 0)
-				period = 10000;
+	period = local64_read(&hwc->period_left);
+	if (period) {
+		if (period < 0)
+			period = 10000;
 
-			local64_set(&hwc->period_left, 0);
-		} else {
-			period = max_t(u64, 10000, hwc->sample_period);
-		}
-		__hrtimer_start_range_ns(&hwc->hrtimer,
+		local64_set(&hwc->period_left, 0);
+	} else {
+		period = max_t(u64, 10000, hwc->sample_period);
+	}
+	__hrtimer_start_range_ns(&hwc->hrtimer,
 				ns_to_ktime(period), 0,
 				HRTIMER_MODE_REL_PINNED, 0);
-	}
 }
 
 static void perf_swevent_cancel_hrtimer(struct perf_event *event)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-26 15:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-23 15:21 [PATCH 1/3] perf: introduce is_sampling_event() Franck Bui-Huu
2010-11-23 15:21 ` [PATCH 2/3] perf: Limit event refresh to sampling event Franck Bui-Huu
2010-11-23 15:21   ` [PATCH 3/3] perf: don't bother to init the hrtimer for no SW sampling counters Franck Bui-Huu
2010-11-26 15:04     ` [tip:perf/core] perf: Don't " tip-bot for Franck Bui-Huu
2010-11-26 15:04   ` [tip:perf/core] perf: Limit event refresh to sampling event tip-bot for Franck Bui-Huu
2010-11-26 15:03 ` [tip:perf/core] perf: Introduce is_sampling_event() tip-bot for Franck Bui-Huu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox