cpufreq: governor: Move abstract gov_attr_set code to seperate file
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 22 Mar 2016 01:49:15 +0000 (02:49 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 1 Apr 2016 23:09:01 +0000 (01:09 +0200)
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>
drivers/cpufreq/Kconfig
drivers/cpufreq/Makefile
drivers/cpufreq/cpufreq_governor.c
drivers/cpufreq/cpufreq_governor.h
drivers/cpufreq/cpufreq_governor_attr_set.c [new file with mode: 0644]

index a7f45853c10337c25a6aea4dca90aa7cca5f99b5..7fd87106ba4667c527a147aa4cd0eaa96e373a05 100644 (file)
@@ -18,7 +18,11 @@ config CPU_FREQ
 
 if CPU_FREQ
 
+config CPU_FREQ_GOV_ATTR_SET
+       bool
+
 config CPU_FREQ_GOV_COMMON
+       select CPU_FREQ_GOV_ATTR_SET
        select IRQ_WORK
        bool
 
index 9e63fb1b09f815fa70e1c4d908707ba39989f8fa..6d1186701a9c10dbc2b84616c2b398b6bb39afcc 100644 (file)
@@ -11,6 +11,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE)  += cpufreq_userspace.o
 obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND)    += cpufreq_ondemand.o
 obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE)        += cpufreq_conservative.o
 obj-$(CONFIG_CPU_FREQ_GOV_COMMON)              += cpufreq_governor.o
+obj-$(CONFIG_CPU_FREQ_GOV_ATTR_SET)    += cpufreq_governor_attr_set.o
 
 obj-$(CONFIG_CPUFREQ_DT)               += cpufreq-dt.o
 
index 6a565e248ad3c300f7d04c556bd34d6c54253e0c..20f0a4e114d13c5252fdabc84c77498c2f041480 100644 (file)
@@ -112,53 +112,6 @@ void gov_update_cpu_data(struct dbs_data *dbs_data)
 }
 EXPORT_SYMBOL_GPL(gov_update_cpu_data);
 
-static inline struct gov_attr_set *to_gov_attr_set(struct kobject *kobj)
-{
-       return container_of(kobj, struct gov_attr_set, kobj);
-}
-
-static inline struct governor_attr *to_gov_attr(struct attribute *attr)
-{
-       return container_of(attr, struct governor_attr, attr);
-}
-
-static ssize_t governor_show(struct kobject *kobj, struct attribute *attr,
-                            char *buf)
-{
-       struct governor_attr *gattr = to_gov_attr(attr);
-
-       return gattr->show(to_gov_attr_set(kobj), buf);
-}
-
-static ssize_t governor_store(struct kobject *kobj, struct attribute *attr,
-                             const char *buf, size_t count)
-{
-       struct gov_attr_set *attr_set = to_gov_attr_set(kobj);
-       struct governor_attr *gattr = to_gov_attr(attr);
-       int ret = -EBUSY;
-
-       mutex_lock(&attr_set->update_lock);
-
-       if (attr_set->usage_count)
-               ret = gattr->store(attr_set, buf, count);
-
-       mutex_unlock(&attr_set->update_lock);
-
-       return ret;
-}
-
-/*
- * Sysfs Ops for accessing governor attributes.
- *
- * All show/store invocations for governor specific sysfs attributes, will first
- * call the below show/store callbacks and the attribute specific callback will
- * be called from within it.
- */
-static const struct sysfs_ops governor_sysfs_ops = {
-       .show   = governor_show,
-       .store  = governor_store,
-};
-
 unsigned int dbs_update(struct cpufreq_policy *policy)
 {
        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,
        gov->free(policy_dbs);
 }
 
-static void gov_attr_set_init(struct gov_attr_set *attr_set,
-                             struct list_head *list_node)
-{
-       INIT_LIST_HEAD(&attr_set->policy_list);
-       mutex_init(&attr_set->update_lock);
-       attr_set->usage_count = 1;
-       list_add(list_node, &attr_set->policy_list);
-}
-
-static void gov_attr_set_get(struct gov_attr_set *attr_set,
-                            struct list_head *list_node)
-{
-       mutex_lock(&attr_set->update_lock);
-       attr_set->usage_count++;
-       list_add(list_node, &attr_set->policy_list);
-       mutex_unlock(&attr_set->update_lock);
-}
-
-static unsigned int gov_attr_set_put(struct gov_attr_set *attr_set,
-                                    struct list_head *list_node)
-{
-       unsigned int count;
-
-       mutex_lock(&attr_set->update_lock);
-       list_del(list_node);
-       count = --attr_set->usage_count;
-       mutex_unlock(&attr_set->update_lock);
-       if (count)
-               return count;
-
-       kobject_put(&attr_set->kobj);
-       mutex_destroy(&attr_set->update_lock);
-       return 0;
-}
-
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
 {
        struct dbs_governor *gov = dbs_governor_of(policy);
index f4ad431130b8e248a53ed7e4211319ca50cae71a..ccdd0814efbc6b83229f096aeb891960a4ca4f9d 100644 (file)
@@ -48,6 +48,12 @@ struct gov_attr_set {
        int usage_count;
 };
 
+extern const struct sysfs_ops governor_sysfs_ops;
+
+void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node);
+void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node);
+unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node);
+
 /*
  * Abbreviations:
  * 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 (file)
index 0000000..52841f8
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Abstract code for CPUFreq governor tunable sysfs attributes.
+ *
+ * Copyright (C) 2016, Intel Corporation
+ * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "cpufreq_governor.h"
+
+static inline struct gov_attr_set *to_gov_attr_set(struct kobject *kobj)
+{
+       return container_of(kobj, struct gov_attr_set, kobj);
+}
+
+static inline struct governor_attr *to_gov_attr(struct attribute *attr)
+{
+       return container_of(attr, struct governor_attr, attr);
+}
+
+static ssize_t governor_show(struct kobject *kobj, struct attribute *attr,
+                            char *buf)
+{
+       struct governor_attr *gattr = to_gov_attr(attr);
+
+       return gattr->show(to_gov_attr_set(kobj), buf);
+}
+
+static ssize_t governor_store(struct kobject *kobj, struct attribute *attr,
+                             const char *buf, size_t count)
+{
+       struct gov_attr_set *attr_set = to_gov_attr_set(kobj);
+       struct governor_attr *gattr = to_gov_attr(attr);
+       int ret;
+
+       mutex_lock(&attr_set->update_lock);
+       ret = attr_set->usage_count ? gattr->store(attr_set, buf, count) : -EBUSY;
+       mutex_unlock(&attr_set->update_lock);
+       return ret;
+}
+
+const struct sysfs_ops governor_sysfs_ops = {
+       .show   = governor_show,
+       .store  = governor_store,
+};
+EXPORT_SYMBOL_GPL(governor_sysfs_ops);
+
+void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node)
+{
+       INIT_LIST_HEAD(&attr_set->policy_list);
+       mutex_init(&attr_set->update_lock);
+       attr_set->usage_count = 1;
+       list_add(list_node, &attr_set->policy_list);
+}
+EXPORT_SYMBOL_GPL(gov_attr_set_init);
+
+void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node)
+{
+       mutex_lock(&attr_set->update_lock);
+       attr_set->usage_count++;
+       list_add(list_node, &attr_set->policy_list);
+       mutex_unlock(&attr_set->update_lock);
+}
+EXPORT_SYMBOL_GPL(gov_attr_set_get);
+
+unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node)
+{
+       unsigned int count;
+
+       mutex_lock(&attr_set->update_lock);
+       list_del(list_node);
+       count = --attr_set->usage_count;
+       mutex_unlock(&attr_set->update_lock);
+       if (count)
+               return count;
+
+       kobject_put(&attr_set->kobj);
+       mutex_destroy(&attr_set->update_lock);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(gov_attr_set_put);