linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <Waiman.Long@hpe.com>
To: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Jason Low <jason.low2@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Waiman Long <Waiman.Long@hpe.com>,
	Waiman Long <Waiman.Long@hp.com>
Subject: [PATCH v2 4/4] sched/fair: Abort wakeup when task is no longer in a sleeping state
Date: Fri, 12 Feb 2016 12:32:15 -0500	[thread overview]
Message-ID: <1455298335-53229-5-git-send-email-Waiman.Long@hpe.com> (raw)
In-Reply-To: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com>

When a task prepares to sleep and then aborts it somehow, there is
a small chance that a waker may be spinning on the on_cpu flag of
that task waiting for the flag to turn off before doing the wakeup
operation. It may keep on spinning for a long time until that task
actually sleeps leading to spurious wakeup.

This patch adds code to detect the change in task state and abort
the wakeup operation, when appropriate, to free up the waker's cpu
to do other useful works.

Signed-off-by: Waiman Long <Waiman.Long@hp.com>
---
 kernel/sched/core.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7e548bd..e4b6e84 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2075,8 +2075,15 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
 	 *
 	 * This ensures that tasks getting woken will be fully ordered against
 	 * their previous state and preserve Program Order.
+	 *
+	 * If the owning cpu decides not to sleep after all by changing back
+	 * its task state, we can return immediately.
 	 */
-	smp_cond_acquire(!p->on_cpu);
+	smp_cond_acquire(!p->on_cpu || !(p->state & state));
+	if (!(p->state & state)) {
+		success = 0;
+		goto out;
+	}
 
 	p->sched_contributes_to_load = !!task_contributes_to_load(p);
 	p->state = TASK_WAKING;
-- 
1.7.1

  parent reply	other threads:[~2016-02-12 17:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 17:32 [PATCH v2 0/4] locking/mutex: Enable optimistic spinning of lock waiter Waiman Long
2016-02-12 17:32 ` [PATCH v2 1/4] locking/mutex: Add waiter parameter to mutex_optimistic_spin() Waiman Long
2016-02-12 20:23   ` Peter Zijlstra
2016-02-12 22:14     ` Davidlohr Bueso
2016-02-13 12:10       ` Peter Zijlstra
2016-02-13 18:14         ` Davidlohr Bueso
2016-02-16  2:15       ` Jason Low
2016-02-16  2:22         ` Jason Low
2016-02-16  8:53           ` Peter Zijlstra
2016-02-17  1:40             ` Waiman Long
2016-02-15 22:06     ` Waiman Long
2016-02-12 20:40   ` Peter Zijlstra
2016-02-15 23:55     ` Waiman Long
2016-02-16  3:00       ` Jason Low
2016-02-16  3:30         ` Waiman Long
2016-02-12 22:02   ` Davidlohr Bueso
2016-02-12 22:09     ` Davidlohr Bueso
2016-02-16  0:03     ` Waiman Long
2016-02-12 17:32 ` [PATCH v2 2/4] locking/mutex: Enable optimistic spinning of woken task in wait queue Waiman Long
2016-02-12 17:32 ` [PATCH v2 3/4] locking/mutex: Avoid missed wakeup of mutex waiter Waiman Long
2016-02-12 17:32 ` Waiman Long [this message]
2016-02-12 20:18   ` [PATCH v2 4/4] sched/fair: Abort wakeup when task is no longer in a sleeping state Peter Zijlstra
2016-02-12 21:22     ` Waiman Long
2016-02-13 12:09       ` Peter Zijlstra
2016-02-16  8:51 ` [PATCH v2 0/4] locking/mutex: Enable optimistic spinning of lock waiter Peter Zijlstra
2016-02-17  1:39   ` Waiman Long
2016-03-22  3:19   ` Waiman Long
2016-03-22  9:59     ` Peter Zijlstra

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=1455298335-53229-5-git-send-email-Waiman.Long@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=Waiman.Long@hp.com \
    --cc=Will.Deacon@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).