clocksource: Extract clocksource lookup code
PATCH 1/2 clocksource: Extract clocksource lookup code
From: Thierry Reding <[email protected]>
Move the clocksource lookup code into a separate function. This will allow subsequent patches to reuse this code.
Signed-off-by Thierry Reding <[email protected]>
--- kernel/time/clocksource.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
kernel/time/clocksource.c +18 -6
@@ -453,6 +453,18 @@ static inline void clocksource_watchdog_unlock(unsigned long *flags) { }#endif /* CONFIG_CLOCKSOURCE_WATCHDOG */ +static struct clocksource *clocksource_lookup (const char *name) +{ +struct clocksource *cs; + +list_for_each_entry (cs, &clocksource_list, list) { +if (strcmp (cs->name, name) ==0 ) +return cs; + } + +return NULL ; +} +static bool clocksource_is_suspend (struct clocksource *cs) {return cs == suspend_clocksource;
@@ -1110,14 +1122,14 @@ static ssize_t unbind_clocksource_store(struct device *dev,if (ret <0 )return ret; - ret = -ENODEV ;mutex_lock (&clocksource_mutex); -list_for_each_entry (cs, &clocksource_list, list) { -if (strcmp (cs->name, name)) -continue ; + + cs =clocksource_lookup (name); +if (cs) ret =clocksource_unbind (cs); -break ; - } +else + ret = -ENODEV ; +mutex_unlock (&clocksource_mutex);return ret ? ret : count;
Signature · 1 line
2.21.0
PATCH 2/2 clocksource: Add suspend clocksource sysfs attribute
From: Thierry Reding <[email protected]>
Allow the currently selected suspend clocksource to be inspected via sysfs. The suspend clocksource can also be set using this attribute, which can be useful for debugging.
Signed-off-by Thierry Reding <[email protected]>
--- kernel/time/clocksource.c | 53 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)
kernel/time/clocksource.c +52 -1
@@ -489,7 +489,8 @@ static void __clocksource_suspend_select(struct clocksource *cs) }/* Pick the best rating. */ -if (!suspend_clocksource || cs->rating > suspend_clocksource->rating) +if (!suspend_clocksource || cs->rating > suspend_clocksource->rating || + (suspend_clocksource->flags &CLOCK_SOURCE_SUSPEND_NONSTOP ) ==0 ) suspend_clocksource = cs; }
@@ -1172,10 +1173,60 @@ static ssize_t available_clocksource_show(struct device *dev, }static DEVICE_ATTR_RO (available_clocksource); +static ssize_t suspend_clocksource_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct clocksource *clksrc = suspend_clocksource; +ssize_t count =0 ; + +if (clksrc) + count +=snprintf (buf,PAGE_SIZE ,"%s\n" , clksrc->name); + +return count; +} + +static ssize_t suspend_clocksource_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct clocksource *cs; +char name[CS_NAME_LEN ]; +ssize_t ret; + + ret =sysfs_get_uname (buf, name, count); +if (ret <0 ) +return ret; + +mutex_lock (&clocksource_mutex); + +if (strlen (name) >0 ) { + cs =clocksource_lookup (name); +if (cs) { +if (!(cs->flags &CLOCK_SOURCE_SUSPEND_NONSTOP )) +pr_warn ("using non-persistent clocksource %s for suspend\n" , + cs->name); + + suspend_clocksource = cs; + }else { + ret = -ENODEV ; + } + }else { +clocksource_suspend_select (false); + } + +mutex_unlock (&clocksource_mutex); + +return ret ? ret : count; +} + +static DEVICE_ATTR_RW (suspend_clocksource); +static struct attribute *clocksource_attrs[] = { &dev_attr_current_clocksource.attr, &dev_attr_unbind_clocksource.attr, &dev_attr_available_clocksource.attr, + &dev_attr_suspend_clocksource.attr,NULL };ATTRIBUTE_GROUPS (clocksource);
Signature · 1 line
2.21.0