Skip to contentSkip to conversation

thermal: set upper and lower limits when binding

RFC PATCH In review Zhang Rui 3 participants 6 messages Jun 11, 2012 – Jun 13, 2012

Subsystems (5)
lore
Share & tools
lore

Zhang Rui

author reviewer
#0 lore raw

RFC PATCH 3/12 thermal: set upper and lower limits when binding

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++----------
 drivers/platform/x86/acerhdf.c |    2 +-
 drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------
 include/linux/thermal.h        |    3 ++-
 4 files changed, 41 insertions(+), 18 deletions(-)
drivers/thermal/thermal_sys.c +14 -6
Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
 				     sizeof("Processor")))
 				thermal_zone_bind_cooling_device(tz,
 								 THERMAL_TRIPS_NONE,
-								 cdev);
+								 cdev, -1, -1);
 		}
 		mutex_unlock(&thermal_list_lock);
 		if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
  */
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 				     int trip,
-				     struct thermal_cooling_device *cdev)
+				     struct thermal_cooling_device *cdev,
+				     long upper, long lower)
 {
 	struct thermal_cooling_device_instance *dev;
 	struct thermal_cooling_device_instance *pos;
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
 	if (tz != pos1 || cdev != pos2)
 		return -EINVAL;
 
+	cdev->ops->get_max_state(cdev, &max_state);
+
+	/* lower default 0, upper default max_state */
+	lower = lower < 0 ? 0 : lower;
+	upper = upper < 0 ? max_state : upper;
+
+	if (lower > upper || upper > max_state)
+		return -EINVAL;
+
 	dev =
 	    kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
 	if (!dev)
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
 	dev->tz = tz;
 	dev->cdev = cdev;
 	dev->trip = trip;
-
-	cdev->ops->get_max_state(dev, &max_state);
-	dev->upper = max_state;
-	dev->lower = 0;
+	dev->upper = upper;
+	dev->lower = lower;
 
 	result = get_idr(&tz->idr, &tz->lock, &dev->id);
 	if (result)
include/linux/thermal.h +2 -1
Index: rtd3/include/linux/thermal.h
===================================================================
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-				     struct thermal_cooling_device *);
+				     struct thermal_cooling_device *,
+				     long, long);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
 				       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *);
drivers/acpi/thermal.c +24 -10
Index: rtd3/drivers/acpi/thermal.c
===================================================================
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
 	return 0;
 }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-		  struct thermal_cooling_device *);
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev,
-					cb action)
+					int bind)
 {
 	struct acpi_device *device = cdev->devdata;
 	struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.passive.devices.handles[i];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result =
+						thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.active[i].devices.handles[j];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result = thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
 		handle = tz->devices.handles[i];
 		status = acpi_bus_get_device(handle, &dev);
 		if (ACPI_SUCCESS(status) && (dev == device)) {
-			result = action(thermal, -1, cdev);
+			if (bind)
+				result = thermal_zone_bind_cooling_device(thermal,
+								-1, cdev, -1, -1);
+			else
+				result = thermal_zone_unbind_cooling_device(thermal,
+								-1, cdev);
 			if (result)
 				goto failed;
 		}
@@ -800,16 +816,14 @@ static int
 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_bind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
 }
 
 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_unbind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 0);
 }
 
 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
drivers/platform/x86/acerhdf.c +1 -1
Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
 	if (cdev != cl_dev)
 		return 0;
 
-	if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+	if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
 		pr_err("error binding cooling dev\n");
 		return -EINVAL;
 	}
#1 lore raw

Hi Rui,

I like this approach of multiple cooling states for ACTIVE type cooling devices. Some comments added.

Quoted 36 lines · Zhang Rui

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++---------- drivers/platform/x86/acerhdf.c |    2 +- drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------ include/linux/thermal.h        |    3 ++-

 4 files changed, 41 insertions(+), 18 deletions(-)

Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================

