Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp160260pxb; Tue, 24 Aug 2021 23:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLlb2UzyVy6FUFU55x5N1/JvGzVHLsuvjqjQbiMmo4AjXK0lZL165bzXRc7OHNGXImKhDA X-Received: by 2002:a92:d3c1:: with SMTP id c1mr29724055ilh.194.1629873009474; Tue, 24 Aug 2021 23:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629873009; cv=none; d=google.com; s=arc-20160816; b=TBcujwPrzuKiNn+8KcH3KfMeYdT9EsD+QllWQCTE2k1DLJEaNyJ4COu/693GqKcTPQ gYiGaIZV1DiQDVFA505o9hLfe4HIbqmEtB+30P7BOdFmCmcy+YeGcbWqnYAaZV2MOZxK TYUCRZp7iu1dKD0A86zfA7mEP4LU9z4NdoCa6d0tZVHCHNWm696KZF0uN/+ZaSSd28Oi jZiyPdBEnu42sjTxKlWa6BOiXL6wBjq6CeIOu2B/gf4D4v0m97vm9xnH1KSU01BO2zBx eOep00J24APZvye4pWtV9uC6+RnN4d/j0JDMjk7lbiIe6HdntD2boZ2DgY9v1Dgke/e6 qYPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=R2Gx1UNxchRZwui7jObffu2HS6SSOgvdMTxL7x3KE9E=; b=URiQkpMJLp2XOEndYYZs+TSczywk9DEb4C5LQSGUf9/nAtXIkanyeMXD1QsGkX9eJp S/x0ClOR9t6DpNc039kcSlbzo5vlSV4RTIk2hZW/gKDNjRuszF1GPmThlmaCJhDNBkKv FjscaWhdX2DRy2MgJ7+mqlt+IAD3fjUnwmXWtLW1LPLbZ7VGW7xWRCgHARNok68/VkDG F01wqN31qHK56tF32PPKDIvKtUpnv1UKibloMe0p2QOMUnWghVyG+UxYnN/ZfGn5Zw4m ACvKCWXQ04Hr7glOw5hR5jI0SzhNBrG7dfEaFl/pYG65BP5aPaTGYPahuuc/2nQduCwd Zwew== ARC-Authentication-Results: i=1; mx.google.com; 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 r84si1913509jac.47.2021.08.24.23.29.51; Tue, 24 Aug 2021 23:30:09 -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; 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 S238513AbhHYG2g (ORCPT + 99 others); Wed, 25 Aug 2021 02:28:36 -0400 Received: from mx423.baidu.com ([119.249.100.231]:8217 "EHLO mx423.baidu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237913AbhHYG2g (ORCPT ); Wed, 25 Aug 2021 02:28:36 -0400 Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by mx423.baidu.com (Postfix) with ESMTP id 8C2F716E00D50; Wed, 25 Aug 2021 14:27:49 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id 7F43DD9932; Wed, 25 Aug 2021 14:27:49 +0800 (CST) From: Li RongQing To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, lirongqing@baidu.com Subject: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity() Date: Wed, 25 Aug 2021 14:27:49 +0800 Message-Id: <1629872869-19829-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Only check the skip buddy when next buddy and last buddy are not picked up, this can save the cycles of checking the skip buddy and computation of the second buddy, when next and last buddy will be picked up for example, yield_to_task_fair() set both next and skip buddy Signed-off-by: Li RongQing --- kernel/sched/fair.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 44c452072a1b..9c6569ddf3eb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4503,11 +4503,22 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) se = left; /* ideally we run the leftmost entity */ - /* - * Avoid running the skip buddy, if running something else can - * be done without getting too unfair. - */ - if (cfs_rq->skip && cfs_rq->skip == se) { + + if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) { + /* + * Someone really wants this to run. If it's not unfair, run it. + */ + se = cfs_rq->next; + } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) { + /* + * Prefer last buddy, try to return the CPU to a preempted task. + */ + se = cfs_rq->last; + } else if (cfs_rq->skip && cfs_rq->skip == se) { + /* + * Avoid running the skip buddy, if running something else can + * be done without getting too unfair. + */ struct sched_entity *second; if (se == curr) { @@ -4522,18 +4533,6 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) se = second; } - if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) { - /* - * Someone really wants this to run. If it's not unfair, run it. - */ - se = cfs_rq->next; - } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) { - /* - * Prefer last buddy, try to return the CPU to a preempted task. - */ - se = cfs_rq->last; - } - return se; } -- 2.33.0.69.gc420321.dirty