a perf and some sched patches
Subsystems (2)
cover a perf and some sched patches
Fixes an issue with the per-task-per-cpu counters, reported by acme. Fixes an false positive in the set_task_cpu() debug check, reported by Ingo. Fixes up the task->state to char bits, gumbled at by tglx.
PATCH 1/6 sched: Move TASK_STATE_TO_CHAR_STR near the TASK_state bits
So that we don't keep forgetting about it
LKML-Reference: <new-submission>
--- include/linux/sched.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/sched.h +2 -2
@@ -193,6 +193,8 @@ print_cfs_rq(struct seq_file *m, int cpu#define TASK_WAKEKILL 128#define TASK_WAKING 256 +#define TASK_STATE_TO_CHAR_STR "RSDTtZX" +/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
@@ -2595,8 +2597,6 @@ static inline void mm_init_owner(struct }#endif /* CONFIG_MM_OWNER */ -#define TASK_STATE_TO_CHAR_STR "RSDTtZX" -#endif /* __KERNEL__ */ #endif
[tip:sched/urgent] sched: Move TASK_STATE_TO_CHAR_STR near the TASK_state bits
Commit-ID: 733421516b42c44b9e21f1793c430cc801ef8324 Gitweb: http://git.kernel.org/tip/733421516b42c44b9e21f1793c430cc801ef8324 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:27 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:22:43 +0100
sched: Move TASK_STATE_TO_CHAR_STR near the TASK_state bits
So that we don't keep forgetting about it.
LKML-Reference: <[email protected]>
--- include/linux/sched.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/sched.h +2 -2
@@ -193,6 +193,8 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)#define TASK_WAKEKILL 128#define TASK_WAKING 256 +#define TASK_STATE_TO_CHAR_STR "RSDTtZX" +/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
@@ -2595,8 +2597,6 @@ static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) }#endif /* CONFIG_MM_OWNER */ -#define TASK_STATE_TO_CHAR_STR "RSDTtZX" -#endif /* __KERNEL__ */ #endif
PATCH 2/6 sched: Add missing state chars to TASK_STATE_TO_CHAR_STR
In reply to Peter ZijlstraWe grew 3 new task states since the last time someone touched it.
LKML-Reference: <new-submission>
--- include/linux/sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
@@ -193,7 +193,7 @@ print_cfs_rq(struct seq_file *m, int cpu#define TASK_WAKEKILL 128#define TASK_WAKING 256 -#define TASK_STATE_TO_CHAR_STR "RSDTtZX" +#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
[tip:sched/urgent] sched: Add missing state chars to TASK_STATE_TO_CHAR_STR
Commit-ID: 44d90df6b757c59651ddd55f1a84f28132b50d29 Gitweb: http://git.kernel.org/tip/44d90df6b757c59651ddd55f1a84f28132b50d29 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:28 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:22:44 +0100
sched: Add missing state chars to TASK_STATE_TO_CHAR_STR
We grew 3 new task states since the last time someone touched it.
LKML-Reference: <[email protected]>
--- include/linux/sched.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/sched.h +1 -1
@@ -193,7 +193,7 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)#define TASK_WAKEKILL 128#define TASK_WAKING 256 -#define TASK_STATE_TO_CHAR_STR "RSDTtZX" +#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
PATCH 3/6 sched: Update task_state_arraypwith new states
In reply to Peter ZijlstraNeglected because its hidden... (who reads comments anyway)
LKML-Reference: <new-submission>
--- fs/proc/array.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/proc/array.c +5 -2
@@ -138,9 +138,12 @@ static const char *task_state_array[] ="S (sleeping)" ,/* 1 */ "D (disk sleep)" ,/* 2 */ "T (stopped)" ,/* 4 */ -"T (tracing stop)" ,/* 8 */ +"t (tracing stop)" ,/* 8 */ "Z (zombie)" ,/* 16 */ - "X (dead)" /* 32 */ +"X (dead)" ,/* 32 */ +"x (dead)" ,/* 64 */ +"K (wakekill)" ,/* 128 */ + "W (waking)", /* 256 */ };static inline const char *get_task_state (struct task_struct *tsk)
[tip:sched/urgent] sched: Update task_state_arraypwith new states
Commit-ID: 464763cf1c6df632dccc8f2f4c7e50163154a2c0 Gitweb: http://git.kernel.org/tip/464763cf1c6df632dccc8f2f4c7e50163154a2c0 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:29 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:22:45 +0100
sched: Update task_state_arraypwith new states
Neglected because its hidden... (who reads comments anyway)
LKML-Reference: <[email protected]>
--- fs/proc/array.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
fs/proc/array.c +5 -2
@@ -138,9 +138,12 @@ static const char *task_state_array[] = {"S (sleeping)" ,/* 1 */ "D (disk sleep)" ,/* 2 */ "T (stopped)" ,/* 4 */ -"T (tracing stop)" ,/* 8 */ +"t (tracing stop)" ,/* 8 */ "Z (zombie)" ,/* 16 */ - "X (dead)" /* 32 */ +"X (dead)" ,/* 32 */ +"x (dead)" ,/* 64 */ +"K (wakekill)" ,/* 128 */ + "W (waking)", /* 256 */ };static inline const char *get_task_state (struct task_struct *tsk)
PATCH 4/6 sched: Assert task state bits at build time
In reply to Peter ZijlstraSince everybody is lazy and prone to forgetting things, make the compiler help us a bit.
LKML-Reference: <new-submission>
--- fs/proc/array.c | 18 ++++++++++-------- include/linux/sched.h | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-)
fs/proc/array.c +10 -8
@@ -134,14 +134,14 @@ static inline void task_name(struct seq_* simple bit tests. */ static const char *task_state_array[] = { -"R (running)" ,/* 0 */ -"S (sleeping)" ,/* 1 */ -"D (disk sleep)" ,/* 2 */ -"T (stopped)" ,/* 4 */ -"t (tracing stop)" ,/* 8 */ -"Z (zombie)" ,/* 16 */ -"X (dead)" ,/* 32 */ -"x (dead)" ,/* 64 */ +"R (running)" ,/* 0 */ +"S (sleeping)" ,/* 1 */ +"D (disk sleep)" ,/* 2 */ +"T (stopped)" ,/* 4 */ +"t (tracing stop)" ,/* 8 */ +"Z (zombie)" ,/* 16 */ +"X (dead)" ,/* 32 */ +"x (dead)" ,/* 64 */ "K (wakekill)" ,/* 128 */ "W (waking)" ,/* 256 */ };
@@ -151,6 +151,8 @@ static inline const char *get_task_stateunsigned int state = (tsk->state &TASK_REPORT ) | tsk->exit_state;const char **p = &task_state_array[0 ]; +BUILD_BUG_ON (1 +ilog2 (TASK_STATE_MAX ) !=ARRAY_SIZE (task_state_array)); +while (state) { p++; state >>=1 ;
include/linux/sched.h +4 -0
@@ -192,9 +192,13 @@ print_cfs_rq(struct seq_file *m, int cpu#define TASK_DEAD 64#define TASK_WAKEKILL 128#define TASK_WAKING 256 +#define TASK_STATE_MAX 512#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" +extern char ___assert_task_state[1 -2 *!!( +sizeof (TASK_STATE_TO_CHAR_STR )-1 !=ilog2 (TASK_STATE_MAX )+1 )]; +/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
[tip:sched/urgent] sched: Assert task state bits at build time
Commit-ID: e1781538cf5c870ab696e9b8f0a5c498d3900f2f Gitweb: http://git.kernel.org/tip/e1781538cf5c870ab696e9b8f0a5c498d3900f2f Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:30 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:22:45 +0100
sched: Assert task state bits at build time
Since everybody is lazy and prone to forgetting things, make the compiler help us a bit.
LKML-Reference: <[email protected]>
--- fs/proc/array.c | 18 ++++++++++-------- include/linux/sched.h | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-)
fs/proc/array.c +10 -8
@@ -134,14 +134,14 @@ static inline void task_name(struct seq_file *m, struct task_struct *p)* simple bit tests. */ static const char *task_state_array[] = { -"R (running)" ,/* 0 */ -"S (sleeping)" ,/* 1 */ -"D (disk sleep)" ,/* 2 */ -"T (stopped)" ,/* 4 */ -"t (tracing stop)" ,/* 8 */ -"Z (zombie)" ,/* 16 */ -"X (dead)" ,/* 32 */ -"x (dead)" ,/* 64 */ +"R (running)" ,/* 0 */ +"S (sleeping)" ,/* 1 */ +"D (disk sleep)" ,/* 2 */ +"T (stopped)" ,/* 4 */ +"t (tracing stop)" ,/* 8 */ +"Z (zombie)" ,/* 16 */ +"X (dead)" ,/* 32 */ +"x (dead)" ,/* 64 */ "K (wakekill)" ,/* 128 */ "W (waking)" ,/* 256 */ };
@@ -151,6 +151,8 @@ static inline const char *get_task_state(struct task_struct *tsk)unsigned int state = (tsk->state &TASK_REPORT ) | tsk->exit_state;const char **p = &task_state_array[0 ]; +BUILD_BUG_ON (1 +ilog2 (TASK_STATE_MAX ) !=ARRAY_SIZE (task_state_array)); +while (state) { p++; state >>=1 ;
include/linux/sched.h +4 -0
@@ -192,9 +192,13 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)#define TASK_DEAD 64#define TASK_WAKEKILL 128#define TASK_WAKING 256 +#define TASK_STATE_MAX 512#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" +extern char ___assert_task_state[1 -2 *!!( +sizeof (TASK_STATE_TO_CHAR_STR )-1 !=ilog2 (TASK_STATE_MAX )+1 )]; +/* Convenience macros for the sake of set_task_state */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
PATCH 5/6 sched: Fix broken assertion
In reply to Peter ZijlstraThere's a preemption race in the set_task_cpu() debug check in that when we get preempted after setting task->state we'd still be on the rq proper, but fail the test.
Check for preempted tasks, since those are always on the RQ.
LKML-Reference: <new-submission>
--- kernel/sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched.c +2 -1
@@ -2041,7 +2041,8 @@ void set_task_cpu(struct task_struct *p,* We should never call set_task_cpu() on a blocked task, * ttwu() will sort out the placement. */ -WARN_ON_ONCE (p->state !=TASK_RUNNING && p->state !=TASK_WAKING ); +WARN_ON_ONCE (p->state !=TASK_RUNNING && p->state !=TASK_WAKING && + !(task_thread_info (p)->preempt_count &PREEMPT_ACTIVE ));#endif trace_sched_migrate_task (p, new_cpu);
[tip:sched/urgent] sched: Fix broken assertion
Commit-ID: 077614ee1e93245a3b9a4e1213659405dbeb0ba6 Gitweb: http://git.kernel.org/tip/077614ee1e93245a3b9a4e1213659405dbeb0ba6 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:31 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:22:46 +0100
sched: Fix broken assertion
There's a preemption race in the set_task_cpu() debug check in that when we get preempted after setting task->state we'd still be on the rq proper, but fail the test.
Check for preempted tasks, since those are always on the RQ.
LKML-Reference: <[email protected]>
--- kernel/sched.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/sched.c +2 -1
@@ -2041,7 +2041,8 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)* We should never call set_task_cpu() on a blocked task, * ttwu() will sort out the placement. */ -WARN_ON_ONCE (p->state !=TASK_RUNNING && p->state !=TASK_WAKING ); +WARN_ON_ONCE (p->state !=TASK_RUNNING && p->state !=TASK_WAKING && + !(task_thread_info (p)->preempt_count &PREEMPT_ACTIVE ));#endif trace_sched_migrate_task (p, new_cpu);
PATCH 6/6 perf: Dont report side-band events on each cpu for per-task-per-cpu events
In reply to Peter ZijlstraAcme noticed that his FORK/MMAP numbers were inflated by about the same factor as his cpu-count.
This led to the discovery of a few more sites that need to respect the event->cpu filter.
--- kernel/perf_event.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
kernel/perf_event.c +18 -14
@@ -1381,6 +1381,9 @@ static void perf_ctx_adjust_freq(structif (event->state !=PERF_EVENT_STATE_ACTIVE )continue ; +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +continue ; + hwc = &event->hw; interrupts = hwc->interrupts;
@@ -3265,6 +3268,9 @@ static void perf_event_task_output(strucstatic int perf_event_task_match (struct perf_event *event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.comm || event->attr.mmap || event->attr.task)return 1 ;
@@ -3290,12 +3296,11 @@ static void perf_event_task_event(structrcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_task_ctx (&cpuctx->ctx, task_event); -put_cpu_var (perf_cpu_context); -if (!ctx) ctx =rcu_dereference (task_event->task->perf_event_ctxp);if (ctx)perf_event_task_ctx (ctx, task_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock (); }
@@ -3372,6 +3377,9 @@ static void perf_event_comm_output(strucstatic int perf_event_comm_match (struct perf_event *event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.comm)return 1 ;
@@ -3408,15 +3416,10 @@ static void perf_event_comm_event(structrcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_comm_ctx (&cpuctx->ctx, comm_event); -put_cpu_var (perf_cpu_context); - -/* -* doesn't really matter which of the child contexts the -* events ends up in. -*/ ctx =rcu_dereference (current->perf_event_ctxp);if (ctx)perf_event_comm_ctx (ctx, comm_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock (); }
@@ -3491,6 +3494,9 @@ static void perf_event_mmap_output(strucstatic int perf_event_mmap_match (struct perf_event *event,struct perf_mmap_event *mmap_event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.mmap)return 1 ;
@@ -3564,15 +3570,10 @@ got_name:rcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_mmap_ctx (&cpuctx->ctx, mmap_event); -put_cpu_var (perf_cpu_context); - -/* -* doesn't really matter which of the child contexts the -* events ends up in. -*/ ctx =rcu_dereference (current->perf_event_ctxp);if (ctx)perf_event_mmap_ctx (ctx, mmap_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock ();kfree (buf);
@@ -3863,6 +3864,9 @@ static int perf_swevent_match(struct per struct perf_sample_data *data, struct pt_regs *regs) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (!perf_swevent_is_counting (event))return 0 ;
[tip:perf/urgent] perf events: Dont report side-band events on each cpu for per-task-per-cpu events
Commit-ID: 5d27c23df09b702868d9a3bff86ec6abd22963ac Gitweb: http://git.kernel.org/tip/5d27c23df09b702868d9a3bff86ec6abd22963ac Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 17 Dec 2009 13:16:32 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 17 Dec 2009 13:21:36 +0100
perf events: Dont report side-band events on each cpu for per-task-per-cpu events
Acme noticed that his FORK/MMAP numbers were inflated by about the same factor as his cpu-count.
This led to the discovery of a few more sites that need to respect the event->cpu filter.
LKML-Reference: <[email protected]>
--- kernel/perf_event.c | 32 ++++++++++++++++++-------------- 1 files changed, 18 insertions(+), 14 deletions(-)
kernel/perf_event.c +18 -14
@@ -1381,6 +1381,9 @@ static void perf_ctx_adjust_freq(struct perf_event_context *ctx)if (event->state !=PERF_EVENT_STATE_ACTIVE )continue ; +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +continue ; + hwc = &event->hw; interrupts = hwc->interrupts;
@@ -3265,6 +3268,9 @@ static void perf_event_task_output(struct perf_event *event,static int perf_event_task_match (struct perf_event *event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.comm || event->attr.mmap || event->attr.task)return 1 ;
@@ -3290,12 +3296,11 @@ static void perf_event_task_event(struct perf_task_event *task_event)rcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_task_ctx (&cpuctx->ctx, task_event); -put_cpu_var (perf_cpu_context); -if (!ctx) ctx =rcu_dereference (task_event->task->perf_event_ctxp);if (ctx)perf_event_task_ctx (ctx, task_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock (); }
@@ -3372,6 +3377,9 @@ static void perf_event_comm_output(struct perf_event *event,static int perf_event_comm_match (struct perf_event *event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.comm)return 1 ;
@@ -3408,15 +3416,10 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)rcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_comm_ctx (&cpuctx->ctx, comm_event); -put_cpu_var (perf_cpu_context); - -/* -* doesn't really matter which of the child contexts the -* events ends up in. -*/ ctx =rcu_dereference (current->perf_event_ctxp);if (ctx)perf_event_comm_ctx (ctx, comm_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock (); }
@@ -3491,6 +3494,9 @@ static void perf_event_mmap_output(struct perf_event *event,static int perf_event_mmap_match (struct perf_event *event,struct perf_mmap_event *mmap_event) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (event->attr.mmap)return 1 ;
@@ -3564,15 +3570,10 @@ got_name:rcu_read_lock (); cpuctx = &get_cpu_var (perf_cpu_context);perf_event_mmap_ctx (&cpuctx->ctx, mmap_event); -put_cpu_var (perf_cpu_context); - -/* -* doesn't really matter which of the child contexts the -* events ends up in. -*/ ctx =rcu_dereference (current->perf_event_ctxp);if (ctx)perf_event_mmap_ctx (ctx, mmap_event); +put_cpu_var (perf_cpu_context);rcu_read_unlock ();kfree (buf);
@@ -3863,6 +3864,9 @@ static int perf_swevent_match(struct perf_event *event, struct perf_sample_data *data, struct pt_regs *regs) { +if (event->cpu !=-1 && event->cpu !=smp_processor_id ()) +return 0 ; +if (!perf_swevent_is_counting (event))return 0 ;
Ingo Molnar
AppliedQuoted 3 lines · Peter Zijlstra
Fixes an issue with the per-task-per-cpu counters, reported by acme. Fixes an false positive in the
set_task_cpu()debug check, reported by Ingo. Fixes up thetask->stateto char bits, gumbled at by tglx.
Applied, thanks Peter!
Ingo