drivers/thermal/thermal_sys.c +3 -2
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
                                     sizeof("Processor")))
                                thermal_zone_bind_cooling_device(tz,
                                                                 THERMAL_TRIPS_NONE,
-                                                                cdev);
+                                                                cdev, -1, -1);
                }
                mutex_unlock(&thermal_list_lock);
                if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
  */
  int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                                     int trip,
-                                    struct thermal_cooling_device *cdev)
+                                    struct thermal_cooling_device *cdev,
+                                    long upper, long lower)
  {
        struct thermal_cooling_device_instance *dev;
        struct thermal_cooling_device_instance *pos;

drivers/thermal/thermal_sys.c int thermal_zone_bind_cooling_device(str · line 792

Quoted 8 lines
drivers/thermal/thermal_sys.c +5 -0
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
        if (tz != pos1 || cdev != pos2)
                return -EINVAL;
 
+       cdev->ops->get_max_state(cdev, &max_state);
+
+       /* lower default 0, upper default max_state */
+       lower = lower < 0 ? 0 : lower;
+       upper = upper < 0 ? max_state : upper;

Also some check can be added here like this,

           cdev->ops->get_max_state(cdev, &cur_state);
Quoted 130 lines
drivers/thermal/thermal_sys.c +4 -0
+
+       if (lower > upper || upper > max_state)
+               return -EINVAL;
+

       dev =
           kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL); if (!dev)

drivers/thermal/thermal_sys.c +2 -4
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
        dev->tz = tz;
        dev->cdev = cdev;
        dev->trip = trip;
-
-       cdev->ops->get_max_state(dev, &max_state);
-       dev->upper = max_state;
-       dev->lower = 0;
+       dev->upper = upper;
+       dev->lower = lower;
 
        result = get_idr(&tz->idr, &tz->lock, &dev->id);
        if (result)

Index: rtd3/include/linux/thermal.h
===================================================================

include/linux/thermal.h +2 -1
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
  void thermal_zone_device_unregister(struct thermal_zone_device *);
 
  int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-                                    struct thermal_cooling_device *);
+                                    struct thermal_cooling_device *,
+                                    long, long);
  int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
                                       struct thermal_cooling_device *);
  void thermal_zone_device_update(struct thermal_zone_device *);

Index: rtd3/drivers/acpi/thermal.c
===================================================================

drivers/acpi/thermal.c +23 -8
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
        return 0;
  }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-                 struct thermal_cooling_device *);
  static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                                        struct thermal_cooling_device *cdev,
-                                       cb action)
+                                       int bind)
  {
        struct acpi_device *device = cdev->devdata;
        struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
                        handle = tz->trips.passive.devices.handles[i];
                        status = acpi_bus_get_device(handle, &dev);
                        if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result =
+                                               thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                                if (result)
                                        goto failed;
                        }
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
                        handle = tz->trips.active[i].devices.handles[j];
                        status = acpi_bus_get_device(handle, &dev);
                        if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result = thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                                if (result)
                                        goto failed;
                        }
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
                handle = tz->devices.handles[i];
                status = acpi_bus_get_device(handle, &dev);
                if (ACPI_SUCCESS(status) && (dev == device)) {
-                       result = action(thermal, -1, cdev);
+                       if (bind)
+                               result = thermal_zone_bind_cooling_device(thermal,
+                                                               -1, cdev, -1, -1);
+                       else
+                               result = thermal_zone_unbind_cooling_device(thermal,
+                                                               -1, cdev);
                        if (result)
                                goto failed;
                }
@@ -800,16 +816,14 @@ static int
  acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
                                        struct thermal_cooling_device *cdev)
  {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_bind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
  }
 

 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_unbind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 0); }

 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================

drivers/platform/x86/acerhdf.c +1 -1
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
        if (cdev != cl_dev)
                return 0;
 
-       if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+       if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
                pr_err("error binding cooling dev\n");
                return -EINVAL;
        }
#2 lore raw
In reply to Zhang Rui

Hi Rui,

Sorry for sending one incomplete mail before.
I like this approach of multiple cooling states for ACTIVE type cooling devices. Some comments added.

