Skip to content

Commit dc7fd27

Browse files
ShuoX Liurjwysocki
authored andcommitted
cpuidle: move field disable from per-driver to per-cpu
Andrew J.Schorr raises a question. When he changes the disable setting on a single CPU, it affects all the other CPUs. Basically, currently, the disable field is per-driver instead of per-cpu. All the C states of the same driver are shared by all CPU in the same machine. The patch changes the `disable' field to per-cpu, so we could set this separately for each cpu. Signed-off-by: ShuoX Liu <shuox.liu@intel.com> Reported-by: Andrew J.Schorr <aschorr@telemetry-investments.com> Reviewed-by: Yanmin Zhang <yanmin_zhang@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
1 parent 6887a41 commit dc7fd27

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ static void poll_idle_init(struct cpuidle_driver *drv)
265265
state->power_usage = -1;
266266
state->flags = 0;
267267
state->enter = poll_idle;
268-
state->disable = 0;
269268
}
270269
#else
271270
static void poll_idle_init(struct cpuidle_driver *drv) {}

‎drivers/cpuidle/governors/menu.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
281281
* unless the timer is happening really really soon.
282282
*/
283283
if (data->expected_us > 5 &&
284-
drv->states[CPUIDLE_DRIVER_STATE_START].disable == 0)
284+
dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable == 0)
285285
data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
286286

287287
/*
@@ -290,8 +290,9 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
290290
*/
291291
for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
292292
struct cpuidle_state *s = &drv->states[i];
293+
struct cpuidle_state_usage *su = &dev->states_usage[i];
293294

294-
if (s->disable)
295+
if (su->disable)
295296
continue;
296297
if (s->target_residency > data->predicted_us)
297298
continue;

‎drivers/cpuidle/sysfs.c‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ struct cpuidle_state_attr {
217217
struct attribute attr;
218218
ssize_t (*show)(struct cpuidle_state *, \
219219
struct cpuidle_state_usage *, char *);
220-
ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
220+
ssize_t (*store)(struct cpuidle_state *, \
221+
struct cpuidle_state_usage *, const char *, size_t);
221222
};
222223

223224
#define define_one_state_ro(_name, show) \
@@ -233,21 +234,22 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, \
233234
return sprintf(buf, "%u\n", state->_name);\
234235
}
235236

236-
#define define_store_state_function(_name) \
237+
#define define_store_state_ull_function(_name) \
237238
static ssize_t store_state_##_name(struct cpuidle_state *state, \
239+
struct cpuidle_state_usage *state_usage, \
238240
const char *buf, size_t size) \
239241
{ \
240-
long value; \
242+
unsigned long long value; \
241243
int err; \
242244
if (!capable(CAP_SYS_ADMIN)) \
243245
return -EPERM; \
244-
err = kstrtol(buf, 0, &value); \
246+
err = kstrtoull(buf, 0, &value); \
245247
if (err) \
246248
return err; \
247249
if (value) \
248-
state->disable = 1; \
250+
state_usage->_name = 1; \
249251
else \
250-
state->disable = 0; \
252+
state_usage->_name = 0; \
251253
return size; \
252254
}
253255

@@ -273,8 +275,8 @@ define_show_state_ull_function(usage)
273275
define_show_state_ull_function(time)
274276
define_show_state_str_function(name)
275277
define_show_state_str_function(desc)
276-
define_show_state_function(disable)
277-
define_store_state_function(disable)
278+
define_show_state_ull_function(disable)
279+
define_store_state_ull_function(disable)
278280

279281
define_one_state_ro(name, show_state_name);
280282
define_one_state_ro(desc, show_state_desc);
@@ -318,10 +320,11 @@ static ssize_t cpuidle_state_store(struct kobject *kobj,
318320
{
319321
int ret = -EIO;
320322
struct cpuidle_state *state = kobj_to_state(kobj);
323+
struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
321324
struct cpuidle_state_attr *cattr = attr_to_stateattr(attr);
322325

323326
if (cattr->store)
324-
ret = cattr->store(state, buf, size);
327+
ret = cattr->store(state, state_usage, buf, size);
325328

326329
return ret;
327330
}

‎include/linux/cpuidle.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct cpuidle_driver;
3434
struct cpuidle_state_usage {
3535
void *driver_data;
3636

37+
unsigned long long disable;
3738
unsigned long long usage;
3839
unsigned long long time; /* in US */
3940
};
@@ -46,7 +47,6 @@ struct cpuidle_state {
4647
unsigned int exit_latency; /* in US */
4748
int power_usage; /* in mW */
4849
unsigned int target_residency; /* in US */
49-
unsigned int disable;
5050

5151
int (*enter) (struct cpuidle_device *dev,
5252
struct cpuidle_driver *drv,

0 commit comments

Comments
 (0)