Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1083275imm; Fri, 17 Aug 2018 11:31:35 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzSONXoqT7YvF1dfVRUtm4gy6xk1C/AIg2VrjoczwfQggjsjFpDd9eOEqbPH+LyMTKCsX39 X-Received: by 2002:a63:91c8:: with SMTP id l191-v6mr33271793pge.180.1534530695762; Fri, 17 Aug 2018 11:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534530695; cv=none; d=google.com; s=arc-20160816; b=Ub+jEKTsJ+FzoKi14mEVHNnhnMtR247urlQHWkWX5b+G0l5qJc9Byjdfm96BYwG9PC cz9IUNB9XYvc/UlyD9exUq6fppD82O7RVDbjzwyofDnbiOsvDrvdOq4hnqmcLzXNR9bj 2kuxrHjc1uKZPjtHkUh2SleTtELS5OgTuhSnkN9cIAjqMv4adQCrKTPp4IkjMqQ6u0fv VkrguB5jPwH99TZYVVckf0XBCRMDfqdAZB0bVE53nxFLzYwOiWRSgDf8yRvhuzN0RwNm lquI8SrKNanuAEONaB3rmqd6aKozJd+5CCQyWLVckWY9dADRXD2Mc5gx7tD0j7QbLoQ+ hzJg== 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=/3Uu972U/RgSEz+2T2FBIwg2AdeaO7TwqX4vV6NphQE=; b=TmT/pI+0SXPuSAjm01pWM697+pcIy1NCemLS0V2audPMga6I08VLKuJvDsLWxf0EhN E+rRV8UAuzLW2+5EQ3D04n+BgnthzUAkuaTf41GsJ1UgG23OWgNho4yibPZzsQEZbmkE xK/qysWs28vBMUblBX5d0RJjIKLNrVUp2pVXFA53teneAsFh0Bx+b1G/rxmQFYX39epH CQ+MjMClUO52IfERn3WffVIvBGzbWanTc95urZhiCPjDpmGgiVFiXBNaYGXegGSkqLnq gtZt2nzdgELK6YmSNBiOVTF5ZwhLFU/a47IItAj/D9RLQ+k+dlodAUVz9Xdezwei2uL/ CHoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OY9yepES; 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 z4-v6si2584348pge.173.2018.08.17.11.30.57; Fri, 17 Aug 2018 11:31:35 -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=OY9yepES; 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 S1727738AbeHQVco (ORCPT + 99 others); Fri, 17 Aug 2018 17:32:44 -0400 Received: from mail-oi0-f73.google.com ([209.85.218.73]:47183 "EHLO mail-oi0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726888AbeHQVcn (ORCPT ); Fri, 17 Aug 2018 17:32:43 -0400 Received: by mail-oi0-f73.google.com with SMTP id w128-v6so7921537oiw.14 for ; Fri, 17 Aug 2018 11:28:19 -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=/3Uu972U/RgSEz+2T2FBIwg2AdeaO7TwqX4vV6NphQE=; b=OY9yepES1Myt+VRCqTO9fTea8yyJU9xfjFzGQsidzzQibbHwfcSASPgH5s44PSxdk6 SutDjO5LT/jNXaKNVF+5NqfwB0PqJRLQ0qW3FKMLx+gXRdJc/G58TnMKlzACFM0Pk+rq wnbO4uaDT/KU/fCajw49OS0PI5zexzlVsdiOkw/LvEQmrtjN3Wu6EsGrs6HuwjwHIUye P07ADrzqgIBvyn/DFu807kIXIQmBTiG0C6PF+E3HkC5jiVhu8ky2+p7tUKwo4ShxGhT5 76lA90VYZJRC4EYvn4JUcPA8ro4RkSg0QuIaCFpo6IaDpUART084cih4h+zrFdzX0x0a Sz4Q== 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=/3Uu972U/RgSEz+2T2FBIwg2AdeaO7TwqX4vV6NphQE=; b=pa4CukHHI5n5UmnParpm+URNBUvWN/ORBjSEbm6xAOcH2jL8aFzEOCEJ0gEafc5AdJ MSKnTSa6p5SGpm5NzDy03ESmdLmAb9MB1TMh8HyvLJBTNRzfSWkaZyXkaMEUUmGvQul3 RVbhuwW1VOquFejp00uL613/scaKCpfmhVtKVxRUOFKZBklReFOxbCbTbzdb3gkKhiei lFX+4pvl9grjIZQ5nC7cKHfIBN1SXDtHGR9IaPooX28cTYtwXN9APAP+ErRtym+6Moez tfAQSbtI09eB3pJcb1IK8oRlOXPdpgsunpq+4bS8pMeDrr79eA3Q/pXxvLF51Uav7LBQ SJhw== X-Gm-Message-State: AOUpUlHm5mnPK9MuTO2E6PKv8hFY0NI3ArZyORtlHo+v2f9nOKQJpWi/ Kbtg/leBznLN5pVWzeqciVzaNV5XfHEp X-Received: by 2002:aca:bcd5:: with SMTP id m204-v6mr22473825oif.101.1534530499179; Fri, 17 Aug 2018 11:28:19 -0700 (PDT) Date: Fri, 17 Aug 2018 11:27:28 -0700 Message-Id: <20180817182728.76129-1-smuckle@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.18.0.865.gffc8e1a3cd6-goog Subject: [PATCH] sched/fair: vruntime should normalize when switching from fair 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 , 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 From: John Dias When rt_mutex_setprio changes a task's scheduling class to RT, we're seeing cases where the task's vruntime is not updated correctly upon return to the fair class. Specifically, the following is being observed: - task is deactivated while still in the fair class - task is boosted to RT via rt_mutex_setprio, which changes the task to RT and calls check_class_changed. - check_class_changed leads to detach_task_cfs_rq, at which point the vruntime_normalized check sees that the task's state is TASK_WAKING, which results in skipping the subtraction of the rq's min_vruntime from the task's vruntime - later, when the prio is deboosted and the task is moved back to the fair class, the fair rq's min_vruntime is added to the task's vruntime, even though it wasn't subtracted earlier. The immediate result is inflation of the task's vruntime, giving it lower priority (starving it if there's enough available work). The longer-term effect is inflation of all vruntimes because the task's vruntime becomes the rq's min_vruntime when the higher priority tasks go idle. That leads to a vicious cycle, where the vruntime inflation repeatedly doubled. The change here is to detect when vruntime_normalized is being called when the task is waking but is waking in another class, and to conclude that this is a case where vruntime has not been normalized. Signed-off-by: John Dias 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..14011d7929d8 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_class == &fair_sched_class)) return true; return false; -- 2.18.0.865.gffc8e1a3cd6-goog