From patchwork Fri Jul 28 14:55:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 127710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp517184vqg; Fri, 28 Jul 2023 08:35:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlEsVr8c0HZWU0F6vMfxPE5/9gv9IFUgolioK2ZljiE9vT6XnpULAn3pglQ26IpAQrf95ses X-Received: by 2002:a05:6a00:1305:b0:686:bd4f:3a6e with SMTP id j5-20020a056a00130500b00686bd4f3a6emr2570361pfu.24.1690558506031; Fri, 28 Jul 2023 08:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690558506; cv=none; d=google.com; s=arc-20160816; b=y5GHa1zLZSFzXARc8qeDwfyTFFnFhTqqsjZ2+ZGdJ870tgKzBzlLAkeiyUUurSutNp PVdqsAxo2j5H8zypDUAJQMRwtNRO7sshmtnHIZ23xT4HVemUcsq08PuD/KjCYTQ/rfLW 8IV/mS/WmMUgbrcgCCgBbt8lCTSolk8nPyT6tW0BCbwM/fx0MC2N+XQQ7PIASyc9tZEB v5TzbPEdqLQSKwpMuAio5zhDPwI1/lZKxqAy1pl8ls+zbEbgQr5QFEe7GJX9hxwPkC9c dMp8Ry16b6Xbo85HOVt89+VZLKTX8Sh60Q3kONM9gMR7oBDy19Nl/bAEGq5owVNBK2lU WZmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=/jk8cjAzNp5umM9o/8ZP9pvl8gboqgF2w9reMo9nXqk=; fh=0hiOkE06jcy/VqUxYDS6cCN+IjKlOJ21bEwL6x6WXH4=; b=FFA3KghXSKuN1BBp7lugqf0uj9NaDLC2PQJkVq59RjblSW1PGrtYRr9aaB9MZZuXDx IO9+ts9fIn645vR6AZU4z87IPe5iapskDPWlkD64sSIE3I2T3lw/Nvfd8DenipCtCfFi 672h5amAxMSsbayfwlBduADqEFAqhBqdZuCi/ZpgHiIYXIfXeenBxDoRxrEbxZ2GHkeV JYR5uGeAz632cg6PY0CMYgEEn80oAG8AWPeF+CHlB0OJIKZ98HrGb73IpfPr5Vk4S05k 0k1M8E2E1o0mKCdQorY5gSTrdwczgvfqAnaLQAjdb/lWwl5p/QGhRyIF9n1WeP/LUzSq VJSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="bKnvshZ/"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a056a00080700b00666aaa3b271si3409534pfk.10.2023.07.28.08.34.47; Fri, 28 Jul 2023 08:35:06 -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=@infradead.org header.s=casper.20170209 header.b="bKnvshZ/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237209AbjG1PBX (ORCPT + 99 others); Fri, 28 Jul 2023 11:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235779AbjG1PBN (ORCPT ); Fri, 28 Jul 2023 11:01:13 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5D72688; Fri, 28 Jul 2023 08:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=/jk8cjAzNp5umM9o/8ZP9pvl8gboqgF2w9reMo9nXqk=; b=bKnvshZ/ndNOvwq1Tklq1Cz0FF vvHXxiHIW2w98Vm4G3ioNeylieIiFQhLuNgDolJXkC5pruqePdPgiqhpDO3JIWxFqkMxXeArZG9Py m6TkobUM+ooLjFSoHvZV61SiHLI1NzMFinHiIb7pS9Fc4MLXZSKGoCTyDhtfFXbneY3K+0bgyFfS/ NGN5yHTSiwzJM5y/Pb5xe4EfMkXU7+O2ZsQ0nYzjLoUkbe2Zbov0O3K/T5AukAn0YyPeZotIW2alO Vs24fwevy7DKg6nsi1LvetldnCjRapaPzGi5QF+pfwrh8qu226UUksEiPjXrRL/s5ZJreTYGVd7Le jFUDTe1w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qPOxY-008ar1-OS; Fri, 28 Jul 2023 15:00:53 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5A5D63003A2; Fri, 28 Jul 2023 17:00:51 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 209E92C8FCA94; Fri, 28 Jul 2023 17:00:51 +0200 (CEST) Message-ID: <20230728145808.835742568@infradead.org> User-Agent: quilt/0.66 Date: Fri, 28 Jul 2023 16:55:16 +0200 From: Peter Zijlstra To: anna-maria@linutronix.de, rafael@kernel.org, tglx@linutronix.de, frederic@kernel.org, gautham.shenoy@amd.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com Subject: [RFC][PATCH 1/3] cpuidle: Inject tick boundary state References: <20230728145515.990749537@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: INBOX X-GMAIL-THRID: 1772679076442422531 X-GMAIL-MSGID: 1772679076442422531 In order to facilitate governors that track history in idle-state buckets (TEO) making a useful decision about NOHZ, make sure we have a bucket that counts tick-and-longer. In order to be inclusive of the tick itself -- after all, if we do not disable NOHZ we'll sleep for a full tick, the actual boundary should be just short of a full tick. IOW, when registering the idle-states, add one that is always disabled, just to have a bucket. Signed-off-by: Peter Zijlstra (Intel) --- drivers/cpuidle/cpuidle.h | 2 + drivers/cpuidle/driver.c | 48 +++++++++++++++++++++++++++++++++++++++++++++- include/linux/cpuidle.h | 2 - 3 files changed, 50 insertions(+), 2 deletions(-) --- a/drivers/cpuidle/cpuidle.h +++ b/drivers/cpuidle/cpuidle.h @@ -72,4 +72,6 @@ static inline void cpuidle_coupled_unreg } #endif +#define SHORT_TICK_NSEC (TICK_NSEC - TICK_NSEC/32) + #endif /* __DRIVER_CPUIDLE_H */ --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -147,13 +147,37 @@ static void cpuidle_setup_broadcast_time tick_broadcast_disable(); } +static int tick_enter(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int index) +{ + return -ENODEV; +} + +static void __cpuidle_state_init_tick(struct cpuidle_state *s) +{ + strcpy(s->name, "TICK"); + strcpy(s->desc, "(no-op)"); + + s->target_residency_ns = SHORT_TICK_NSEC; + s->target_residency = div_u64(SHORT_TICK_NSEC, NSEC_PER_USEC); + + s->exit_latency_ns = 0; + s->exit_latency = 0; + + s->flags |= CPUIDLE_FLAG_UNUSABLE; + + s->enter = tick_enter; + s->enter_s2idle = tick_enter; +} + /** * __cpuidle_driver_init - initialize the driver's internal data * @drv: a valid pointer to a struct cpuidle_driver */ static void __cpuidle_driver_init(struct cpuidle_driver *drv) { - int i; + int tick = 0, i; /* * Use all possible CPUs as the default, because if the kernel boots @@ -163,6 +187,9 @@ static void __cpuidle_driver_init(struct if (!drv->cpumask) drv->cpumask = (struct cpumask *)cpu_possible_mask; + if (WARN_ON_ONCE(drv->state_count >= CPUIDLE_STATE_MAX-2)) + tick = 1; + for (i = 0; i < drv->state_count; i++) { struct cpuidle_state *s = &drv->states[i]; @@ -192,6 +219,25 @@ static void __cpuidle_driver_init(struct s->exit_latency_ns = 0; else s->exit_latency = div_u64(s->exit_latency_ns, NSEC_PER_USEC); + + if (!tick && s->target_residency_ns >= SHORT_TICK_NSEC) { + tick = 1; + + if (s->target_residency_ns == SHORT_TICK_NSEC) + continue; + + memmove(&drv->states[i+1], &drv->states[i], + sizeof(struct cpuidle_state) * (CPUIDLE_STATE_MAX - i - 1)); + __cpuidle_state_init_tick(s); + drv->state_count++; + i++; + } + } + + if (!tick) { + struct cpuidle_state *s = &drv->states[i]; + __cpuidle_state_init_tick(s); + drv->state_count++; } } --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -16,7 +16,7 @@ #include #include -#define CPUIDLE_STATE_MAX 10 +#define CPUIDLE_STATE_MAX 16 #define CPUIDLE_NAME_LEN 16 #define CPUIDLE_DESC_LEN 32