Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp19596imm; Fri, 31 Aug 2018 15:44:27 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda+mJEnmuIWSZQZFTNLgFCb//1P/mSIOxnrqR2dD656f2/5iRn8MTqO8kYOZFvISqdmvyI+ X-Received: by 2002:a63:66c7:: with SMTP id a190-v6mr14304927pgc.411.1535755467140; Fri, 31 Aug 2018 15:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535755467; cv=none; d=google.com; s=arc-20160816; b=H/L8tuoKJYtYXWsXuu+dH55cTdZFAutDMNxEHbcpcjLaPLGw+N1u3TSkWSDh/T3mF0 /aTnftJY1kY8WeQcB77K7mWzQWosh2rOPa4R/6hA9M/cgCJW1eCBwBap/8hTBdVyzyVb HbhEne1HLxbnozlf5OaEkGF+3k+Is0L0QpKpcszC/t7gR2nqGSad/r82jVekfknU5/X5 EsJQsyLbqofcuXQ7LsZUWdCuCNXZyngP04HFroFO4borsy8qKNUzGMgmCBxrYxpl7sGy jfOaCAzopEcXBw/nM+U8A2XTryRAudvTghxE8McjNxWlM1tLJUWMDbekfgMcYaB9Yu8G LksA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature:arc-authentication-results; bh=bSWtmVHdy6cuRwB7rIChRFaGA6F6tUQK3awO6ib4VPI=; b=VJmFV4G/l8RWa8deqyeeQ87LpvfAiXO3GFtS7s/CuMrW1EHss5wc2CvqvB8KPn4Tcp 6N0kCKBoa+Up77t2qEv7wzEvSJxQ9XJzyAhKcOGAki+qgDQv243yefuOzuNhVE+9kvl+ emxVPNo1OMokTWaDDmC7xvgg2bZjg36W54Mv+n4fG2NeHz0qxptsGXHF/zkmkCSxkjcA HHL/eFyB3XXolKxEN/CLgu0h1Her0jUmusTwh2zqIieNldBKTdTHXxoCgSBfdDLotbXH uoZWAfq0IABIKdVZ1MYYR25RhjARtrHoNZG77WyYUZDdxyb+tCINzqEjongxU2kVqCTe r73g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XS530OL3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f73-v6si11542159pfk.97.2018.08.31.15.44.11; Fri, 31 Aug 2018 15:44:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XS530OL3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727443AbeIACwK (ORCPT + 99 others); Fri, 31 Aug 2018 22:52:10 -0400 Received: from mail-qt0-f202.google.com ([209.85.216.202]:41471 "EHLO mail-qt0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727232AbeIACwK (ORCPT ); Fri, 31 Aug 2018 22:52:10 -0400 Received: by mail-qt0-f202.google.com with SMTP id y54-v6so16128284qta.8 for ; Fri, 31 Aug 2018 15:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=bSWtmVHdy6cuRwB7rIChRFaGA6F6tUQK3awO6ib4VPI=; b=XS530OL3vf4EYSY01G75QbooLYiWxPdTWpbJklWHmmGchcBtXZ+j5EEjzlUihKLU7T 8xOQoQlA+IvkIvkSJBRLGzg3DPxIc6PI+wY4aTw5xi9M8GzqwIzXWCmQzWNVBnnEZT7a ti2rPfxyCworVLO7u6Cziz5MDawJ7UyPncvVAo0xDeO/w7LSGsNU/vmTIn1O+5l5C9GF mYyc5edWgShNtLUKG1JpOwTVY8D2v9TtFXeIu2VmxXy1vJSk1hkmg7QL90L7js4XRs/d KIkgMDDxsB82H5CuUUcCkIjxl7fL9C8uuRn+DKSic3N7Z7H4UDmD+iARhAJ2UEmzonhM zk5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=bSWtmVHdy6cuRwB7rIChRFaGA6F6tUQK3awO6ib4VPI=; b=oaxUeaU7Wtq0EU8YianAu6kUkGGQ+u3uF+nurJKhKy9cEMkbXNoFgSPkz98b+9j16m 5udZ9YLafLb2f7WzQUldpmhv2TwtxyWha6K4uCobsGt/eT4fSGe2blPmU7MlX9o2PkDK +hxGM6AFKazDvtKMsBeV7NxzK8zNugkoiHXWLM7Yqzfdk6PuvHIldLyqiptBoH+u8Kxv 0qa+nIeDehAZcAfYOPm6bilJWpIxFX7x45xPB/FhHsuGQm/q5VwUNE275K+LpBblD1B1 I15T/bVdYc3lidxoxwKJ1cRSZVI9fZAj8CBj8wdoeodUomoX+o8Ft/i8uk3uRKyxFXdc vgTw== X-Gm-Message-State: APzg51AV7xGtZ4KChh+KfzWheRjfs9JdcazyloMTRM7AGGWI4Hw/rhFS j5+yiP2VFYnYs33GV0qw6+gwPxITYq10 X-Received: by 2002:ac8:2943:: with SMTP id z3-v6mr9929647qtz.1.1535755353713; Fri, 31 Aug 2018 15:42:33 -0700 (PDT) Date: Fri, 31 Aug 2018 15:42:17 -0700 Message-Id: <20180831224217.169476-1-smuckle@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.rc1.350.ge57e33dbd1-goog Subject: [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup From: Steve Muckle To: Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Todd Kjos , Paul Turner , Quentin Perret , Patrick Bellasi , Chris Redpath , Morten Rasmussen , Dietmar Eggemann , Miguel de Dios , John Dias , Steve Muckle Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a task which previously ran on a given CPU is remotely queued to wake up on that same CPU, there is a period where the task's state is TASK_WAKING and its vruntime is not normalized. This is not accounted for in vruntime_normalized() which will cause an error in the task's vruntime if it is switched from the fair class during this time, for example if it is boosted to RT priority via rt_mutex_setprio. The rq's min_vruntime will not be subtracted from the task's vruntime but it will be added again when the task returns to the fair class. The task's vruntime will have been erroneously doubled and the effective priority of the task will be reduced. Note this will also lead to inflation of all vruntimes since the doubled vruntime value will become the rq's min_vruntime when other tasks leave the rq. This leads to repeated doubling of the vruntime and priority penalty. Fix this by recognizing a WAKING task's vruntime as normalized only if sched_remote_wakeup is true. This indicates a migration, in which case the vruntime would have been normalized in migrate_task_rq_fair(). Based on a similar patch from joaodias@google.com. Suggested-by: Peter Zijlstra Signed-off-by: Steve Muckle --- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b39fb596f6c1..b3b62cf37fb6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9638,7 +9638,8 @@ static inline bool vruntime_normalized(struct task_struct *p) * - A task which has been woken up by try_to_wake_up() and * waiting for actually being woken up by sched_ttwu_pending(). */ - if (!se->sum_exec_runtime || p->state == TASK_WAKING) + if (!se->sum_exec_runtime || + (p->state == TASK_WAKING && p->sched_remote_wakeup)) return true; return false; -- 2.19.0.rc1.350.ge57e33dbd1-goog