From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Tejun Heo <tj@kernel.org>
Subject: [RFC][PATCH 03/10] workqueue: It is likely that WORKER_NOT_RUNNING is true
Date: Mon, 06 Dec 2010 20:58:37 -0500 [thread overview]
Message-ID: <20101207021328.847976021@goodmis.org> (raw)
In-Reply-To: 20101207015834.196176991@goodmis.org
[-- Attachment #1: 0003-workqueue-It-is-likely-that-WORKER_NOT_RUNNING-is-tr.patch --]
[-- Type: text/plain, Size: 2290 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
Running the annotate branch profiler on three boxes, including my
main box that runs firefox, evolution, xchat, and is part of the distcc farm,
showed this with the likelys in the workqueue code:
correct incorrect % Function File Line
------- --------- - -------- ---- ----
96 996253 99 wq_worker_sleeping workqueue.c 703
96 996247 99 wq_worker_waking_up workqueue.c 677
The likely()s in this case were assuming that WORKER_NOT_RUNNING will
most likely be false. But this is not the case. The reason is
(and shown by adding trace_printks and testing it) that most of the time
WORKER_PREP is set.
In worker_thread() we have:
worker_clr_flags(worker, WORKER_PREP);
[ do work stuff ]
worker_set_flags(worker, WORKER_PREP, false);
(that 'false' means not to wake up an idle worker)
The wq_worker_sleeping() is called from schedule when a worker thread
is putting itself to sleep. Which happens most of the time outside
of that [ do work stuff ].
The wq_worker_waking_up is called by the wakeup worker code, which
is also callod outside that [ do work stuff ].
Thus, the likely and unlikely used by those two functions are actually
backwards.
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/workqueue.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 90db1bd..b3afcce 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -661,7 +661,7 @@ void wq_worker_waking_up(struct task_struct *task, unsigned int cpu)
{
struct worker *worker = kthread_data(task);
- if (likely(!(worker->flags & WORKER_NOT_RUNNING)))
+ if (unlikely(!(worker->flags & WORKER_NOT_RUNNING)))
atomic_inc(get_gcwq_nr_running(cpu));
}
@@ -687,7 +687,7 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task,
struct global_cwq *gcwq = get_gcwq(cpu);
atomic_t *nr_running = get_gcwq_nr_running(cpu);
- if (unlikely(worker->flags & WORKER_NOT_RUNNING))
+ if (likely(worker->flags & WORKER_NOT_RUNNING))
return NULL;
/* this can only happen on the local cpu */
--
1.7.2.3
next prev parent reply other threads:[~2010-12-07 2:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-07 1:58 [RFC][PATCH 00/10] incorrect unlikely() and likely() cleanups Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 01/10] sched: Change rt_task(prev) in pre_schedule_rt to likely Steven Rostedt
2010-12-07 3:25 ` Yong Zhang
2010-12-07 3:32 ` Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 02/10] mm: Remove likely() from mapping_unevictable() Steven Rostedt
2010-12-07 2:22 ` Steven Rostedt
2010-12-07 7:02 ` Nick Piggin
2010-12-07 13:06 ` Steven Rostedt
2010-12-07 16:26 ` Rik van Riel
2010-12-10 7:00 ` KOSAKI Motohiro
2010-12-10 7:06 ` Joe Perches
2010-12-10 8:08 ` Miles Bader
2010-12-11 0:09 ` Steven Rostedt
2010-12-07 1:58 ` Steven Rostedt [this message]
2010-12-07 9:49 ` [RFC][PATCH 03/10] workqueue: It is likely that WORKER_NOT_RUNNING is true Tejun Heo
2010-12-07 13:07 ` Steven Rostedt
2010-12-11 0:08 ` Steven Rostedt
2010-12-11 0:09 ` Tejun Heo
2010-12-11 0:12 ` Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 04/10] sched: Change pick_next_task_rt from unlikely to likely Steven Rostedt
2010-12-07 2:46 ` Gregory Haskins
2010-12-07 2:59 ` Steven Rostedt
2010-12-11 0:07 ` Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 05/10] mm: Remove likely() from grab_cache_page_write_begin() Steven Rostedt
2010-12-07 2:24 ` Steven Rostedt
2010-12-07 6:56 ` Nick Piggin
2010-12-07 1:58 ` [RFC][PATCH 06/10] sched: Remove unlikely() from rt_policy() in sched.c Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 07/10] x86: Remove unlikey()s from sched_switch segment tests Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 08/10] fs: Remove unlikely() from fput_light() Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 09/10] fs: Remove unlikely() from fget_light() Steven Rostedt
2010-12-07 1:58 ` [RFC][PATCH 10/10] sched: Remove unlikely() from ttwu_post_activation Steven Rostedt
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=20101207021328.847976021@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tj@kernel.org \
/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