Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3849825pxu; Tue, 20 Oct 2020 02:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNYnDMvrDPb1IhT26zp9Gex85v5bxY+NYReVNDWHT1gVsanoK7+s4ZdcmbgukuKldt/PhX X-Received: by 2002:a17:906:3e4b:: with SMTP id t11mr2028447eji.420.1603184443591; Tue, 20 Oct 2020 02:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603184443; cv=none; d=google.com; s=arc-20160816; b=0c3UdljP3ZV7a4LoliLbXGfchF4FPxqtM/mnuj6fwu70fMJ/jZvmFajPnCUMrKd78O oQZAdXqTJFOUoIwIG8DXKLrWWbwipwc8EosLG0N+0w31X3Mh1ZRSPEt1iQPDkyfsf9Ow 0vWP/2yY5BXOwZY67r9I15K98JBgLt/WE7J9pc6VU+738eonxZHYDR02uQsQvUEQ/lFo hFCn3RsoQzfo/Q0sdeemVfHcPjFZrltsFDbspvQA8smUOUuxCMP5kY4pVCWypvrZjMk+ kXoWbFDv4Jgf8JTo/xkznhU5DZn09I5EdGd3cOwexGY0TVWbH+veSvlstuyeY4Gx/6I3 vP2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nlj6uMgqye3sNdx+NX3t8GEGIV8O1B0tM0quVu2qzg0=; b=fx+ezjoAJ8FHpnR0WbtU675gQU6evs9XiEcjKBtJxeJqUYyo6qEjENrBzt1Y65xHV2 fvuQ7Y8PYUEj/R01AYiuPFXBrHYLuAjMYBMKT9IOrP2xw0ZUdEp8owKMj9KOYLIiCmdJ gHUR2ZpwbYMAg5IOW3ONCYM/gEr706I/vQSix9R8VtOZtzk8IeOCZh+uy3cQWXG7ZsW+ YOOPv7U1KanCCwemRFBO/7Ss8mOiJ27iYbX+yB2trMxtthWngjFbv1SAKpiYmNL3DW71 J/7h4YUPrDK8uYyj9twKw6Wxi5KmEmygpC2W+huKMOc8s/eXMmur6Ubmqvc3EkEuh7+o 4IKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=RW80QFNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id er22si842885ejc.463.2020.10.20.02.00.20; Tue, 20 Oct 2020 02:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=RW80QFNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390177AbgJTBoJ (ORCPT + 99 others); Mon, 19 Oct 2020 21:44:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728305AbgJTBoH (ORCPT ); Mon, 19 Oct 2020 21:44:07 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95EA5C0613CE for ; Mon, 19 Oct 2020 18:44:07 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id 67so558069iob.8 for ; Mon, 19 Oct 2020 18:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nlj6uMgqye3sNdx+NX3t8GEGIV8O1B0tM0quVu2qzg0=; b=RW80QFNL4iqRO+dc1gvPnm/ISemqsNIJpzAYBArJKVUJ96Y8SwG92ht2qjuMUUNSre s0+k4M9OYZsP1u0BSTEc00AKJmgGr6vq29YDrClEP7dnO6x1JFc/vLKmpWCMSSrgPAJ4 A0dOPk3ydEtMrzy2BIXLrBbsNRIJhKlYP/M7M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nlj6uMgqye3sNdx+NX3t8GEGIV8O1B0tM0quVu2qzg0=; b=pwtUrUWwkbcg8FOIepfN8gBnmiCuCtWVqWfpfrYA4H5MXavVLNzVOq817KEbj+wYs6 XT+e5hatmBrFOrbw2cbry9+i8xJp6l3xlqk2H9dt7T4/8u1JCl7NwC7AF9GwhBfmU1BJ m/XBbiPAYXaYFveCLMw8OeRSPfX0lOvLLCaAelQlR6M/fqpcHNGxv04QThrVXLeU3Iq9 o6b3Z6o/reUcoEbuy8WiL5hcOZ9eSeZbObhAS9NoRaWyHwTWApD4HrXlFbOAs3xTVaL1 AdEMwfCRIggRpxyMvSAr56d+RECJwYni8AIgm3kqAO00YJXPsT5k4SXT6Olj1MIyINao z8FQ== X-Gm-Message-State: AOAM530lW2lXUwkWyMN3OoTDnC5eKSXn5w4Zt+CjR0GJtShNvO7mPPvB pLx1mgTNxgxDPn+6qviehqC2Uw== X-Received: by 2002:a6b:e51a:: with SMTP id y26mr484709ioc.86.1603158246978; Mon, 19 Oct 2020 18:44:06 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id t22sm485306ili.9.2020.10.19.18.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 18:44:06 -0700 (PDT) From: "Joel Fernandes (Google)" To: Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org Cc: mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , joel@joelfernandes.org, vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Vineeth Remanan Pillai , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: [PATCH v8 -tip 07/26] sched/fair: Fix forced idle sibling starvation corner case Date: Mon, 19 Oct 2020 21:43:17 -0400 Message-Id: <20201020014336.2076526-8-joel@joelfernandes.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201020014336.2076526-1-joel@joelfernandes.org> References: <20201020014336.2076526-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineeth Pillai If there is only one long running local task and the sibling is forced idle, it might not get a chance to run until a schedule event happens on any cpu in the core. So we check for this condition during a tick to see if a sibling is starved and then give it a chance to schedule. Tested-by: Julien Desfossez Signed-off-by: Vineeth Remanan Pillai Signed-off-by: Julien Desfossez --- kernel/sched/core.c | 15 ++++++++------- kernel/sched/fair.c | 40 ++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 2 +- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 12030b77bd6d..469428979182 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4710,16 +4710,15 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) /* reset state */ rq->core->core_cookie = 0UL; + if (rq->core->core_forceidle) { + need_sync = true; + rq->core->core_forceidle = false; + } for_each_cpu(i, smt_mask) { struct rq *rq_i = cpu_rq(i); rq_i->core_pick = NULL; - if (rq_i->core_forceidle) { - need_sync = true; - rq_i->core_forceidle = false; - } - if (i != cpu) update_rq_clock(rq_i); } @@ -4839,8 +4838,10 @@ next_class:; if (!rq_i->core_pick) continue; - if (is_task_rq_idle(rq_i->core_pick) && rq_i->nr_running) - rq_i->core_forceidle = true; + if (is_task_rq_idle(rq_i->core_pick) && rq_i->nr_running && + !rq_i->core->core_forceidle) { + rq_i->core->core_forceidle = true; + } if (i == cpu) { rq_i->core_pick = NULL; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 58f670e5704d..56bea0decda1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10652,6 +10652,44 @@ static void rq_offline_fair(struct rq *rq) #endif /* CONFIG_SMP */ +#ifdef CONFIG_SCHED_CORE +static inline bool +__entity_slice_used(struct sched_entity *se, int min_nr_tasks) +{ + u64 slice = sched_slice(cfs_rq_of(se), se); + u64 rtime = se->sum_exec_runtime - se->prev_sum_exec_runtime; + + return (rtime * min_nr_tasks > slice); +} + +#define MIN_NR_TASKS_DURING_FORCEIDLE 2 +static inline void task_tick_core(struct rq *rq, struct task_struct *curr) +{ + if (!sched_core_enabled(rq)) + return; + + /* + * If runqueue has only one task which used up its slice and + * if the sibling is forced idle, then trigger schedule to + * give forced idle task a chance. + * + * sched_slice() considers only this active rq and it gets the + * whole slice. But during force idle, we have siblings acting + * like a single runqueue and hence we need to consider runnable + * tasks on this cpu and the forced idle cpu. Ideally, we should + * go through the forced idle rq, but that would be a perf hit. + * We can assume that the forced idle cpu has atleast + * MIN_NR_TASKS_DURING_FORCEIDLE - 1 tasks and use that to check + * if we need to give up the cpu. + */ + if (rq->core->core_forceidle && rq->cfs.nr_running == 1 && + __entity_slice_used(&curr->se, MIN_NR_TASKS_DURING_FORCEIDLE)) + resched_curr(rq); +} +#else +static inline void task_tick_core(struct rq *rq, struct task_struct *curr) {} +#endif + /* * scheduler tick hitting a task of our scheduling class. * @@ -10675,6 +10713,8 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) update_misfit_status(curr, rq); update_overutilized_status(task_rq(curr)); + + task_tick_core(rq, curr); } /* diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 2b6e0bf61720..884d23d5e55d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1056,12 +1056,12 @@ struct rq { unsigned int core_enabled; unsigned int core_sched_seq; struct rb_root core_tree; - unsigned char core_forceidle; /* shared state */ unsigned int core_task_seq; unsigned int core_pick_seq; unsigned long core_cookie; + unsigned char core_forceidle; #endif }; -- 2.29.0.rc1.297.gfa9743e501-goog