Quoted 52 lines · Zhang Rui

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++---------- drivers/platform/x86/acerhdf.c |    2 +- drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------ include/linux/thermal.h        |    3 ++-

 4 files changed, 41 insertions(+), 18 deletions(-)

Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================

drivers/thermal/thermal_sys.c +12 -2
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
                                     sizeof("Processor")))
                                thermal_zone_bind_cooling_device(tz,
                                                                 THERMAL_TRIPS_NONE,
-                                                                cdev);
+                                                                cdev, -1, -1);
                }
                mutex_unlock(&thermal_list_lock);
                if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
  */
  int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                                     int trip,
-                                    struct thermal_cooling_device *cdev)
+                                    struct thermal_cooling_device *cdev,
+                                    long upper, long lower)
  {
        struct thermal_cooling_device_instance *dev;
        struct thermal_cooling_device_instance *pos;
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
        if (tz != pos1 || cdev != pos2)
                return -EINVAL;
 
+       cdev->ops->get_max_state(cdev, &max_state);
+
+       /* lower default 0, upper default max_state */
+       lower = lower < 0 ? 0 : lower;
+       upper = upper < 0 ? max_state : upper;
+
+       if (lower > upper || upper > max_state)
+               return -EINVAL;
+

       dev =
           kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL); if (!dev)

drivers/thermal/thermal_sys.c int thermal_zone_bind_cooling_device(str · line 805

Quoted 9 lines
drivers/thermal/thermal_sys.c +2 -4
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
        dev->tz = tz;
        dev->cdev = cdev;
        dev->trip = trip;
-
-       cdev->ops->get_max_state(dev, &max_state);
-       dev->upper = max_state;
-       dev->lower = 0;
+       dev->upper = upper;
+       dev->lower = lower;

Also some check can be added here like this,

          cdev->ops->get_max_state(cdev, &cur_state);
          if (cur_state !=  lower) {
              print_err("Set the initial state of the cooling device
to lower\n");
              return -EINVAL;
           }
           This is needed because in your thermal_zone_update

implementation the state change is from lower - upper.

Quoted 105 lines
drivers/thermal/thermal_sys.c +0 -0
        result = get_idr(&tz->idr, &tz->lock, &dev->id);
        if (result)

Index: rtd3/include/linux/thermal.h
===================================================================

include/linux/thermal.h +2 -1
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
  void thermal_zone_device_unregister(struct thermal_zone_device *);
 
  int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-                                    struct thermal_cooling_device *);
+                                    struct thermal_cooling_device *,
+                                    long, long);
  int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
                                       struct thermal_cooling_device *);
  void thermal_zone_device_update(struct thermal_zone_device *);

Index: rtd3/drivers/acpi/thermal.c
===================================================================

drivers/acpi/thermal.c +23 -8
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
        return 0;
  }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-                 struct thermal_cooling_device *);
  static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                                        struct thermal_cooling_device *cdev,
-                                       cb action)
+                                       int bind)
  {
        struct acpi_device *device = cdev->devdata;
        struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
                        handle = tz->trips.passive.devices.handles[i];
                        status = acpi_bus_get_device(handle, &dev);
                        if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result =
+                                               thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                                if (result)
                                        goto failed;
                        }
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
                        handle = tz->trips.active[i].devices.handles[j];
                        status = acpi_bus_get_device(handle, &dev);
                        if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result = thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                                if (result)
                                        goto failed;
                        }
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
                handle = tz->devices.handles[i];
                status = acpi_bus_get_device(handle, &dev);
                if (ACPI_SUCCESS(status) && (dev == device)) {
-                       result = action(thermal, -1, cdev);
+                       if (bind)
+                               result = thermal_zone_bind_cooling_device(thermal,
+                                                               -1, cdev, -1, -1);
+                       else
+                               result = thermal_zone_unbind_cooling_device(thermal,
+                                                               -1, cdev);
                        if (result)
                                goto failed;
                }
@@ -800,16 +816,14 @@ static int
  acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
                                        struct thermal_cooling_device *cdev)
  {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_bind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
  }
 

 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_unbind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 0); }

 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================

drivers/platform/x86/acerhdf.c static int acerhdf_bind(struct thermal_z · line 335

Quoted 8 lines
drivers/platform/x86/acerhdf.c +1 -1
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
        if (cdev != cl_dev)
                return 0;
 
-       if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+       if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
                pr_err("error binding cooling dev\n");
                return -EINVAL;
        }

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

author reviewer
#3 lore raw
Quoted 4 lines · Amit Kachhap

Hi Rui,

Sorry for sending one incomplete mail before.
I like this approach of multiple cooling states for ACTIVE type cooling devices.

Great, thanks.

Quoted 64 lines

Some comments added.

Quoted 52 lines · Zhang Rui

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++----------
 drivers/platform/x86/acerhdf.c |    2 +-
 drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------
 include/linux/thermal.h        |    3 ++-
 4 files changed, 41 insertions(+), 18 deletions(-)

Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================

drivers/thermal/thermal_sys.c +12 -2
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
                                    sizeof("Processor")))
                               thermal_zone_bind_cooling_device(tz,
                                                                THERMAL_TRIPS_NONE,
-                                                                cdev);
+                                                                cdev, -1, -1);
               }
               mutex_unlock(&thermal_list_lock);
               if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
 */
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                                    int trip,
-                                    struct thermal_cooling_device *cdev)
+                                    struct thermal_cooling_device *cdev,
+                                    long upper, long lower)
 {
       struct thermal_cooling_device_instance *dev;
       struct thermal_cooling_device_instance *pos;
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
       if (tz != pos1 || cdev != pos2)
               return -EINVAL;
 
+       cdev->ops->get_max_state(cdev, &max_state);
+
+       /* lower default 0, upper default max_state */
+       lower = lower < 0 ? 0 : lower;
+       upper = upper < 0 ? max_state : upper;
+
+       if (lower > upper || upper > max_state)
+               return -EINVAL;
+
       dev =
           kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
       if (!dev)

drivers/thermal/thermal_sys.c int thermal_zone_bind_cooling_device(str · line 805

Quoted 9 lines
drivers/thermal/thermal_sys.c +2 -4
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
       dev->tz = tz;
       dev->cdev = cdev;
       dev->trip = trip;
-
-       cdev->ops->get_max_state(dev, &max_state);
-       dev->upper = max_state;
-       dev->lower = 0;
+       dev->upper = upper;
+       dev->lower = lower;

Also some check can be added here like this,

Quoted 1 line
          cdev->ops->get_max_state(cdev, &cur_state);

you mean set_cur_state?

Quoted 7 lines

if (cur_state != lower) {
print_err("Set the initial state of the cooling device

to lower\n");
              return -EINVAL;
           }
           This is needed because in your thermal_zone_update

implementation the state change is from lower - upper.

No. we should not set it.
Say, you are binding a fan to a active trip point 50, and the current temperature is 30.

And further more, if you read all the patch set, you can see that every binding is actually invalid from the beginning.
So the upper and lower limits are just indicators here, it makes real sense only if this binding is activated.

thanks,
rui

Quoted 106 lines
Quoted 106 lines
drivers/thermal/thermal_sys.c +0 -0
       result = get_idr(&tz->idr, &tz->lock, &dev->id);
       if (result)

Index: rtd3/include/linux/thermal.h
===================================================================

include/linux/thermal.h +2 -1
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-                                    struct thermal_cooling_device *);
+                                    struct thermal_cooling_device *,
+                                    long, long);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
                                      struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *);

Index: rtd3/drivers/acpi/thermal.c
===================================================================

