Skip to content

Commit 4fcb2fc

Browse files
Venkatesh Pallipadilenb
authored andcommitted
ACPI, cpuidle: Clarify C-state description in sysfs
Add a new sysfs entry under cpuidle states. desc - can be used by driver to communicate to userspace any specific information about the state. This helps in identifying the exact hardware C-states behind the ACPI C-state definition. Idea is to export this through powertop, which will help to map the C-state reported by powertop to actual hardware C-state. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent e760e71 commit 4fcb2fc

6 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎arch/x86/kernel/acpi/cstate.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
126126
printk(KERN_DEBUG "Monitor-Mwait will be used to enter C-%d "
127127
"state\n", cx->type);
128128
}
129+
snprintf(cx->desc, ACPI_CX_DESC_LEN, "ACPI FFH INTEL MWAIT 0x%x",
130+
cx->address);
129131

130132
out:
131133
set_cpus_allowed(current, saved_mask);

‎drivers/acpi/processor_idle.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,16 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
945945
* Otherwise, ignore this info and continue.
946946
*/
947947
cx.entry_method = ACPI_CSTATE_HALT;
948+
snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
948949
} else {
949950
continue;
950951
}
952+
} else {
953+
snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x",
954+
cx.address);
951955
}
952956

957+
953958
obj = &(element->package.elements[2]);
954959
if (obj->type != ACPI_TYPE_INTEGER)
955960
continue;
@@ -1643,6 +1648,11 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
16431648
return -EINVAL;
16441649
}
16451650

1651+
for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
1652+
dev->states[i].name[0] = '\0';
1653+
dev->states[i].desc[0] = '\0';
1654+
}
1655+
16461656
for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
16471657
cx = &pr->power.states[i];
16481658
state = &dev->states[count];
@@ -1659,6 +1669,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
16591669
cpuidle_set_statedata(state, cx);
16601670

16611671
snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1672+
strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
16621673
state->exit_latency = cx->latency;
16631674
state->target_residency = cx->latency * latency_factor;
16641675
state->power_usage = cx->power;

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ static void poll_idle_init(struct cpuidle_device *dev)
219219

220220
cpuidle_set_statedata(state, NULL);
221221

222-
snprintf(state->name, CPUIDLE_NAME_LEN, "C0 (poll idle)");
222+
snprintf(state->name, CPUIDLE_NAME_LEN, "C0");
223+
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
223224
state->exit_latency = 0;
224225
state->target_residency = 0;
225226
state->power_usage = -1;

‎drivers/cpuidle/sysfs.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,31 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
218218
return sprintf(buf, "%u\n", state->_name);\
219219
}
220220

221-
static ssize_t show_state_name(struct cpuidle_state *state, char *buf)
222-
{
223-
return sprintf(buf, "%s\n", state->name);
221+
#define define_show_state_str_function(_name) \
222+
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
223+
{ \
224+
if (state->_name[0] == '\0')\
225+
return sprintf(buf, "<null>\n");\
226+
return sprintf(buf, "%s\n", state->_name);\
224227
}
225228

226229
define_show_state_function(exit_latency)
227230
define_show_state_function(power_usage)
228231
define_show_state_function(usage)
229232
define_show_state_function(time)
233+
define_show_state_str_function(name)
234+
define_show_state_str_function(desc)
235+
230236
define_one_state_ro(name, show_state_name);
237+
define_one_state_ro(desc, show_state_desc);
231238
define_one_state_ro(latency, show_state_exit_latency);
232239
define_one_state_ro(power, show_state_power_usage);
233240
define_one_state_ro(usage, show_state_usage);
234241
define_one_state_ro(time, show_state_time);
235242

236243
static struct attribute *cpuidle_state_default_attrs[] = {
237244
&attr_name.attr,
245+
&attr_desc.attr,
238246
&attr_latency.attr,
239247
&attr_power.attr,
240248
&attr_usage.attr,

‎include/acpi/processor.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
#define DOMAIN_COORD_TYPE_SW_ANY 0xfd
3333
#define DOMAIN_COORD_TYPE_HW_ALL 0xfe
3434

35-
#define ACPI_CSTATE_SYSTEMIO (0)
36-
#define ACPI_CSTATE_FFH (1)
37-
#define ACPI_CSTATE_HALT (2)
35+
#define ACPI_CSTATE_SYSTEMIO 0
36+
#define ACPI_CSTATE_FFH 1
37+
#define ACPI_CSTATE_HALT 2
38+
39+
#define ACPI_CX_DESC_LEN 32
3840

3941
/* Power Management */
4042

@@ -74,6 +76,7 @@ struct acpi_processor_cx {
7476
u64 time;
7577
struct acpi_processor_cx_policy promotion;
7678
struct acpi_processor_cx_policy demotion;
79+
char desc[ACPI_CX_DESC_LEN];
7780
};
7881

7982
struct acpi_processor_power {

‎include/linux/cpuidle.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#define CPUIDLE_STATE_MAX 8
2121
#define CPUIDLE_NAME_LEN 16
22+
#define CPUIDLE_DESC_LEN 32
2223

2324
struct cpuidle_device;
2425

@@ -29,6 +30,7 @@ struct cpuidle_device;
2930

3031
struct cpuidle_state {
3132
char name[CPUIDLE_NAME_LEN];
33+
char desc[CPUIDLE_DESC_LEN];
3234
void *driver_data;
3335

3436
unsigned int flags;

0 commit comments

Comments
 (0)