Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp438055pxb; Mon, 16 Aug 2021 08:46:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPu4G7CaDrUmJI9OhDCC1EGCF6D4qlFU/izl9KCiGdTjkOwgI6BLLy9uCvwWDip9ox6181 X-Received: by 2002:a92:b711:: with SMTP id k17mr9611234ili.247.1629128799878; Mon, 16 Aug 2021 08:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629128799; cv=none; d=google.com; s=arc-20160816; b=0OEhBTPpe24EacpwrwVrFY6wlZvDdPLsZzG4TsPgZEWVWfP4l4o1W9yjfBY300jEJr 2rpnFJ61z4Tj1QkTUgfURaQCdCerWoI6tGVMOCWvDI750ULrGiB9550H40yFQ0iAD52z kL6iTTAsf2vovpbvXhYsSE5CB7I6RMDlAx1qG4v/OefgAvqdSlHsnIrGdGzOr4kBfS+V DfpOk71gcCLP/sCoIpQ6LcFwrS20sPc7kPAu9csD3aeEu3O9Eeq/kfYrdfKii85lr5y0 bnIznvN3WmEXp8uCNQ1x5scky9l8s2gLizy+24E4srZDcpG81HUFwvVZJuz0dN1yCEAP dZqg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=wZOfG71ek7P3J0Y5q4vioyYHaOIo86xNbpEBIPvcq4M=; b=xbkiNvL3AjmkHDew5J+aWg2IrPmUf0JNx0f1iepAx2cBPlvup7VXSjc9a+2galNIeh GOuSj0RoJ/oKP9u5eAgz/4HPVZRp28CS4gv/Xqg2mSodlhk0Npy3VQeDMMIGHoI7Xmap bYcfXpQMy4Ofkbwdmkxq48/YjX5mwcDyvEGZSBJi7Wr+LZPVuPAJUaY4gV4jS+Q2vsQr Pmres+xLZnO2nsJEmK1o92XtObDRQIeDR+MQKzTMvNNjnbr76y6pzSdSSprcFezzMBAQ Y39WhX+/C+drwxnIGQopFf+XHNVRBBg9ARZdplc3ycFscmLDWHlwASbbPeU4OChIHFdy MY9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xmZ7spvQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si12540039ilu.60.2021.08.16.08.46.27; Mon, 16 Aug 2021 08:46:39 -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=@linux.dev header.s=key1 header.b=xmZ7spvQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236634AbhHPPot (ORCPT + 99 others); Mon, 16 Aug 2021 11:44:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236652AbhHPPor (ORCPT ); Mon, 16 Aug 2021 11:44:47 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1ED4C0617AD for ; Mon, 16 Aug 2021 08:44:14 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1629128652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wZOfG71ek7P3J0Y5q4vioyYHaOIo86xNbpEBIPvcq4M=; b=xmZ7spvQkIBAPpxyuyDC5DZMBIuaeCq2Tw3PNXn/3KK9seoMM0gyZQyw72qcA+nEKJ3tD3 afFKwrMbf+XgYed5ITYemyfI+8m9vl1biNjrpH073wFC4hQr1t3s5nB44gngAI+gonyGqd NhaHW+uo+lk0kZbPWCMGBkepiSDzGOM= From: Tao Zhou To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, tglx@linutronix.de, joel@joelfernandes.org, chris.hyser@oracle.com, joshdon@google.com, mingo@kernel.org, vincent.guittot@linaro.org, valentin.schneider@arm.com, mgorman@suse.de, tao.zhou@linux.dev Subject: [PATCH] sched/core: An optimization of pick_next_task() not sure Date: Mon, 16 Aug 2021 23:44:01 +0800 Message-Id: <20210816154401.23919-1-tao.zhou@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: tao.zhou@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When find a new candidate max, wipe the stale and start over. Goto again: and use the new max to loop to pick the the task. Here first want to get the max of the core and use this new max to loop once to pick the task on each thread. Not sure this is an optimization and just stop here a little and move on.. Compiled. --- kernel/sched/core.c | 52 +++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 20ffcc044134..bddcd328df96 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5403,7 +5403,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) const struct sched_class *class; const struct cpumask *smt_mask; bool fi_before = false; - int i, j, cpu, occ = 0; + int i, cpu, occ = 0; bool need_sync; if (!sched_core_enabled(rq)) @@ -5508,11 +5508,27 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) * order. */ for_each_class(class) { -again: + struct rq *rq_i; + struct task_struct *p; + for_each_cpu_wrap(i, smt_mask, cpu) { - struct rq *rq_i = cpu_rq(i); - struct task_struct *p; + rq_i = cpu_rq(i); + p = pick_task(rq_i, class, max, fi_before); + /* + * If this new candidate is of higher priority than the + * previous; and they're incompatible; pick_task makes + * sure that p's priority is more than max if it doesn't + * match max's cookie. Update max. + * + * NOTE: this is a linear max-filter and is thus bounded + * in execution time. + */ + if (!max || !cookie_match(max, p)) + max = p; + } + for_each_cpu_wrap(i, smt_mask, cpu) { + rq_i = cpu_rq(i); if (rq_i->core_pick) continue; @@ -5536,34 +5552,6 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) rq->core->core_forceidle_seq++; } - /* - * If this new candidate is of higher priority than the - * previous; and they're incompatible; we need to wipe - * the slate and start over. pick_task makes sure that - * p's priority is more than max if it doesn't match - * max's cookie. - * - * NOTE: this is a linear max-filter and is thus bounded - * in execution time. - */ - if (!max || !cookie_match(max, p)) { - struct task_struct *old_max = max; - - rq->core->core_cookie = p->core_cookie; - max = p; - - if (old_max) { - rq->core->core_forceidle = false; - for_each_cpu(j, smt_mask) { - if (j == i) - continue; - - cpu_rq(j)->core_pick = NULL; - } - occ = 1; - goto again; - } - } } } -- 2.31.1