Message ID | CAHOvCC7yjceArav9Ps0v1EP4CjfkrxbfXFgABK54cdFKNoE8iw@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1744334wrn; Tue, 21 Feb 2023 00:29:15 -0800 (PST) X-Google-Smtp-Source: AK7set+gLvnR+FpfhRt+qUizwGuHrEx3xW2h2dYpcjslAeY8kJpRfPJraP1OSKW1M6CEd0xmDVpB X-Received: by 2002:a17:906:bcd8:b0:8ae:f1cd:9551 with SMTP id lw24-20020a170906bcd800b008aef1cd9551mr12674858ejb.76.1676968155138; Tue, 21 Feb 2023 00:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676968155; cv=none; d=google.com; s=arc-20160816; b=LesGBTgqilBTbL6Srf6v4uJx2QPdAbCmbamsrIXFE519tldlmlTTHkx8X+Mgob6kSm z0Wc1882ciG+vMbysZy8dLTz9slDx/Mafne7tA2uuVFGULIXY8pq22SB7c1C0b1v1xCJ LIOaWk3oP91h+4dFpgcFhOAkb2ax4uOJnTRYCU2EKHSvr4YGP/jvaVYI1apD8GoBy9Ot Zs6NME8ZTUe60i2TRnDTJjnE6Z8buk9s6opGM46MWwpcl+e55pF/8bQxheeXO10AsJPz k1vahJNLcrpS+iaZQqQGTN25q3PSO+oB9BYasM9Cguy+7tQogOcMX+sPvOVWlCu4NyPL 1ZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:mime-version :dkim-signature; bh=oPBARR1XQLY58c737UTH5eoRSYkaY0yhf7AxAKsB3Ys=; b=roWwN9ig5e3XhGpAu8lhHpdFczJNjn0+pOA7s7FdIDecUpNt3Hcazi23jUljtgL3UO wZ0mOxTNf4lNRwnxAbFsiJq3ZnCYbqjAhD1482i5VfBjv2jLPJ4vmrqMJeaYzkcRU4qe GwEmPNmHlfKJzkeSCTJazBDM9ZXHaS6FtLSGKPSpmdEVKZnjcjulq0b1T4YkgAqImL0a hmlLWGuLrgKCkbF6kC4v2rMmFTXS2yDT+F5Sen+DFEPxPfReXC12I04zSOg5kr5UnZJ5 ZzvM4TTI+JbW3ZnRdo8h3ddF5Q+QX7xlwiUKy9CERN8QXdym2Ev4cxyH6n5JTwjH8CD6 342Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FTilw8op; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ka6-20020a170907920600b008e161646775si546151ejb.180.2023.02.21.00.28.49; Tue, 21 Feb 2023 00:29:15 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FTilw8op; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233293AbjBUIYn (ORCPT <rfc822;kautuk.consul.80@gmail.com> + 99 others); Tue, 21 Feb 2023 03:24:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbjBUIYm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Feb 2023 03:24:42 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0681C1EFF4 for <linux-kernel@vger.kernel.org>; Tue, 21 Feb 2023 00:24:41 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id o12so14171479edb.9 for <linux-kernel@vger.kernel.org>; Tue, 21 Feb 2023 00:24:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=oPBARR1XQLY58c737UTH5eoRSYkaY0yhf7AxAKsB3Ys=; b=FTilw8opE7NXkwjgsqlx6udSECCNGFBY5jaRwzj4cGQKeJb5vWv+kxlubSWOd+ugd3 YUoiba4n0y27qNw2IG7TyFincOVCdOnSS5o8Yt1r6jLDQ5C8uD/cOa/FWgdTkS9ZXfok 0Vvy9OT547060nJLz8ilID+aiMbTrxQlPVicHnmM06nMDACwhPUPfzJAIymM56uUXkX+ dI9ixC3Q47KBiisYcvISlL28WTmCHZS2MXFAB87dPSsWVA9CXUtTFR9LRuuwcMtXqet4 Gvpy0DSSTvGany6XHc+Fn2uEUf/Jdn8z8BXax70b58KSU+SHVNnvXaVDYMvhemsre1kM PITw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oPBARR1XQLY58c737UTH5eoRSYkaY0yhf7AxAKsB3Ys=; b=GJAXKdGMS+9Ems/DSAHBjx7eBa1ZIFPCD1kyWhd5eOF/ScnfA6tM3RBjWOpcaCp/Uy Mg4DQchM+oqaRt1lEkdFHxWqZ6V5vXqvvgoilzjnBV79D3tNLxUcv88usIqq5fROTYQq yoEy3dhbwBOpcwmOGnm8w6haPfH3x+XynJzWC+H1q4LwSRPb7ySLBzNEmLAebuYn8ktO NKhHr+D3Lzsk0HPlr2R5Nev8boWjPT+/28EfgjGjYuamhrFfD0RS40g8h95TBVJyMVl6 Y84U/NMQd6yg+G+41YmEneAhfhp6tSa9LCiTnpIxdxXdhZxDC3EHEj/M0wDmz495znSc SyAQ== X-Gm-Message-State: AO0yUKWJqOL5D4/NSVN4e9eZ4oHO5d6JQRksKGwDoHvxz2Y37ycTrpLY lTI9kigtewpSmhzRlUcxvGDG51GVYbbauOu8jwRg4Fhgu6A= X-Received: by 2002:a17:906:d966:b0:889:8b2f:75d1 with SMTP id rp6-20020a170906d96600b008898b2f75d1mr5350016ejb.10.1676967879345; Tue, 21 Feb 2023 00:24:39 -0800 (PST) MIME-Version: 1.0 From: JaeJoon Jung <rgbi3307@gmail.com> Date: Tue, 21 Feb 2023 17:24:27 +0900 Message-ID: <CAHOvCC7yjceArav9Ps0v1EP4CjfkrxbfXFgABK54cdFKNoE8iw@mail.gmail.com> Subject: [PATCH] kernel/sched/core.c: Modified prio_less(). To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com> Cc: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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?1758428559946956611?= X-GMAIL-MSGID: =?utf-8?q?1758428559946956611?= |
Series |
kernel/sched/core.c: Modified prio_less().
|
|
Commit Message
JaeJoon Jung
Feb. 21, 2023, 8:24 a.m. UTC
The sched_class structure is defined to be sorted by pointer size.
You can see it in the macro definition like this:
kernel/sched/sched.h
#define DEFINE_SCHED_CLASS(name)
const struct sched_class name##_sched_class \
__aligned(__alignof__(struct sched_class)) \
__section("__" #name "_sched_class")
include/asm-generic/vmlinux.lds.h
#define SCHED_DATA \
STRUCT_ALIGN(); \
__sched_class_highest = .; \
*(__stop_sched_class) \
*(__dl_sched_class) \
*(__rt_sched_class) \
*(__fair_sched_class) \
*(__idle_sched_class) \
__sched_class_lowest = .;
And in the System.map file,
you can see that they are arranged in memory address order.
System.map
----------------------------------------------------------------
ffffffff8260d520 R __sched_class_highest
ffffffff8260d520 R stop_sched_class
ffffffff8260d5f0 R dl_sched_class
ffffffff8260d6c0 R rt_sched_class
ffffffff8260d790 R fair_sched_class
ffffffff8260d860 R idle_sched_class
ffffffff8260d930 R __sched_class_lowest
----------------------------------------------------------------
This matches the sched class priority.
In the prio_less() function in kernel/sched/core.c,
the less value can be determined by pointer operation as follows.
If the prio_less() function is modified as follows,
the __task_prio() function is not required.
Thanks,
Signed-off-by: JaeJoon Jung <rgbi3307@gmail.com>
---
kernel/sched/core.c | 42 +++++++++++-------------------------------
1 file changed, 11 insertions(+), 31 deletions(-)
static inline bool __sched_core_less(struct task_struct *a, struct
task_struct *b)
Comments
On Tue, Feb 21, 2023 at 05:24:27PM +0900, JaeJoon Jung wrote: > The sched_class structure is defined to be sorted by pointer size. > You can see it in the macro definition like this: > > kernel/sched/sched.h > #define DEFINE_SCHED_CLASS(name) > const struct sched_class name##_sched_class \ > __aligned(__alignof__(struct sched_class)) \ > __section("__" #name "_sched_class") > > include/asm-generic/vmlinux.lds.h > #define SCHED_DATA \ > STRUCT_ALIGN(); \ > __sched_class_highest = .; \ > *(__stop_sched_class) \ > *(__dl_sched_class) \ > *(__rt_sched_class) \ > *(__fair_sched_class) \ > *(__idle_sched_class) \ > __sched_class_lowest = .; > > And in the System.map file, > you can see that they are arranged in memory address order. > > System.map > ---------------------------------------------------------------- > ffffffff8260d520 R __sched_class_highest > ffffffff8260d520 R stop_sched_class > ffffffff8260d5f0 R dl_sched_class > ffffffff8260d6c0 R rt_sched_class > ffffffff8260d790 R fair_sched_class > ffffffff8260d860 R idle_sched_class > ffffffff8260d930 R __sched_class_lowest > ---------------------------------------------------------------- > > This matches the sched class priority. > In the prio_less() function in kernel/sched/core.c, > the less value can be determined by pointer operation as follows. > > If the prio_less() function is modified as follows, > the __task_prio() function is not required. By what? > > Thanks, > > > Signed-off-by: JaeJoon Jung <rgbi3307@gmail.com> > --- > kernel/sched/core.c | 42 +++++++++++------------------------------- > 1 file changed, 11 insertions(+), 31 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 2a4918a1faa9..75075d92a198 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -151,21 +151,6 @@ __read_mostly int scheduler_running; > > DEFINE_STATIC_KEY_FALSE(__sched_core_enabled); > > -/* kernel prio, less is more */ > -static inline int __task_prio(struct task_struct *p) > -{ > - if (p->sched_class == &stop_sched_class) /* trumps deadline */ > - return -2; > - > - if (rt_prio(p->prio)) /* includes deadline */ > - return p->prio; /* [-1, 99] */ > - > - if (p->sched_class == &idle_sched_class) > - return MAX_RT_PRIO + NICE_WIDTH; /* 140 */ > - > - return MAX_RT_PRIO + MAX_NICE; /* 120, squash fair */ > -} > - > /* > * l(a,b) > * le(a,b) := !l(b,a) > @@ -176,22 +161,17 @@ static inline int __task_prio(struct task_struct *p) > /* real prio, less is less */ > static inline bool prio_less(struct task_struct *a, struct > task_struct *b, bool in_fi) > { > - > - int pa = __task_prio(a), pb = __task_prio(b); > - > - if (-pa < -pb) > - return true; > - > - 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 == MAX_RT_PRIO + MAX_NICE) /* fair */ > - return cfs_prio_less(a, b, in_fi); > - > - return false; > + int less = a->sched_class - b->sched_class; > + if (less == 0) { > + if (a->sched_class == &dl_sched_class) > + return !dl_time_before(a->dl.deadline, b->dl.deadline); > + > + else if (a->sched_class == &fair_sched_class) > + return cfs_prio_less(a, b, in_fi); > + else > + return false; > + } else > + return (less > 0) ? true : false; > } I smell indentation-corrupted patch here. Please use git-send-email(1) to submit patches. For the patch subject, I can't imagine what are you doing since you wrote too generic subject ("Modified foo") without clearly describe in the patch description what are you doing. How can maintainers accept your patch if you don't take care of how to describe it? Last but not least, don't top-post when replying; reply inline with appropriate context instead. Thanks.
I'm sorry for the inconvenience caused by my carelessness. I had the problem you pointed out by copying and sending the contents generated by git patch as text. I will learn the git-send-email method you shared and send it again. Thanks. On Tue, 21 Feb 2023 at 22:17, Bagas Sanjaya <bagasdotme@gmail.com> wrote: > > On Tue, Feb 21, 2023 at 05:24:27PM +0900, JaeJoon Jung wrote: > > The sched_class structure is defined to be sorted by pointer size. > > You can see it in the macro definition like this: > > > > kernel/sched/sched.h > > #define DEFINE_SCHED_CLASS(name) > > const struct sched_class name##_sched_class \ > > __aligned(__alignof__(struct sched_class)) \ > > __section("__" #name "_sched_class") > > > > include/asm-generic/vmlinux.lds.h > > #define SCHED_DATA \ > > STRUCT_ALIGN(); \ > > __sched_class_highest = .; \ > > *(__stop_sched_class) \ > > *(__dl_sched_class) \ > > *(__rt_sched_class) \ > > *(__fair_sched_class) \ > > *(__idle_sched_class) \ > > __sched_class_lowest = .; > > > > And in the System.map file, > > you can see that they are arranged in memory address order. > > > > System.map > > ---------------------------------------------------------------- > > ffffffff8260d520 R __sched_class_highest > > ffffffff8260d520 R stop_sched_class > > ffffffff8260d5f0 R dl_sched_class > > ffffffff8260d6c0 R rt_sched_class > > ffffffff8260d790 R fair_sched_class > > ffffffff8260d860 R idle_sched_class > > ffffffff8260d930 R __sched_class_lowest > > ---------------------------------------------------------------- > > > > This matches the sched class priority. > > In the prio_less() function in kernel/sched/core.c, > > the less value can be determined by pointer operation as follows. > > > > If the prio_less() function is modified as follows, > > the __task_prio() function is not required. > > By what? > > > > > Thanks, > > > > > > Signed-off-by: JaeJoon Jung <rgbi3307@gmail.com> > > --- > > kernel/sched/core.c | 42 +++++++++++------------------------------- > > 1 file changed, 11 insertions(+), 31 deletions(-) > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 2a4918a1faa9..75075d92a198 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -151,21 +151,6 @@ __read_mostly int scheduler_running; > > > > DEFINE_STATIC_KEY_FALSE(__sched_core_enabled); > > > > -/* kernel prio, less is more */ > > -static inline int __task_prio(struct task_struct *p) > > -{ > > - if (p->sched_class == &stop_sched_class) /* trumps deadline */ > > - return -2; > > - > > - if (rt_prio(p->prio)) /* includes deadline */ > > - return p->prio; /* [-1, 99] */ > > - > > - if (p->sched_class == &idle_sched_class) > > - return MAX_RT_PRIO + NICE_WIDTH; /* 140 */ > > - > > - return MAX_RT_PRIO + MAX_NICE; /* 120, squash fair */ > > -} > > - > > /* > > * l(a,b) > > * le(a,b) := !l(b,a) > > @@ -176,22 +161,17 @@ static inline int __task_prio(struct task_struct *p) > > /* real prio, less is less */ > > static inline bool prio_less(struct task_struct *a, struct > > task_struct *b, bool in_fi) > > { > > - > > - int pa = __task_prio(a), pb = __task_prio(b); > > - > > - if (-pa < -pb) > > - return true; > > - > > - 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 == MAX_RT_PRIO + MAX_NICE) /* fair */ > > - return cfs_prio_less(a, b, in_fi); > > - > > - return false; > > + int less = a->sched_class - b->sched_class; > > + if (less == 0) { > > + if (a->sched_class == &dl_sched_class) > > + return !dl_time_before(a->dl.deadline, b->dl.deadline); > > + > > + else if (a->sched_class == &fair_sched_class) > > + return cfs_prio_less(a, b, in_fi); > > + else > > + return false; > > + } else > > + return (less > 0) ? true : false; > > } > > I smell indentation-corrupted patch here. Please use git-send-email(1) > to submit patches. > > For the patch subject, I can't imagine what are you doing since you > wrote too generic subject ("Modified foo") without clearly describe in > the patch description what are you doing. How can maintainers accept > your patch if you don't take care of how to describe it? > > Last but not least, don't top-post when replying; reply inline with > appropriate context instead. > > Thanks. > > -- > An old man doll... just what I always wanted! - Clara
On 2/22/23 07:51, JaeJoon Jung wrote: > I'm sorry for the inconvenience caused by my carelessness. > I had the problem you pointed out by copying and sending the contents > generated by git patch as text. > I will learn the git-send-email method you shared and send it again. > OK but please don't top-post your reply in the future. Doing so, other people (like me) don't see the context you write (hence I delete it). Thanks!
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2a4918a1faa9..75075d92a198 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -151,21 +151,6 @@ __read_mostly int scheduler_running; DEFINE_STATIC_KEY_FALSE(__sched_core_enabled); -/* kernel prio, less is more */ -static inline int __task_prio(struct task_struct *p) -{ - if (p->sched_class == &stop_sched_class) /* trumps deadline */ - return -2; - - if (rt_prio(p->prio)) /* includes deadline */ - return p->prio; /* [-1, 99] */ - - if (p->sched_class == &idle_sched_class) - return MAX_RT_PRIO + NICE_WIDTH; /* 140 */ - - return MAX_RT_PRIO + MAX_NICE; /* 120, squash fair */ -} - /* * l(a,b) * le(a,b) := !l(b,a) @@ -176,22 +161,17 @@ static inline int __task_prio(struct task_struct *p) /* real prio, less is less */ static inline bool prio_less(struct task_struct *a, struct task_struct *b, bool in_fi) { - - int pa = __task_prio(a), pb = __task_prio(b); - - if (-pa < -pb) - return true; - - 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 == MAX_RT_PRIO + MAX_NICE) /* fair */ - return cfs_prio_less(a, b, in_fi); - - return false; + int less = a->sched_class - b->sched_class; + if (less == 0) { + if (a->sched_class == &dl_sched_class) + return !dl_time_before(a->dl.deadline, b->dl.deadline); + + else if (a->sched_class == &fair_sched_class) + return cfs_prio_less(a, b, in_fi); + else + return false; + } else + return (less > 0) ? true : false; }