Message ID | 1618594.EyAyXTlIBb@vostro.rjw.lan (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Mon, Jan 21, 2013 at 02:05:47PM +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Since ACPI power resources are going to be used more extensively on > new hardware platforms, it becomes necessary for user space (powertop > in particular) to observe some properties of those resources for > diagnostics purposes. > > For this reason, export the reference counts of ACPI power resources > to user space by adding a new reference_count attribute to the sysfs > directory representing each power resource. The value read from > that attribute represents the number of devices using the power > resource at the given time. If that value is 0, it meas that the > power resource is not used and therefore it has been turned off. Why does userspace need to know a reference count? Is it so that if it is not 0, it can work to try to lower it to 0? Or something else? thanks, greg k-h -- 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
On Mon, Jan 21, 2013 at 11:35:51PM +0100, Rafael J. Wysocki wrote: > On Monday, January 21, 2013 12:53:57 PM Greg Kroah-Hartman wrote: > > On Mon, Jan 21, 2013 at 02:05:47PM +0100, Rafael J. Wysocki wrote: > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > > > Since ACPI power resources are going to be used more extensively on > > > new hardware platforms, it becomes necessary for user space (powertop > > > in particular) to observe some properties of those resources for > > > diagnostics purposes. > > > > > > For this reason, export the reference counts of ACPI power resources > > > to user space by adding a new reference_count attribute to the sysfs > > > directory representing each power resource. The value read from > > > that attribute represents the number of devices using the power > > > resource at the given time. If that value is 0, it meas that the > > > power resource is not used and therefore it has been turned off. > > > > Why does userspace need to know a reference count? Is it so that if it > > is not 0, it can work to try to lower it to 0? Or something else? > > Yes, this information is needed to say if (1) the power resource is in use > and (2) how many users there are at the moment, so that we can go and look > if it really has to be in use. > > Perhaps I can just expose the "in use"/"not in use" information. I don't > think it will be much less convenient, because we should scan all of the > possible users anyway in case they are coming and going frequently. > > So should I do that and rename the attribute to "resource_in_use" (or something > similar)? That makes a bit more sense to do, thanks. greg k-h -- 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
On Monday, January 21, 2013 12:53:57 PM Greg Kroah-Hartman wrote: > On Mon, Jan 21, 2013 at 02:05:47PM +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > Since ACPI power resources are going to be used more extensively on > > new hardware platforms, it becomes necessary for user space (powertop > > in particular) to observe some properties of those resources for > > diagnostics purposes. > > > > For this reason, export the reference counts of ACPI power resources > > to user space by adding a new reference_count attribute to the sysfs > > directory representing each power resource. The value read from > > that attribute represents the number of devices using the power > > resource at the given time. If that value is 0, it meas that the > > power resource is not used and therefore it has been turned off. > > Why does userspace need to know a reference count? Is it so that if it > is not 0, it can work to try to lower it to 0? Or something else? Yes, this information is needed to say if (1) the power resource is in use and (2) how many users there are at the moment, so that we can go and look if it really has to be in use. Perhaps I can just expose the "in use"/"not in use" information. I don't think it will be much less convenient, because we should scan all of the possible users anyway in case they are coming and going frequently. So should I do that and rename the attribute to "resource_in_use" (or something similar)? Rafael
Index: linux-pm/include/acpi/acpi_bus.h =================================================================== --- linux-pm.orig/include/acpi/acpi_bus.h +++ linux-pm/include/acpi/acpi_bus.h @@ -280,6 +280,7 @@ struct acpi_device { struct mutex physical_node_lock; DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE); struct list_head power_dependent; + void (*remove)(struct acpi_device *); }; static inline void *acpi_driver_data(struct acpi_device *d) Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -771,6 +771,9 @@ static void acpi_device_unregister(struc acpi_power_add_remove_device(device, false); acpi_device_remove_files(device); + if (device->remove) + device->remove(device); + device_unregister(&device->dev); /* * Drop the reference counts of all power resources the device depends Index: linux-pm/drivers/acpi/power.c =================================================================== --- linux-pm.orig/drivers/acpi/power.c +++ linux-pm/drivers/acpi/power.c @@ -87,6 +87,12 @@ static DEFINE_MUTEX(power_resource_list_ Power Resource Management -------------------------------------------------------------------------- */ +static inline +struct acpi_power_resource *to_power_resource(struct acpi_device *device) +{ + return container_of(device, struct acpi_power_resource, device); +} + static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle) { struct acpi_device *device; @@ -94,7 +100,7 @@ static struct acpi_power_resource *acpi_ if (acpi_bus_get_device(handle, &device)) return NULL; - return container_of(device, struct acpi_power_resource, device); + return to_power_resource(device); } static int acpi_power_resources_list_add(acpi_handle handle, @@ -679,6 +685,21 @@ static void acpi_release_power_resource( kfree(resource); } +static ssize_t acpi_power_refcount_show(struct device *dev, + struct device_attribute *attr, + char *buf) { + struct acpi_power_resource *resource; + + resource = to_power_resource(to_acpi_device(dev)); + return sprintf(buf, "%u\n", resource->ref_count); +} +static DEVICE_ATTR(reference_count, 0444, acpi_power_refcount_show, NULL); + +static void acpi_power_sysfs_remove(struct acpi_device *device) +{ + device_remove_file(&device->dev, &dev_attr_reference_count); +} + int acpi_add_power_resource(acpi_handle handle) { struct acpi_power_resource *resource; @@ -726,6 +747,9 @@ int acpi_add_power_resource(acpi_handle if (result) goto err; + if (!device_create_file(&device->dev, &dev_attr_reference_count)) + device->remove = acpi_power_sysfs_remove; + mutex_lock(&power_resource_list_lock); list_add(&resource->list_node, &acpi_power_resource_list); mutex_unlock(&power_resource_list_lock); Index: linux-pm/Documentation/ABI/testing/sysfs-devices-reference_count =================================================================== --- /dev/null +++ linux-pm/Documentation/ABI/testing/sysfs-devices-reference_count @@ -0,0 +1,13 @@ +What: /sys/devices/.../reference_count +Date: January 2013 +Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com> +Description: + The /sys/devices/.../reference_count attribute is only present + for device objects representing ACPI power resources. + + If present, it contains the current number of devices using the + ACPI power resource represented by the given device object. If + that number is 0, the power resource is currently not in use and + therefore it has been turned off. + + This attribute is read-only.