Commit 6dad2a29646ce3792c40cfc52d77e9b65a7bb143

Authored by Borislav Petkov
Committed by H. Peter Anvin
1 parent 679370641e

cpufreq: Unify sysfs attribute definition macros

Multiple modules used to define those which are with identical
functionality and were needlessly replicated among the different cpufreq
drivers. Push them into the header and remove duplication.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
LKML-Reference: <1270065406-1814-7-git-send-email-bp@amd64.org>
Reviewed-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>

Showing 4 changed files with 72 additions and 86 deletions Side-by-side Diff

drivers/cpufreq/cpufreq.c
... ... @@ -662,32 +662,20 @@
662 662 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
663 663 }
664 664  
665   -#define define_one_ro(_name) \
666   -static struct freq_attr _name = \
667   -__ATTR(_name, 0444, show_##_name, NULL)
668   -
669   -#define define_one_ro0400(_name) \
670   -static struct freq_attr _name = \
671   -__ATTR(_name, 0400, show_##_name, NULL)
672   -
673   -#define define_one_rw(_name) \
674   -static struct freq_attr _name = \
675   -__ATTR(_name, 0644, show_##_name, store_##_name)
676   -
677   -define_one_ro0400(cpuinfo_cur_freq);
678   -define_one_ro(cpuinfo_min_freq);
679   -define_one_ro(cpuinfo_max_freq);
680   -define_one_ro(cpuinfo_transition_latency);
681   -define_one_ro(scaling_available_governors);
682   -define_one_ro(scaling_driver);
683   -define_one_ro(scaling_cur_freq);
684   -define_one_ro(bios_limit);
685   -define_one_ro(related_cpus);
686   -define_one_ro(affected_cpus);
687   -define_one_rw(scaling_min_freq);
688   -define_one_rw(scaling_max_freq);
689   -define_one_rw(scaling_governor);
690   -define_one_rw(scaling_setspeed);
  665 +cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
  666 +cpufreq_freq_attr_ro(cpuinfo_min_freq);
  667 +cpufreq_freq_attr_ro(cpuinfo_max_freq);
  668 +cpufreq_freq_attr_ro(cpuinfo_transition_latency);
  669 +cpufreq_freq_attr_ro(scaling_available_governors);
  670 +cpufreq_freq_attr_ro(scaling_driver);
  671 +cpufreq_freq_attr_ro(scaling_cur_freq);
  672 +cpufreq_freq_attr_ro(bios_limit);
  673 +cpufreq_freq_attr_ro(related_cpus);
  674 +cpufreq_freq_attr_ro(affected_cpus);
  675 +cpufreq_freq_attr_rw(scaling_min_freq);
  676 +cpufreq_freq_attr_rw(scaling_max_freq);
  677 +cpufreq_freq_attr_rw(scaling_governor);
  678 +cpufreq_freq_attr_rw(scaling_setspeed);
691 679  
692 680 static struct attribute *default_attrs[] = {
693 681 &cpuinfo_min_freq.attr,
drivers/cpufreq/cpufreq_conservative.c
... ... @@ -178,13 +178,9 @@
178 178 return sprintf(buf, "%u\n", min_sampling_rate);
179 179 }
180 180  
181   -#define define_one_ro(_name) \
182   -static struct global_attr _name = \
183   -__ATTR(_name, 0444, show_##_name, NULL)
  181 +define_one_global_ro(sampling_rate_max);
  182 +define_one_global_ro(sampling_rate_min);
184 183  
185   -define_one_ro(sampling_rate_max);
186   -define_one_ro(sampling_rate_min);
187   -
188 184 /* cpufreq_conservative Governor Tunables */
189 185 #define show_one(file_name, object) \
190 186 static ssize_t show_##file_name \
191 187  
... ... @@ -221,13 +217,9 @@
221 217 show_one_old(sampling_rate_min);
222 218 show_one_old(sampling_rate_max);
223 219  
224   -#define define_one_ro_old(object, _name) \
225   -static struct freq_attr object = \
226   -__ATTR(_name, 0444, show_##_name##_old, NULL)
  220 +cpufreq_freq_attr_ro_old(sampling_rate_min);
  221 +cpufreq_freq_attr_ro_old(sampling_rate_max);
227 222  
228   -define_one_ro_old(sampling_rate_min_old, sampling_rate_min);
229   -define_one_ro_old(sampling_rate_max_old, sampling_rate_max);
230   -
231 223 /*** delete after deprecation time ***/
232 224  
233 225 static ssize_t store_sampling_down_factor(struct kobject *a,
234 226  
... ... @@ -364,17 +356,13 @@
364 356 return count;
365 357 }
366 358  
367   -#define define_one_rw(_name) \
368   -static struct global_attr _name = \
369   -__ATTR(_name, 0644, show_##_name, store_##_name)
  359 +define_one_global_rw(sampling_rate);
  360 +define_one_global_rw(sampling_down_factor);
  361 +define_one_global_rw(up_threshold);
  362 +define_one_global_rw(down_threshold);
  363 +define_one_global_rw(ignore_nice_load);
  364 +define_one_global_rw(freq_step);
370 365  
371   -define_one_rw(sampling_rate);
372   -define_one_rw(sampling_down_factor);
373   -define_one_rw(up_threshold);
374   -define_one_rw(down_threshold);
375   -define_one_rw(ignore_nice_load);
376   -define_one_rw(freq_step);
377   -
378 366 static struct attribute *dbs_attributes[] = {
379 367 &sampling_rate_max.attr,
380 368 &sampling_rate_min.attr,
... ... @@ -409,16 +397,12 @@
409 397 write_one_old(ignore_nice_load);
410 398 write_one_old(freq_step);
411 399  
412   -#define define_one_rw_old(object, _name) \
413   -static struct freq_attr object = \
414   -__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
415   -
416   -define_one_rw_old(sampling_rate_old, sampling_rate);
417   -define_one_rw_old(sampling_down_factor_old, sampling_down_factor);
418   -define_one_rw_old(up_threshold_old, up_threshold);
419   -define_one_rw_old(down_threshold_old, down_threshold);
420   -define_one_rw_old(ignore_nice_load_old, ignore_nice_load);
421   -define_one_rw_old(freq_step_old, freq_step);
  400 +cpufreq_freq_attr_rw_old(sampling_rate);
  401 +cpufreq_freq_attr_rw_old(sampling_down_factor);
  402 +cpufreq_freq_attr_rw_old(up_threshold);
  403 +cpufreq_freq_attr_rw_old(down_threshold);
  404 +cpufreq_freq_attr_rw_old(ignore_nice_load);
  405 +cpufreq_freq_attr_rw_old(freq_step);
422 406  
423 407 static struct attribute *dbs_attributes_old[] = {
424 408 &sampling_rate_max_old.attr,
drivers/cpufreq/cpufreq_ondemand.c
... ... @@ -234,13 +234,9 @@
234 234 return sprintf(buf, "%u\n", min_sampling_rate);
235 235 }
236 236  
237   -#define define_one_ro(_name) \
238   -static struct global_attr _name = \
239   -__ATTR(_name, 0444, show_##_name, NULL)
  237 +define_one_global_ro(sampling_rate_max);
  238 +define_one_global_ro(sampling_rate_min);
240 239  
241   -define_one_ro(sampling_rate_max);
242   -define_one_ro(sampling_rate_min);
243   -
244 240 /* cpufreq_ondemand Governor Tunables */
245 241 #define show_one(file_name, object) \
246 242 static ssize_t show_##file_name \
247 243  
... ... @@ -274,13 +270,9 @@
274 270 show_one_old(sampling_rate_min);
275 271 show_one_old(sampling_rate_max);
276 272  
277   -#define define_one_ro_old(object, _name) \
278   -static struct freq_attr object = \
279   -__ATTR(_name, 0444, show_##_name##_old, NULL)
  273 +cpufreq_freq_attr_ro_old(sampling_rate_min);
  274 +cpufreq_freq_attr_ro_old(sampling_rate_max);
280 275  
281   -define_one_ro_old(sampling_rate_min_old, sampling_rate_min);
282   -define_one_ro_old(sampling_rate_max_old, sampling_rate_max);
283   -
284 276 /*** delete after deprecation time ***/
285 277  
286 278 static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b,
287 279  
... ... @@ -376,15 +368,11 @@
376 368 return count;
377 369 }
378 370  
379   -#define define_one_rw(_name) \
380   -static struct global_attr _name = \
381   -__ATTR(_name, 0644, show_##_name, store_##_name)
  371 +define_one_global_rw(sampling_rate);
  372 +define_one_global_rw(up_threshold);
  373 +define_one_global_rw(ignore_nice_load);
  374 +define_one_global_rw(powersave_bias);
382 375  
383   -define_one_rw(sampling_rate);
384   -define_one_rw(up_threshold);
385   -define_one_rw(ignore_nice_load);
386   -define_one_rw(powersave_bias);
387   -
388 376 static struct attribute *dbs_attributes[] = {
389 377 &sampling_rate_max.attr,
390 378 &sampling_rate_min.attr,
... ... @@ -415,14 +403,10 @@
415 403 write_one_old(ignore_nice_load);
416 404 write_one_old(powersave_bias);
417 405  
418   -#define define_one_rw_old(object, _name) \
419   -static struct freq_attr object = \
420   -__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
421   -
422   -define_one_rw_old(sampling_rate_old, sampling_rate);
423   -define_one_rw_old(up_threshold_old, up_threshold);
424   -define_one_rw_old(ignore_nice_load_old, ignore_nice_load);
425   -define_one_rw_old(powersave_bias_old, powersave_bias);
  406 +cpufreq_freq_attr_rw_old(sampling_rate);
  407 +cpufreq_freq_attr_rw_old(up_threshold);
  408 +cpufreq_freq_attr_rw_old(ignore_nice_load);
  409 +cpufreq_freq_attr_rw_old(powersave_bias);
426 410  
427 411 static struct attribute *dbs_attributes_old[] = {
428 412 &sampling_rate_max_old.attr,
include/linux/cpufreq.h
... ... @@ -278,6 +278,27 @@
278 278 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
279 279 };
280 280  
  281 +#define cpufreq_freq_attr_ro(_name) \
  282 +static struct freq_attr _name = \
  283 +__ATTR(_name, 0444, show_##_name, NULL)
  284 +
  285 +#define cpufreq_freq_attr_ro_perm(_name, _perm) \
  286 +static struct freq_attr _name = \
  287 +__ATTR(_name, _perm, show_##_name, NULL)
  288 +
  289 +#define cpufreq_freq_attr_ro_old(_name) \
  290 +static struct freq_attr _name##_old = \
  291 +__ATTR(_name, 0444, show_##_name##_old, NULL)
  292 +
  293 +#define cpufreq_freq_attr_rw(_name) \
  294 +static struct freq_attr _name = \
  295 +__ATTR(_name, 0644, show_##_name, store_##_name)
  296 +
  297 +#define cpufreq_freq_attr_rw_old(_name) \
  298 +static struct freq_attr _name##_old = \
  299 +__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
  300 +
  301 +
281 302 struct global_attr {
282 303 struct attribute attr;
283 304 ssize_t (*show)(struct kobject *kobj,
... ... @@ -285,6 +306,15 @@
285 306 ssize_t (*store)(struct kobject *a, struct attribute *b,
286 307 const char *c, size_t count);
287 308 };
  309 +
  310 +#define define_one_global_ro(_name) \
  311 +static struct global_attr _name = \
  312 +__ATTR(_name, 0444, show_##_name, NULL)
  313 +
  314 +#define define_one_global_rw(_name) \
  315 +static struct global_attr _name = \
  316 +__ATTR(_name, 0644, show_##_name, store_##_name)
  317 +
288 318  
289 319 /*********************************************************************
290 320 * CPUFREQ 2.6. INTERFACE *