diff mbox

[PATCHv4,07/15] Thermal: Add a policy sysfs attribute

Message ID 1347946506-18449-8-git-send-email-durgadoss.r@intel.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

durgadoss.r@intel.com Sept. 18, 2012, 5:34 a.m. UTC
This patch adds a policy sysfs attribute to a thermal zone.
This attribute denotes the throttling governor used for the
zone. This is a RW attribute.

Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
---
 drivers/thermal/thermal_sys.c |   42 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

Comments

Zhang Rui Sept. 21, 2012, 8:07 a.m. UTC | #1
On ?, 2012-09-18 at 11:04 +0530, Durgadoss R wrote:
> This patch adds a policy sysfs attribute to a thermal zone.
> This attribute denotes the throttling governor used for the
> zone. This is a RW attribute.
> 
> Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
> ---
>  drivers/thermal/thermal_sys.c |   42 ++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> index a67c6c0..0948a60 100644
> --- a/drivers/thermal/thermal_sys.c
> +++ b/drivers/thermal/thermal_sys.c
> @@ -454,10 +454,41 @@ passive_show(struct device *dev, struct device_attribute *attr,
>  	return sprintf(buf, "%d\n", tz->forced_passive);
>  }
>  
> +static ssize_t
> +policy_store(struct device *dev, struct device_attribute *attr,
> +		    const char *buf, size_t count)
> +{
> +	int ret = -EINVAL;
> +	struct thermal_zone_device *tz = to_thermal_zone(dev);
> +	struct thermal_governor *gov;
> +
> +	mutex_lock(&thermal_governor_lock);
> +
> +	gov = __find_governor(buf);
> +	if (!gov)
> +		goto exit;
> +
> +	tz->governor = gov;
> +	ret = count;
> +
> +exit:
> +	mutex_unlock(&thermal_governor_lock);
> +	return ret;
> +}
> +
> +static ssize_t
> +policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct thermal_zone_device *tz = to_thermal_zone(dev);
> +
> +	return sprintf(buf, "%s\n", tz->governor->name);
> +}
> +

we should introduce an API for platform thermal drivers to switch their
policy.
say they may want to switch to "userspace" to disable the kernel thermal
control.
and policy_store should invoke that function directly.

BTW, IMO, deactiving all the thermal_instances and updating the cooling
devices when a thermal zone switches to "userspace" governor is
reasonable.

thanks,
rui
>  static DEVICE_ATTR(type, 0444, type_show, NULL);
>  static DEVICE_ATTR(temp, 0444, temp_show, NULL);
>  static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
>  static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
> +static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
>  
>  /* sys I/F for cooling device */
>  #define to_cooling_device(_dev)	\
> @@ -1512,10 +1543,14 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
>  			passive = 1;
>  	}
>  
> -	if (!passive)
> -		result = device_create_file(&tz->device,
> -					    &dev_attr_passive);
> +	if (!passive) {
> +		result = device_create_file(&tz->device, &dev_attr_passive);
> +		if (result)
> +			goto unregister;
> +	}
>  
> +	/* Create policy attribute */
> +	result = device_create_file(&tz->device, &dev_attr_policy);
>  	if (result)
>  		goto unregister;
>  
> @@ -1591,6 +1626,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
>  	device_remove_file(&tz->device, &dev_attr_temp);
>  	if (tz->ops->get_mode)
>  		device_remove_file(&tz->device, &dev_attr_mode);
> +	device_remove_file(&tz->device, &dev_attr_policy);
>  	remove_trip_attrs(tz);
>  	tz->governor = NULL;
>  


