Skip to content

Commit b1c0f99

Browse files
committed
ACPI / PM: Expose current status of ACPI power resources
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, expose the current status of each ACPI power resource to user space via sysfs by adding a new resource_in_use attribute to the sysfs directory representing the given power resource. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 836aedb commit b1c0f99

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
What: /sys/devices/.../resource_in_use
2+
Date: January 2013
3+
Contact: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4+
Description:
5+
The /sys/devices/.../resource_in_use attribute is only present
6+
for device objects representing ACPI power resources.
7+
8+
If present, it contains a number (0 or 1) representing the
9+
current status of the given power resource (0 means that the
10+
resource is not in use and therefore it has been turned off).
11+
12+
This attribute is read-only.

‎drivers/acpi/power.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,20 @@ static DEFINE_MUTEX(power_resource_list_lock);
8787
Power Resource Management
8888
-------------------------------------------------------------------------- */
8989

90+
static inline
91+
struct acpi_power_resource *to_power_resource(struct acpi_device *device)
92+
{
93+
return container_of(device, struct acpi_power_resource, device);
94+
}
95+
9096
static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
9197
{
9298
struct acpi_device *device;
9399

94100
if (acpi_bus_get_device(handle, &device))
95101
return NULL;
96102

97-
return container_of(device, struct acpi_power_resource, device);
103+
return to_power_resource(device);
98104
}
99105

100106
static int acpi_power_resources_list_add(acpi_handle handle,
@@ -678,6 +684,21 @@ static void acpi_release_power_resource(struct device *dev)
678684
kfree(resource);
679685
}
680686

687+
static ssize_t acpi_power_in_use_show(struct device *dev,
688+
struct device_attribute *attr,
689+
char *buf) {
690+
struct acpi_power_resource *resource;
691+
692+
resource = to_power_resource(to_acpi_device(dev));
693+
return sprintf(buf, "%u\n", !!resource->ref_count);
694+
}
695+
static DEVICE_ATTR(resource_in_use, 0444, acpi_power_in_use_show, NULL);
696+
697+
static void acpi_power_sysfs_remove(struct acpi_device *device)
698+
{
699+
device_remove_file(&device->dev, &dev_attr_resource_in_use);
700+
}
701+
681702
int acpi_add_power_resource(acpi_handle handle)
682703
{
683704
struct acpi_power_resource *resource;
@@ -725,6 +746,9 @@ int acpi_add_power_resource(acpi_handle handle)
725746
if (result)
726747
goto err;
727748

749+
if (!device_create_file(&device->dev, &dev_attr_resource_in_use))
750+
device->remove = acpi_power_sysfs_remove;
751+
728752
mutex_lock(&power_resource_list_lock);
729753
list_add(&resource->list_node, &acpi_power_resource_list);
730754
mutex_unlock(&power_resource_list_lock);

‎drivers/acpi/scan.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ static void acpi_device_unregister(struct acpi_device *device)
791791

792792
acpi_power_add_remove_device(device, false);
793793
acpi_device_remove_files(device);
794+
if (device->remove)
795+
device->remove(device);
796+
794797
device_del(&device->dev);
795798
/*
796799
* Drop the reference counts of all power resources the device depends

‎include/acpi/acpi_bus.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ struct acpi_device {
280280
struct mutex physical_node_lock;
281281
DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
282282
struct list_head power_dependent;
283+
void (*remove)(struct acpi_device *);
283284
};
284285

285286
static inline void *acpi_driver_data(struct acpi_device *d)

0 commit comments

Comments
 (0)