Message ID | 20221031125113.72980-2-zhangqiao22@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2285257wru; Mon, 31 Oct 2022 05:33:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5M6asySlpUFzgXGxSETWFPC+uB6NZxEPKBk9on6rRfi45Cc/D2aiZOfQKELXJgo6T86Jka X-Received: by 2002:a63:4f20:0:b0:46f:b887:4cc9 with SMTP id d32-20020a634f20000000b0046fb8874cc9mr5446856pgb.306.1667219603934; Mon, 31 Oct 2022 05:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667219603; cv=none; d=google.com; s=arc-20160816; b=iO0eNRIrrfAoyxmK4G5GgpFV8wH8v2Gzl72IP0Q7WDT62nPupZbpRrCUigjJaS1hSV lTMVkDYz0hzJ+LMwwTTIEOYAoL7EpOsbT1ss6z1xsyUGLY9akVqoEKXihGgT0k70+Qyk WYVU0BOiHModSVq554JFAbP3W9/EqnnK1VUBzdaAIjXqL9JpsvIQG5ZjvKfBJkvTNqa1 pTBxSRhRUgl36+RSwjwlRf7xxA3prkvYWqwUDhOszx8NHhSCDsmnfpNJ5zax63yPvNtY C3wUtmiNgRpPh6f60Gnyevp1GvgdyCEDLOqbVAVTduVXKFzYicpbDyGTXKZWpL3rkUp0 ZvJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Twqc2M1U/2q+dKwi4vzB0JrL4JXAB+DfkRyBmi/jVQo=; b=UIk6pePhYa1sqKPfk/f8fAOMZTUZZnEyoaMFdPYRIueGKZoPXcko1BtYkFdhgVKZcb f0U7mqIzsLrB4EaSSI8G1Nyybz7VVqrMtD4E4J5UYokqXWrCWaoJDRixjfNe5m1qVj5X Qh2Ex5wGXB0zhX2V/+GItzbcUKx4B/PGgERfsBhjUTDtPGQs16WrFNmuyyx9ZjrC1JhQ dEmar1WNC2/hMxPfuoKcb5wLv9t4JjbU9FW9HGTCA+t0Nki8hT94MWLWl6uJMbi/n+Sc TeW9IsbX/MrjUHhuAOYIz9MnE+VJmzXMST5HjHy1tDqjizJv+vEOv8MORe9IwmO8m8K3 uC7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b0046fd05d55e0si2212143pgi.567.2022.10.31.05.33.10; Mon, 31 Oct 2022 05:33:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbiJaMXB (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Mon, 31 Oct 2022 08:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbiJaMWt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Oct 2022 08:22:49 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D22F02D for <linux-kernel@vger.kernel.org>; Mon, 31 Oct 2022 05:22:14 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N1Bwn66ZDz15MHl; Mon, 31 Oct 2022 20:17:13 +0800 (CST) Received: from dggpeml500018.china.huawei.com (7.185.36.186) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 20:22:13 +0800 Received: from huawei.com (10.67.174.191) by dggpeml500018.china.huawei.com (7.185.36.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 20:22:13 +0800 From: Zhang Qiao <zhangqiao22@huawei.com> To: <mingo@redhat.com>, <peterz@infradead.org>, <juri.lelli@redhat.com>, <vincent.guittot@linaro.org> CC: <zhangqiao22@huawei.com>, <dietmar.eggemann@arm.com>, <rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>, <bristot@redhat.com>, <vschneid@redhat.com>, <brauner@kernel.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH next 1/2] sched: Init new task's vruntime after select cpu Date: Mon, 31 Oct 2022 20:51:12 +0800 Message-ID: <20221031125113.72980-2-zhangqiao22@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221031125113.72980-1-zhangqiao22@huawei.com> References: <20221031125113.72980-1-zhangqiao22@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.191] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500018.china.huawei.com (7.185.36.186) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748206462915765950?= X-GMAIL-MSGID: =?utf-8?q?1748206462915765950?= |
Series |
sched: sched_fork() optimizations
|
|
Commit Message
Zhang Qiao
Oct. 31, 2022, 12:51 p.m. UTC
When create a new task, we initialize vruntime of the new task
at sched_cgroup_fork(). However, this action is executed too
early and may be incorrect, because it use current cpu to
init the vruntime, but the new task actually runs on the
cpu assigned at wake_up_new_task().
So the patch call task_fork() after select fork cpu and use
the ready cpu(the child will run on it) init the new task.
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
kernel/sched/core.c | 7 ++++++-
kernel/sched/fair.c | 7 +------
2 files changed, 7 insertions(+), 7 deletions(-)
Comments
Hi Zhang, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on next-20221031] url: https://github.com/intel-lab-lkp/linux/commits/Zhang-Qiao/sched-sched_fork-optimizations/20221031-202427 patch link: https://lore.kernel.org/r/20221031125113.72980-2-zhangqiao22%40huawei.com patch subject: [PATCH next 1/2] sched: Init new task's vruntime after select cpu config: i386-tinyconfig compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/dd85b689329a85b7c34067d160a67569c82327c6 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Zhang-Qiao/sched-sched_fork-optimizations/20221031-202427 git checkout dd85b689329a85b7c34067d160a67569c82327c6 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/sched/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> kernel/sched/core.c:4654:6: warning: no previous prototype for 'sched_task_fork' [-Wmissing-prototypes] 4654 | void sched_task_fork(struct task_struct *p) | ^~~~~~~~~~~~~~~ vim +/sched_task_fork +4654 kernel/sched/core.c 4653 > 4654 void sched_task_fork(struct task_struct *p) 4655 { 4656 if (p->sched_class->task_fork) 4657 p->sched_class->task_fork(p); 4658 } 4659
Hi Zhang, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on next-20221031] url: https://github.com/intel-lab-lkp/linux/commits/Zhang-Qiao/sched-sched_fork-optimizations/20221031-202427 patch link: https://lore.kernel.org/r/20221031125113.72980-2-zhangqiao22%40huawei.com patch subject: [PATCH next 1/2] sched: Init new task's vruntime after select cpu config: hexagon-randconfig-r006-20221101 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/dd85b689329a85b7c34067d160a67569c82327c6 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Zhang-Qiao/sched-sched_fork-optimizations/20221031-202427 git checkout dd85b689329a85b7c34067d160a67569c82327c6 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/sched/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from kernel/sched/core.c:9: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from kernel/sched/core.c:9: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from kernel/sched/core.c:9: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ >> kernel/sched/core.c:4654:6: warning: no previous prototype for function 'sched_task_fork' [-Wmissing-prototypes] void sched_task_fork(struct task_struct *p) ^ kernel/sched/core.c:4654:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void sched_task_fork(struct task_struct *p) ^ static kernel/sched/core.c:3579:20: warning: unused function 'rq_has_pinned_tasks' [-Wunused-function] static inline bool rq_has_pinned_tasks(struct rq *rq) ^ kernel/sched/core.c:5645:20: warning: unused function 'sched_tick_start' [-Wunused-function] static inline void sched_tick_start(int cpu) { } ^ kernel/sched/core.c:5646:20: warning: unused function 'sched_tick_stop' [-Wunused-function] static inline void sched_tick_stop(int cpu) { } ^ kernel/sched/core.c:6340:20: warning: unused function 'sched_core_cpu_starting' [-Wunused-function] static inline void sched_core_cpu_starting(unsigned int cpu) {} ^ kernel/sched/core.c:6341:20: warning: unused function 'sched_core_cpu_deactivate' [-Wunused-function] static inline void sched_core_cpu_deactivate(unsigned int cpu) {} ^ kernel/sched/core.c:6342:20: warning: unused function 'sched_core_cpu_dying' [-Wunused-function] static inline void sched_core_cpu_dying(unsigned int cpu) {} ^ 13 warnings generated. vim +/sched_task_fork +4654 kernel/sched/core.c 4653 > 4654 void sched_task_fork(struct task_struct *p) 4655 { 4656 if (p->sched_class->task_fork) 4657 p->sched_class->task_fork(p); 4658 } 4659
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e4ce124ec701..ca5677206efd 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4627,9 +4627,13 @@ void sched_cgroup_fork(struct task_struct *p, struct kernel_clone_args *kargs) * so use __set_task_cpu(). */ __set_task_cpu(p, smp_processor_id()); + raw_spin_unlock_irqrestore(&p->pi_lock, flags); +} + +void sched_task_fork(struct task_struct *p) +{ if (p->sched_class->task_fork) p->sched_class->task_fork(p); - raw_spin_unlock_irqrestore(&p->pi_lock, flags); } void sched_post_fork(struct task_struct *p) @@ -4682,6 +4686,7 @@ void wake_up_new_task(struct task_struct *p) #endif rq = __task_rq_lock(p, &rf); update_rq_clock(rq); + sched_task_fork(p); post_init_entity_util_avg(p); activate_task(rq, p, ENQUEUE_NOCLOCK); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e4a0b8bd941c..34845d425180 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11603,12 +11603,8 @@ static void task_fork_fair(struct task_struct *p) struct cfs_rq *cfs_rq; struct sched_entity *se = &p->se, *curr; struct rq *rq = this_rq(); - struct rq_flags rf; - rq_lock(rq, &rf); - update_rq_clock(rq); - - cfs_rq = task_cfs_rq(current); + cfs_rq = task_cfs_rq(p); curr = cfs_rq->curr; if (curr) { update_curr(cfs_rq); @@ -11626,7 +11622,6 @@ static void task_fork_fair(struct task_struct *p) } se->vruntime -= cfs_rq->min_vruntime; - rq_unlock(rq, &rf); } /*