From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
Zhaolei <zhaolei@cn.fujitsu.com>, Oleg Nesterov <oleg@redhat.com>,
Anton Blanchard <anton@samba.org>,
Steven Rostedt <rostedt@goodmis.org>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 1/5] tracing/workqueue: get rid of searching last executed worklet in probe_worklet_complete()
Date: Mon, 1 Jun 2009 19:17:13 +0200 [thread overview]
Message-ID: <1243876637-6616-2-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1243876637-6616-1-git-send-email-fweisbec@gmail.com>
From: Zhaolei <zhaolei@cn.fujitsu.com>
We don't need to search the worklet which was latest executed
inside the workqueue's worklet list.
Instead, we can use a pointer in cpu_workqueue_stats to remember
which worklet was last executed.
Thanks Oleg for pointing it out.
Changelog:
v1->v2: Oleg pointed out that if searching executed workfunc_stats failed
in probe_worklet_execute(), for example, workfunc_stats's memory allocation
failed previously, cpu_workqueue_stats->last_workfunc is not set to correct
value, and it will cause wrong accessing in probe_worklet_complete().
This problem is fixed in v2.
[ Impact: make worklet tracing faster ]
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Reported-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
kernel/trace/trace_workqueue.c | 39 ++++++++++++++++-----------------------
1 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
index c67be60..740de3b 100644
--- a/kernel/trace/trace_workqueue.c
+++ b/kernel/trace/trace_workqueue.c
@@ -25,13 +25,6 @@ struct workfunc_stats {
unsigned int inserted;
unsigned int executed;
- /*
- * save latest work_struct's pointer to use as identifier in
- * probe_worklet_complete, because we can't use work_struct->...
- * after worklet got executed
- */
- void *work;
-
/* save execution time temporarily for calculate executed time */
u64 start_time;
u64 max_executed_time;
@@ -46,10 +39,17 @@ struct cpu_workqueue_stats {
/* Protected by cpu workqueue lock */
unsigned int inserted;
unsigned int executed;
+
/* list of struct workfunc_stats in this workqueue */
struct list_head workfunclist;
/*
+ * pointer to last executed worklet's workfunc_stats in this workqueue,
+ * used by probe_worklet_complete()
+ */
+ struct workfunc_stats *last_workfunc;
+
+ /*
* the task maybe destroyed when we read stat file
* we define it to void * because we only use it as a identifier
*/
@@ -163,9 +163,10 @@ found_wq:
if (wfnode->func == work->func) {
wfnode->executed++;
wfnode->start_time = trace_clock_global();
- wfnode->work = work;
+ node->last_workfunc = wfnode;
goto found_wf;
}
+ node->last_workfunc = NULL;
pr_debug("trace_workqueue: worklet not found\n");
goto end;
@@ -180,7 +181,7 @@ probe_worklet_complete(struct task_struct *wq_thread, void *work)
{
int cpu = cpumask_first(&wq_thread->cpus_allowed);
struct cpu_workqueue_stats *node;
- struct workfunc_stats *wfnode;
+ u64 executed_time;
unsigned long flags;
spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
@@ -192,22 +193,14 @@ probe_worklet_complete(struct task_struct *wq_thread, void *work)
goto end;
found_wq:
- list_for_each_entry(wfnode, &node->workfunclist, list) {
- u64 executed_time;
+ if (!node->last_workfunc)
+ goto end;
- if (wfnode->work != work)
- continue;
+ executed_time = trace_clock_global() - node->last_workfunc->start_time;
+ node->last_workfunc->total_time += executed_time;
+ if (executed_time > node->last_workfunc->max_executed_time)
+ node->last_workfunc->max_executed_time = executed_time;
- executed_time = trace_clock_global() - wfnode->start_time;
- wfnode->total_time += executed_time;
- if (executed_time > wfnode->max_executed_time)
- wfnode->max_executed_time = executed_time;
- goto found_wf;
- }
- pr_debug("trace_workqueue: worklet not found\n");
- goto end;
-
-found_wf:
end:
spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags);
}
--
1.6.2.3
next prev parent reply other threads:[~2009-06-01 17:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-01 17:17 [PATCH 0/5] tracing/workqueue updates Frederic Weisbecker
2009-06-01 17:17 ` Frederic Weisbecker [this message]
2009-06-01 17:17 ` [PATCH 2/5] tracing/events: use %pf in workqueue trace events Frederic Weisbecker
2009-06-01 17:17 ` [PATCH 3/5] tracing/events: rename worklet_execute to worklet_entry and worklet_complete to worklet_exit Frederic Weisbecker
2009-06-01 17:17 ` [PATCH 4/5] tracing/workqueue: fix list header and function name format Frederic Weisbecker
2009-06-01 17:17 ` [PATCH 5/5] tracing/workqueue: cleanup for trace_workqueue.c Frederic Weisbecker
2009-06-01 21:42 ` [PATCH 0/5] tracing/workqueue updates 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=1243876637-6616-2-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anton@samba.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=zhaolei@cn.fujitsu.com \
/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
all inboxes | Powered by JetHome®