From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, hpa@zytor.com,
mingo@redhat.com, rostedt@goodmis.org, a.p.zijlstra@chello.nl,
tglx@linutronix.de, mingo@elte.hu
Subject: [tip:perfcounters/core] perf_counter: generic context switch event
Date: Fri, 20 Mar 2009 10:24:59 GMT [thread overview]
Message-ID: <tip-56675f6a68ace46db70af12bdd39b6103cc54929@git.kernel.org> (raw)
In-Reply-To: <20090319194233.283522645@chello.nl>
Commit-ID: 56675f6a68ace46db70af12bdd39b6103cc54929
Gitweb: http://git.kernel.org/tip/56675f6a68ace46db70af12bdd39b6103cc54929
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 19 Mar 2009 20:26:12 +0100
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 20 Mar 2009 11:15:11 +0100
perf_counter: generic context switch event
Impact: cleanup
Use the generic software events for context switches.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090319194233.283522645@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/sched.h | 1 -
kernel/perf_counter.c | 60 +++---------------------------------------------
kernel/sched.c | 6 -----
3 files changed, 4 insertions(+), 63 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3e9bb18..1410859 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -137,7 +137,6 @@ extern unsigned long nr_running(void);
extern unsigned long nr_uninterruptible(void);
extern unsigned long nr_active(void);
extern unsigned long nr_iowait(void);
-extern u64 cpu_nr_switches(int cpu);
extern u64 cpu_nr_migrations(int cpu);
extern unsigned long get_parent_ip(unsigned long addr);
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 4c4e9eb..99d5930 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -710,10 +710,13 @@ void perf_counter_task_sched_out(struct task_struct *task, int cpu)
{
struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
struct perf_counter_context *ctx = &task->perf_counter_ctx;
+ struct pt_regs *regs;
if (likely(!cpuctx->task_ctx))
return;
+ regs = task_pt_regs(task);
+ perf_swcounter_event(PERF_COUNT_CONTEXT_SWITCHES, 1, 1, regs);
__perf_counter_sched_out(ctx, cpuctx);
cpuctx->task_ctx = NULL;
@@ -1668,58 +1671,6 @@ static const struct hw_perf_counter_ops perf_ops_task_clock = {
};
/*
- * Software counter: context switches
- */
-
-static u64 get_context_switches(struct perf_counter *counter)
-{
- struct task_struct *curr = counter->ctx->task;
-
- if (curr)
- return curr->nvcsw + curr->nivcsw;
- return cpu_nr_switches(smp_processor_id());
-}
-
-static void context_switches_perf_counter_update(struct perf_counter *counter)
-{
- u64 prev, now;
- s64 delta;
-
- prev = atomic64_read(&counter->hw.prev_count);
- now = get_context_switches(counter);
-
- atomic64_set(&counter->hw.prev_count, now);
-
- delta = now - prev;
-
- atomic64_add(delta, &counter->count);
-}
-
-static void context_switches_perf_counter_read(struct perf_counter *counter)
-{
- context_switches_perf_counter_update(counter);
-}
-
-static int context_switches_perf_counter_enable(struct perf_counter *counter)
-{
- if (counter->prev_state <= PERF_COUNTER_STATE_OFF)
- atomic64_set(&counter->hw.prev_count,
- get_context_switches(counter));
- return 0;
-}
-
-static void context_switches_perf_counter_disable(struct perf_counter *counter)
-{
- context_switches_perf_counter_update(counter);
-}
-
-static const struct hw_perf_counter_ops perf_ops_context_switches = {
- .enable = context_switches_perf_counter_enable,
- .disable = context_switches_perf_counter_disable,
- .read = context_switches_perf_counter_read,
-};
-
-/*
* Software counter: cpu migrations
*/
@@ -1808,11 +1759,8 @@ sw_perf_counter_init(struct perf_counter *counter)
case PERF_COUNT_PAGE_FAULTS:
case PERF_COUNT_PAGE_FAULTS_MIN:
case PERF_COUNT_PAGE_FAULTS_MAJ:
- hw_ops = &perf_ops_generic;
- break;
case PERF_COUNT_CONTEXT_SWITCHES:
- if (!counter->hw_event.exclude_kernel)
- hw_ops = &perf_ops_context_switches;
+ hw_ops = &perf_ops_generic;
break;
case PERF_COUNT_CPU_MIGRATIONS:
if (!counter->hw_event.exclude_kernel)
diff --git a/kernel/sched.c b/kernel/sched.c
index cbfa5ab..7a4667d 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2911,14 +2911,8 @@ unsigned long nr_active(void)
/*
* Externally visible per-cpu scheduler statistics:
- * cpu_nr_switches(cpu) - number of context switches on that cpu
* cpu_nr_migrations(cpu) - number of migrations into that cpu
*/
-u64 cpu_nr_switches(int cpu)
-{
- return cpu_rq(cpu)->nr_switches;
-}
-
u64 cpu_nr_migrations(int cpu)
{
return cpu_rq(cpu)->nr_migrations_in;
next prev parent reply other threads:[~2009-03-20 10:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-19 19:26 [PATCH 00/10] tracepoint perf counter events and new ABI Peter Zijlstra
2009-03-19 19:26 ` [PATCH 01/10] perf_counter: fix uninitialized usage of event_list Peter Zijlstra
2009-03-20 10:24 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 02/10] perf_counter: generic context switch event Peter Zijlstra
2009-03-20 10:24 ` Peter Zijlstra [this message]
2009-03-19 19:26 ` [PATCH 03/10] ftrace: provide an id file for each event Peter Zijlstra
2009-03-20 10:19 ` [tip:tracing/ftrace] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 04/10] ftrace: ensure every event gets an id Peter Zijlstra
2009-03-20 10:19 ` [tip:tracing/ftrace] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 05/10] ftrace: event profile hooks Peter Zijlstra
2009-03-20 10:19 ` [tip:tracing/ftrace] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 06/10] perf_counter: fix up counter free paths Peter Zijlstra
2009-03-20 10:25 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 07/10] perf_counter: hook up the tracepoint events Peter Zijlstra
2009-03-20 10:25 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-22 8:57 ` Ingo Molnar
2009-07-29 1:01 ` Jeff Garzik
2009-07-29 8:35 ` Peter Zijlstra
2009-07-29 8:59 ` Jeff Garzik
2009-07-29 9:12 ` Peter Zijlstra
2009-08-02 13:09 ` [tip:perfcounters/core] tracing, perf_counter: Add help text to CONFIG_EVENT_PROFILE tip-bot for Peter Zijlstra
2009-03-19 19:26 ` [PATCH 08/10] perf_counter: revamp syscall input ABI Peter Zijlstra
2009-03-20 10:25 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 09/10] perf_counter: unify irq output code Peter Zijlstra
2009-03-20 10:25 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-19 19:26 ` [PATCH 10/10] perf_counter: powerpc: clean up perc_counter_interrupt Peter Zijlstra
2009-03-19 22:17 ` Paul Mackerras
2009-03-20 8:54 ` Ingo Molnar
2009-03-20 10:25 ` [tip:perfcounters/core] " Paul Mackerras
2009-03-20 9:27 ` [PATCH 00/10] tracepoint perf counter events and new ABI Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-56675f6a68ace46db70af12bdd39b6103cc54929@git.kernel.org \
--to=a.p.zijlstra@chello.nl \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox