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

drivers base/cacheinfo: Convert to hotplug state machine

Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs. No functional change.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20161103145021.28528-13-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Sebastian Andrzej Siewior and committed by
Thomas Gleixner
7cc277b4 dfbbd86a

+15 -42
+15 -42
drivers/base/cacheinfo.c
··· 498 498 return rc; 499 499 } 500 500 501 - static void cache_remove_dev(unsigned int cpu) 501 + static int cacheinfo_cpu_online(unsigned int cpu) 502 502 { 503 - if (!cpumask_test_cpu(cpu, &cache_dev_map)) 504 - return; 505 - cpumask_clear_cpu(cpu, &cache_dev_map); 503 + int rc = detect_cache_attributes(cpu); 506 504 507 - cpu_cache_sysfs_exit(cpu); 505 + if (rc) 506 + return rc; 507 + rc = cache_add_dev(cpu); 508 + if (rc) 509 + free_cache_attributes(cpu); 510 + return rc; 508 511 } 509 512 510 - static int cacheinfo_cpu_callback(struct notifier_block *nfb, 511 - unsigned long action, void *hcpu) 513 + static int cacheinfo_cpu_pre_down(unsigned int cpu) 512 514 { 513 - unsigned int cpu = (unsigned long)hcpu; 514 - int rc = 0; 515 + if (cpumask_test_and_clear_cpu(cpu, &cache_dev_map)) 516 + cpu_cache_sysfs_exit(cpu); 515 517 516 - switch (action & ~CPU_TASKS_FROZEN) { 517 - case CPU_ONLINE: 518 - rc = detect_cache_attributes(cpu); 519 - if (!rc) 520 - rc = cache_add_dev(cpu); 521 - break; 522 - case CPU_DEAD: 523 - cache_remove_dev(cpu); 524 - free_cache_attributes(cpu); 525 - break; 526 - } 527 - return notifier_from_errno(rc); 518 + free_cache_attributes(cpu); 519 + return 0; 528 520 } 529 521 530 522 static int __init cacheinfo_sysfs_init(void) 531 523 { 532 - int cpu, rc = 0; 533 - 534 - cpu_notifier_register_begin(); 535 - 536 - for_each_online_cpu(cpu) { 537 - rc = detect_cache_attributes(cpu); 538 - if (rc) 539 - goto out; 540 - rc = cache_add_dev(cpu); 541 - if (rc) { 542 - free_cache_attributes(cpu); 543 - pr_err("error populating cacheinfo..cpu%d\n", cpu); 544 - goto out; 545 - } 546 - } 547 - __hotcpu_notifier(cacheinfo_cpu_callback, 0); 548 - 549 - out: 550 - cpu_notifier_register_done(); 551 - return rc; 524 + return cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "base/cacheinfo:online", 525 + cacheinfo_cpu_online, cacheinfo_cpu_pre_down); 552 526 } 553 - 554 527 device_initcall(cacheinfo_sysfs_init);