drivers/acpi/thermal.c +24 -10
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
       return 0;
 }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-                 struct thermal_cooling_device *);
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                                       struct thermal_cooling_device *cdev,
-                                       cb action)
+                                       int bind)
 {
       struct acpi_device *device = cdev->devdata;
       struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
                       handle = tz->trips.passive.devices.handles[i];
                       status = acpi_bus_get_device(handle, &dev);
                       if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result =
+                                               thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                               if (result)
                                       goto failed;
                       }
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
                       handle = tz->trips.active[i].devices.handles[j];
                       status = acpi_bus_get_device(handle, &dev);
                       if (ACPI_SUCCESS(status) && (dev == device)) {
-                               result = action(thermal, trip, cdev);
+                               if (bind)
+                                       result =
+                                               thermal_zone_bind_cooling_device(
+                                                       thermal, trip, cdev, -1, -1);
+                               else
+                                       result = thermal_zone_unbind_cooling_device(
+                                                       thermal, trip, cdev);
                               if (result)
                                       goto failed;
                       }
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
               handle = tz->devices.handles[i];
               status = acpi_bus_get_device(handle, &dev);
               if (ACPI_SUCCESS(status) && (dev == device)) {
-                       result = action(thermal, -1, cdev);
+                       if (bind)
+                               result = thermal_zone_bind_cooling_device(thermal,
+                                                               -1, cdev, -1, -1);
+                       else
+                               result = thermal_zone_unbind_cooling_device(thermal,
+                                                               -1, cdev);
                       if (result)
                               goto failed;
               }
@@ -800,16 +816,14 @@ static int
 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
                                       struct thermal_cooling_device *cdev)
 {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_bind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
 }
 
 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
                                       struct thermal_cooling_device *cdev)
 {
-       return acpi_thermal_cooling_device_cb(thermal, cdev,
-                               thermal_zone_unbind_cooling_device);
+       return acpi_thermal_cooling_device_cb(thermal, cdev, 0);
 }
 
 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {

Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================

drivers/platform/x86/acerhdf.c +0 -0
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
       if (cdev != cl_dev)
               return 0;
 
Quoted 7 lines

drivers/platform/x86/acerhdf.c static int acerhdf_bind(struct thermal_z · line 335

Quoted 7 lines
drivers/platform/x86/acerhdf.c +1 -1
-       if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+       if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
               pr_err("error binding cooling dev\n");
               return -EINVAL;
       }

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm

#4 lore raw
In reply to Zhang Rui

Hello Rui,

Quoted 49 lines · Zhang Rui

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++----------
 drivers/platform/x86/acerhdf.c |    2 +-
 drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------
 include/linux/thermal.h        |    3 ++-
 4 files changed, 41 insertions(+), 18 deletions(-)

Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================

drivers/thermal/thermal_sys.c +12 -2
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
 				     sizeof("Processor")))
 				thermal_zone_bind_cooling_device(tz,
 								 THERMAL_TRIPS_NONE,
-								 cdev);
+								 cdev, -1, -1);
 		}
 		mutex_unlock(&thermal_list_lock);
 		if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
  */
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 				     int trip,
-				     struct thermal_cooling_device *cdev)
+				     struct thermal_cooling_device *cdev,
+				     long upper, long lower)
 {
 	struct thermal_cooling_device_instance *dev;
 	struct thermal_cooling_device_instance *pos;
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
 	if (tz != pos1 || cdev != pos2)
 		return -EINVAL;
 
+	cdev->ops->get_max_state(cdev, &max_state);
+
+	/* lower default 0, upper default max_state */
+	lower = lower < 0 ? 0 : lower;
+	upper = upper < 0 ? max_state : upper;
+
+	if (lower > upper || upper > max_state)
+		return -EINVAL;
+
 
Quoted 1 line

From this version of the code, I assume we want to:

a. Allow cooling binding instances to have ranges overlapping. b. Allow a binding with only one state (lower == upper).

Is this the expected behavior?

Quoted 126 lines
drivers/thermal/thermal_sys.c +2 -4
 	dev =
 	    kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
 	if (!dev)
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
 	dev->tz = tz;
 	dev->cdev = cdev;
 	dev->trip = trip;
-
-	cdev->ops->get_max_state(dev, &max_state);
-	dev->upper = max_state;
-	dev->lower = 0;
+	dev->upper = upper;
+	dev->lower = lower;
 
 	result = get_idr(&tz->idr, &tz->lock, &dev->id);
 	if (result)

Index: rtd3/include/linux/thermal.h
===================================================================

include/linux/thermal.h +2 -1
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-				     struct thermal_cooling_device *);
+				     struct thermal_cooling_device *,
+				     long, long);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
 				       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *);

