From 7b0e1bf171effb71fa946e26d28895219de179cc Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 1 Dec 2015 17:14:13 +0100 Subject: [PATCH 1/6] cpupower: Fix precedence issue Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki --- tools/power/cpupower/utils/helpers/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/power/cpupower/utils/helpers/topology.c b/tools/power/cpupower/utils/helpers/topology.c index 9cbb7fd75171..5f9c908f4557 100644 --- a/tools/power/cpupower/utils/helpers/topology.c +++ b/tools/power/cpupower/utils/helpers/topology.c @@ -106,7 +106,7 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) cpu_top->pkgs++; } } - if (!cpu_top->core_info[0].pkg == -1) + if (!(cpu_top->core_info[0].pkg == -1)) cpu_top->pkgs++; /* Intel's cores count is not consecutively numbered, there may From e51207f0030474958e59bbc7e002f169bdb05c50 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 1 Dec 2015 17:14:14 +0100 Subject: [PATCH 2/6] cpupower: Provide STATIC variable in Makefile for debug builds When working on cpupower code, you often want to compile library code into the binary. This allows to execute modified cpupower code, even with library changes without doing "make install" Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki --- tools/power/cpupower/Makefile | 19 +++++++++++++++++++ tools/power/cpupower/bench/Makefile | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index 2e2ba2efa0d9..0adaf0c7c03a 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile @@ -47,6 +47,11 @@ NLS ?= true # cpufreq-bench benchmarking tool CPUFREQ_BENCH ?= true +# Do not build libraries, but build the code in statically +# Libraries are still built, otherwise the Makefile code would +# be rather ugly. +export STATIC ?= false + # Prefix to the directories we're installing to DESTDIR ?= @@ -161,6 +166,12 @@ ifeq ($(strip $(CPUFREQ_BENCH)),true) COMPILE_BENCH += compile-bench endif +ifeq ($(strip $(STATIC)),true) + UTIL_OBJS += $(LIB_OBJS) + UTIL_HEADERS += $(LIB_HEADERS) + UTIL_SRC += $(LIB_SRC) +endif + CFLAGS += $(WARNINGS) ifeq ($(strip $(V)),false) @@ -209,7 +220,11 @@ $(OUTPUT)%.o: %.c $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ) $(ECHO) " CC " $@ +ifeq ($(strip $(STATIC)),true) + $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@ +else $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@ +endif $(QUIET) $(STRIPCMD) $@ $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC) @@ -291,7 +306,11 @@ install-bench: @#DESTDIR must be set from outside to survive @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install +ifeq ($(strip $(STATIC)),true) +install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) +else install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) +endif uninstall: - rm -f $(DESTDIR)${libdir}/libcpupower.* diff --git a/tools/power/cpupower/bench/Makefile b/tools/power/cpupower/bench/Makefile index 7ec7021a29cd..d0f879b223fc 100644 --- a/tools/power/cpupower/bench/Makefile +++ b/tools/power/cpupower/bench/Makefile @@ -5,9 +5,15 @@ ifneq ($(O),) endif endif +ifeq ($(strip $(STATIC)),true) +LIBS = -L../ -L$(OUTPUT) -lm +OBJS = $(OUTPUT)main.o $(OUTPUT)parse.o $(OUTPUT)system.o $(OUTPUT)benchmark.o \ + $(OUTPUT)../lib/cpufreq.o $(OUTPUT)../lib/sysfs.o +else LIBS = -L../ -L$(OUTPUT) -lm -lcpupower - OBJS = $(OUTPUT)main.o $(OUTPUT)parse.o $(OUTPUT)system.o $(OUTPUT)benchmark.o +endif + CFLAGS += -D_GNU_SOURCE -I../lib -DDEFAULT_CONFIG_FILE=\"$(confdir)/cpufreq-bench.conf\" $(OUTPUT)%.o : %.c From ce512b84045459f4a6c119a109c950c6bc4a6f3a Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 1 Dec 2015 17:14:15 +0100 Subject: [PATCH 3/6] cpupower: Do not analyse offlined cpus Use sysfs_is_cpu_online(cpu) instead of cpufreq_cpu_exists(cpu) to detect offlined cpus. Re-arrange printfs slightly to have a consistent output even if you have multiple CPUs as output and even if offlined cores are in between. Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki --- tools/power/cpupower/utils/cpufreq-info.c | 11 ++++++++--- tools/power/cpupower/utils/cpuidle-info.c | 16 ++++++++++------ tools/power/cpupower/utils/cpupower-info.c | 9 ++++++--- tools/power/cpupower/utils/cpupower-set.c | 10 +++++++--- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index 0e6764330241..522b357f4110 100644 --- a/tools/power/cpupower/utils/cpufreq-info.c +++ b/tools/power/cpupower/utils/cpufreq-info.c @@ -14,6 +14,7 @@ #include #include "cpufreq.h" +#include "helpers/sysfs.h" #include "helpers/helpers.h" #include "helpers/bitmask.h" @@ -647,11 +648,14 @@ int cmd_freq_info(int argc, char **argv) if (!bitmask_isbitset(cpus_chosen, cpu)) continue; - if (cpufreq_cpu_exists(cpu)) { - printf(_("couldn't analyze CPU %d as it doesn't seem to be present\n"), cpu); + + printf(_("analyzing CPU %d:\n"), cpu); + + if (sysfs_is_cpu_online(cpu) != 1) { + printf(_(" *is offline\n")); + printf("\n"); continue; } - printf(_("analyzing CPU %d:\n"), cpu); switch (output_param) { case 'b': @@ -693,6 +697,7 @@ int cmd_freq_info(int argc, char **argv) } if (ret) return ret; + printf("\n"); } return ret; } diff --git a/tools/power/cpupower/utils/cpuidle-info.c b/tools/power/cpupower/utils/cpuidle-info.c index 750c1d82c3f7..8bf8ab5ffa25 100644 --- a/tools/power/cpupower/utils/cpuidle-info.c +++ b/tools/power/cpupower/utils/cpuidle-info.c @@ -12,7 +12,6 @@ #include #include #include -#include #include "helpers/helpers.h" #include "helpers/sysfs.h" @@ -25,8 +24,6 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose) unsigned int idlestates, idlestate; char *tmp; - printf(_ ("Analyzing CPU %d:\n"), cpu); - idlestates = sysfs_get_idlestate_count(cpu); if (idlestates == 0) { printf(_("CPU %u: No idle states\n"), cpu); @@ -71,7 +68,6 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose) printf(_("Duration: %llu\n"), sysfs_get_idlestate_time(cpu, idlestate)); } - printf("\n"); } static void cpuidle_general_output(void) @@ -189,10 +185,17 @@ int cmd_idle_info(int argc, char **argv) for (cpu = bitmask_first(cpus_chosen); cpu <= bitmask_last(cpus_chosen); cpu++) { - if (!bitmask_isbitset(cpus_chosen, cpu) || - cpufreq_cpu_exists(cpu)) + if (!bitmask_isbitset(cpus_chosen, cpu)) continue; + printf(_("analyzing CPU %d:\n"), cpu); + + if (sysfs_is_cpu_online(cpu) != 1) { + printf(_(" *is offline\n")); + printf("\n"); + continue; + } + switch (output_param) { case 'o': @@ -203,6 +206,7 @@ int cmd_idle_info(int argc, char **argv) cpuidle_cpu_output(cpu, verbose); break; } + printf("\n"); } return EXIT_SUCCESS; } diff --git a/tools/power/cpupower/utils/cpupower-info.c b/tools/power/cpupower/utils/cpupower-info.c index 10299f2e9d2a..c7caa8eaa6d0 100644 --- a/tools/power/cpupower/utils/cpupower-info.c +++ b/tools/power/cpupower/utils/cpupower-info.c @@ -12,7 +12,6 @@ #include #include -#include #include "helpers/helpers.h" #include "helpers/sysfs.h" @@ -83,12 +82,16 @@ int cmd_info(int argc, char **argv) for (cpu = bitmask_first(cpus_chosen); cpu <= bitmask_last(cpus_chosen); cpu++) { - if (!bitmask_isbitset(cpus_chosen, cpu) || - cpufreq_cpu_exists(cpu)) + if (!bitmask_isbitset(cpus_chosen, cpu)) continue; printf(_("analyzing CPU %d:\n"), cpu); + if (sysfs_is_cpu_online(cpu) != 1){ + printf(_(" *is offline\n")); + continue; + } + if (params.perf_bias) { ret = msr_intel_get_perf_bias(cpu); if (ret < 0) { diff --git a/tools/power/cpupower/utils/cpupower-set.c b/tools/power/cpupower/utils/cpupower-set.c index 3e6f374f8dd7..532f46b9a335 100644 --- a/tools/power/cpupower/utils/cpupower-set.c +++ b/tools/power/cpupower/utils/cpupower-set.c @@ -12,7 +12,6 @@ #include #include -#include #include "helpers/helpers.h" #include "helpers/sysfs.h" #include "helpers/bitmask.h" @@ -78,10 +77,15 @@ int cmd_set(int argc, char **argv) for (cpu = bitmask_first(cpus_chosen); cpu <= bitmask_last(cpus_chosen); cpu++) { - if (!bitmask_isbitset(cpus_chosen, cpu) || - cpufreq_cpu_exists(cpu)) + if (!bitmask_isbitset(cpus_chosen, cpu)) continue; + if (sysfs_is_cpu_online(cpu) != 1){ + fprintf(stderr, _("Cannot set values on CPU %d:"), cpu); + fprintf(stderr, _(" *is offline\n")); + continue; + } + if (params.perf_bias) { ret = msr_intel_set_perf_bias(cpu, perf_bias); if (ret) { From 562e5f1a352977f45d0d0ed3279b556d3e41e1ba Mon Sep 17 00:00:00 2001 From: Jacob Tanenbaum Date: Tue, 1 Dec 2015 17:14:16 +0100 Subject: [PATCH 4/6] cpupower: rework the "cpupower frequency-info" command this patch makes two changes to the way that "cpupower frequancy-info" operates 1. make it so that querying individual values always returns a message to the user currently cpupower frequency info doesn't return anything to the user when querying an individual value cannot be returned [root@amd-dinar-09 cpupower]# cpupower -c 4 frequency-info -d analyzing CPU 4: [root@amd-dinar-09 cpupower]# I added messages so that each query prints a message to the terminal [root@amd-dinar-09 cpupower]# ./cpupower -c 4 frequency-info -d analyzing CPU 4: no or unknown cpufreq driver is active on this CPU [root@amd-dinar-09 cpupower]# (this is just one example) 2. change debug_output_one() to use the functions already provided by cpufreq-info.c to query individual values of interest. Signed-off-by: Jacob Tanenbaum Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki --- tools/power/cpupower/utils/cpufreq-info.c | 235 ++++++++-------------- 1 file changed, 88 insertions(+), 147 deletions(-) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index 522b357f4110..c13bc8c7c860 100644 --- a/tools/power/cpupower/utils/cpufreq-info.c +++ b/tools/power/cpupower/utils/cpufreq-info.c @@ -245,149 +245,21 @@ static int get_boost_mode(unsigned int cpu) return 0; } -static void debug_output_one(unsigned int cpu) -{ - char *driver; - struct cpufreq_affected_cpus *cpus; - struct cpufreq_available_frequencies *freqs; - unsigned long min, max, freq_kernel, freq_hardware; - unsigned long total_trans, latency; - unsigned long long total_time; - struct cpufreq_policy *policy; - struct cpufreq_available_governors *governors; - struct cpufreq_stats *stats; - - if (cpufreq_cpu_exists(cpu)) - return; - - freq_kernel = cpufreq_get_freq_kernel(cpu); - freq_hardware = cpufreq_get_freq_hardware(cpu); - - driver = cpufreq_get_driver(cpu); - if (!driver) { - printf(_(" no or unknown cpufreq driver is active on this CPU\n")); - } else { - printf(_(" driver: %s\n"), driver); - cpufreq_put_driver(driver); - } - - cpus = cpufreq_get_related_cpus(cpu); - if (cpus) { - printf(_(" CPUs which run at the same hardware frequency: ")); - while (cpus->next) { - printf("%d ", cpus->cpu); - cpus = cpus->next; - } - printf("%d\n", cpus->cpu); - cpufreq_put_related_cpus(cpus); - } - - cpus = cpufreq_get_affected_cpus(cpu); - if (cpus) { - printf(_(" CPUs which need to have their frequency coordinated by software: ")); - while (cpus->next) { - printf("%d ", cpus->cpu); - cpus = cpus->next; - } - printf("%d\n", cpus->cpu); - cpufreq_put_affected_cpus(cpus); - } - - latency = cpufreq_get_transition_latency(cpu); - if (latency) { - printf(_(" maximum transition latency: ")); - print_duration(latency); - printf(".\n"); - } - - if (!(cpufreq_get_hardware_limits(cpu, &min, &max))) { - printf(_(" hardware limits: ")); - print_speed(min); - printf(" - "); - print_speed(max); - printf("\n"); - } - - freqs = cpufreq_get_available_frequencies(cpu); - if (freqs) { - printf(_(" available frequency steps: ")); - while (freqs->next) { - print_speed(freqs->frequency); - printf(", "); - freqs = freqs->next; - } - print_speed(freqs->frequency); - printf("\n"); - cpufreq_put_available_frequencies(freqs); - } - - governors = cpufreq_get_available_governors(cpu); - if (governors) { - printf(_(" available cpufreq governors: ")); - while (governors->next) { - printf("%s, ", governors->governor); - governors = governors->next; - } - printf("%s\n", governors->governor); - cpufreq_put_available_governors(governors); - } - - policy = cpufreq_get_policy(cpu); - if (policy) { - printf(_(" current policy: frequency should be within ")); - print_speed(policy->min); - printf(_(" and ")); - print_speed(policy->max); - - printf(".\n "); - printf(_("The governor \"%s\" may" - " decide which speed to use\n within this range.\n"), - policy->governor); - cpufreq_put_policy(policy); - } - - if (freq_kernel || freq_hardware) { - printf(_(" current CPU frequency is ")); - if (freq_hardware) { - print_speed(freq_hardware); - printf(_(" (asserted by call to hardware)")); - } else - print_speed(freq_kernel); - printf(".\n"); - } - stats = cpufreq_get_stats(cpu, &total_time); - if (stats) { - printf(_(" cpufreq stats: ")); - while (stats) { - print_speed(stats->frequency); - printf(":%.2f%%", (100.0 * stats->time_in_state) / total_time); - stats = stats->next; - if (stats) - printf(", "); - } - cpufreq_put_stats(stats); - total_trans = cpufreq_get_transitions(cpu); - if (total_trans) - printf(" (%lu)\n", total_trans); - else - printf("\n"); - } - get_boost_mode(cpu); - -} - /* --freq / -f */ static int get_freq_kernel(unsigned int cpu, unsigned int human) { unsigned long freq = cpufreq_get_freq_kernel(cpu); - if (!freq) + printf(_(" current CPU frequency: ")); + if (!freq) { + printf(_(" Unable to call to kernel\n")); return -EINVAL; + } if (human) { print_speed(freq); - printf("\n"); } else - printf("%lu\n", freq); + printf("%lu", freq); + printf(_(" (asserted by call to kernel)\n")); return 0; } @@ -397,13 +269,16 @@ static int get_freq_kernel(unsigned int cpu, unsigned int human) static int get_freq_hardware(unsigned int cpu, unsigned int human) { unsigned long freq = cpufreq_get_freq_hardware(cpu); - if (!freq) + printf(_(" current CPU frequency: ")); + if (!freq) { + printf("Unable to call hardware\n"); return -EINVAL; + } if (human) { print_speed(freq); - printf("\n"); } else - printf("%lu\n", freq); + printf("%lu", freq); + printf(_(" (asserted by call to hardware)\n")); return 0; } @@ -412,9 +287,17 @@ static int get_freq_hardware(unsigned int cpu, unsigned int human) static int get_hardware_limits(unsigned int cpu) { unsigned long min, max; - if (cpufreq_get_hardware_limits(cpu, &min, &max)) + + printf(_(" hardware limits: ")); + if (cpufreq_get_hardware_limits(cpu, &min, &max)) { + printf(_("Not Available\n")); return -EINVAL; - printf("%lu %lu\n", min, max); + } + + print_speed(min); + printf(" - "); + print_speed(max); + printf("\n"); return 0; } @@ -423,9 +306,11 @@ static int get_hardware_limits(unsigned int cpu) static int get_driver(unsigned int cpu) { char *driver = cpufreq_get_driver(cpu); - if (!driver) + if (!driver) { + printf(_(" no or unknown cpufreq driver is active on this CPU\n")); return -EINVAL; - printf("%s\n", driver); + } + printf(" driver: %s\n", driver); cpufreq_put_driver(driver); return 0; } @@ -435,9 +320,19 @@ static int get_driver(unsigned int cpu) static int get_policy(unsigned int cpu) { struct cpufreq_policy *policy = cpufreq_get_policy(cpu); - if (!policy) + if (!policy) { + printf(_(" Unable to determine current policy\n")); return -EINVAL; - printf("%lu %lu %s\n", policy->min, policy->max, policy->governor); + } + printf(_(" current policy: frequency should be within ")); + print_speed(policy->min); + printf(_(" and ")); + print_speed(policy->max); + + printf(".\n "); + printf(_("The governor \"%s\" may decide which speed to use\n" + " within this range.\n"), + policy->governor); cpufreq_put_policy(policy); return 0; } @@ -448,8 +343,12 @@ static int get_available_governors(unsigned int cpu) { struct cpufreq_available_governors *governors = cpufreq_get_available_governors(cpu); - if (!governors) + + printf(_(" available cpufreq governors: ")); + if (!governors) { + printf(_("Not Available\n")); return -EINVAL; + } while (governors->next) { printf("%s ", governors->governor); @@ -466,8 +365,12 @@ static int get_available_governors(unsigned int cpu) static int get_affected_cpus(unsigned int cpu) { struct cpufreq_affected_cpus *cpus = cpufreq_get_affected_cpus(cpu); - if (!cpus) + + printf(_(" CPUs which need to have their frequency coordinated by software: ")); + if (!cpus) { + printf(_("Not Available\n")); return -EINVAL; + } while (cpus->next) { printf("%d ", cpus->cpu); @@ -483,8 +386,12 @@ static int get_affected_cpus(unsigned int cpu) static int get_related_cpus(unsigned int cpu) { struct cpufreq_affected_cpus *cpus = cpufreq_get_related_cpus(cpu); - if (!cpus) + + printf(_(" CPUs which run at the same hardware frequency: ")); + if (!cpus) { + printf(_("Not Available\n")); return -EINVAL; + } while (cpus->next) { printf("%d ", cpus->cpu); @@ -525,8 +432,12 @@ static int get_freq_stats(unsigned int cpu, unsigned int human) static int get_latency(unsigned int cpu, unsigned int human) { unsigned long latency = cpufreq_get_transition_latency(cpu); - if (!latency) + + printf(_(" maximum transition latency: ")); + if (!latency) { + printf(_(" Cannot determine latency.\n")); return -EINVAL; + } if (human) { print_duration(latency); @@ -536,6 +447,36 @@ static int get_latency(unsigned int cpu, unsigned int human) return 0; } +static void debug_output_one(unsigned int cpu) +{ + struct cpufreq_available_frequencies *freqs; + + get_driver(cpu); + get_related_cpus(cpu); + get_affected_cpus(cpu); + get_latency(cpu, 1); + get_hardware_limits(cpu); + + freqs = cpufreq_get_available_frequencies(cpu); + if (freqs) { + printf(_(" available frequency steps: ")); + while (freqs->next) { + print_speed(freqs->frequency); + printf(", "); + freqs = freqs->next; + } + print_speed(freqs->frequency); + printf("\n"); + cpufreq_put_available_frequencies(freqs); + } + + get_available_governors(cpu); + get_policy(cpu); + if (get_freq_hardware(cpu, 1) < 0) + get_freq_kernel(cpu, 1); + get_boost_mode(cpu); +} + static struct option info_opts[] = { {"debug", no_argument, NULL, 'e'}, {"boost", no_argument, NULL, 'b'}, From e98f033f94f385a9cf498d4e9f2ac1e6198b545a Mon Sep 17 00:00:00 2001 From: Jacob Tanenbaum Date: Tue, 1 Dec 2015 17:14:17 +0100 Subject: [PATCH 5/6] cpupower: fix how "cpupower frequency-info" interprets latency the intel-pstate driver does not support the ondemand governor and does not have a valid value in /sys/devices/system/cpu/cpu[x]/cpufreq/cpuinfo_transition_latency. The intel-pstate driver sets cpuinfo_transition_latency to CPUFREQ_ETERNAL (-1), the value written into cpuinfo_transition_latency is defind as an unsigned int so checking the read value against max unsigned int will determine if the value is valid. Signed-off-by: Jacob Tanenbaum Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki --- tools/power/cpupower/utils/cpufreq-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index c13bc8c7c860..8f3f5bb9c74e 100644 --- a/tools/power/cpupower/utils/cpufreq-info.c +++ b/tools/power/cpupower/utils/cpufreq-info.c @@ -434,8 +434,8 @@ static int get_latency(unsigned int cpu, unsigned int human) unsigned long latency = cpufreq_get_transition_latency(cpu); printf(_(" maximum transition latency: ")); - if (!latency) { - printf(_(" Cannot determine latency.\n")); + if (!latency || latency == UINT_MAX) { + printf(_(" Cannot determine or is not supported.\n")); return -EINVAL; } From a1e9ca6967d68209c70e616a224efa89a6b86ca6 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sat, 2 Jan 2016 03:09:16 +0100 Subject: [PATCH 6/6] PM / sleep: Add support for read-only sysfs attributes Some sysfs attributes in /sys/power/ should really be read-only, so add support for that, convert those attributes to read-only and drop the stub .show() routines from them. Original-by: Sergey Senozhatsky Signed-off-by: Rafael J. Wysocki --- kernel/power/main.c | 17 ++--------------- kernel/power/power.h | 9 +++++++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/kernel/power/main.c b/kernel/power/main.c index b2dd4d999900..27946975eff0 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -280,13 +280,7 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj, return pm_wakeup_irq ? sprintf(buf, "%u\n", pm_wakeup_irq) : -ENODATA; } -static ssize_t pm_wakeup_irq_store(struct kobject *kobj, - struct kobj_attribute *attr, - const char *buf, size_t n) -{ - return -EINVAL; -} -power_attr(pm_wakeup_irq); +power_attr_ro(pm_wakeup_irq); #else /* !CONFIG_PM_SLEEP_DEBUG */ static inline void pm_print_times_init(void) {} @@ -564,14 +558,7 @@ static ssize_t pm_trace_dev_match_show(struct kobject *kobj, return show_trace_dev_match(buf, PAGE_SIZE); } -static ssize_t -pm_trace_dev_match_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t n) -{ - return -EINVAL; -} - -power_attr(pm_trace_dev_match); +power_attr_ro(pm_trace_dev_match); #endif /* CONFIG_PM_TRACE */ diff --git a/kernel/power/power.h b/kernel/power/power.h index caadb566e82b..efe1b3b17c88 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -77,6 +77,15 @@ static struct kobj_attribute _name##_attr = { \ .store = _name##_store, \ } +#define power_attr_ro(_name) \ +static struct kobj_attribute _name##_attr = { \ + .attr = { \ + .name = __stringify(_name), \ + .mode = S_IRUGO, \ + }, \ + .show = _name##_show, \ +} + /* Preferred image size in bytes (default 500 MB) */ extern unsigned long image_size; /* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */