Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[CPUFREQ] ondemand - Use global sysfs dir for tuning settings

Ondemand has only global variables for userspace tunings via sysfs.
But they were exposed per CPU which wrongly implies to the user that
his settings are applied per cpu. Also locking sysfs against concurrent
access won't be necessary anymore after deprecation time.

This means the ondemand config dir is moved:
/sys/devices/system/cpu/cpu*/cpufreq/ondemand ->
/sys/devices/system/cpu/cpufreq/ondemand

The old files will still exist, but reading or writing to them will
result in one (printk_once) deprecation msg to syslog per file.

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Dave Jones <davej@redhat.com>

authored by

Thomas Renninger and committed by
Dave Jones
0e625ac1 8aa84ad8

+113 -26
+113 -26
drivers/cpufreq/cpufreq_ondemand.c
··· 55 55 #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) 56 56 57 57 static void do_dbs_timer(struct work_struct *work); 58 + static int cpufreq_governor_dbs(struct cpufreq_policy *policy, 59 + unsigned int event); 60 + 61 + #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND 62 + static 63 + #endif 64 + struct cpufreq_governor cpufreq_gov_ondemand = { 65 + .name = "ondemand", 66 + .governor = cpufreq_governor_dbs, 67 + .max_transition_latency = TRANSITION_LATENCY_LIMIT, 68 + .owner = THIS_MODULE, 69 + }; 58 70 59 71 /* Sampling types */ 60 72 enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE}; ··· 218 206 } 219 207 220 208 /************************** sysfs interface ************************/ 221 - static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) 209 + 210 + static ssize_t show_sampling_rate_max(struct kobject *kobj, 211 + struct attribute *attr, char *buf) 222 212 { 223 213 printk_once(KERN_INFO "CPUFREQ: ondemand sampling_rate_max " 224 214 "sysfs file is deprecated - used by: %s\n", current->comm); 225 215 return sprintf(buf, "%u\n", -1U); 226 216 } 227 217 228 - static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf) 218 + static ssize_t show_sampling_rate_min(struct kobject *kobj, 219 + struct attribute *attr, char *buf) 229 220 { 230 221 return sprintf(buf, "%u\n", min_sampling_rate); 231 222 } 232 223 233 224 #define define_one_ro(_name) \ 234 - static struct freq_attr _name = \ 225 + static struct global_attr _name = \ 235 226 __ATTR(_name, 0444, show_##_name, NULL) 236 227 237 228 define_one_ro(sampling_rate_max); ··· 243 228 /* cpufreq_ondemand Governor Tunables */ 244 229 #define show_one(file_name, object) \ 245 230 static ssize_t show_##file_name \ 246 - (struct cpufreq_policy *unused, char *buf) \ 231 + (struct kobject *kobj, struct attribute *attr, char *buf) \ 247 232 { \ 248 233 return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ 249 234 } ··· 252 237 show_one(ignore_nice_load, ignore_nice); 253 238 show_one(powersave_bias, powersave_bias); 254 239 255 - static ssize_t store_sampling_rate(struct cpufreq_policy *unused, 256 - const char *buf, size_t count) 240 + /*** delete after deprecation time ***/ 241 + 242 + #define DEPRECATION_MSG(file_name) \ 243 + printk_once(KERN_INFO "CPUFREQ: Per core ondemand sysfs " \ 244 + "interface is deprecated - " #file_name "\n"); 245 + 246 + #define show_one_old(file_name) \ 247 + static ssize_t show_##file_name##_old \ 248 + (struct cpufreq_policy *unused, char *buf) \ 249 + { \ 250 + printk_once(KERN_INFO "CPUFREQ: Per core ondemand sysfs " \ 251 + "interface is deprecated - " #file_name "\n"); \ 252 + return show_##file_name(NULL, NULL, buf); \ 253 + } 254 + show_one_old(sampling_rate); 255 + show_one_old(up_threshold); 256 + show_one_old(ignore_nice_load); 257 + show_one_old(powersave_bias); 258 + show_one_old(sampling_rate_min); 259 + show_one_old(sampling_rate_max); 260 + 261 + #define define_one_ro_old(object, _name) \ 262 + static struct freq_attr object = \ 263 + __ATTR(_name, 0444, show_##_name##_old, NULL) 264 + 265 + define_one_ro_old(sampling_rate_min_old, sampling_rate_min); 266 + define_one_ro_old(sampling_rate_max_old, sampling_rate_max); 267 + 268 + /*** delete after deprecation time ***/ 269 + 270 + static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b, 271 + const char *buf, size_t count) 257 272 { 258 273 unsigned int input; 259 274 int ret; ··· 298 253 return count; 299 254 } 300 255 301 - static ssize_t store_up_threshold(struct cpufreq_policy *unused, 302 - const char *buf, size_t count) 256 + static ssize_t store_up_threshold(struct kobject *a, struct attribute *b, 257 + const char *buf, size_t count) 303 258 { 304 259 unsigned int input; 305 260 int ret; ··· 317 272 return count; 318 273 } 319 274 320 - static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy, 321 - const char *buf, size_t count) 275 + static ssize_t store_ignore_nice_load(struct kobject *a, struct attribute *b, 276 + const char *buf, size_t count) 322 277 { 323 278 unsigned int input; 324 279 int ret; ··· 354 309 return count; 355 310 } 356 311 357 - static ssize_t store_powersave_bias(struct cpufreq_policy *unused, 358 - const char *buf, size_t count) 312 + static ssize_t store_powersave_bias(struct kobject *a, struct attribute *b, 313 + const char *buf, size_t count) 359 314 { 360 315 unsigned int input; 361 316 int ret; ··· 376 331 } 377 332 378 333 #define define_one_rw(_name) \ 379 - static struct freq_attr _name = \ 334 + static struct global_attr _name = \ 380 335 __ATTR(_name, 0644, show_##_name, store_##_name) 381 336 382 337 define_one_rw(sampling_rate); ··· 398 353 .attrs = dbs_attributes, 399 354 .name = "ondemand", 400 355 }; 356 + 357 + /*** delete after deprecation time ***/ 358 + 359 + #define write_one_old(file_name) \ 360 + static ssize_t store_##file_name##_old \ 361 + (struct cpufreq_policy *unused, const char *buf, size_t count) \ 362 + { \ 363 + printk_once(KERN_INFO "CPUFREQ: Per core ondemand sysfs " \ 364 + "interface is deprecated - " #file_name "\n"); \ 365 + return store_##file_name(NULL, NULL, buf, count); \ 366 + } 367 + write_one_old(sampling_rate); 368 + write_one_old(up_threshold); 369 + write_one_old(ignore_nice_load); 370 + write_one_old(powersave_bias); 371 + 372 + #define define_one_rw_old(object, _name) \ 373 + static struct freq_attr object = \ 374 + __ATTR(_name, 0644, show_##_name##_old, store_##_name##_old) 375 + 376 + define_one_rw_old(sampling_rate_old, sampling_rate); 377 + define_one_rw_old(up_threshold_old, up_threshold); 378 + define_one_rw_old(ignore_nice_load_old, ignore_nice_load); 379 + define_one_rw_old(powersave_bias_old, powersave_bias); 380 + 381 + static struct attribute *dbs_attributes_old[] = { 382 + &sampling_rate_max_old.attr, 383 + &sampling_rate_min_old.attr, 384 + &sampling_rate_old.attr, 385 + &up_threshold_old.attr, 386 + &ignore_nice_load_old.attr, 387 + &powersave_bias_old.attr, 388 + NULL 389 + }; 390 + 391 + static struct attribute_group dbs_attr_group_old = { 392 + .attrs = dbs_attributes_old, 393 + .name = "ondemand", 394 + }; 395 + 396 + /*** delete after deprecation time ***/ 401 397 402 398 /************************** sysfs end ************************/ 403 399 ··· 630 544 631 545 mutex_lock(&dbs_mutex); 632 546 633 - rc = sysfs_create_group(&policy->kobj, &dbs_attr_group); 547 + rc = sysfs_create_group(&policy->kobj, &dbs_attr_group_old); 634 548 if (rc) { 635 549 mutex_unlock(&dbs_mutex); 636 550 return rc; ··· 651 565 } 652 566 this_dbs_info->cpu = cpu; 653 567 ondemand_powersave_bias_init_cpu(cpu); 654 - mutex_init(&this_dbs_info->timer_mutex); 655 568 /* 656 569 * Start the timerschedule work, when this governor 657 570 * is used for first time 658 571 */ 659 572 if (dbs_enable == 1) { 660 573 unsigned int latency; 574 + 575 + rc = sysfs_create_group(cpufreq_global_kobject, 576 + &dbs_attr_group); 577 + if (rc) { 578 + mutex_unlock(&dbs_mutex); 579 + return rc; 580 + } 581 + 661 582 /* policy latency is in nS. Convert it to uS first */ 662 583 latency = policy->cpuinfo.transition_latency / 1000; 663 584 if (latency == 0) ··· 678 585 } 679 586 mutex_unlock(&dbs_mutex); 680 587 588 + mutex_init(&this_dbs_info->timer_mutex); 681 589 dbs_timer_init(this_dbs_info); 682 590 break; 683 591 ··· 686 592 dbs_timer_exit(this_dbs_info); 687 593 688 594 mutex_lock(&dbs_mutex); 689 - sysfs_remove_group(&policy->kobj, &dbs_attr_group); 595 + sysfs_remove_group(&policy->kobj, &dbs_attr_group_old); 690 596 mutex_destroy(&this_dbs_info->timer_mutex); 691 597 dbs_enable--; 692 598 mutex_unlock(&dbs_mutex); 599 + if (!dbs_enable) 600 + sysfs_remove_group(cpufreq_global_kobject, 601 + &dbs_attr_group); 693 602 694 603 break; 695 604 ··· 709 612 } 710 613 return 0; 711 614 } 712 - 713 - #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND 714 - static 715 - #endif 716 - struct cpufreq_governor cpufreq_gov_ondemand = { 717 - .name = "ondemand", 718 - .governor = cpufreq_governor_dbs, 719 - .max_transition_latency = TRANSITION_LATENCY_LIMIT, 720 - .owner = THIS_MODULE, 721 - }; 722 615 723 616 static int __init cpufreq_gov_dbs_init(void) 724 617 {