Index: rtd3/drivers/acpi/thermal.c
===================================================================

drivers/acpi/thermal.c +24 -10
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
 	return 0;
 }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-		  struct thermal_cooling_device *);
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev,
-					cb action)
+					int bind)
 {
 	struct acpi_device *device = cdev->devdata;
 	struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.passive.devices.handles[i];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result =
+						thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.active[i].devices.handles[j];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result = thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
 		handle = tz->devices.handles[i];
 		status = acpi_bus_get_device(handle, &dev);
 		if (ACPI_SUCCESS(status) && (dev == device)) {
-			result = action(thermal, -1, cdev);
+			if (bind)
+				result = thermal_zone_bind_cooling_device(thermal,
+								-1, cdev, -1, -1);
+			else
+				result = thermal_zone_unbind_cooling_device(thermal,
+								-1, cdev);
 			if (result)
 				goto failed;
 		}
@@ -800,16 +816,14 @@ static int
 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_bind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
 }
 
 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_unbind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 0);
 }
 
 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {

Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================

drivers/platform/x86/acerhdf.c +1 -1
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
 	if (cdev != cl_dev)
 		return 0;
 
-	if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+	if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
 		pr_err("error binding cooling dev\n");
 		return -EINVAL;
 	}
author reviewer
#5 lore raw
Quoted 42 lines · Eduardo Valentin

Hello Rui,

Quoted 39 lines · Zhang Rui

Set upper and lower limits when binding
a thermal cooling device to a thermal zone device.

---
 drivers/acpi/thermal.c         |   34 ++++++++++++++++++++++++----------
 drivers/platform/x86/acerhdf.c |    2 +-
 drivers/thermal/thermal_sys.c  |   20 ++++++++++++++------
 include/linux/thermal.h        |    3 ++-
 4 files changed, 41 insertions(+), 18 deletions(-)

Index: rtd3/drivers/thermal/thermal_sys.c
===================================================================

drivers/thermal/thermal_sys.c +3 -2
@@ -248,7 +248,7 @@ passive_store(struct device *dev, struct
 				     sizeof("Processor")))
 				thermal_zone_bind_cooling_device(tz,
 								 THERMAL_TRIPS_NONE,
-								 cdev);
+								 cdev, -1, -1);
 		}
 		mutex_unlock(&thermal_list_lock);
 		if (!tz->passive_delay)