--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
durgadoss.r@intel.com Sept. 21, 2012, 8:09 a.m. UTC | #2
SGkgUnVpLA0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IFpoYW5nLCBS
dWkNCj4gU2VudDogRnJ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ID4gKwl9DQo+
ID4NCj4gPiArCS8qIENyZWF0ZSBwb2xpY3kgYXR0cmlidXRlICovDQo+ID4gKwlyZXN1bHQgPSBk
ZXZpY2VfY3JlYXRlX2ZpbGUoJnR6LT5kZXZpY2UsICZkZXZfYXR0cl9wb2xpY3kpOw0KPiA+ICAJ
aWYgKHJlc3VsdCkNCj4gPiAgCQlnb3RvIHVucmVnaXN0ZXI7DQo+ID4NCj4gPiBAQCAtMTU5MSw2
ICsxNjI2LDcgQEAgdm9pZCB0aGVybWFsX3pvbmVfZGV2aWNlX3VucmVnaXN0ZXIoc3RydWN0DQo+
IHRoZXJtYWxfem9uZV9kZXZpY2UgKnR6KQ0KPiA+ICAJZGV2aWNlX3JlbW92ZV9maWxlKCZ0ei0+
ZGV2aWNlLCAmZGV2X2F0dHJfdGVtcCk7DQo+ID4gIAlpZiAodHotPm9wcy0+Z2V0X21vZGUpDQo+
ID4gIAkJZGV2aWNlX3JlbW92ZV9maWxlKCZ0ei0+ZGV2aWNlLCAmZGV2X2F0dHJfbW9kZSk7DQo+
ID4gKwlkZXZpY2VfcmVtb3ZlX2ZpbGUoJnR6LT5kZXZpY2UsICZkZXZfYXR0cl9wb2xpY3kpOw0K
PiA+ICAJcmVtb3ZlX3RyaXBfYXR0cnModHopOw0KPiA+ICAJdHotPmdvdmVybm9yID0gTlVMTDsN
Cj4gPg0KPiANCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Zhang Rui Sept. 24, 2012, 5:44 a.m. UTC | #3
On ?, 2012-09-21 at 02:09 -0600, R, Durgadoss wrote:
> Hi Rui,
> 
> > -----Original Message-----
> > From: Zhang, Rui
> > Sent: Friday, September 21, 2012 1:37 PM
> > To: R, Durgadoss
> > Cc: lenb@kernel.org; linux-acpi@vger.kernel.org; eduardo.valentin@ti.com
> > Subject: Re: [PATCHv4 07/15] Thermal: Add a policy sysfs attribute
> > 
> > On ?, 2012-09-18 at 11:04 +0530, Durgadoss R wrote:
> > > This patch adds a policy sysfs attribute to a thermal zone.
> > > This attribute denotes the throttling governor used for the
> > > zone. This is a RW attribute.
> > >
> > > Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
> > > ---
> > >  drivers/thermal/thermal_sys.c |   42
> > ++++++++++++++++++++++++++++++++++++++---
> > >  1 file changed, 39 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
> > > index a67c6c0..0948a60 100644
> > > --- a/drivers/thermal/thermal_sys.c
> > > +++ b/drivers/thermal/thermal_sys.c
> > > @@ -454,10 +454,41 @@ passive_show(struct device *dev, struct
> > device_attribute *attr,
> > >  	return sprintf(buf, "%d\n", tz->forced_passive);
> > >  }
> > >
> > > +static ssize_t
> > > +policy_store(struct device *dev, struct device_attribute *attr,
> > > +		    const char *buf, size_t count)
> > > +{
> > > +	int ret = -EINVAL;
> > > +	struct thermal_zone_device *tz = to_thermal_zone(dev);
> > > +	struct thermal_governor *gov;
> > > +
> > > +	mutex_lock(&thermal_governor_lock);
> > > +
> > > +	gov = __find_governor(buf);
> > > +	if (!gov)
> > > +		goto exit;
> > > +
> > > +	tz->governor = gov;
> > > +	ret = count;
> > > +
> > > +exit:
> > > +	mutex_unlock(&thermal_governor_lock);
> > > +	return ret;
> > > +}
> > > +
> > > +static ssize_t
> > > +policy_show(struct device *dev, struct device_attribute *devattr, char
> > *buf)
> > > +{
> > > +	struct thermal_zone_device *tz = to_thermal_zone(dev);
> > > +
> > > +	return sprintf(buf, "%s\n", tz->governor->name);
> > > +}
> > > +
> > 
> > we should introduce an API for platform thermal drivers to switch their
> > policy.
> > say they may want to switch to "userspace" to disable the kernel thermal
> > control.
> > and policy_store should invoke that function directly.
> 
> Yes, makes sense, we can introduce an EXPORT_SYMBOL API.

