diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-03-21 21:49:15 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-04-01 19:09:01 -0400 |
commit | 2d0c58ad60376160ee8b535e570a38b9a349b6a4 (patch) | |
tree | 33357ded3208ada747bfd93a6dce5cae10421b7b | |
parent | 0dd3c1d678aa219a7332984fcedbdd8970e92d5b (diff) |
cpufreq: governor: Move abstract gov_attr_set code to seperate file
Move abstract code related to struct gov_attr_set to a separate (new)
file so it can be shared with (future) goverernors that won't share
more code with "ondemand" and "conservative".
No intentional functional changes.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
-rw-r--r-- | drivers/cpufreq/Kconfig | 4 | ||||
-rw-r--r-- | drivers/cpufreq/Makefile | 1 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_governor.c | 82 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_governor.h | 6 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_governor_attr_set.c | 84 |
5 files changed, 95 insertions, 82 deletions
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index a7f45853c103..7fd87106ba46 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig | |||
@@ -18,7 +18,11 @@ config CPU_FREQ | |||
18 | 18 | ||
19 | if CPU_FREQ | 19 | if CPU_FREQ |
20 | 20 | ||
21 | config CPU_FREQ_GOV_ATTR_SET | ||
22 | bool | ||
23 | |||
21 | config CPU_FREQ_GOV_COMMON | 24 | config CPU_FREQ_GOV_COMMON |
25 | select CPU_FREQ_GOV_ATTR_SET | ||
22 | select IRQ_WORK | 26 | select IRQ_WORK |
23 | bool | 27 | bool |
24 | 28 | ||
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 9e63fb1b09f8..6d1186701a9c 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
@@ -11,6 +11,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o | |||
11 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o | 11 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o |
12 | obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o | 12 | obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o |
13 | obj-$(CONFIG_CPU_FREQ_GOV_COMMON) += cpufreq_governor.o | 13 | obj-$(CONFIG_CPU_FREQ_GOV_COMMON) += cpufreq_governor.o |
14 | obj-$(CONFIG_CPU_FREQ_GOV_ATTR_SET) += cpufreq_governor_attr_set.o | ||
14 | 15 | ||
15 | obj-$(CONFIG_CPUFREQ_DT) += cpufreq-dt.o | 16 | obj-$(CONFIG_CPUFREQ_DT) += cpufreq-dt.o |
16 | 17 | ||
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c index 6a565e248ad3..20f0a4e114d1 100644 --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c | |||
@@ -112,53 +112,6 @@ void gov_update_cpu_data(struct dbs_data *dbs_data) | |||
112 | } | 112 | } |
113 | EXPORT_SYMBOL_GPL(gov_update_cpu_data); | 113 | EXPORT_SYMBOL_GPL(gov_update_cpu_data); |
114 | 114 | ||
115 | static inline struct gov_attr_set *to_gov_attr_set(struct kobject *kobj) | ||
116 | { | ||
117 | return container_of(kobj, struct gov_attr_set, kobj); | ||
118 | } | ||
119 | |||
120 | static inline struct governor_attr *to_gov_attr(struct attribute *attr) | ||
121 | { | ||
122 | return container_of(attr, struct governor_attr, attr); | ||
123 | } | ||
124 | |||
125 | static ssize_t governor_show(struct kobject *kobj, struct attribute *attr, | ||
126 | char *buf) | ||
127 | { | ||
128 | struct governor_attr *gattr = to_gov_attr(attr); | ||
129 | |||
130 | return gattr->show(to_gov_attr_set(kobj), buf); | ||
131 | } | ||
132 | |||
133 | static ssize_t governor_store(struct kobject *kobj, struct attribute *attr, | ||
134 | const char *buf, size_t count) | ||
135 | { | ||
136 | struct gov_attr_set *attr_set = to_gov_attr_set(kobj); | ||
137 | struct governor_attr *gattr = to_gov_attr(attr); | ||
138 | int ret = -EBUSY; | ||
139 | |||
140 | mutex_lock(&attr_set->update_lock); | ||
141 | |||
142 | if (attr_set->usage_count) | ||
143 | ret = gattr->store(attr_set, buf, count); | ||
144 | |||
145 | mutex_unlock(&attr_set->update_lock); | ||
146 | |||
147 | return ret; | ||
148 | } | ||
149 | |||
150 | /* | ||
151 | * Sysfs Ops for accessing governor attributes. | ||
152 | * | ||
153 | * All show/store invocations for governor specific sysfs attributes, will first | ||
154 | * call the below show/store callbacks and the attribute specific callback will | ||
155 | * be called from within it. | ||
156 | */ | ||
157 | static const struct sysfs_ops governor_sysfs_ops = { | ||
158 | .show = governor_show, | ||
159 | .store = governor_store, | ||
160 | }; | ||
161 | |||
162 | unsigned int dbs_update(struct cpufreq_policy *policy) | 115 | unsigned int dbs_update(struct cpufreq_policy *policy) |
163 | { | 116 | { |
164 | struct policy_dbs_info *policy_dbs = policy->governor_data; | 117 | struct policy_dbs_info *policy_dbs = policy->governor_data; |
@@ -425,41 +378,6 @@ static void free_policy_dbs_info(struct policy_dbs_info *policy_dbs, | |||
425 | gov->free(policy_dbs); | 378 | gov->free(policy_dbs); |
426 | } | 379 | } |
427 | 380 | ||
428 | static void gov_attr_set_init(struct gov_attr_set *attr_set, | ||
429 | struct list_head *list_node) | ||
430 | { | ||
431 | INIT_LIST_HEAD(&attr_set->policy_list); | ||
432 | mutex_init(&attr_set->update_lock); | ||
433 | attr_set->usage_count = 1; | ||
434 | list_add(list_node, &attr_set->policy_list); | ||
435 | } | ||
436 | |||
437 | static void gov_attr_set_get(struct gov_attr_set *attr_set, | ||
438 | struct list_head *list_node) | ||
439 | { | ||
440 | mutex_lock(&attr_set->update_lock); | ||
441 | attr_set->usage_count++; | ||
442 | list_add(list_node, &attr_set->policy_list); | ||
443 | mutex_unlock(&attr_set->update_lock); | ||
444 | } | ||
445 | |||
446 | static unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, | ||
447 | struct list_head *list_node) | ||
448 | { | ||
449 | unsigned int count; | ||
450 | |||
451 | mutex_lock(&attr_set->update_lock); | ||
452 | list_del(list_node); | ||
453 | count = --attr_set->usage_count; | ||
454 | mutex_unlock(&attr_set->update_lock); | ||
455 | if (count) | ||
456 | return count; | ||
457 | |||
458 | kobject_put(&attr_set->kobj); | ||
459 | mutex_destroy(&attr_set->update_lock); | ||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | static int cpufreq_governor_init(struct cpufreq_policy *policy) | 381 | static int cpufreq_governor_init(struct cpufreq_policy *policy) |
464 | { | 382 | { |
465 | struct dbs_governor *gov = dbs_governor_of(policy); | 383 | struct dbs_governor *gov = dbs_governor_of(policy); |
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h index f4ad431130b8..ccdd0814efbc 100644 --- a/drivers/cpufreq/cpufreq_governor.h +++ b/drivers/cpufreq/cpufreq_governor.h | |||
@@ -48,6 +48,12 @@ struct gov_attr_set { | |||
48 | int usage_count; | 48 | int usage_count; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | extern const struct sysfs_ops governor_sysfs_ops; | ||
52 | |||
53 | void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node); | ||
54 | void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node); | ||
55 | unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node); | ||
56 | |||
51 | /* | 57 | /* |
52 | * Abbreviations: | 58 | * Abbreviations: |
53 | * dbs: used as a shortform for demand based switching It helps to keep variable | 59 | * dbs: used as a shortform for demand based switching It helps to keep variable |
diff --git a/drivers/cpufreq/cpufreq_governor_attr_set.c b/drivers/cpufreq/cpufreq_governor_attr_set.c new file mode 100644 index 000000000000..52841f807a7e --- /dev/null +++ b/drivers/cpufreq/cpufreq_governor_attr_set.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * Abstract code for CPUFreq governor tunable sysfs attributes. | ||
3 | * | ||
4 | * Copyright (C) 2016, Intel Corporation | ||
5 | * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include "cpufreq_governor.h" | ||
13 | |||
14 | static inline struct gov_attr_set *to_gov_attr_set(struct kobject *kobj) | ||
15 | { | ||
16 | return container_of(kobj, struct gov_attr_set, kobj); | ||
17 | } | ||
18 | |||
19 | static inline struct governor_attr *to_gov_attr(struct attribute *attr) | ||
20 | { | ||
21 | return container_of(attr, struct governor_attr, attr); | ||
22 | } | ||
23 | |||
24 | static ssize_t governor_show(struct kobject *kobj, struct attribute *attr, | ||
25 | char *buf) | ||
26 | { | ||
27 | struct governor_attr *gattr = to_gov_attr(attr); | ||
28 | |||
29 | return gattr->show(to_gov_attr_set(kobj), buf); | ||
30 | } | ||
31 | |||
32 | static ssize_t governor_store(struct kobject *kobj, struct attribute *attr, | ||
33 | const char *buf, size_t count) | ||
34 | { | ||
35 | struct gov_attr_set *attr_set = to_gov_attr_set(kobj); | ||
36 | struct governor_attr *gattr = to_gov_attr(attr); | ||
37 | int ret; | ||
38 | |||
39 | mutex_lock(&attr_set->update_lock); | ||
40 | ret = attr_set->usage_count ? gattr->store(attr_set, buf, count) : -EBUSY; | ||
41 | mutex_unlock(&attr_set->update_lock); | ||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | const struct sysfs_ops governor_sysfs_ops = { | ||
46 | .show = governor_show, | ||
47 | .store = governor_store, | ||
48 | }; | ||
49 | EXPORT_SYMBOL_GPL(governor_sysfs_ops); | ||
50 | |||
51 | void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node) | ||
52 | { | ||
53 | INIT_LIST_HEAD(&attr_set->policy_list); | ||
54 | mutex_init(&attr_set->update_lock); | ||
55 | attr_set->usage_count = 1; | ||
56 | list_add(list_node, &attr_set->policy_list); | ||
57 | } | ||
58 | EXPORT_SYMBOL_GPL(gov_attr_set_init); | ||
59 | |||
60 | void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node) | ||
61 | { | ||
62 | mutex_lock(&attr_set->update_lock); | ||
63 | attr_set->usage_count++; | ||
64 | list_add(list_node, &attr_set->policy_list); | ||
65 | mutex_unlock(&attr_set->update_lock); | ||
66 | } | ||
67 | EXPORT_SYMBOL_GPL(gov_attr_set_get); | ||
68 | |||
69 | unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node) | ||
70 | { | ||
71 | unsigned int count; | ||
72 | |||
73 | mutex_lock(&attr_set->update_lock); | ||
74 | list_del(list_node); | ||
75 | count = --attr_set->usage_count; | ||
76 | mutex_unlock(&attr_set->update_lock); | ||
77 | if (count) | ||
78 | return count; | ||
79 | |||
80 | kobject_put(&attr_set->kobj); | ||
81 | mutex_destroy(&attr_set->update_lock); | ||
82 | return 0; | ||
83 | } | ||
84 | EXPORT_SYMBOL_GPL(gov_attr_set_put); | ||