Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4628538rwb; Mon, 8 Aug 2022 04:39:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uxWnbCSHfgehUBvoIApmHh1Qy/JkXfbK0oFiAvSjr7atVBoU+sj4wCWFr2evM9TzIpNFY X-Received: by 2002:a17:902:db11:b0:16f:342:a439 with SMTP id m17-20020a170902db1100b0016f0342a439mr18055571plx.13.1659958766938; Mon, 08 Aug 2022 04:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659958766; cv=none; d=google.com; s=arc-20160816; b=Ia9kGZ0Ddf7BatXOmwAySVnuLTp8wTE7Zgj+5bEo7HeKttJ3zGlUrbL2unObwHY6II e7ZGMdh19n2KlFf5PpIGxqbE/pfYULi4fnWjBE7tkq1aXLslWv/Znx05zWY6VckHpfC7 9H4N3G41UGXljU41gefhafPPQYe+8lSFD5562S2LfI1/bKsJ3DSgT0DMSo5s8J2CyrMc HnLnuF6sBvNUTKhrqgJOO6WA2txUiyLF/QpS2WWD2mhFUPT3WFoOcpzR9nw+LtNAYvJj rBjh/yvpgvrbYS+C/3gO2K5Dv4+C+kzdBly2DDI2dXybmjtNQcP7fDVsB0Hrmt8Vim7y 2FXw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZF+ptlZ7x1rV90unZdPOJJUv9JpctUIbzaWac6sYWYU=; b=bN7hr3304aBTpR98gSqjGuVyXH8V0hZxVbgXPLLzlvcMxigV+RPV4SqIUZHENu7f8n 53BPg/YssX3JwMOIXaCz0uddKfPPJ9i1exTD7+E51neKoLLh+qAuOt4i90ZP6xa0ExiU 2/Mq5+991tVyT0NEkX/7iEicjjC1x7Zbe064+l5teC5ymEvpRBRSbqIzLyXI+9ueclWU SG4ZTbYrPf7zpwDGWmnMSavhwNuOHvPkt+cevM8CqYxygldSJRLMlTBPmYsXGwvrmRRy jSywRDHRdepvpUMudGBjlRK67kwRyVoWpT3FCemSgX03nXu+9jxBQGFIKXBZbiYmSu3r HebQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=IT9T5n3u; 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=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a633d03000000b0041bfb11f138si10676372pga.442.2022.08.08.04.39.10; Mon, 08 Aug 2022 04:39:26 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=IT9T5n3u; 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=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242693AbiHHLFr (ORCPT + 99 others); Mon, 8 Aug 2022 07:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242856AbiHHLFM (ORCPT ); Mon, 8 Aug 2022 07:05:12 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7640A14D17 for ; Mon, 8 Aug 2022 04:05:10 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 15-20020a17090a098f00b001f305b453feso14178661pjo.1 for ; Mon, 08 Aug 2022 04:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZF+ptlZ7x1rV90unZdPOJJUv9JpctUIbzaWac6sYWYU=; b=IT9T5n3uzaIyYCDoAvf1GKOtIDooo4d192E3n80U67HsrhgOBrqqRKN65ZT3tIZeS8 r7J9Npsendjqi2CuZuFjuvWCjxioqgm2ZFQENgvKsOeMpFRYJRk4WeXmU3kDGo3uggLG C4Pk+lVauLT0M9bz1asuYe4TPOjS2qL9jxzDs1K0BOg7Uz/132vLzLC4OARg6kH+FrcX YF7g2xylrqFW05z8L54j37rsi0S7tiCDlkr7Y7notxS2bt+mYzYkhh6xZ04P4LKHUBqt Nii6RUV4eBr8iz9Y6oKxnuLvsAx1Dvb6E+ByIAWszbpkWUGpQRceGc0bBhM/vibPHULV 97nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZF+ptlZ7x1rV90unZdPOJJUv9JpctUIbzaWac6sYWYU=; b=Ev8ACKd+l+5W0wuAVRa8iOXhy9N13sXIYPtVs6lh+hqGiwD9zwbGXR2eK8+VCBD8Xm 1nGlw34FKbaEjf3CC4tIlm3HlxgsrH9sqaip2wzIpJFexA+aa0cvQ9ehmoHqh3HOdGs0 yL3V5mQibTIVkBjsKGRYR69zYV6HJSsDpM5P4AnXV5uLpvFvhSQV1RnHjEhQ3tOpN6/l twEJG/Hn/TvdH76ETr8pRH4bXfDw7YE0rhGjst4sul7l9Pke22RN/ycplnci/P7Q31dk yDD2hHf74pT72NGhM8VqiJ1c59qfrwcTJEWs++opJSUZlRqhVxHA+rKRI09UP8oOM/ik cUFw== X-Gm-Message-State: ACgBeo2wXhemzsDh3ZBxmJ+de8tDMQtzTzbrX6l7XVIB3WxmGxXDM41e HC8SB8GVBWqrdatMLYtrgAsL0Q== X-Received: by 2002:a17:902:edc4:b0:16d:4635:130c with SMTP id q4-20020a170902edc400b0016d4635130cmr18779724plk.64.1659956709766; Mon, 08 Aug 2022 04:05:09 -0700 (PDT) Received: from C02CV1DAMD6P.bytedance.net ([139.177.225.240]) by smtp.gmail.com with ESMTPSA id o12-20020aa7978c000000b0052dbad1ea2esm8393180pfp.6.2022.08.08.04.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 04:05:09 -0700 (PDT) From: Chengming Zhou To: hannes@cmpxchg.org, tj@kernel.org, corbet@lwn.net, surenb@google.com, mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, songmuchun@bytedance.com, Chengming Zhou Subject: [PATCH v2 07/10] sched/psi: remove NR_ONCPU task accounting Date: Mon, 8 Aug 2022 19:03:38 +0800 Message-Id: <20220808110341.15799-8-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808110341.15799-1-zhouchengming@bytedance.com> References: <20220808110341.15799-1-zhouchengming@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Johannes Weiner We put all fields updated by the scheduler in the first cacheline of struct psi_group_cpu for performance. Since we want add another PSI_IRQ_FULL to track IRQ/SOFTIRQ pressure, we need to reclaim space first. This patch remove NR_ONCPU task accounting in struct psi_group_cpu, use one bit in state_mask to track instead. Signed-off-by: Johannes Weiner Signed-off-by: Chengming Zhou Reviewed-by: Chengming Zhou Tested-by: Chengming Zhou --- include/linux/psi_types.h | 16 +++++++--------- kernel/sched/psi.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index c7fe7c089718..54cb74946db4 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -15,13 +15,6 @@ enum psi_task_count { NR_IOWAIT, NR_MEMSTALL, NR_RUNNING, - /* - * This can't have values other than 0 or 1 and could be - * implemented as a bit flag. But for now we still have room - * in the first cacheline of psi_group_cpu, and this way we - * don't have to special case any state tracking for it. - */ - NR_ONCPU, /* * For IO and CPU stalls the presence of running/oncpu tasks * in the domain means a partial rather than a full stall. @@ -32,16 +25,18 @@ enum psi_task_count { * threads and memstall ones. */ NR_MEMSTALL_RUNNING, - NR_PSI_TASK_COUNTS = 5, + NR_PSI_TASK_COUNTS = 4, }; /* Task state bitmasks */ #define TSK_IOWAIT (1 << NR_IOWAIT) #define TSK_MEMSTALL (1 << NR_MEMSTALL) #define TSK_RUNNING (1 << NR_RUNNING) -#define TSK_ONCPU (1 << NR_ONCPU) #define TSK_MEMSTALL_RUNNING (1 << NR_MEMSTALL_RUNNING) +/* Only one task can be scheduled, no corresponding task count */ +#define TSK_ONCPU (1 << NR_PSI_TASK_COUNTS) + /* Resources that workloads could be stalled on */ enum psi_res { PSI_IO, @@ -68,6 +63,9 @@ enum psi_states { NR_PSI_STATES = 7, }; +/* Use one bit in the state mask to track TSK_ONCPU */ +#define PSI_ONCPU (1 << NR_PSI_STATES) + enum psi_aggregators { PSI_AVGS = 0, PSI_POLL, diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 595a6c8230b7..1c675715ed33 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -216,7 +216,7 @@ void __init psi_init(void) group_init(&psi_system); } -static bool test_state(unsigned int *tasks, enum psi_states state) +static bool test_state(unsigned int *tasks, enum psi_states state, bool oncpu) { switch (state) { case PSI_IO_SOME: @@ -229,9 +229,9 @@ static bool test_state(unsigned int *tasks, enum psi_states state) return unlikely(tasks[NR_MEMSTALL] && tasks[NR_RUNNING] == tasks[NR_MEMSTALL_RUNNING]); case PSI_CPU_SOME: - return unlikely(tasks[NR_RUNNING] > tasks[NR_ONCPU]); + return unlikely(tasks[NR_RUNNING] > oncpu); case PSI_CPU_FULL: - return unlikely(tasks[NR_RUNNING] && !tasks[NR_ONCPU]); + return unlikely(tasks[NR_RUNNING] && !oncpu); case PSI_NONIDLE: return tasks[NR_IOWAIT] || tasks[NR_MEMSTALL] || tasks[NR_RUNNING]; @@ -693,9 +693,9 @@ static void psi_group_change(struct psi_group *group, int cpu, bool wake_clock) { struct psi_group_cpu *groupc; - u32 state_mask = 0; unsigned int t, m; enum psi_states s; + u32 state_mask; groupc = per_cpu_ptr(group->pcpu, cpu); @@ -711,6 +711,26 @@ static void psi_group_change(struct psi_group *group, int cpu, record_times(groupc, now); + /* + * Start with TSK_ONCPU, which doesn't have a corresponding + * task count - it's just a boolean flag directly encoded in + * the state mask. Clear, set, or carry the current state if + * no changes are requested. + */ + if (clear & TSK_ONCPU) { + state_mask = 0; + clear &= ~TSK_ONCPU; + } else if (set & TSK_ONCPU) { + state_mask = PSI_ONCPU; + set &= ~TSK_ONCPU; + } else { + state_mask = groupc->state_mask & PSI_ONCPU; + } + + /* + * The rest of the state mask is calculated based on the task + * counts. Update those first, then construct the mask. + */ for (t = 0, m = clear; m; m &= ~(1 << t), t++) { if (!(m & (1 << t))) continue; @@ -730,9 +750,8 @@ static void psi_group_change(struct psi_group *group, int cpu, if (set & (1 << t)) groupc->tasks[t]++; - /* Calculate state mask representing active states */ for (s = 0; s < NR_PSI_STATES; s++) { - if (test_state(groupc->tasks, s)) + if (test_state(groupc->tasks, s, state_mask & PSI_ONCPU)) state_mask |= (1 << s); } @@ -744,7 +763,7 @@ static void psi_group_change(struct psi_group *group, int cpu, * task in a cgroup is in_memstall, the corresponding groupc * on that cpu is in PSI_MEM_FULL state. */ - if (unlikely(groupc->tasks[NR_ONCPU] && cpu_curr(cpu)->in_memstall)) + if (unlikely((state_mask & PSI_ONCPU) && cpu_curr(cpu)->in_memstall)) state_mask |= (1 << PSI_MEM_FULL); groupc->state_mask = state_mask; @@ -835,7 +854,8 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, */ iter = NULL; while ((group = iterate_groups(next, &iter))) { - if (per_cpu_ptr(group->pcpu, cpu)->tasks[NR_ONCPU]) { + if (per_cpu_ptr(group->pcpu, cpu)->state_mask & + PSI_ONCPU) { common = group; break; } -- 2.36.1