Re: [PATCH 3/5] cpufreq: loongson3: Replace per-package mutex with per-node

From: Huacai Chen

Date: Wed Aug 26 2026 - 10:50:07 EST


Hi, Zhongqiu,

On Thu, Aug 20, 2026 at 7:35 PM Zhongqiu Han
<zhongqiu.han@xxxxxxxxxxxxxxxx> wrote:
>
> On 8/18/2026 8:39 PM, Huacai Chen wrote:
> > Our server productions (e.g. Loongson-3D6000/3E6000) can have multiple
> > nodes in one package and SMC mailboxes are also per-node. So replace the
> > per-package mutex with per-node one.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Hongliang Wang <wanghongliang@xxxxxxxxxxx>
> > Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> > ---
> > drivers/cpufreq/loongson3_cpufreq.c | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/cpufreq/loongson3_cpufreq.c b/drivers/cpufreq/loongson3_cpufreq.c
> > index 630f679aa739..e3cd78a5ab18 100644
> > --- a/drivers/cpufreq/loongson3_cpufreq.c
> > +++ b/drivers/cpufreq/loongson3_cpufreq.c
> > @@ -169,7 +169,7 @@ struct loongson3_freq_data {
> > struct cpufreq_frequency_table table[];
> > };
> >
> > -static struct mutex cpufreq_mutex[MAX_PACKAGES];
> > +static struct mutex cpufreq_mutex[MAX_NUMNODES];
> > static struct cpufreq_driver loongson3_cpufreq_driver;
> > static DEFINE_PER_CPU(struct loongson3_freq_data *, freq_data);
> >
> > @@ -177,14 +177,14 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext
> > {
> > int retries;
> > unsigned int cpu = raw_smp_processor_id();
> > - unsigned int package = cpu_data[cpu].package;
> > + unsigned int nid = cpu_to_node(cpu);
> > union smc_message msg, last;
> >
> > - mutex_lock(&cpufreq_mutex[package]);
> > + mutex_lock(&cpufreq_mutex[nid]);
> >
> > last.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX);
> > if (!last.complete) {
> > - mutex_unlock(&cpufreq_mutex[package]);
> > + mutex_unlock(&cpufreq_mutex[nid]);
> > return -EPERM;
> > }
> >
> > @@ -208,11 +208,11 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext
> > }
> >
> > if (!msg.complete || msg.cmd != CMD_OK) {
> > - mutex_unlock(&cpufreq_mutex[package]);
> > + mutex_unlock(&cpufreq_mutex[nid]);
> > return -EPERM;
> > }
> >
> > - mutex_unlock(&cpufreq_mutex[package]);
> > + mutex_unlock(&cpufreq_mutex[nid]);
>
> An optimization independent of this patch: considering to use
> guard(mutex)(xxx.lock)
This can be improved in the future, but not suitable in the bug fix patches.

Huacai

>
> >
> > return msg.val;
> > }
> > @@ -337,7 +337,7 @@ static int loongson3_cpufreq_probe(struct platform_device *pdev)
> > {
> > int i, ret;
> >
> > - for (i = 0; i < MAX_PACKAGES; i++) {
> > + for (i = 0; i < MAX_NUMNODES; i++) {
> > ret = devm_mutex_init(&pdev->dev, &cpufreq_mutex[i]);
> > if (ret)
> > return ret;
>
>
> --
> Thx and BRs,
> Zhongqiu Han