From patchwork Tue Oct 18 12:42:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JaeJoon Jung X-Patchwork-Id: 4153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1940091wrs; Tue, 18 Oct 2022 05:47:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM46ZcxwO8/JkeYsGkc6y12CH17WiSFMGPqkfBaZ3g7Y7GazCML5iQ2FmE4bgNFqg+Bs/o8T X-Received: by 2002:a17:907:628f:b0:72f:57da:c33d with SMTP id nd15-20020a170907628f00b0072f57dac33dmr2272229ejc.374.1666097245013; Tue, 18 Oct 2022 05:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666097245; cv=none; d=google.com; s=arc-20160816; b=rzUtvUyM3y09A4ZULDSFfSzL3EsLD/c92/oTIfZYdaXc3EbLukjDytmHXY/7Kpkfpq uYvWcU0vqP7YZI6APMl8lo4LJbVerw8m7raSUXBqQ85hXpCxqMA2vV87n6soXtj8b8xI 3UPE5Fu64s7jt6AGY2SezdsUJJMcATvSQgbA3nrfsjbsi4p0p7h2iODKctVqmQa33nJ5 WHmR7Pk48NQoI7AlH9CWyhGp1UxTPlvskijj0dSRLLUof5rSDFFIUAwVJ1dJ0oY7DoM9 ihmMOkG/68b4UlxNIypXhDZ59SsERVBmLrdY+rdb2lsO05JaTMgl/i6wSISbj86XdNX9 FosA== 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=yMP6fIsH3iK8GvA/5hVJOpgVRfJnpqAP6lVmWiyWygE=; b=mInQ3Rk3FFtPndXBHmC74gSpazMsRteGIaoZ2ZDpt6Px13J6BhHZiwYVZ/sgQk52Pn 6oaHZIL7XKQdNaiYqf2/PsdbmNkWIT1IpSJIQlVebqfmg4kBHhKTl2ObgKMG0tKXJpyn BrW1gToWY2Ny8z9GnI3lVrO8CYUjg9xFPPPX1bRQRbR4vQ2KPiomSsJSdTTccFNETeXK SbUvsgcp0uWNEXEST09/HXreRcVlnrJSI25oChFPe+NrJP+YFm+wxQg/jbqsADJMb/A3 C0L4EDC+DK+Ky648N/nJ4ER3KoQnblCYoL+cxUpKdPEOliibzgxfmnEHqZH24D/i2sGe lmmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f+yELfdZ; 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 sz15-20020a1709078b0f00b0076f16ec62d6si8712157ejc.959.2022.10.18.05.46.57; Tue, 18 Oct 2022 05:47:25 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f+yELfdZ; 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 S230127AbiJRMm5 (ORCPT + 99 others); Tue, 18 Oct 2022 08:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbiJRMmz (ORCPT ); Tue, 18 Oct 2022 08:42:55 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36A3FC1D9F for ; Tue, 18 Oct 2022 05:42:53 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id z97so20241983ede.8 for ; Tue, 18 Oct 2022 05:42:53 -0700 (PDT) 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=yMP6fIsH3iK8GvA/5hVJOpgVRfJnpqAP6lVmWiyWygE=; b=f+yELfdZ47XzJ+BJzeb7htVmv1joFeJ0NqAak3zL6TROI4B11piQZ2iVrsJcg+5F31 gAXNnWkUOREl4sLTvoKD18xGUjkyuYK0LuWBnA8g17PMusFAqNYjbqhQFW15fGAh382g dp8ZCnrIOq6F6W47+MkAOhaAJm3WNgTX5kPolUG3mcOiEuVxB8FD6toXYuhPhGpXf60f Z8uoxnRDs8Nx69yZkmqiitDM4W6hGAu/QxBVmJI2FdjwAeifjFhZP384qxt9RdMp3voA 95sLDELZHhIihTc1Oz8Z02WUrjzGr3J13dbyNWxijVCFX//MVHs2PxeIN5eQkQehdb0K PFfw== 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=yMP6fIsH3iK8GvA/5hVJOpgVRfJnpqAP6lVmWiyWygE=; b=uH0X+WikEmLcSFvMReimhhX45V+SNXE2QIo15EA4OuqVFgs3tnfmIC26uvnn6Xkxm3 5nBEmRBbdzhAl2khDiqG05xv2PBDjs0V83BeH4Bi2krBH5LYEbTtSOxURrZBqzO4XjU3 8EJm+EXZ9iyh8e0pgDxB4QaGWEk19HRKzFL+HTG1MixqUmhyaA0QK+mZh3JtmaVsulSE 8wNXq8OIDq8IANS/TCpr4CG1qylPA65NpKHvlI56BY/BYyexpb4ZCWQYhyYEtht+axPn EJGesvkbEQf0nAtXEsgiaaBas0gs+EZOizr2QKyACrBcdFYY8v+oXgZTGOTe9yv46r/4 iWhw== X-Gm-Message-State: ACrzQf2pV2Ick31AgOAwgrHqw4rk7FNx7GSFDgSacmcPX+h9XyvIdqD1 0MUPKviOMhdH7EdROi13PsGlWnYswF5JBRnsobopgEEgXAg= X-Received: by 2002:a05:6402:27d4:b0:45d:a69e:336d with SMTP id c20-20020a05640227d400b0045da69e336dmr2416594ede.298.1666096971346; Tue, 18 Oct 2022 05:42:51 -0700 (PDT) MIME-Version: 1.0 From: JaeJoon Jung Date: Tue, 18 Oct 2022 21:42:39 +0900 Message-ID: Subject: [core-scheduling] Modify prio_less() with in CONFIG_SCHED_CORE To: Peter Zijlstra , Chris Hyser , Don Hiatt , Hongyu Ning , Vincent Guittot , Cruz Zhao Cc: linux-kernel@vger.kernel.org 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747029584914661051?= X-GMAIL-MSGID: =?utf-8?q?1747029584914661051?= Hello, Since the priority of sched_class can be determined by pointer operation, the prio_less() function can be modified as follows. With this fix, the __task_prio() function is not needed. Please review. Thanks, JaeJoon Jung. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ee28253c9ac0..24b86773da04 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -154,21 +154,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) @@ -179,22 +164,18 @@ 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) { + return (less > 0) ? true : false; + } else { + if (a->sched_class == &fair_sched_class) + return cfs_prio_less(a, b, in_fi); + else if (a->sched_class == &dl_sched_class) + return !dl_time_before(a->dl.deadline, b->dl.deadline); + else + return (a->prio - b->prio > 0) ? true : false; + } }