From patchwork Mon Feb 13 01:11:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JaeJoon Jung X-Patchwork-Id: 55992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2120584wrn; Sun, 12 Feb 2023 17:24:26 -0800 (PST) X-Google-Smtp-Source: AK7set/D+267swfZthP1+ZT6VdPSre76a3pQNkOHujF81owvI55d7caMmubs5eFJdu5jzid71u+/ X-Received: by 2002:a17:906:1286:b0:88f:9c29:d232 with SMTP id k6-20020a170906128600b0088f9c29d232mr22434755ejb.57.1676251466469; Sun, 12 Feb 2023 17:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676251466; cv=none; d=google.com; s=arc-20160816; b=ONjzU787VbgbpwtIOEmVfeeB/t6/4DPOBycJGMXv7AphxPQVBN3xHnERP3KvVIOcw2 /MVqoShmLIZ+RE7uQPJMqkJumbnV20ddpezsnSlOsaf9pxj3uR1RQXZQg15b6MM8Ap+Y HXjrcEXSmUw2zkAj5HirljVLxi7yeBVS66I7t9d6vCHhG2PFWbYN6x9uY191ln4NmVEw wzIKTHgpG0NFDgtblNG9+kKe3Qbf15zhwpSkUeiyb90Qi1O4O9l5lKwE6XADl6ngogMg kmSb1St1Js0I16tKpuxCSmWzVrxRDhIcqCzfQ7MacAMyszEIqCNHDNm/LVTLSmTc9dlZ Fblw== 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=IakcplcyOMI6hcsTU0uVigj1wRCTVwjpSFZg+1qq3Ls=; b=qIaQKZTVWBrhMXtt6BTtmZGFdy96BhyaoP0RIJ7+EPfHyroIsjmlqSyN6gzvzPJ9Ch VIWrekjY3N4mfDhhRZ/FY4LBR4DdbViZ2Ap072PMAKcFHvxt63t5tBFeB8nJ/v/Xz+T1 kiZiayb80RKq2UWEr7InwfsQxuMmmIrs5jAz6b4QbOT2GTZpK9lFcanFG1JkU6yuFn5j AB+8zW/LiAETtOSjLaa7tNztmIA/tA/4uXIbJrrfzquZUCQkHxqCiK/XTsVauAShxKKH PzBPfl1miGj8savaDXvmRvzQbXXt5CVWUfVrrl77IUncVaWbQ/j4fSg22j2DxLi9odiz 15tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=E3I1FlWD; 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 mr17-20020a170907829100b008b103d41fd8si2821035ejc.806.2023.02.12.17.24.03; Sun, 12 Feb 2023 17:24:26 -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=E3I1FlWD; 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 S229637AbjBMBLV (ORCPT + 99 others); Sun, 12 Feb 2023 20:11:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjBMBLU (ORCPT ); Sun, 12 Feb 2023 20:11:20 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 273B54C17 for ; Sun, 12 Feb 2023 17:11:19 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id p26so28183507ejx.13 for ; Sun, 12 Feb 2023 17:11:19 -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=IakcplcyOMI6hcsTU0uVigj1wRCTVwjpSFZg+1qq3Ls=; b=E3I1FlWDirT3zSdL+WrzsgzrqX9WnGjCQ/wzr4AK2qor0yzOKCXFCVEYWDF6XU/wtj 9IxkXw0i8v6b0BnpoXxIu1g/1gT3+wd4EPUyXVA1rp+/xVNPVif9ULxQFAEOurZbgyO3 8z7gznw7b9qPWm77xuTg/nTPtVXU1g7zZUkNup6ReQTE3H4rZLECA8Pdh9wQgQ0KmISk EbxuEihKTI0994DX1amNpf41dxw97ynye6ppjEXGT7cMpfiSWAT2bTHxzx3fqK7CiCVh YX1QzU+J5tzFS1kCudIoD8KlOFNeiqoNT2YKj8W3Fu0yG5wR9M6iqsUwJg48EpM8lqhe Spuw== 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=IakcplcyOMI6hcsTU0uVigj1wRCTVwjpSFZg+1qq3Ls=; b=qeM0Ub/aA4imF7XJ3L1IuAbVD9rDBwfa8trsBigR78XDYWQfSs+mj4id5egjOoAUQC UcjqWq8rUVv6OUh1K/eDahtr0/HEWid/cneiWpIculfAifTfw6wg5iB7FEvAhSzQk1nQ clI+xvArtEdZkwU2U83ApKEbAbNvNfa3OpkefYMLKAQrnTrLun2BDWYZkfnQWu9ixlY1 1ituHriAZwrMluc5E/65XXVpWClvX/N15DsSzx8zxAkMdxqu3TzTBMXcywQ2ApmDtY1Z lRtRF2jZMRf2uhgWus8Uk1QBfZhu8L2lTIdhLyEm/snXefhH8m3qxlkWssY4bE0X5RBS VA/Q== X-Gm-Message-State: AO0yUKVHlTDrgE2O+lmvkQ5u5N3yCJ8R7f0M59Eyr9MCEDtOVCO4p2yK RVQ+qhdq3CCJl8l1hYHuFGAk9B5qhqgEOUDxezP9PV2mquE= X-Received: by 2002:a17:906:1e0e:b0:87a:56fc:9df1 with SMTP id g14-20020a1709061e0e00b0087a56fc9df1mr3693853ejj.3.1676250677668; Sun, 12 Feb 2023 17:11:17 -0800 (PST) MIME-Version: 1.0 From: JaeJoon Jung Date: Mon, 13 Feb 2023 10:11:04 +0900 Message-ID: Subject: [kernel/sched/core.c] Review and Modified of the prio_less() about sched class priority. To: Peter Zijlstra , Ingo Molnar 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?1757677057537558657?= X-GMAIL-MSGID: =?utf-8?q?1757677057537558657?= 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. Therefore, 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 above, the __task_prio() function is not required. Please review. Thanks, From JaeJoon Jung. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f730b6fe94a7..7a64ac8ea3d8 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,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 less = a->sched_class - b->sched_class; - int pa = __task_prio(a), pb = __task_prio(b); + if (less == 0) { + if (a->sched_class == &dl_sched_class) + return !dl_time_before(a->dl.deadline, b->dl.deadline); - 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; + 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; }