Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2007403lqb; Mon, 27 May 2024 05:08:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsdfRPzcV2/M4ALfr8bUkS+EgCIKsrWA5AqMsUpQTdz40iylyVo0HTZoIVhe3YC4BHj55ElFVhpA8oCRupKYZE/BF6iKo5X9I0EjGXeA== X-Google-Smtp-Source: AGHT+IE75RjW5McmYAAqWOgl7Z/9R9rmJxkvSfH2P5c1AVf2lXV4i7iZJ8TyUhWAQkcBhb1ya1JX X-Received: by 2002:a17:907:cb1b:b0:a5a:1b60:7c9a with SMTP id a640c23a62f3a-a62651565f9mr771271866b.71.1716811720637; Mon, 27 May 2024 05:08:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716811720; cv=pass; d=google.com; s=arc-20160816; b=LMMRI5vRRchhXL0PIlOps2891ALzEEfivCbX3wrB7qpEtN5tpfRmZW22DFEAClqMtU qkVyiZjcsY9yZzFpxpTvIMu4y8b1tl35Qh3w7MaOjs6wqz8EuTmefIwpAlrzwBcCxRvZ QozLe/hYDSydrDExRSxifTimFbGn/Gi+44SDSiiD4uG913Mg0tFK2YiWVkLL1ZSInUQB Q71lCnA2KGVLOU3X0MXPcslTkieSWy0cQ0wP3/g6Wc8pHJ4V6l1KaaqSUfFkQBF9tn66 wDliwcvd1e4uUNuvM8Q+Vfqkbbbl6AJPE8hsjult189Z9svur/1Rrxfhu4E3qKalWF48 ygow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sf1xdQSveEFlNjiGEWBRQerJqqqieew7+FPNPjTHRpM=; fh=HU7ivrnk+91Ajh81gryUDbZXf63BwQAlqSQDHkrjwDI=; b=GgIMWX9lh0IsaDu5aONh95PtCrCWAxZJOUsowQcoELN3e/huYn+8I4ceJRaNYhpC/7 bljcgWeQuHhqeZ/I/qV0meoi/Qm1rTm1E7NyRLXsKN57Woub1NnlYkprFtjWTyb9SNQD ge8dYRsYjbzpOVeUABxja8xjsrO2UwmSIFHFsUiFiBhJSbya5CEvKDCzzby9Y90QV7D3 50vE5TffL1Q8mTGxGBgfoC3RnrilEc8qTEM8dYmen2y2dWxPZeH+6YW6z+cPZlmdBdvc xe+xmqfqBqcarpZFiULvm19a+7991iuqKKR6vFAGSDArKvzv2fj67NVhVcfR8XpwcZb7 3HLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vPr2yflF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190534-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cd90232si376068566b.717.2024.05.27.05.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:08:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190534-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vPr2yflF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190534-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190534-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5EECE1F215FE for ; Mon, 27 May 2024 12:08:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC1FB15E5C3; Mon, 27 May 2024 12:07:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vPr2yflF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6D1F15E5A1 for ; Mon, 27 May 2024 12:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716811662; cv=none; b=WGrkARdPQtIeRnRwERsIukPbOoM3m2XEcnKr9sCDl2NmCZe6I2Y6sk1ef3l7UjVc2U99Yp3tXGJGPFewGwOSRsAzqEqdGtroRC6tiJqW3MdQGzYTOEy/CWSoHb+aHHhsAc/vPPIRM/EuPXuTWgCUapJy+MsHhZGhoPSFw6ICxcQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716811662; c=relaxed/simple; bh=NDyaoW3Q0zMLZglcicXIeo2NJZBNXM84ySYhq0BL5yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g3MdB9+PE3umBVfxCBJfZo1vSyCFHNtkGi4xPG6gXHybx0lT2mJLucMKpYRFu7QOSgcZ3KWnGpkNH9J8yTKx3oQ5cXnIf8U5YMTPhOBqyyjHFydse8Xg6ZQddjhUttJXn/U9I4QFO4hrhV77D/A0g695OVwAOvOw+tWh8zXc42c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vPr2yflF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A87F4C32789; Mon, 27 May 2024 12:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716811662; bh=NDyaoW3Q0zMLZglcicXIeo2NJZBNXM84ySYhq0BL5yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vPr2yflFqRxoc2GaYKemAj+WW3w2guVJfzqE48MR3fXAcEl1cJ2+30qlA7ZuKuZgV PxRayVXh1XMqTyg65D9nZ7YfbICGl1+Ez29gjR5icOTLg077RVhuepX0IOEiWCQv6N 5fYySXbJtFcZ9wZWgQ51h5reHWplz11AYcMp0fSHZWrph12GjOGTUUNxLlrGiWBXM+ hoje3t+pzPuFqlgDOKJnDsgN5aIkRWoR2y6jdxq+VdIsbdKS7grvfNaL5XZH6sUdQq Dka+SLuJicCz6ncXVz0P2FCypn3eYIWI+w0criGF/ogt2DOohHf3BBdV6YSXllDm/R a9fIvwV6ockcQ== From: Daniel Bristot de Oliveira To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Luca Abeni , Tommaso Cucinotta , Thomas Gleixner , Joel Fernandes , Vineeth Pillai , Shuah Khan , bristot@kernel.org, Phil Auld , Suleiman Souhlal , Youssef Esmat Subject: [PATCH V7 7/9] sched/core: Fix priority checking for DL server picks Date: Mon, 27 May 2024 14:06:53 +0200 Message-ID: <48b78521d86f3b33c24994d843c1aad6b987dda9.1716811044.git.bristot@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Joel Fernandes (Google)" In core scheduling, a DL server pick (which is CFS task) should be given higher priority than tasks in other classes. Not doing so causes CFS starvation. A kselftest is added later to demonstrate this. A CFS task that is competing with RT tasks can be completely starved without this and the DL server's boosting completely ignored. Fix these problems. Reviewed-by: Vineeth Pillai Reported-by: Suleiman Souhlal Signed-off-by: Joel Fernandes (Google) Signed-off-by: Daniel Bristot de Oliveira --- kernel/sched/core.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 53f0470a1d0a..01336277eac9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -162,6 +162,9 @@ static inline int __task_prio(const struct task_struct *p) if (p->sched_class == &stop_sched_class) /* trumps deadline */ return -2; + if (p->dl_server) + return -1; /* deadline */ + if (rt_prio(p->prio)) /* includes deadline */ return p->prio; /* [-1, 99] */ @@ -191,8 +194,24 @@ static inline bool prio_less(const struct task_struct *a, if (-pb < -pa) return false; - if (pa == -1) /* dl_prio() doesn't work because of stop_class above */ - return !dl_time_before(a->dl.deadline, b->dl.deadline); + if (pa == -1) { /* dl_prio() doesn't work because of stop_class above */ + const struct sched_dl_entity *a_dl, *b_dl; + + a_dl = &a->dl; + /* + * Since,'a' and 'b' can be CFS tasks served by DL server, + * __task_prio() can return -1 (for DL) even for those. In that + * case, get to the dl_server's DL entity. + */ + if (a->dl_server) + a_dl = a->dl_server; + + b_dl = &b->dl; + if (b->dl_server) + b_dl = b->dl_server; + + return !dl_time_before(a_dl->deadline, b_dl->deadline); + } if (pa == MAX_RT_PRIO + MAX_NICE) /* fair */ return cfs_prio_less(a, b, in_fi); -- 2.45.1