Skip to content

Commit 4202735

Browse files
Deepthi Dharwarlenb
authored andcommitted
cpuidle: Split cpuidle_state structure and move per-cpu statistics fields
This is the first step towards global registration of cpuidle states. The statistics used primarily by the governor are per-cpu and have to be split from rest of the fields inside cpuidle_state, which would be made global i.e. single copy. The driver_data field is also per-cpu and moved. Signed-off-by: Deepthi Dharwar <deepthi@linux.vnet.ibm.com> Signed-off-by: Trinabh Gupta <g.trinabh@gmail.com> Tested-by: Jean Pihet <j-pihet@ti.com> Reviewed-by: Kevin Hilman <khilman@ti.com> Acked-by: Arjan van de Ven <arjan@linux.intel.com> Acked-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent b25edc4 commit 4202735

7 files changed

Lines changed: 90 additions & 54 deletions

File tree

‎arch/arm/mach-davinci/cpuidle.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ static struct davinci_ops davinci_states[DAVINCI_CPUIDLE_MAX_STATES] = {
8080
static int davinci_enter_idle(struct cpuidle_device *dev,
8181
int index)
8282
{
83-
struct davinci_ops *ops = cpuidle_get_statedata(&dev->states[index]);
83+
struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
84+
struct davinci_ops *ops = cpuidle_get_statedata(state_usage);
8485
struct timeval before, after;
8586
int idle_time;
8687

@@ -142,7 +143,7 @@ static int __init davinci_cpuidle_probe(struct platform_device *pdev)
142143
strcpy(device->states[1].desc, "WFI and DDR Self Refresh");
143144
if (pdata->ddr2_pdown)
144145
davinci_states[1].flags |= DAVINCI_CPUIDLE_FLAGS_DDR2_PWDN;
145-
cpuidle_set_statedata(&device->states[1], &davinci_states[1]);
146+
cpuidle_set_statedata(&device->states_usage[1], &davinci_states[1]);
146147

147148
device->state_count = DAVINCI_CPUIDLE_MAX_STATES;
148149

‎arch/arm/mach-omap2/cpuidle34xx.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int omap3_enter_idle(struct cpuidle_device *dev,
9797
int index)
9898
{
9999
struct omap3_idle_statedata *cx =
100-
cpuidle_get_statedata(&dev->states[index]);
100+
cpuidle_get_statedata(&dev->states_usage[index]);
101101
struct timespec ts_preidle, ts_postidle, ts_idle;
102102
u32 mpu_state = cx->mpu_state, core_state = cx->core_state;
103103
int idle_time;
@@ -160,8 +160,9 @@ static int omap3_enter_idle(struct cpuidle_device *dev,
160160
static int next_valid_state(struct cpuidle_device *dev,
161161
int index)
162162
{
163+
struct cpuidle_state_usage *curr_usage = &dev->states_usage[index];
163164
struct cpuidle_state *curr = &dev->states[index];
164-
struct omap3_idle_statedata *cx = cpuidle_get_statedata(curr);
165+
struct omap3_idle_statedata *cx = cpuidle_get_statedata(curr_usage);
165166
u32 mpu_deepest_state = PWRDM_POWER_RET;
166167
u32 core_deepest_state = PWRDM_POWER_RET;
167168
int next_index = -1;
@@ -202,7 +203,7 @@ static int next_valid_state(struct cpuidle_device *dev,
202203
*/
203204
idx--;
204205
for (; idx >= 0; idx--) {
205-
cx = cpuidle_get_statedata(&dev->states[idx]);
206+
cx = cpuidle_get_statedata(&dev->states_usage[idx]);
206207
if ((cx->valid) &&
207208
(cx->mpu_state >= mpu_deepest_state) &&
208209
(cx->core_state >= core_deepest_state)) {
@@ -231,7 +232,6 @@ static int next_valid_state(struct cpuidle_device *dev,
231232
static int omap3_enter_idle_bm(struct cpuidle_device *dev,
232233
int index)
233234
{
234-
struct cpuidle_state *state = &dev->states[index];
235235
int new_state_idx;
236236
u32 core_next_state, per_next_state = 0, per_saved_state = 0, cam_state;
237237
struct omap3_idle_statedata *cx;
@@ -264,7 +264,7 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
264264
* Prevent PER off if CORE is not in retention or off as this
265265
* would disable PER wakeups completely.
266266
*/
267-
cx = cpuidle_get_statedata(state);
267+
cx = cpuidle_get_statedata(&dev->states_usage[index]);
268268
core_next_state = cx->core_state;
269269
per_next_state = per_saved_state = pwrdm_read_next_pwrst(per_pd);
270270
if ((per_next_state == PWRDM_POWER_OFF) &&
@@ -318,6 +318,7 @@ static inline struct omap3_idle_statedata *_fill_cstate(
318318
{
319319
struct omap3_idle_statedata *cx = &omap3_idle_data[idx];
320320
struct cpuidle_state *state = &dev->states[idx];
321+
struct cpuidle_state_usage *state_usage = &dev->states_usage[idx];
321322

322323
state->exit_latency = cpuidle_params_table[idx].exit_latency;
323324
state->target_residency = cpuidle_params_table[idx].target_residency;
@@ -326,7 +327,7 @@ static inline struct omap3_idle_statedata *_fill_cstate(
326327
cx->valid = cpuidle_params_table[idx].valid;
327328
sprintf(state->name, "C%d", idx + 1);
328329
strncpy(state->desc, descr, CPUIDLE_DESC_LEN);
329-
cpuidle_set_statedata(state, cx);
330+
cpuidle_set_statedata(state_usage, cx);
330331

331332
return cx;
332333
}

‎drivers/acpi/processor_idle.c‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,13 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
745745
*
746746
* This is equivalent to the HALT instruction.
747747
*/
748-
static int acpi_idle_enter_c1(struct cpuidle_device *dev,
749-
int index)
748+
static int acpi_idle_enter_c1(struct cpuidle_device *dev, int index)
750749
{
751750
ktime_t kt1, kt2;
752751
s64 idle_time;
753752
struct acpi_processor *pr;
754-
struct cpuidle_state *state = &dev->states[index];
755-
struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
753+
struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
754+
struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
756755

757756
pr = __this_cpu_read(processors);
758757
dev->last_residency = 0;
@@ -790,12 +789,11 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
790789
* @dev: the target CPU
791790
* @index: the index of suggested state
792791
*/
793-
static int acpi_idle_enter_simple(struct cpuidle_device *dev,
794-
int index)
792+
static int acpi_idle_enter_simple(struct cpuidle_device *dev, int index)
795793
{
796794
struct acpi_processor *pr;
797-
struct cpuidle_state *state = &dev->states[index];
798-
struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
795+
struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
796+
struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
799797
ktime_t kt1, kt2;
800798
s64 idle_time_ns;
801799
s64 idle_time;
@@ -875,12 +873,11 @@ static DEFINE_SPINLOCK(c3_lock);
875873
*
876874
* If BM is detected, the deepest non-C3 idle state is entered instead.
877875
*/
878-
static int acpi_idle_enter_bm(struct cpuidle_device *dev,
879-
int index)
876+
static int acpi_idle_enter_bm(struct cpuidle_device *dev, int index)
880877
{
881878
struct acpi_processor *pr;
882-
struct cpuidle_state *state = &dev->states[index];
883-
struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
879+
struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
880+
struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
884881
ktime_t kt1, kt2;
885882
s64 idle_time_ns;
886883
s64 idle_time;
@@ -1004,6 +1001,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
10041001
int i, count = CPUIDLE_DRIVER_STATE_START;
10051002
struct acpi_processor_cx *cx;
10061003
struct cpuidle_state *state;
1004+
struct cpuidle_state_usage *state_usage;
10071005
struct cpuidle_device *dev = &pr->power.dev;
10081006

10091007
if (!pr->flags.power_setup_done)
@@ -1026,6 +1024,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
10261024
for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
10271025
cx = &pr->power.states[i];
10281026
state = &dev->states[count];
1027+
state_usage = &dev->states_usage[count];
10291028

10301029
if (!cx->valid)
10311030
continue;
@@ -1036,7 +1035,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
10361035
!(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
10371036
continue;
10381037
#endif
1039-
cpuidle_set_statedata(state, cx);
1038+
cpuidle_set_statedata(state_usage, cx);
10401039

10411040
snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
10421041
strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ int cpuidle_idle_call(void)
105105
/* This can be moved to within driver enter routine
106106
* but that results in multiple copies of same code.
107107
*/
108-
dev->states[entered_state].time +=
108+
dev->states_usage[entered_state].time +=
109109
(unsigned long long)dev->last_residency;
110-
dev->states[entered_state].usage++;
110+
dev->states_usage[entered_state].usage++;
111111
}
112112

113113
/* give the governor an opportunity to reflect on the outcome */
@@ -186,8 +186,9 @@ static int poll_idle(struct cpuidle_device *dev, int index)
186186
static void poll_idle_init(struct cpuidle_device *dev)
187187
{
188188
struct cpuidle_state *state = &dev->states[0];
189+
struct cpuidle_state_usage *state_usage = &dev->states_usage[0];
189190

190-
cpuidle_set_statedata(state, NULL);
191+
cpuidle_set_statedata(state_usage, NULL);
191192

192193
snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
193194
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
@@ -235,8 +236,8 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
235236
goto fail_sysfs;
236237

237238
for (i = 0; i < dev->state_count; i++) {
238-
dev->states[i].usage = 0;
239-
dev->states[i].time = 0;
239+
dev->states_usage[i].usage = 0;
240+
dev->states_usage[i].time = 0;
240241
}
241242
dev->last_residency = 0;
242243

‎drivers/cpuidle/sysfs.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,27 +216,31 @@ static struct kobj_type ktype_cpuidle = {
216216

217217
struct cpuidle_state_attr {
218218
struct attribute attr;
219-
ssize_t (*show)(struct cpuidle_state *, char *);
219+
ssize_t (*show)(struct cpuidle_state *, \
220+
struct cpuidle_state_usage *, char *);
220221
ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
221222
};
222223

223224
#define define_one_state_ro(_name, show) \
224225
static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
225226

226227
#define define_show_state_function(_name) \
227-
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
228+
static ssize_t show_state_##_name(struct cpuidle_state *state, \
229+
struct cpuidle_state_usage *state_usage, char *buf) \
228230
{ \
229231
return sprintf(buf, "%u\n", state->_name);\
230232
}
231233

232234
#define define_show_state_ull_function(_name) \
233-
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
235+
static ssize_t show_state_##_name(struct cpuidle_state *state, \
236+
struct cpuidle_state_usage *state_usage, char *buf) \
234237
{ \
235-
return sprintf(buf, "%llu\n", state->_name);\
238+
return sprintf(buf, "%llu\n", state_usage->_name);\
236239
}
237240

238241
#define define_show_state_str_function(_name) \
239-
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
242+
static ssize_t show_state_##_name(struct cpuidle_state *state, \
243+
struct cpuidle_state_usage *state_usage, char *buf) \
240244
{ \
241245
if (state->_name[0] == '\0')\
242246
return sprintf(buf, "<null>\n");\
@@ -269,16 +273,18 @@ static struct attribute *cpuidle_state_default_attrs[] = {
269273

270274
#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
271275
#define kobj_to_state(k) (kobj_to_state_obj(k)->state)
276+
#define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
272277
#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
273278
static ssize_t cpuidle_state_show(struct kobject * kobj,
274279
struct attribute * attr ,char * buf)
275280
{
276281
int ret = -EIO;
277282
struct cpuidle_state *state = kobj_to_state(kobj);
283+
struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
278284
struct cpuidle_state_attr * cattr = attr_to_stateattr(attr);
279285

280286
if (cattr->show)
281-
ret = cattr->show(state, buf);
287+
ret = cattr->show(state, state_usage, buf);
282288

283289
return ret;
284290
}
@@ -323,6 +329,7 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
323329
if (!kobj)
324330
goto error_state;
325331
kobj->state = &device->states[i];
332+
kobj->state_usage = &device->states_usage[i];
326333
init_completion(&kobj->kobj_unregister);
327334

328335
ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,

‎drivers/idle/intel_idle.c‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,20 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
109109
{ /* MWAIT C1 */
110110
.name = "C1-NHM",
111111
.desc = "MWAIT 0x00",
112-
.driver_data = (void *) 0x00,
113112
.flags = CPUIDLE_FLAG_TIME_VALID,
114113
.exit_latency = 3,
115114
.target_residency = 6,
116115
.enter = &intel_idle },
117116
{ /* MWAIT C2 */
118117
.name = "C3-NHM",
119118
.desc = "MWAIT 0x10",
120-
.driver_data = (void *) 0x10,
121119
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
122120
.exit_latency = 20,
123121
.target_residency = 80,
124122
.enter = &intel_idle },
125123
{ /* MWAIT C3 */
126124
.name = "C6-NHM",
127125
.desc = "MWAIT 0x20",
128-
.driver_data = (void *) 0x20,
129126
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
130127
.exit_latency = 200,
131128
.target_residency = 800,
@@ -137,31 +134,27 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
137134
{ /* MWAIT C1 */
138135
.name = "C1-SNB",
139136
.desc = "MWAIT 0x00",
140-
.driver_data = (void *) 0x00,
141137
.flags = CPUIDLE_FLAG_TIME_VALID,
142138
.exit_latency = 1,
143139
.target_residency = 1,
144140
.enter = &intel_idle },
145141
{ /* MWAIT C2 */
146142
.name = "C3-SNB",
147143
.desc = "MWAIT 0x10",
148-
.driver_data = (void *) 0x10,
149144
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
150145
.exit_latency = 80,
151146
.target_residency = 211,
152147
.enter = &intel_idle },
153148
{ /* MWAIT C3 */
154149
.name = "C6-SNB",
155150
.desc = "MWAIT 0x20",
156-
.driver_data = (void *) 0x20,
157151
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
158152
.exit_latency = 104,
159153
.target_residency = 345,
160154
.enter = &intel_idle },
161155
{ /* MWAIT C4 */
162156
.name = "C7-SNB",
163157
.desc = "MWAIT 0x30",
164-
.driver_data = (void *) 0x30,
165158
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
166159
.exit_latency = 109,
167160
.target_residency = 345,
@@ -173,15 +166,13 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
173166
{ /* MWAIT C1 */
174167
.name = "C1-ATM",
175168
.desc = "MWAIT 0x00",
176-
.driver_data = (void *) 0x00,
177169
.flags = CPUIDLE_FLAG_TIME_VALID,
178170
.exit_latency = 1,
179171
.target_residency = 4,
180172
.enter = &intel_idle },
181173
{ /* MWAIT C2 */
182174
.name = "C2-ATM",
183175
.desc = "MWAIT 0x10",
184-
.driver_data = (void *) 0x10,
185176
.flags = CPUIDLE_FLAG_TIME_VALID,
186177
.exit_latency = 20,
187178
.target_residency = 80,
@@ -190,7 +181,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
190181
{ /* MWAIT C4 */
191182
.name = "C4-ATM",
192183
.desc = "MWAIT 0x30",
193-
.driver_data = (void *) 0x30,
194184
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
195185
.exit_latency = 100,
196186
.target_residency = 400,
@@ -199,13 +189,41 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
199189
{ /* MWAIT C6 */
200190
.name = "C6-ATM",
201191
.desc = "MWAIT 0x52",
202-
.driver_data = (void *) 0x52,
203192
.flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
204193
.exit_latency = 140,
205194
.target_residency = 560,
206195
.enter = &intel_idle },
207196
};
208197

198+
static int get_driver_data(int cstate)
199+
{
200+
int driver_data;
201+
switch (cstate) {
202+
203+
case 1: /* MWAIT C1 */
204+
driver_data = 0x00;
205+
break;
206+
case 2: /* MWAIT C2 */
207+
driver_data = 0x10;
208+
break;
209+
case 3: /* MWAIT C3 */
210+
driver_data = 0x20;
211+
break;
212+
case 4: /* MWAIT C4 */
213+
driver_data = 0x30;
214+
break;
215+
case 5: /* MWAIT C5 */
216+
driver_data = 0x40;
217+
break;
218+
case 6: /* MWAIT C6 */
219+
driver_data = 0x52;
220+
break;
221+
default:
222+
driver_data = 0x00;
223+
}
224+
return driver_data;
225+
}
226+
209227
/**
210228
* intel_idle
211229
* @dev: cpuidle_device
@@ -216,7 +234,8 @@ static int intel_idle(struct cpuidle_device *dev, int index)
216234
{
217235
unsigned long ecx = 1; /* break on interrupt flag */
218236
struct cpuidle_state *state = &dev->states[index];
219-
unsigned long eax = (unsigned long)cpuidle_get_statedata(state);
237+
struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
238+
unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
220239
unsigned int cstate;
221240
ktime_t kt_before, kt_after;
222241
s64 usec_delta;
@@ -451,6 +470,9 @@ static int intel_idle_cpuidle_devices_init(void)
451470
dev->states[dev->state_count] = /* structure copy */
452471
cpuidle_state_table[cstate];
453472

473+
dev->states_usage[dev->state_count].driver_data =
474+
(void *)get_driver_data(cstate);
475+
454476
dev->state_count += 1;
455477
}
456478

0 commit comments

Comments
 (0)