linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Zhang Rui <rui.zhang@intel.com>
Cc: jdelvare@suse.com, fenghua.yu@intel.com,
	linux-hwmon@vger.kernel.org, srinivas.pandruvada@linux.intel.com
Subject: Re: [PATCH V2 1/3] hwmon (coretemp): rearrange tjmax handing code
Date: Mon, 14 Nov 2022 15:21:27 -0800	[thread overview]
Message-ID: <20221114232127.GA2289924@roeck-us.net> (raw)
In-Reply-To: <20221113153145.32696-2-rui.zhang@intel.com>

On Sun, Nov 13, 2022 at 11:31:43PM +0800, Zhang Rui wrote:
> Rearrange the tjmax handling code so that it can be used directly in
> the sysfs attribute callbacks without forward declarations.
> 
> No functional change in this patch.
> 
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>  drivers/hwmon/coretemp.c | 156 +++++++++++++++++++--------------------
>  1 file changed, 78 insertions(+), 78 deletions(-)
> 
> diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> index ec35ada68455..50b640bfa504 100644
> --- a/drivers/hwmon/coretemp.c
> +++ b/drivers/hwmon/coretemp.c
> @@ -93,84 +93,6 @@ struct platform_data {
>  	struct device_attribute name_attr;
>  };
>  
> -/* Keep track of how many zone pointers we allocated in init() */
> -static int max_zones __read_mostly;
> -/* Array of zone pointers. Serialized by cpu hotplug lock */
> -static struct platform_device **zone_devices;
> -
> -static ssize_t show_label(struct device *dev,
> -				struct device_attribute *devattr, char *buf)
> -{
> -	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> -	struct platform_data *pdata = dev_get_drvdata(dev);
> -	struct temp_data *tdata = pdata->core_data[attr->index];
> -
> -	if (tdata->is_pkg_data)
> -		return sprintf(buf, "Package id %u\n", pdata->pkg_id);
> -
> -	return sprintf(buf, "Core %u\n", tdata->cpu_core_id);
> -}
> -
> -static ssize_t show_crit_alarm(struct device *dev,
> -				struct device_attribute *devattr, char *buf)
> -{
> -	u32 eax, edx;
> -	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> -	struct platform_data *pdata = dev_get_drvdata(dev);
> -	struct temp_data *tdata = pdata->core_data[attr->index];
> -
> -	mutex_lock(&tdata->update_lock);
> -	rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
> -	mutex_unlock(&tdata->update_lock);
> -
> -	return sprintf(buf, "%d\n", (eax >> 5) & 1);
> -}
> -
> -static ssize_t show_tjmax(struct device *dev,
> -			struct device_attribute *devattr, char *buf)
> -{
> -	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> -	struct platform_data *pdata = dev_get_drvdata(dev);
> -
> -	return sprintf(buf, "%d\n", pdata->core_data[attr->index]->tjmax);
> -}
> -
> -static ssize_t show_ttarget(struct device *dev,
> -				struct device_attribute *devattr, char *buf)
> -{
> -	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> -	struct platform_data *pdata = dev_get_drvdata(dev);
> -
> -	return sprintf(buf, "%d\n", pdata->core_data[attr->index]->ttarget);
> -}
> -
> -static ssize_t show_temp(struct device *dev,
> -			struct device_attribute *devattr, char *buf)
> -{
> -	u32 eax, edx;
> -	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> -	struct platform_data *pdata = dev_get_drvdata(dev);
> -	struct temp_data *tdata = pdata->core_data[attr->index];
> -
> -	mutex_lock(&tdata->update_lock);
> -
> -	/* Check whether the time interval has elapsed */
> -	if (time_after(jiffies, tdata->last_updated + HZ)) {
> -		rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
> -		/*
> -		 * Ignore the valid bit. In all observed cases the register
> -		 * value is either low or zero if the valid bit is 0.
> -		 * Return it instead of reporting an error which doesn't
> -		 * really help at all.
> -		 */
> -		tdata->temp = tdata->tjmax - ((eax >> 16) & 0x7f) * 1000;
> -		tdata->last_updated = jiffies;
> -	}
> -
> -	mutex_unlock(&tdata->update_lock);
> -	return sprintf(buf, "%d\n", tdata->temp);
> -}
> -
>  struct tjmax_pci {
>  	unsigned int device;
>  	int tjmax;
> @@ -373,6 +295,84 @@ static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
>  	return adjust_tjmax(c, id, dev);
>  }
>  
> +/* Keep track of how many zone pointers we allocated in init() */
> +static int max_zones __read_mostly;
> +/* Array of zone pointers. Serialized by cpu hotplug lock */
> +static struct platform_device **zone_devices;
> +
> +static ssize_t show_label(struct device *dev,
> +				struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct platform_data *pdata = dev_get_drvdata(dev);
> +	struct temp_data *tdata = pdata->core_data[attr->index];
> +
> +	if (tdata->is_pkg_data)
> +		return sprintf(buf, "Package id %u\n", pdata->pkg_id);
> +
> +	return sprintf(buf, "Core %u\n", tdata->cpu_core_id);
> +}
> +
> +static ssize_t show_crit_alarm(struct device *dev,
> +				struct device_attribute *devattr, char *buf)
> +{
> +	u32 eax, edx;
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct platform_data *pdata = dev_get_drvdata(dev);
> +	struct temp_data *tdata = pdata->core_data[attr->index];
> +
> +	mutex_lock(&tdata->update_lock);
> +	rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
> +	mutex_unlock(&tdata->update_lock);
> +
> +	return sprintf(buf, "%d\n", (eax >> 5) & 1);
> +}
> +
> +static ssize_t show_tjmax(struct device *dev,
> +			struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct platform_data *pdata = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d\n", pdata->core_data[attr->index]->tjmax);
> +}
> +
> +static ssize_t show_ttarget(struct device *dev,
> +				struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct platform_data *pdata = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d\n", pdata->core_data[attr->index]->ttarget);
> +}
> +
> +static ssize_t show_temp(struct device *dev,
> +			struct device_attribute *devattr, char *buf)
> +{
> +	u32 eax, edx;
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct platform_data *pdata = dev_get_drvdata(dev);
> +	struct temp_data *tdata = pdata->core_data[attr->index];
> +
> +	mutex_lock(&tdata->update_lock);
> +
> +	/* Check whether the time interval has elapsed */
> +	if (time_after(jiffies, tdata->last_updated + HZ)) {
> +		rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
> +		/*
> +		 * Ignore the valid bit. In all observed cases the register
> +		 * value is either low or zero if the valid bit is 0.
> +		 * Return it instead of reporting an error which doesn't
> +		 * really help at all.
> +		 */
> +		tdata->temp = tdata->tjmax - ((eax >> 16) & 0x7f) * 1000;
> +		tdata->last_updated = jiffies;
> +	}
> +
> +	mutex_unlock(&tdata->update_lock);
> +	return sprintf(buf, "%d\n", tdata->temp);
> +}
> +
>  static int create_core_attrs(struct temp_data *tdata, struct device *dev,
>  			     int attr_no)
>  {

  reply	other threads:[~2022-11-14 23:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13 15:31 [PATCH V2 0/3] hwmon (coretemp): Add support for dynamic tjmax/ttarget Zhang Rui
2022-11-13 15:31 ` [PATCH V2 1/3] hwmon (coretemp): rearrange tjmax handing code Zhang Rui
2022-11-14 23:21   ` Guenter Roeck [this message]
2022-11-13 15:31 ` [PATCH V2 2/3] hwmon (coretemp): Add support for dynamic tjmax Zhang Rui
2022-11-14 23:24   ` Guenter Roeck
2022-11-13 15:31 ` [PATCH V2 3/3] hwmon (coretemp): Add support for dynamic ttarget Zhang Rui
2022-11-14 23:25   ` Guenter Roeck

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=20221114232127.GA2289924@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=fenghua.yu@intel.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).