yes, we can have an incremental path for this.

thanks,
rui
> 
> Thanks,
> Durga
> 
> > BTW, IMO, deactiving all the thermal_instances and updating the cooling
> > devices when a thermal zone switches to "userspace" governor is
> > reasonable.
> > 
> > thanks,
> > rui
> > >  static DEVICE_ATTR(type, 0444, type_show, NULL);
> > >  static DEVICE_ATTR(temp, 0444, temp_show, NULL);
> > >  static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
> > >  static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show,
> > passive_store);
> > > +static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show,
> > policy_store);
> > >
> > >  /* sys I/F for cooling device */
> > >  #define to_cooling_device(_dev)	\
> > > @@ -1512,10 +1543,14 @@ struct thermal_zone_device
> > *thermal_zone_device_register(const char *type,
> > >  			passive = 1;
> > >  	}
> > >
> > > -	if (!passive)
> > > -		result = device_create_file(&tz->device,
> > > -					    &dev_attr_passive);
> > > +	if (!passive) {
> > > +		result = device_create_file(&tz->device, &dev_attr_passive);
> > > +		if (result)
> > > +			goto unregister;
> > > +	}
> > >
> > > +	/* Create policy attribute */
> > > +	result = device_create_file(&tz->device, &dev_attr_policy);
> > >  	if (result)
> > >  		goto unregister;
> > >
> > > @@ -1591,6 +1626,7 @@ void thermal_zone_device_unregister(struct
> > thermal_zone_device *tz)
> > >  	device_remove_file(&tz->device, &dev_attr_temp);
> > >  	if (tz->ops->get_mode)
> > >  		device_remove_file(&tz->device, &dev_attr_mode);
> > > +	device_remove_file(&tz->device, &dev_attr_policy);
> > >  	remove_trip_attrs(tz);
> > >  	tz->governor = NULL;
> > >
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index a67c6c0..0948a60 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -454,10 +454,41 @@  passive_show(struct device *dev, struct device_attribute *attr,
 	return sprintf(buf, "%d\n", tz->forced_passive);
 }
 
+static ssize_t
+policy_store(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	int ret = -EINVAL;
+	struct thermal_zone_device *tz = to_thermal_zone(dev);
+	struct thermal_governor *gov;
+
+	mutex_lock(&thermal_governor_lock);
+
+	gov = __find_governor(buf);
+	if (!gov)
+		goto exit;
+
+	tz->governor = gov;
+	ret = count;
+
+exit:
+	mutex_unlock(&thermal_governor_lock);
+	return ret;
+}
+
+static ssize_t
+policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct thermal_zone_device *tz = to_thermal_zone(dev);
+
+	return sprintf(buf, "%s\n", tz->governor->name);
+}
+
 static DEVICE_ATTR(type, 0444, type_show, NULL);
 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
+static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
 
 /* sys I/F for cooling device */
 #define to_cooling_device(_dev)	\
@@ -1512,10 +1543,14 @@  struct thermal_zone_device *thermal_zone_device_register(const char *type,
 			passive = 1;
 	}
 
-	if (!passive)
-		result = device_create_file(&tz->device,
-					    &dev_attr_passive);
+	if (!passive) {
+		result = device_create_file(&tz->device, &dev_attr_passive);
+		if (result)
+			goto unregister;
+	}
 
+	/* Create policy attribute */
+	result = device_create_file(&tz->device, &dev_attr_policy);
 	if (result)
 		goto unregister;
 
@@ -1591,6 +1626,7 @@  void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	device_remove_file(&tz->device, &dev_attr_temp);
 	if (tz->ops->get_mode)
 		device_remove_file(&tz->device, &dev_attr_mode);
+	device_remove_file(&tz->device, &dev_attr_policy);
 	remove_trip_attrs(tz);
 	tz->governor = NULL;