From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=93.87.244.166 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796500605; b=tw2WxZpxDCYdXYLkqFZIdbE7GaID0DOu+Dj4sn9ekG+LgXD4deeotffN0MN7DnRtwXjm rwiEbiMBqsbhas+R9XNgvC4Ek2i/RFEDWdHU3sucPB81NP1feuxoBXIOWpLZNpnetaUEf FLVEl2IxyZpf0xwlNUKplmqNZrrV+IF1K5aAdEBbR/E49AQyqHPJCWycq1FyDzlDOxx6J N5xpQLPZ4FQGLMpxRIpHmefL4ylkFfjaC5L8dDVT9PgQPWWi8c/pVrf5GVgedDw459rvp 7QaBFqsKCn4r3/W+9xrotz4+JgrzpQ7MNvuEwxZ6m5kUjxjKvF4YibYxTbBWU9odb0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796500605; h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=Z8n1F/ZlCDzXwRVJ/9mL8Jk/s0Idxg0N4gnCXO4/lI0=; b=Lpl9FqB/iGZrB2UVoNClR+Hqv02brt97eNeZZqqYid8PYuzx6f9qnXHToVPwapjzdwDe l+LBxfkS550V6B6ZiBjal/8IOpavXqFRW85tJttaBNRTDLWbauAp/RnJdsbsBQX7ZWeWF H8PvyNPzpSShTRs35cwQIp+hAMtiIwFDQtMpV6yeoy6H4QTG0wReTQacm7Y/MlqA/R0B9 lXRIVgsS/cs2JVxx0nkqlw+J8NZLi+HfqYPqL+OHI5NI2cZ+Wkb0jykedocMXkPSahynJ O2v372qmTApJPgYHWCgv3f2LR+Xzd2aMonSLdzLF5APkBOEPFg8rSX8ARgLx7/guoww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=arvanta.net; spf=pass smtp.mailfrom=arvanta.net; arc=none smtp.remote-ip=93.87.244.166 Received: from fx.arvanta.net (93-87-244-166.static.isp.telekom.rs [93.87.244.166]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB8FD606A322 for ; Sat, 5 Dec 2026 19:56:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AB8FD606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=arvanta.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arvanta.net Received: from air (m1pro.arvanta.net [10.5.1.11]) by fx.arvanta.net (Postfix) with SMTP id 60FC541E; Sat, 05 Dec 2026 20:56:37 +0100 (CET) Date: Sat, 5 Dec 2026 20:56:37 +0100 From: Milan =?utf-8?Q?P=2E_Stani=C4=87?= To: Natanael Copa Cc: "Rafael J . Wysocki" , Viresh Kumar , Nishanth Menon , Stephen Boyd , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Yixun Lan , Troy Mitchell , Shuwei Wu , Aurelien Jarno , spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, stable@vger.kernel.org Subject: Re: [PATCH] cpufreq: dt: Set the initial OPP to apply its voltage constraints Message-ID: <20261205195637.GA35858@air> References: <20261111130430.10359-1-ncopa@alpinelinux.org> X-Mailing-List: spacemit@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261111130430.10359-1-ncopa@alpinelinux.org> Hi, [ sorry for late answer] On Wed, 2026-11-11 at 14:04, Natanael Copa wrote: > The cpufreq core skips requests for the current frequency, so a policy > has no voltage constraint on its supply until its first frequency > change. Another policy sharing the supply can then lower the voltage > too far. > > On the SpacemiT K1, both clusters share one supply and boot at 1.6 GHz. > When policy0 scales down, the supply drops to 0.95 V while policy4 > still runs at 1.6 GHz, causing random crashes during boot. > > Set the OPP for the current clock rate of all CPUs before registering > the driver. I tried to reproduce crash on banana pi F3 and spacemit musebook (K1 SoC both) with kernel 7.3 and 7.4-rc series without this patch but in all my tests clock works fine with different schedulers. I'm using mainline opensbi on these machines and not vendor (spacemit) one. Maybe because this all works fine in my tests. -- Kind regards > Fixes: 3b9c34556fc1 ("riscv: dts: spacemit: Add cpu scaling for K1 SoC") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-5-5 > Assisted-by: Claude:claude-fable-5-2 > Signed-off-by: Natanael Copa > --- > Reproducer, booted with cpufreq.default_governor=performance: > > # echo 614400 > /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq > > buck1 drops to 950000 uV while policy4 is still at 1600000 kHz, which > crashed my board within seconds. > > Tested on a Banana Pi BPI-F3 with v7.3.3 and v7.4-rc2. Without the > patch, v7.3.3 crashed on every boot with schedutil (three). With the > patch, the reproducer keeps buck1 at 1050000 uV, and five boots with > schedutil were clean on each kernel. Not tested on other SoCs. > > Other OPP users that never set their current OPP have the same gap. If > you would rather fix this in the OPP core, I can rework it. > > Found and fixed with the help of an AI assistant (Claude). I reviewed > and tested the result. > > drivers/cpufreq/cpufreq-dt.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c > index eb15650f99bf..2646dda10aac 100644 > --- a/drivers/cpufreq/cpufreq-dt.c > +++ b/drivers/cpufreq/cpufreq-dt.c > @@ -153,6 +153,30 @@ static struct cpufreq_driver dt_cpufreq_driver = { > .suspend = cpufreq_generic_suspend, > }; > > +/* > + * Set the OPP for the current clock rate, so that its voltage constraints > + * apply before any policy can change frequency. Otherwise another policy > + * sharing the supply could lower the voltage below what this one needs. > + */ > +static void dt_cpufreq_set_initial_opp(struct device *cpu_dev) > +{ > + struct clk *clk = clk_get(cpu_dev, NULL); > + unsigned long rate; > + int ret; > + > + if (IS_ERR(clk)) > + return; > + > + rate = clk_get_rate(clk); > + clk_put(clk); > + if (!rate) > + return; > + > + ret = dev_pm_opp_set_rate(cpu_dev, rate); > + if (ret) > + dev_warn(cpu_dev, "failed to set initial OPP: %d\n", ret); > +} > + > static int dt_cpufreq_early_init(struct device *dev, int cpu) > { > struct private_data *priv; > @@ -251,6 +275,8 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu) > goto out; > } > > + dt_cpufreq_set_initial_opp(cpu_dev); > + > list_add(&priv->node, &priv_list); > return 0; > > > base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620 > -- > 2.56.1 > From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C306C606A31F for ; Sat, 5 Dec 2026 20:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=aTTRM62/ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=5Ec1/ilFv1qg61S5TFX19ZuZ6ZNN9m29BDV2IZg6Ot4=; b=aTTRM62/kTSQJSu220NFwlIV1w TMNVMrjK0JtwRGXeQvmaf7HAgKtHluVHuVrvQNj9DleTKJBvjTiPry1Hd/7R7HB72+NjC0cPZmVhc 5ODo46k9NWipgH5i+2X6NV9pS1qHsXlvXedtEluuDCL7+mngo/bwokxUVv/vaRfzdG27+KDbc1B1O QxOXwOajj0Webp9TAU/n2YdZ04kn5VGLvSNsmOEBlaoxylZ6TcSLbYNqxPbI5UQ8TRbh/1iuqusO4 KiVla7fsYXq6tJUF31AFGnxZ3w0Qy2BFe4iwS0OKH1NMAqjcmFA8ZqJIuIWWfFDoULg8Z1ofRnd6/ N2JnbTGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZwmb-00000002sl3-3f5J; Sat, 05 Dec 2026 20:55:01 +0000 Received: from 93-87-244-166.static.isp.telekom.rs ([93.87.244.166] helo=fx.arvanta.net) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZwmY-00000002skP-2c64 for linux-riscv@lists.infradead.org; Sat, 05 Dec 2026 20:54:59 +0000 Received: from air (m1pro.arvanta.net [10.5.1.11]) by fx.arvanta.net (Postfix) with SMTP id 60FC541E; Sat, 05 Dec 2026 20:56:37 +0100 (CET) Date: Sat, 5 Dec 2026 20:56:37 +0100 From: Milan =?utf-8?Q?P=2E_Stani=C4=87?= To: Natanael Copa Cc: "Rafael J . Wysocki" , Viresh Kumar , Nishanth Menon , Stephen Boyd , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Yixun Lan , Troy Mitchell , Shuwei Wu , Aurelien Jarno , spacemit@lists.linux.dev, linux-riscv@lists.infradead.org, stable@vger.kernel.org Subject: Re: [PATCH] cpufreq: dt: Set the initial OPP to apply its voltage constraints Message-ID: <20261205195637.GA35858@air> References: <20261111130430.10359-1-ncopa@alpinelinux.org> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20261111130430.10359-1-ncopa@alpinelinux.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261205_125458_837566_20C42DE7 X-CRM114-Status: GOOD ( 28.04 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi, [ sorry for late answer] On Wed, 2026-11-11 at 14:04, Natanael Copa wrote: > The cpufreq core skips requests for the current frequency, so a policy > has no voltage constraint on its supply until its first frequency > change. Another policy sharing the supply can then lower the voltage > too far. > > On the SpacemiT K1, both clusters share one supply and boot at 1.6 GHz. > When policy0 scales down, the supply drops to 0.95 V while policy4 > still runs at 1.6 GHz, causing random crashes during boot. > > Set the OPP for the current clock rate of all CPUs before registering > the driver. I tried to reproduce crash on banana pi F3 and spacemit musebook (K1 SoC both) with kernel 7.3 and 7.4-rc series without this patch but in all my tests clock works fine with different schedulers. I'm using mainline opensbi on these machines and not vendor (spacemit) one. Maybe because this all works fine in my tests. -- Kind regards > Fixes: 3b9c34556fc1 ("riscv: dts: spacemit: Add cpu scaling for K1 SoC") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-5-5 > Assisted-by: Claude:claude-fable-5-2 > Signed-off-by: Natanael Copa > --- > Reproducer, booted with cpufreq.default_governor=performance: > > # echo 614400 > /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq > > buck1 drops to 950000 uV while policy4 is still at 1600000 kHz, which > crashed my board within seconds. > > Tested on a Banana Pi BPI-F3 with v7.3.3 and v7.4-rc2. Without the > patch, v7.3.3 crashed on every boot with schedutil (three). With the > patch, the reproducer keeps buck1 at 1050000 uV, and five boots with > schedutil were clean on each kernel. Not tested on other SoCs. > > Other OPP users that never set their current OPP have the same gap. If > you would rather fix this in the OPP core, I can rework it. > > Found and fixed with the help of an AI assistant (Claude). I reviewed > and tested the result. > > drivers/cpufreq/cpufreq-dt.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c > index eb15650f99bf..2646dda10aac 100644 > --- a/drivers/cpufreq/cpufreq-dt.c > +++ b/drivers/cpufreq/cpufreq-dt.c > @@ -153,6 +153,30 @@ static struct cpufreq_driver dt_cpufreq_driver = { > .suspend = cpufreq_generic_suspend, > }; > > +/* > + * Set the OPP for the current clock rate, so that its voltage constraints > + * apply before any policy can change frequency. Otherwise another policy > + * sharing the supply could lower the voltage below what this one needs. > + */ > +static void dt_cpufreq_set_initial_opp(struct device *cpu_dev) > +{ > + struct clk *clk = clk_get(cpu_dev, NULL); > + unsigned long rate; > + int ret; > + > + if (IS_ERR(clk)) > + return; > + > + rate = clk_get_rate(clk); > + clk_put(clk); > + if (!rate) > + return; > + > + ret = dev_pm_opp_set_rate(cpu_dev, rate); > + if (ret) > + dev_warn(cpu_dev, "failed to set initial OPP: %d\n", ret); > +} > + > static int dt_cpufreq_early_init(struct device *dev, int cpu) > { > struct private_data *priv; > @@ -251,6 +275,8 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu) > goto out; > } > > + dt_cpufreq_set_initial_opp(cpu_dev); > + > list_add(&priv->node, &priv_list); > return 0; > > > base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620 > -- > 2.56.1 > _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv