Skip to content

Commit

Permalink
Merge branch 'pm-cpuidle' into pm-domains
Browse files Browse the repository at this point in the history
* pm-cpuidle:
  PM / cpuidle: Add driver reference counter
  cpuidle: move field disable from per-driver to per-cpu
  • Loading branch information
Rafael J. Wysocki committed Jul 3, 2012
2 parents 80de3d7 + 6e797a0 commit e3b8cdd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
1 change: 0 additions & 1 deletion drivers/cpuidle/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ static void poll_idle_init(struct cpuidle_driver *drv)
state->power_usage = -1;
state->flags = 0;
state->enter = poll_idle;
state->disable = 0;
}
#else
static void poll_idle_init(struct cpuidle_driver *drv) {}
Expand Down
29 changes: 28 additions & 1 deletion drivers/cpuidle/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

static struct cpuidle_driver *cpuidle_curr_driver;
DEFINE_SPINLOCK(cpuidle_driver_lock);
int cpuidle_driver_refcount;

static void __cpuidle_register_driver(struct cpuidle_driver *drv)
{
Expand Down Expand Up @@ -89,8 +90,34 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv)
}

spin_lock(&cpuidle_driver_lock);
cpuidle_curr_driver = NULL;

if (!WARN_ON(cpuidle_driver_refcount > 0))
cpuidle_curr_driver = NULL;

spin_unlock(&cpuidle_driver_lock);
}

EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);

struct cpuidle_driver *cpuidle_driver_ref(void)
{
struct cpuidle_driver *drv;

spin_lock(&cpuidle_driver_lock);

drv = cpuidle_curr_driver;
cpuidle_driver_refcount++;

spin_unlock(&cpuidle_driver_lock);
return drv;
}

void cpuidle_driver_unref(void)
{
spin_lock(&cpuidle_driver_lock);

if (!WARN_ON(cpuidle_driver_refcount <= 0))
cpuidle_driver_refcount--;

spin_unlock(&cpuidle_driver_lock);
}
5 changes: 3 additions & 2 deletions drivers/cpuidle/governors/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
* unless the timer is happening really really soon.
*/
if (data->expected_us > 5 &&
drv->states[CPUIDLE_DRIVER_STATE_START].disable == 0)
dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable == 0)
data->last_state_idx = CPUIDLE_DRIVER_STATE_START;

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

if (s->disable)
if (su->disable)
continue;
if (s->target_residency > data->predicted_us)
continue;
Expand Down
21 changes: 12 additions & 9 deletions drivers/cpuidle/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ struct cpuidle_state_attr {
struct attribute attr;
ssize_t (*show)(struct cpuidle_state *, \
struct cpuidle_state_usage *, char *);
ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
ssize_t (*store)(struct cpuidle_state *, \
struct cpuidle_state_usage *, const char *, size_t);
};

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

#define define_store_state_function(_name) \
#define define_store_state_ull_function(_name) \
static ssize_t store_state_##_name(struct cpuidle_state *state, \
struct cpuidle_state_usage *state_usage, \
const char *buf, size_t size) \
{ \
long value; \
unsigned long long value; \
int err; \
if (!capable(CAP_SYS_ADMIN)) \
return -EPERM; \
err = kstrtol(buf, 0, &value); \
err = kstrtoull(buf, 0, &value); \
if (err) \
return err; \
if (value) \
state->disable = 1; \
state_usage->_name = 1; \
else \
state->disable = 0; \
state_usage->_name = 0; \
return size; \
}

Expand All @@ -273,8 +275,8 @@ define_show_state_ull_function(usage)
define_show_state_ull_function(time)
define_show_state_str_function(name)
define_show_state_str_function(desc)
define_show_state_function(disable)
define_store_state_function(disable)
define_show_state_ull_function(disable)
define_store_state_ull_function(disable)

define_one_state_ro(name, show_state_name);
define_one_state_ro(desc, show_state_desc);
Expand Down Expand Up @@ -318,10 +320,11 @@ static ssize_t cpuidle_state_store(struct kobject *kobj,
{
int ret = -EIO;
struct cpuidle_state *state = kobj_to_state(kobj);
struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
struct cpuidle_state_attr *cattr = attr_to_stateattr(attr);

if (cattr->store)
ret = cattr->store(state, buf, size);
ret = cattr->store(state, state_usage, buf, size);

return ret;
}
Expand Down
8 changes: 6 additions & 2 deletions include/linux/cpuidle.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct cpuidle_driver;
struct cpuidle_state_usage {
void *driver_data;

unsigned long long disable;
unsigned long long usage;
unsigned long long time; /* in US */
};
Expand All @@ -46,7 +47,6 @@ struct cpuidle_state {
unsigned int exit_latency; /* in US */
int power_usage; /* in mW */
unsigned int target_residency; /* in US */
unsigned int disable;

int (*enter) (struct cpuidle_device *dev,
struct cpuidle_driver *drv,
Expand Down Expand Up @@ -136,7 +136,9 @@ struct cpuidle_driver {
extern void disable_cpuidle(void);
extern int cpuidle_idle_call(void);
extern int cpuidle_register_driver(struct cpuidle_driver *drv);
struct cpuidle_driver *cpuidle_get_driver(void);
extern struct cpuidle_driver *cpuidle_get_driver(void);
extern struct cpuidle_driver *cpuidle_driver_ref(void);
extern void cpuidle_driver_unref(void);
extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
extern int cpuidle_register_device(struct cpuidle_device *dev);
extern void cpuidle_unregister_device(struct cpuidle_device *dev);
Expand All @@ -157,6 +159,8 @@ static inline int cpuidle_idle_call(void) { return -ENODEV; }
static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
{return -ENODEV; }
static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; }
static inline void cpuidle_driver_unref(void) {}
static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
static inline int cpuidle_register_device(struct cpuidle_device *dev)
{return -ENODEV; }
Expand Down

0 comments on commit e3b8cdd

Please sign in to comment.