From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752233AbcBLRda (ORCPT ); Fri, 12 Feb 2016 12:33:30 -0500 Received: from g2t4621.austin.hp.com ([15.73.212.80]:35906 "EHLO g2t4621.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbcBLRci (ORCPT ); Fri, 12 Feb 2016 12:32:38 -0500 From: Waiman Long To: Ingo Molnar Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Linus Torvalds , Ding Tianhong , Jason Low , Davidlohr Bueso , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen , Waiman Long , Waiman Long 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 Message-Id: <1455298335-53229-5-git-send-email-Waiman.Long@hpe.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com> References: <1455298335-53229-1-git-send-email-Waiman.Long@hpe.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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