@@ -760,7 +760,8 @@ static void thermal_zone_device_check(st
  */
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 				     int trip,
-				     struct thermal_cooling_device *cdev)
+				     struct thermal_cooling_device *cdev,
+				     long upper, long lower)
 {
 	struct thermal_cooling_device_instance *dev;
 	struct thermal_cooling_device_instance *pos;
@@ -784,6 +785,15 @@ int thermal_zone_bind_cooling_device(str
 	if (tz != pos1 || cdev != pos2)
 		return -EINVAL;
 
Quoted 12 lines

drivers/thermal/thermal_sys.c int thermal_zone_bind_cooling_device(str · line 796

Quoted 9 lines
drivers/thermal/thermal_sys.c +9 -0
+	cdev->ops->get_max_state(cdev, &max_state);
+
+	/* lower default 0, upper default max_state */
+	lower = lower < 0 ? 0 : lower;
+	upper = upper < 0 ? max_state : upper;
+
+	if (lower > upper || upper > max_state)
+		return -EINVAL;
+

From this version of the code, I assume we want to:
a. Allow cooling binding instances to have ranges overlapping.

yep.

Quoted 2 lines

b. Allow a binding with only one state (lower == upper).

yep.

Quoted 2 lines

Is this the expected behavior?

yes. :)

thanks,
rui

Quoted 119 lines
Quoted 119 lines
drivers/thermal/thermal_sys.c +2 -4
 	dev =
 	    kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
 	if (!dev)
@@ -791,10 +801,8 @@ int thermal_zone_bind_cooling_device(str
 	dev->tz = tz;
 	dev->cdev = cdev;
 	dev->trip = trip;
-
-	cdev->ops->get_max_state(dev, &max_state);
-	dev->upper = max_state;
-	dev->lower = 0;
+	dev->upper = upper;
+	dev->lower = lower;
 
 	result = get_idr(&tz->idr, &tz->lock, &dev->id);
 	if (result)

Index: rtd3/include/linux/thermal.h
===================================================================

include/linux/thermal.h +2 -1
@@ -143,7 +143,8 @@ struct thermal_zone_device *thermal_zone
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
-				     struct thermal_cooling_device *);
+				     struct thermal_cooling_device *,
+				     long, long);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
 				       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *);

Index: rtd3/drivers/acpi/thermal.c
===================================================================

drivers/acpi/thermal.c +24 -10
@@ -729,11 +729,9 @@ static int thermal_notify(struct thermal
 	return 0;
 }
 
-typedef int (*cb)(struct thermal_zone_device *, int,
-		  struct thermal_cooling_device *);
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev,
-					cb action)
+					int bind)
 {
 	struct acpi_device *device = cdev->devdata;
 	struct acpi_thermal *tz = thermal->devdata;
@@ -758,7 +756,14 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.passive.devices.handles[i];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result =
+						thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -775,7 +780,13 @@ static int acpi_thermal_cooling_device_c
 			handle = tz->trips.active[i].devices.handles[j];
 			status = acpi_bus_get_device(handle, &dev);
 			if (ACPI_SUCCESS(status) && (dev == device)) {
-				result = action(thermal, trip, cdev);
+				if (bind)
+					result =
+						thermal_zone_bind_cooling_device(
+							thermal, trip, cdev, -1, -1);
+				else
+					result = thermal_zone_unbind_cooling_device(
+							thermal, trip, cdev);
 				if (result)
 					goto failed;
 			}
@@ -786,7 +797,12 @@ static int acpi_thermal_cooling_device_c
 		handle = tz->devices.handles[i];
 		status = acpi_bus_get_device(handle, &dev);
 		if (ACPI_SUCCESS(status) && (dev == device)) {
-			result = action(thermal, -1, cdev);
+			if (bind)
+				result = thermal_zone_bind_cooling_device(thermal,
+								-1, cdev, -1, -1);
+			else
+				result = thermal_zone_unbind_cooling_device(thermal,
+								-1, cdev);
 			if (result)
 				goto failed;
 		}
@@ -800,16 +816,14 @@ static int
 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_bind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 1);
 }
 
 static int
 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
 					struct thermal_cooling_device *cdev)
 {
-	return acpi_thermal_cooling_device_cb(thermal, cdev,
-				thermal_zone_unbind_cooling_device);
+	return acpi_thermal_cooling_device_cb(thermal, cdev, 0);
 }
 
 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {

Index: rtd3/drivers/platform/x86/acerhdf.c
===================================================================

drivers/platform/x86/acerhdf.c +0 -0
@@ -329,7 +329,7 @@ static int acerhdf_bind(struct thermal_z
 	if (cdev != cl_dev)
 		return 0;
 
Quoted 7 lines

drivers/platform/x86/acerhdf.c static int acerhdf_bind(struct thermal_z · line 335

Quoted 7 lines
drivers/platform/x86/acerhdf.c +1 -1
-	if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) {
+	if (thermal_zone_bind_cooling_device(thermal, 0, cdev, -1, -1)) {
 		pr_err("error binding cooling dev\n");
 		return -EINVAL;
 	}

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