Power Capping Framework
Subsystems (2)
cover Power Capping Framework
Highlights
As suggested
- Didn't use any raw kobject calls, only using device_xx calls.
- No device_create_file/device_remove_file for attributes, so that user space can see all attributes when notification is received for device creation.
Overview
With the evolution of technologies, which enables power monitoring and limiting, more and more devices are able to constrain their power consumption under certain limits. There are several use cases for such technologies:
- Power monitoring: Each device can report its power consumption.
- Power Limiting: Setting power limits on the devices allows users to guard against platform reaching max system power level.
- Maximize performance: While staying below a power limit, it allows devices to automatically adjust performance to meet demands
- Dynamic control and re-budgeting: If each device can be constrained to some power, extra power can redistributed to other devices, which needs additional performance.
One such example of technology is RAPL (Running Average Power Limit) mechanism available in the latest Intel Processors. Intel is slowly adding many devices under RAPL control. Also there are other technologies available, for power capping various devices. Soon it is very likely that other vendors are also adding or considering such implementation.
Power Capping framework is an effort to have a uniform interface available to Linux drivers, which will enable
- A uniform sys-fs interface for all devices which can offer power capping
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.
Once this framework is approved, we will submit a RAPL client driver using this framework.
Revisions:
v01:
Use device model only to register zones and controllers.
v00:
Presented options
Srinivas Pandruvada (3):
PowerCap: Documentation
PowerCap: Add class driver
PowerCap: Added to drivers build
Documentation/powercap/PowerCappingFramework.txt | 677 ++++++++++++++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/powercap/Kconfig | 16 + drivers/powercap/Makefile | 5 + drivers/powercap/powercap_sys.c | 985 +++++++++++++++++++++++ include/linux/powercap.h | 300 +++++++ 7 files changed, 1986 insertions(+) create mode 100644 Documentation/powercap/PowerCappingFramework.txt create mode 100644 drivers/powercap/Kconfig create mode 100644 drivers/powercap/Makefile create mode 100644 drivers/powercap/powercap_sys.c create mode 100644 include/linux/powercap.h
Signature · 1 line
1.8.3.1
RFC 1/3 PowerCap: Documentation
Added power cap framework documentation. This explains the use of power capping framework, sys-fs and programming interface.
--- Documentation/powercap/PowerCappingFramework.txt | 677 +++++++++++++++++++++++ 1 file changed, 677 insertions(+) create mode 100644 Documentation/powercap/PowerCappingFramework.txt
Documentation/powercap/PowerCappingFramework.txt new file +677 -0
@@ -0,0 +1,677 @@ +Power Capping Framework +================================== + +The Linux Power Capping Framework provides user-space with a common +API to kernel-mode power-capping drivers. At the same time, +it provides the hardware-specific power-capping drivers with +a uniform API to user-space. + +Terminology +========================= +The Power Capping framework organizes power capping devices under a tree structure. +At the root level, each device is under some "controller", which is the enabler +of technology. For example this can be "RAPL". +Under each controllers, there are multiple power zones, which can be independently +monitored and controlled. +Each power zone can be organized as a tree with parent, children and siblings. +Each power zone defines attributes to enable power monitoring and constraints. + +Example Sysfs interface tree: + +/sys/devices/virtual/power_cap +└── intel-rapl + ├── intel-rapl:0 + │ ├── constraint_0_name + │ ├── constraint_0_power_limit_uw + │ ├── constraint_0_time_window_us + │ ├── constraint_1_name + │ ├── constraint_1_power_limit_uw + │ ├── constraint_1_time_window_us + │ ├── device -> ../../intel-rapl + │ ├── energy_uj + │ ├── intel-rapl:0:0 + │ │ ├── constraint_0_name + │ │ ├── constraint_0_power_limit_uw + │ │ ├── constraint_0_time_window_us + │ │ ├── constraint_1_name + │ │ ├── constraint_1_power_limit_uw + │ │ ├── constraint_1_time_window_us + │ │ ├── device -> ../../intel-rapl:0 + │ │ ├── energy_uj + │ │ ├── max_energy_range_uj + │ │ ├── name + │ │ ├── power + │ │ │ ├── async + │ │ │ ├── autosuspend_delay_ms + │ │ │ ├── control + │ │ │ ├── runtime_active_kids + │ │ │ ├── runtime_active_time + │ │ │ ├── runtime_enabled + │ │ │ ├── runtime_status + │ │ │ ├── runtime_suspended_time + │ │ │ └── runtime_usage + │ │ ├── subsystem -> ../../../../../../class/power_cap + │ │ ├── type + │ │ └── uevent + │ ├── intel-rapl:0:1 + │ │ ├── constraint_0_name + │ │ ├── constraint_0_power_limit_uw + │ │ ├── constraint_0_time_window_us + │ │ ├── constraint_1_name + │ │ ├── constraint_1_power_limit_uw + │ │ ├── constraint_1_time_window_us + │ │ ├── device -> ../../intel-rapl:0 + │ │ ├── energy_uj + │ │ ├── max_energy_range_uj + │ │ ├── name + │ │ ├── power + │ │ │ ├── async + │ │ │ ├── autosuspend_delay_ms + │ │ │ ├── control + │ │ │ ├── runtime_active_kids + │ │ │ ├── runtime_active_time + │ │ │ ├── runtime_enabled + │ │ │ ├── runtime_status + │ │ │ ├── runtime_suspended_time + │ │ │ └── runtime_usage + │ │ ├── subsystem -> ../../../../../../class/power_cap + │ │ ├── type + │ │ └── uevent + │ ├── max_energy_range_uj + │ ├── max_power_range_uw + │ ├── name + │ ├── power + │ │ ├── async + │ │ ├── autosuspend_delay_ms + │ │ ├── control + │ │ ├── runtime_active_kids + │ │ ├── runtime_active_time + │ │ ├── runtime_enabled + │ │ ├── runtime_status + │ │ ├── runtime_suspended_time + │ │ └── runtime_usage + │ ├── subsystem -> ../../../../../class/power_cap + │ ├── type + │ └── uevent + ├── intel-rapl:1 + │ ├── constraint_0_name + │ ├── constraint_0_power_limit_uw + │ ├── constraint_0_time_window_us + │ ├── constraint_1_name + │ ├── constraint_1_power_limit_uw + │ ├── constraint_1_time_window_us + │ ├── device -> ../../intel-rapl + │ ├── energy_uj + │ ├── intel-rapl:1:0 + │ │ ├── constraint_0_name + │ │ ├── constraint_0_power_limit_uw + │ │ ├── constraint_0_time_window_us + │ │ ├── constraint_1_name + │ │ ├── constraint_1_power_limit_uw + │ │ ├── constraint_1_time_window_us + │ │ ├── device -> ../../intel-rapl:1 + │ │ ├── energy_uj + │ │ ├── max_energy_range_uj + │ │ ├── name + │ │ ├── power + │ │ │ ├── async + │ │ │ ├── autosuspend_delay_ms + │ │ │ ├── control + │ │ │ ├── runtime_active_kids + │ │ │ ├── runtime_active_time + │ │ │ ├── runtime_enabled + │ │ │ ├── runtime_status + │ │ │ ├── runtime_suspended_time + │ │ │ └── runtime_usage + │ │ ├── subsystem -> ../../../../../../class/power_cap + │ │ ├── type + │ │ └── uevent + │ ├── intel-rapl:1:1 + │ │ ├── constraint_0_name + │ │ ├── constraint_0_power_limit_uw + │ │ ├── constraint_0_time_window_us + │ │ ├── constraint_1_name + │ │ ├── constraint_1_power_limit_uw + │ │ ├── constraint_1_time_window_us + │ │ ├── device -> ../../intel-rapl:1 + │ │ ├── energy_uj + │ │ ├── max_energy_range_uj + │ │ ├── name + │ │ ├── power + │ │ │ ├── async + │ │ │ ├── autosuspend_delay_ms + │ │ │ ├── control + │ │ │ ├── runtime_active_kids + │ │ │ ├── runtime_active_time + │ │ │ ├── runtime_enabled + │ │ │ ├── runtime_status + │ │ │ ├── runtime_suspended_time + │ │ │ └── runtime_usage + │ │ ├── subsystem -> ../../../../../../class/power_cap + │ │ ├── type + │ │ └── uevent + │ ├── max_energy_range_uj + │ ├── max_power_range_uw + │ ├── name + │ ├── powerintel-rapl:0 + │ │ ├── async + │ │ ├── autosuspend_delay_ms + │ │ ├── control + │ │ ├── runtime_active_kids + │ │ ├── runtime_active_time + │ │ ├── runtime_enabled + │ │ ├── runtime_status + │ │ ├── runtime_suspended_time + │ │ └── runtime_usage + │ ├── subsystem -> ../../../../../class/power_cap + │ ├── type + │ └── uevent + ├── power + │ ├── async + │ ├── autosuspend_delay_ms + │ ├── control + │ ├── runtime_active_kids + │ ├── runtime_active_time + │ ├── runtime_enabled + │ ├── runtime_status + │ ├── runtime_suspended_time + │ └── runtime_usage + ├── subsystem -> ../../../../class/power_cap + ├── type + └── uevent + + +For example, above powercap sysfs tree represents RAPL(Running Average Power Limit) +type controls available in the Intel® 64 and IA-32 Processor Architectures. Here +under controller "intel-rapl" there are two CPU packages (package-0/1), which can +provide power monitoring and controls (intel-rapl:0 and intel-rapl:1). Each power +zone has a name. +For example: +cat /sys/class/power_cap/intel-rapl/intel-rapl:0/name +package-0 + +In addition to providing monitoring and control at package level, each package +is further divided into child power zones (called domains in the RAPL specifications). +Here zones represent controls for core and dram parts. These zones can be represented +as children of package. +For example: +cat /sys/class/power_cap/intel-rapl/intel-rapl:0/intel-rapl:0:1/name +dram + +Under RAPL framework there are two constraints, one for +short term and one for long term, with two different time windows. These can be +represented as two constraints, with different time windows, power limits and names. +For example: + constraint_0_name + constraint_0_power_limit_uw + constraint_0_time_window_us + constraint_1_name + constraint_1_power_limit_uw + constraint_1_time_window_us + +Power Zone Attributes +================================= +Monitoring attributes +---------------------- + +energy_uj (rw): Current energy counter in micro-joules. Write to energy counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only. + +max_energy_range_uj (ro): Range of the above energy counter in micro-joules. + +power_uw (rw): Current power counter in micro-watts. Write to this counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only. +max_power_range_uw (ro): Range of the above energy counter in micro-watts. + +It is possible that some domains can have both power and energy counters and +ranges, but at least one is mandatory. + +Constraints +---------------- +power_limit_uw (rw): Power limit in micro-watts, which should be applicable for +the time window specified by "time_window_us". +time_window_us (rw): Time window in micro seconds. +name (ro): An optional name of the constraint + +In addition each node has an attribute "type", which shows, whether is a controller +or power zone. + +Power Cap Client Driver Interface +================================== +The API summary: + +Call powercap_allocate_controller to define a controller with a name. +Call powercap_zone_register for each power zone for this controller. +power zones can have other power zone as a parent or don't have a +parent. +During powercap_zone_register defines number of constraints and callbacks. + +To Free a power zone call powercap_zone_unregister. +To free a controller call powercap_deallocate_controller. + +Rest of this document is generated by using kernel-doc on +powercap.h + +struct powercap_zone_constraint_ops - Define constraint callbacks + +struct powercap_zone_constraint_ops { + int (* set_power_limit_uw) (struct powercap_zone_device *, int, u64); + int (* get_power_limit_uw) (struct powercap_zone_device *, int, u64 *); + int (* set_time_window_us) (struct powercap_zone_device *, int, u64); + int (* get_time_window_us) (struct powercap_zone_device *, int, u64 *); + int (* get_max_power_uw) (struct powercap_zone_device *, int, u64 *); + int (* get_min_power_uw) (struct powercap_zone_device *, int, u64 *); + int (* get_max_time_window_us) (struct powercap_zone_device *, int, u64 *); + int (* get_min_time_window_us) (struct powercap_zone_device *, int, u64 *); + const char *(* get_name) (struct powercap_zone_device *, int); + void (* cleanup) (struct powercap_zone_device *, int); +}; + +Members: + +set_power_limit_uw + Set power limit in micro-watts. + +get_power_limit_uw + Get power limit in micro-watts. + +set_time_window_us + Set time window in micro-seconds. + +get_time_window_us + Get time window in micro-seconds. + +get_max_power_uw + Get max power allowed in micro-watts. + +get_min_power_uw + Get min power allowed in micro-watts. + +get_max_time_window_us + Get max time window allowed in micro-seconds. + +get_min_time_window_us + Get min time window allowed in micro-seconds. + +get_name + Get the name of constraint + +cleanup + Do any clean up before the constraint is freed +This structure is used to define the constraint callbacks for the client +drivers. The following callbacks are mandatory and can't be NULL: + set_power_limit_uw + get_power_limit_uw + set_time_window_us + get_time_window_us + get_name + + + + + +struct powercap_controller - Defines a powercap controller + +struct powercap_controller { + char name[POWERCAP_CTRL_NAME_LENGTH + 1]; + struct device device; + struct idr idr; + void * root_node; + struct mutex node_lock; + struct list_head ctrl_inst; +}; + +Members: + +name[POWERCAP_CTRL_NAME_LENGTH + 1] + name of controller + +device + device for this controller + +idr + idr to have unique id for its child + +root_node + Root holding power zones for this controller + +node_lock + mutex for node + +ctrl_inst + link to the controller list + + + +Description: + +Defines powercap controller instance + + +struct powercap_zone_ops - Define power zone callbacks + +struct powercap_zone_ops { + int (* get_max_energy_range_uj) (struct powercap_zone_device *, u64 *); + int (* get_energy_uj) (struct powercap_zone_device *, u64 *); + int (* reset_energy_uj) (struct powercap_zone_device *); + int (* get_max_power_range_uw) (struct powercap_zone_device *, u64 *); + int (* get_power_uw) (struct powercap_zone_device *, u64 *); + int (* reset_power_uw) (struct powercap_zone_device *); + void (* cleanup) (struct powercap_zone_device *); +}; + +Members: + +get_max_energy_range_uj + Get maximum range of energy counter in + micro-joules. + +get_energy_uj + Get current energy counter in micro-joules. + +reset_energy_uj + Reset micro-joules energy counter. + +get_max_power_range_uw + Get maximum range of power counter in + micro-watts. + +get_power_uw + Get current power counter in micro-watts. + +reset_power_uw + Reset micro-watts power counter. + +cleanup + Do any clean up before the zone is freed + + + +Description: + +This structure defines zone callbacks to be implemented by client drivers. +Client drives can define both energy and power related callbacks. But at +the least one type (either power or energy) is mandatory. + + +struct powercap_zone_attr - Defines a per zone attribute group + +struct powercap_zone_attr { + struct attribute * zone_dev_attrs[POWERCAP_ZONE_MAX_ATTRS]; + int zone_attr_count; + struct attribute * const_dev_attrs[POWERCAP_CONSTRAINTS_MAX_ATTRS]; + int const_attr_count; + struct attribute_group dev_zone_attr_group; + struct attribute_group dev_const_attr_group; + int attr_grp_cnt; + const struct attribute_group * dev_attr_groups[POWERCAP_MAX_ATTR_GROUPS + 1]; +}; + +Members: + +zone_dev_attrs[POWERCAP_ZONE_MAX_ATTRS] + Device attribute list for power zone. + +zone_attr_count + Number of power zone attributes. + +const_dev_attrs[POWERCAP_CONSTRAINTS_MAX_ATTRS] + Constraint attributes. + +const_attr_count + Number of constraint related attributes + +dev_zone_attr_group + Attribute group for power zone attributes + +dev_const_attr_group + Attribute group for constraints + +attr_grp_cnt + Number of attribute groups + +dev_attr_groups[POWERCAP_MAX_ATTR_GROUPS + 1] + Used to assign to dev->group + + + +Description: + +Used to add an attribute group unique to a zone based on registry. + + +struct powercap_zone_device - Defines instance of a power cap zone + +struct powercap_zone_device { + int id; + char * zone_dev_name; + char name[POWERCAP_ZONE_NAME_LENGTH + 1]; + void * controller_inst; + const struct powercap_zone_ops * ops; + struct device device; + struct powercap_zone_attr attrs; + void * node; + int const_id_cnt; + struct mutex lock; + struct idr idr; + struct idr * par_idr; + void * drv_data; + struct list_head constraint_list; +}; + +Members: + +id + Unique id + +zone_dev_name + Zone device sysfs node name + +name[POWERCAP_ZONE_NAME_LENGTH + 1] + Power zone name. + +controller_inst + Controller instance for this zone + +ops + Pointer to the zone operation structure. + +device + Instance of a device. + +attrs + Attributes associated with this device + +node + Node pointer to insert to a tree data structure. + +const_id_cnt + Constraint id count + +lock + Mutex to protect zone related operations. + +idr + Instance to an idr entry for children zones. + +par_idr + To remove reference from the parent idr + +drv_data + Driver private data + +constraint_list + Link to the next power zone for this controller. + + + +Description: + +This defines a power zone instance. The fields of this structure are +private, and should not be used by client drivers. + + +Name: + +powercap_set_zone_data - Set private data for a zone + +Synopsis: + +void powercap_set_zone_data (struct powercap_zone_device * pcd_dev, + void * pdata); + +Arguments: + +pcd_dev + A pointer to the valid zone instance. + +pdata + A pointer to the user private data. + + +Description: + +Allows client drivers to associate some private data to zone instance. + + +Name: + +powercap_get_zone_data - Get private data for a zone + +Synopsis: + +void * powercap_get_zone_data (struct powercap_zone_device * pcd_dev); + +Arguments: + +pcd_dev + A pointer to the valid zone instance. + + +Description: + +Allows client drivers to get private data associate with a zone, +using call to powercap_set_zone_data. + + +Name: + +powercap_allocate_controller - Allocates a controller + +Synopsis: + +struct powercap_controller * powercap_allocate_controller (const char * controller_name); + +Arguments: + +controller_name + The Name of this controller, which will be shown + in the sysfs Interface. + + +Description: + +Used to create a controller with the power capping class. Here controller +can represent a type of technology, which can control a range of power zones. +For example a controller can be RAPL (Running Average Power Limit) +Intel® 64 and IA-32 Processor Architectures. The name can be any string +which must be unique, otherwise this function returns NULL. +On successful allocation, this API returns a pointer to the +controller instance. + + +Name: + +powercap_deallocate_controller - Deallocates a controller + +Synopsis: + +void powercap_deallocate_controller (struct powercap_controller * instance); + +Arguments: + +instance + A pointer to the valid controller instance. + + +Description: + +Used to deallocate a controller with the power capping class. This +takes only one argument, which is the pointer to the instance returned +by a call to powercap_allocate_controller. +When a controller is deallocated, all zones and associated constraints +are freed. + + +Name: + +powercap_zone_register - Register a power zone + +Synopsis: + +struct powercap_zone_device * powercap_zone_register (struct powercap_controller * controller, + const char * name, + struct powercap_zone_device * parent, + const struct powercap_zone_ops * ops, + int no_constraints, + struct powercap_zone_constraint_ops * const_ops); + +Arguments: + +controller + A controller instance under which this zone operates. + +name + A name for this zone. + +parent + A pointer to the parent power zone instance if any or NULL + +ops + Pointer to zone operation callback structure. + +no_constraints + Number of constraints for this zone + +const_ops + Pointer to constraint callback structure + + +Description: + +Used to register a power zone for a controller. Zones are organized in +a tree like structure in sysfs under a controller. +A power zone must a register a pointer to a structure representing zone +callbacks. +A power zone can have a some other power zone as a parent or it can be +NULL to appear as a direct descendant of a controller. +Each power zone can have number of constraints. Constraints appears +under zones as attributes with unique id. + + +Name: + +powercap_zone_unregister - Unregister a zone device + +Synopsis: + +int powercap_zone_unregister (struct powercap_controller * controller, + struct powercap_zone_device * pcd_dev); + +Arguments: + +controller + A pointer to the valid instance of a controller. + +pcd_dev + A pointer to the valid zone instance for a controller + + +Description: + +Used to unregister a zone device for a controller. Once a zone is +unregistered then all its children and associated constraints are freed. + +
Signature · 1 line
1.8.3.1
Re: [RFC v01 1/3] PowerCap: Documentation
Quoted 2 lines · Srinivas Pandruvada
Added power cap framework documentation. This explains the use of power capping framework, sys-fs and programming interface.
[]
Quoted 8 lines
Documentation/powercap/PowerCappingFramework.txt new file +8
-0+Power Zone Attributes +================================= +Monitoring attributes +---------------------- + +energy_uj (rw): Current energy counter in micro-joules. Write to energy counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only.
Documentation/powercap/PowerCappingFramework.txt line 229
Quoted 10 lines
Documentation/powercap/PowerCappingFramework.txt new file +10
-0+ +max_energy_range_uj (ro): Range of the above energy counter in micro-joules. + +power_uw (rw): Current power counter in micro-watts. Write to this counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only. +max_power_range_uw (ro): Range of the above energy counter in micro-watts. + +It is possible that some domains can have both power and energy counters and +ranges, but at least one is mandatory.
Given that the ranges seem to be u64s, perhaps the lower bounds are too high. Why not nano/pico/fempto watts/joules/seconds?
Re: [RFC v01 1/3] PowerCap: Documentation
Quoted 4 lines · Joe Perches
Quoted 2 lines · Srinivas Pandruvada
Added power cap framework documentation. This explains the use of power capping framework, sys-fs and programming interface.
[]
Didn't understand this comment.
Quoted 13 lines
Quoted 13 lines
Documentation/powercap/PowerCappingFramework.txt new file +13
-0+Power Zone Attributes +================================= +Monitoring attributes +---------------------- + +energy_uj (rw): Current energy counter in micro-joules. Write to energy counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only. + +max_energy_range_uj (ro): Range of the above energy counter in micro-joules. + +power_uw (rw): Current power counter in micro-watts. Write to this counter +resets the counter to zero. If the counter can not be reset, then this attribute
Quoted 8 lines
Documentation/powercap/PowerCappingFramework.txt line 229
Quoted 5 lines
Documentation/powercap/PowerCappingFramework.txt new file +5
-0+is read-only. +max_power_range_uw (ro): Range of the above energy counter in micro-watts. + +It is possible that some domains can have both power and energy counters and +ranges, but at least one is mandatory.Given that the ranges seem to be u64s, perhaps the lower bounds are too high. Why not nano/pico/fempto watts/joules/seconds?
I think they are too small to realistically set a limits on power or measure. Let's see what others think.
Quoted 2 lines
Thanks,
Srinivas
Re: [RFC v01 1/3] PowerCap: Documentation
Quoted 6 lines · Srinivas Pandruvada
Quoted 4 lines · Joe Perches
Quoted 2 lines · Srinivas Pandruvada
Added power cap framework documentation. This explains the use of power capping framework, sys-fs and programming interface.
[]
Didn't understand this comment.
Not a comment, just notation showing skipping a bunch context.
Quoted 5 lines
Quoted 3 lines
Given that the ranges seem to be u64s, perhaps the lower bounds are too high. Why not nano/pico/fempto watts/joules/seconds?
I think they are too small to realistically set a limits on power or measure. Let's see what others think.
No rush.
Jonathan Corbet
maintainerRe: [RFC v01 1/3] PowerCap: Documentation
In reply to Srinivas PandruvadaDocumentation/powercap/PowerCappingFramework.txt line 225
Quoted 3 lines · On Fri, 2 Aug 2013 11:08:50 -0700 Srinivas Pandruvada…
Documentation/powercap/PowerCappingFramework.txt new file +3
-0+power_uw (rw): Current power counter in micro-watts. Write to this counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only.
Sorry if I'm slow, but... power is an instantaneous quantity, so why would you use a counter for it? And why would you want to reset it to zero?
Thanks,
jon
Re: [RFC v01 1/3] PowerCap: Documentation
Quoted 8 lines · Jonathan Corbet
Documentation/powercap/PowerCappingFramework.txt line 225
Quoted 3 lines · On Fri, 2 Aug 2013 11:08:50 -0700 Srinivas Pandruvada…
Documentation/powercap/PowerCappingFramework.txt new file +3
-0+power_uw (rw): Current power counter in micro-watts. Write to this counter +resets the counter to zero. If the counter can not be reset, then this attribute +is read-only.Sorry if I'm slow, but... power is an instantaneous quantity, so why would you use a counter for it? And why would you want to reset it to zero?
It is an instantaneous value. When I say counter, either in hardware or in driver somewhere, it is reading energy and using a time delta and continuously updating this value.
Reset to zero will allow user space to reset its internal energy counter used to calculate power. Our hardware at this time can only provide energy_uj at this time, added power_uw for some future devices. This was suggested in internal reviews. But based on feedback, we can drop this attribute totally, till we have a device needing this.
Quoted 4 lines
Thanks,
jon
RFC 2/3 PowerCap: Add class driver
In reply to Srinivas PandruvadaAdded power cap class driver, which provides an API for client drivers to use and provide a consistant sys-fs interface to user mode. For details on API refer to PowerCappingFramework.txt under Documentation/powercap.
--- drivers/powercap/Kconfig | 16 + drivers/powercap/Makefile | 5 + drivers/powercap/powercap_sys.c | 985 ++++++++++++++++++++++++++++++++++++++++ include/linux/powercap.h | 300 ++++++++++++ 4 files changed, 1306 insertions(+) create mode 100644 drivers/powercap/Kconfig create mode 100644 drivers/powercap/Makefile create mode 100644 drivers/powercap/powercap_sys.c create mode 100644 include/linux/powercap.h
drivers/powercap/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# +# Generic powercap sysfs drivers configuration +# + +menuconfig POWERCAP_SUPPORT + tristate "Generic powercap sysfs driver" + help + A Power Capping Sysfs driver offers a generic mechanism for + power capping. Usually it's made up of one or more controllers, + power zones and constraints. + If you want this support, you should say Y or M here. + +if POWERCAP_SUPPORT +# Add client driver config here. + +endif
drivers/powercap/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for powercap drivers +# + +obj-$(CONFIG_POWERCAP_SUPPORT) += powercap_sys.o
drivers/powercap/powercap_sys.c new file +985 -0
985 lines not on this page · raw message
include/linux/powercap.h new file +300 -0
300 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v01 2/3] PowerCap: Add class driver
Quoted 2 lines · Srinivas Pandruvada
Added power cap class driver, which provides an API for client drivers to use and provide a consistant sys-fs interface to user mode.
Just some stylistic notes.
drivers/powercap/powercap_sys.c
Quoted 1 line
drivers/powercap/powercap_sys.c +0
-0
[]
drivers/powercap/powercap_sys.c line 118
Quoted 4 lines
drivers/powercap/powercap_sys.c +4
-0+/* Power zone show function */ +#define define_device_show (_attr) \ +static ssize_t show_##_attr(struct device *dev, struct device_attribute *attr,\ + char *buf) \
Using _attr and another variable named attr is at least visually confusing.
Maybe use name or type instead of _attr?
Quoted 10 lines
drivers/powercap/powercap_sys.c +10
-0+{ \ +u64 value; \ +ssize_t len = -EINVAL ; \ +struct powercap_zone_device *pcd_dev =dev_get_drvdata (dev); \ + \ + if (pcd_dev && pcd_dev->ops && pcd_dev->ops->get_##_attr) { \ +mutex_lock (&pcd_dev->lock); \ + if (!pcd_dev->ops->get_##_attr(pcd_dev, &value)) \ + len =sprintf (buf,"%lld\n" , value); \ +mutex_unlock (&pcd_dev->lock); \
drivers/powercap/powercap_sys.c line 138
Quoted 10 lines
drivers/powercap/powercap_sys.c +10
-0+ } \ + \ +return len; \ +} + +/* Power zone store function; only reset is possible */ +#define define_device_store (_attr) \ +static ssize_t store_##_attr(struct device *dev,\ + struct device_attribute *attr, \ + const char *buf, size_t count) \
here too
[]
drivers/powercap/powercap_sys.c line 181
Quoted 5 lines
drivers/powercap/powercap_sys.c +5
-0+/* Power zone constraint show function */ +#define define_device_constraint_show (_attr) \ +static ssize_t show_constraint_##_attr(struct device *dev, \ + struct device_attribute *attr,\ + char *buf) \
and here
[]
drivers/powercap/powercap_sys.c line 208
Quoted 5 lines
drivers/powercap/powercap_sys.c +5
-0+/* Power zone constraint store function */ +#define define_device_constraint_store (_attr) \ +static ssize_t store_constraint_##_attr(struct device *dev,\ + struct device_attribute *attr, \ + const char *buf, size_t count) \
etc...
drivers/powercap/powercap_sys.c line 398
Quoted 4 lines
drivers/powercap/powercap_sys.c +4
-0+struct powercap_zone_constraint *powercap_zone_add_constraint ( +struct powercap_zone_device *pcd_dev, +struct powercap_zone_constraint_ops *ops) +{
[]
drivers/powercap/powercap_sys.c line 405
Quoted 1 line
drivers/powercap/powercap_sys.c +1
-0+dev_dbg (&pcd_dev->device,"powercap_zone_add_constraint\n" );
These logging messages aren't useful.
function tracing works very well.
Re: [RFC v01 2/3] PowerCap: Add class driver
Quoted 56 lines · Joe Perches
Quoted 2 lines · Srinivas Pandruvada
Added power cap class driver, which provides an API for client drivers to use and provide a consistant sys-fs interface to user mode.
Just some stylistic notes.
drivers/powercap/powercap_sys.c
Quoted 1 line
drivers/powercap/powercap_sys.c +0
-0[]
drivers/powercap/powercap_sys.c line 118
Quoted 4 lines
drivers/powercap/powercap_sys.c +4
-0+/* Power zone show function */ +#define define_device_show (_attr) \ +static ssize_t show_##_attr(struct device *dev, struct device_attribute *attr,\ + char *buf) \Using
_attrand another variable named attr is at least visually confusing.Maybe use name or type instead of
_attr?Quoted 10 lines
drivers/powercap/powercap_sys.c +10
-0+{ \ +u64 value; \ +ssize_t len = -EINVAL ; \ +struct powercap_zone_device *pcd_dev =dev_get_drvdata (dev); \ + \ + if (pcd_dev && pcd_dev->ops && pcd_dev->ops->get_##_attr) { \ +mutex_lock (&pcd_dev->lock); \ + if (!pcd_dev->ops->get_##_attr(pcd_dev, &value)) \ + len =sprintf (buf,"%lld\n" , value); \ +mutex_unlock (&pcd_dev->lock); \drivers/powercap/powercap_sys.c line 138
Quoted 10 lines
drivers/powercap/powercap_sys.c +10
-0+ } \ + \ +return len; \ +} + +/* Power zone store function; only reset is possible */ +#define define_device_store (_attr) \ +static ssize_t store_##_attr(struct device *dev,\ + struct device_attribute *attr, \ + const char *buf, size_t count) \here too
[]
drivers/powercap/powercap_sys.c line 181
Quoted 5 lines
drivers/powercap/powercap_sys.c +5
-0+/* Power zone constraint show function */ +#define define_device_constraint_show (_attr) \ +static ssize_t show_constraint_##_attr(struct device *dev, \ + struct device_attribute *attr,\ + char *buf) \and here
[]
drivers/powercap/powercap_sys.c line 208
Quoted 5 lines
drivers/powercap/powercap_sys.c +5
-0+/* Power zone constraint store function */ +#define define_device_constraint_store (_attr) \ +static ssize_t store_constraint_##_attr(struct device *dev,\ + struct device_attribute *attr, \ + const char *buf, size_t count) \etc...
Quoted 11 lines
drivers/powercap/powercap_sys.c line 398
Quoted 4 lines
drivers/powercap/powercap_sys.c +4
-0+struct powercap_zone_constraint *powercap_zone_add_constraint ( +struct powercap_zone_device *pcd_dev, +struct powercap_zone_constraint_ops *ops) +{[]
drivers/powercap/powercap_sys.c line 405
Quoted 1 line
drivers/powercap/powercap_sys.c +1
-0+dev_dbg (&pcd_dev->device,"powercap_zone_add_constraint\n" );These logging messages aren't useful.
function tracing works very well.
Thanks. Will change in the next patchset.
Thanks,
Srinivas
RFC 3/3 PowerCap: Added to drivers build
In reply to Srinivas PandruvadaAdded changes to Makefile and Kconfig to include in driver build.
--- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + 2 files changed, 3 insertions(+)
drivers/Kconfig +2 -0
@@ -166,4 +166,6 @@ source "drivers/ipack/Kconfig" source "drivers/reset/Kconfig" +source "drivers/powercap/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -152,3 +152,4 @@ obj-$(CONFIG_IIO) += iio/ obj-$(CONFIG_VME_BUS) += vme/ obj-$(CONFIG_IPACK_BUS) += ipack/ obj-$(CONFIG_NTB) += ntb/ +obj-$(CONFIG_POWERCAP_SUPPORT) += powercap/
Signature · 1 line
1.8.3.1
Quoted 1 line · Srinivas Pandruvada
- A uniform sys-fs interface for all devices which can offer power capping
There is no "-" in sysfs please.
Quoted 5 lines
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.
Once this framework is approved, we will submit a RAPL client driver using this framework.
No, you need users of a framework in order for it to be approved, we don't add infrastructure without users.
Especially as what usually happens is, when you add actual users, the framework changes to fix the bugs found in it :)
Ideally you will have more than one client driver submitted, as a "framework" for just one driver seems a bit odd, don't you think?
Also, you add lots of new sysfs files, those need to be documented in Documentation/ABI/ with this series.
thanks,
greg k-h
Quoted 3 lines · Greg KH
Quoted 1 line · Srinivas Pandruvada
- A uniform sys-fs interface for all devices which can offer power capping
There is no "-" in sysfs please.
OK.
Quoted 10 lines
Quoted 5 lines
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.
Once this framework is approved, we will submit a RAPL client driver using this framework.
No, you need users of a framework in order for it to be approved, we don't add infrastructure without users.
Especially as what usually happens is, when you add actual users, the framework changes to fix the bugs found in it :)
I will post the one client driver, which is already using this framework as this series.
Quoted 2 lines
Ideally you will have more than one client driver submitted, as a "framework" for just one driver seems a bit odd, don't you think?
There are other groups and vendors interested in using this framework. But they want to make sure that this framework can go to upstream Linux. We will provide one client using this framework at this time. Do you think this is a problem?
Quoted 2 lines
Also, you add lots of new sysfs files, those need to be documented in
Documentation/ABI/with this series.
I have a Documentation patch, which describes ABI and framework. It is under Documentation/powercap. Do I need to move this to Documentation/ABI?
Quoted 3 lines
thanks,
greg k-h
Thanks,
Srinivas
Quoted 17 lines · Srinivas Pandruvada
Quoted 3 lines · Greg KH
Quoted 1 line · Srinivas Pandruvada
- A uniform sys-fs interface for all devices which can offer power capping
There is no "-" in sysfs please.
OK.
Quoted 10 lines
Quoted 5 lines
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.
Once this framework is approved, we will submit a RAPL client driver using this framework.
No, you need users of a framework in order for it to be approved, we don't add infrastructure without users.
Especially as what usually happens is, when you add actual users, the framework changes to fix the bugs found in it :)
I will post the one client driver, which is already using this framework as this series.
Quoted 7 lines
Quoted 2 lines
Ideally you will have more than one client driver submitted, as a "framework" for just one driver seems a bit odd, don't you think?
There are other groups and vendors interested in using this framework. But they want to make sure that this
framework can go to upstream Linux. We will provide one client using this framework at this time.
Do you think this is a problem?
I would love to see the feedback from those groups and vendors as well, to ensure that they agree with this. Ideally, they would sign off on the patches, and provide clients that work with the framework at the same time. Otherwise, I just have to take your word for it :)
Quoted 5 lines
Quoted 2 lines
Also, you add lots of new sysfs files, those need to be documented in
Documentation/ABI/with this series.I have a Documentation patch, which describes ABI and framework. It is under
Documentation/powercap.
Do I need to move this toDocumentation/ABI?
The files in that directory need to follow the format that is described in Documentation/ABI/README. I suggest keeping the file you currently have, and also adding entries into the ABI/ subdirectory as well.
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 9 lines
I will post the one client driver, which is already using this framework as this series.
Quoted 2 lines
Ideally you will have more than one client driver submitted, as a "framework" for just one driver seems a bit odd, don't you think?
There are other groups and vendors interested in using this framework. But they want to make sure that this
framework can go to upstream Linux. We will provide one client using this framework at this time.
Do you think this is a problem?
Quoted 4 lines
I would love to see the feedback from those groups and vendors as well, to ensure that they agree with this. Ideally, they would sign off on the patches, and provide clients that work with the framework at the same time. Otherwise, I just have to take your word for it :)
I suspect that in some ways Intel is a year or two ahead in this regard, we'll see if others are willing to speak up yet ;-)
Quoted 2 lines · Srinivas Pandruvada
Once this framework is approved, we will submit a RAPL client driver using this framework.
Also, given that you work with a lot of kernel developers, I would like to see their review and signed-off-by: on these patches before you resend them, please. That way I know that they agree with this framework as a way for their future changes in this area.
thanks,
greg k-h
Quoted 8 lines · Greg KH
Quoted 2 lines · Srinivas Pandruvada
Once this framework is approved, we will submit a RAPL client driver using this framework.
Also, given that you work with a lot of kernel developers, I would like to see their review and signed-off-by: on these patches before you resend them, please. That way I know that they agree with this framework as a way for their future changes in this area.
Before is a bit hard on public mailing lists isn't it?
Shouldn't the reviewed-by/acked-by/signed-off-by's be done after a real patch is submitted?
This is just an RFC patchset.
Quoted 11 lines · Joe Perches
Quoted 8 lines · Greg KH
Quoted 2 lines · Srinivas Pandruvada
Once this framework is approved, we will submit a RAPL client driver using this framework.
Also, given that you work with a lot of kernel developers, I would like to see their review and signed-off-by: on these patches before you resend them, please. That way I know that they agree with this framework as a way for their future changes in this area.
Before is a bit hard on public mailing lists isn't it?
That's implying that Intel doesn't have internal mailing lists where kernel patches are reviewed and proposed before being made public...
Quoted 2 lines
Shouldn't the reviewed-by/acked-by/signed-off-by's be done after a real patch is submitted?
That's fine too, but then the needed people need to be cc:ed.
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 2 lines · Srinivas Pandruvada
Once this framework is approved, we will submit a RAPL client driver using this framework.
Also, given that you work with a lot of kernel developers, I would like to see their review and signed-off-by: on these patches before you resend them, please. That way I know that they agree with this framework as a way for their future changes in this area.
The framework was presented internally number of times to Intel Linux Architects (including Rafael, Len Brown and Arjan (copied in this email)). Actual implementation, was reviewed by few developers. But I am expecting lots of positive/negative feedback on implementation from community.
Quoted 4 lines
thanks,
greg k-h
Thanks,
Srinivas
Quoted 11 lines · Srinivas Pandruvada
Quoted 7 lines · Greg KH
Quoted 2 lines · Srinivas Pandruvada
Once this framework is approved, we will submit a RAPL client driver using this framework.
Also, given that you work with a lot of kernel developers, I would like to see their review and signed-off-by: on these patches before you resend them, please. That way I know that they agree with this framework as a way for their future changes in this area.
The framework was presented internally number of times to Intel Linux Architects (including Rafael, Len Brown and Arjan (copied in this email)).
That's good to hear, ideally they would sign off on this as well to show people like me that they agree with this, otherwise I have no idea that they have even looked at it.
thanks,
greg k-h