Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "linux@roeck-us.net" <linux@roeck-us.net>,
	"jdelvare@suse.com" <jdelvare@suse.com>
Cc: "Yu, Fenghua" <fenghua.yu@intel.com>,
	"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] hwmon: (coretemp) Fix core count limitation
Date: Fri, 1 Dec 2023 17:41:19 +0000	[thread overview]
Message-ID: <f9e69ebafe7e767eeb1fba250af9c9f7629bae5e.camel@intel.com> (raw)
In-Reply-To: <91a3f785-8d69-4425-ad23-a6ac0ebddb07@roeck-us.net>

On Thu, 2023-11-30 at 19:06 -0800, Guenter Roeck wrote:
> On 11/27/23 05:16, Zhang Rui wrote:
> > Currently, coretemp driver only supports 128 cores per package.
> > This loses some core temperation information on systems that have
> > more
> > than 128 cores per package.
> >   [   58.685033] coretemp coretemp.0: Adding Core 128 failed
> >   [   58.692009] coretemp coretemp.0: Adding Core 129 failed
> > 
> > Fix the problem by using a per package list to maintain the per
> > core
> > temp_data instead of the fixed length pdata->core_data[] array.
> > 
> > Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> > ---
> >   drivers/hwmon/coretemp.c | 110 ++++++++++++++++++----------------
> > -----
> >   1 file changed, 52 insertions(+), 58 deletions(-)
> > 
> > diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> > index cef43fedbd58..1bb1a6e4b07b 100644
> > --- a/drivers/hwmon/coretemp.c
> > +++ b/drivers/hwmon/coretemp.c
> > @@ -39,11 +39,7 @@ static int force_tjmax;
> >   module_param_named(tjmax, force_tjmax, int, 0444);
> >   MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
> >   
> > -#define PKG_SYSFS_ATTR_NO      1       /* Sysfs attribute for
> > package temp */
> > -#define BASE_SYSFS_ATTR_NO     2       /* Sysfs Base attr no for
> > coretemp */
> > -#define NUM_REAL_CORES         128     /* Number of Real cores per
> > cpu */
> >   #define CORETEMP_NAME_LENGTH  28      /* String Length of attrs
> > */
> > -#define MAX_CORE_DATA          (NUM_REAL_CORES +
> > BASE_SYSFS_ATTR_NO)
> >   
> >   enum coretemp_attr_index {
> >         ATTR_LABEL,
> > @@ -90,17 +86,17 @@ struct temp_data {
> >         struct attribute *attrs[TOTAL_ATTRS + 1];
> >         struct attribute_group attr_group;
> >         struct mutex update_lock;
> > +       struct list_head node;
> >   };
> >   
> >   /* Platform Data per Physical CPU */
> >   struct platform_data {
> >         struct device           *hwmon_dev;
> >         u16                     pkg_id;
> > -       u16                     cpu_map[NUM_REAL_CORES];
> > -       struct ida              ida;
> >         struct cpumask          cpumask;
> > -       struct temp_data        *core_data[MAX_CORE_DATA];
> >         struct device_attribute name_attr;
> > +       struct mutex            core_data_lock;
> > +       struct list_head        core_data_list;
> >   };
> >   
> >   struct tjmax_pci {
> > @@ -491,6 +487,23 @@ static struct temp_data
> > *init_temp_data(unsigned int cpu, int pkg_flag)
> >         return tdata;
> >   }
> >   
> > +static struct temp_data *get_tdata(struct platform_data *pdata,
> > int cpu)
> > +{
> > +       struct temp_data *tdata;
> > +
> > +       mutex_lock(&pdata->core_data_lock);
> > +       list_for_each_entry(tdata, &pdata->core_data_list, node) {
> > +               if (cpu >= 0 && !tdata->is_pkg_data && tdata-
> > >cpu_core_id == topology_core_id(cpu))
> > +                       goto found;
> > +               if (cpu < 0 && tdata->is_pkg_data)
> > +                       goto found;
> > +       }
> 
> I really don't like this. With 128+ cores, it gets terribly
> expensive.

I think this is only invoked in the cpu online/offline code, which is
not the hot path.

> 
> How about calculating the number of cores in the probe function and
> allocating cpu_map[] and core_data[] instead ?

Problem is that the number of cores is not available due to some
limitations in current CPU topology code.

Thomas has some patch series to fix this but that has not been merged
yet and we don't know when.

A simpler workaround for this issue is to change NUM_REAL_CORES to a
bigger value, and do dynamic memory allocation first. And we can change
the code to use the real number of cores later if that information
becomes available.

thanks,
rui

      reply	other threads:[~2023-12-01 17:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27 13:16 [PATCH 0/3] hwmon: (coretemp) Fix core count limitation Zhang Rui
2023-11-27 13:16 ` [PATCH 1/3] hwmon: (coretemp) Introduce enum for attr index Zhang Rui
2023-11-30 21:51   ` Ashok Raj
2023-12-01  4:14     ` Guenter Roeck
2023-12-01  4:47       ` Ashok Raj
2023-12-01 17:29         ` Zhang, Rui
2023-12-05 19:20           ` Ashok Raj
2023-11-27 13:16 ` [PATCH 2/3] hwmon: (coretemp) Remove unnecessary dependency of array index Zhang Rui
2023-12-01  1:27   ` Ashok Raj
2023-12-01  3:26     ` Guenter Roeck
2023-12-01  4:34       ` Ashok Raj
2023-12-01 17:31       ` Zhang, Rui
2023-11-27 13:16 ` [PATCH 3/3] hwmon: (coretemp) Fix core count limitation Zhang Rui
2023-12-01  2:08   ` Ashok Raj
2023-12-01 17:47     ` Zhang, Rui
2023-12-01 22:58       ` Ashok Raj
2023-12-02  7:22         ` Zhang, Rui
2023-12-01  3:06   ` Guenter Roeck
2023-12-01 17:41     ` Zhang, Rui [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9e69ebafe7e767eeb1fba250af9c9f7629bae5e.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox