-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Rafael J. Wysocki
committed
Apr 1, 2016
1 parent
0dd3c1d
commit 2d0c58a
Showing
5 changed files
with
95 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |