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

sparc64: Refactor MDESC cpu scanning code using an iterator.

Signed-off-by: David S. Miller <davem@davemloft.net>

+90 -57
+1
arch/sparc/include/asm/mdesc.h
··· 72 72 extern void mdesc_register_notifier(struct mdesc_notifier_client *client); 73 73 74 74 extern void mdesc_fill_in_cpu_data(cpumask_t mask); 75 + extern void mdesc_populate_present_mask(cpumask_t *mask); 75 76 76 77 extern void sun4v_mdesc_init(void); 77 78
+89 -57
arch/sparc/kernel/mdesc.c
··· 574 574 mdesc_release(hp); 575 575 } 576 576 577 - static void __devinit fill_in_one_cache(cpuinfo_sparc *c, 577 + static void __cpuinit fill_in_one_cache(cpuinfo_sparc *c, 578 578 struct mdesc_handle *hp, 579 579 u64 mp) 580 580 { ··· 619 619 } 620 620 } 621 621 622 - static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp, 623 - int core_id) 622 + static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id) 624 623 { 625 624 u64 a; 626 625 ··· 652 653 } 653 654 } 654 655 655 - static void __devinit set_core_ids(struct mdesc_handle *hp) 656 + static void __cpuinit set_core_ids(struct mdesc_handle *hp) 656 657 { 657 658 int idx; 658 659 u64 mp; ··· 677 678 } 678 679 } 679 680 680 - static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, 681 - int proc_id) 681 + static void __cpuinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id) 682 682 { 683 683 u64 a; 684 684 ··· 696 698 } 697 699 } 698 700 699 - static void __devinit __set_proc_ids(struct mdesc_handle *hp, 700 - const char *exec_unit_name) 701 + static void __cpuinit __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name) 701 702 { 702 703 int idx; 703 704 u64 mp; ··· 717 720 } 718 721 } 719 722 720 - static void __devinit set_proc_ids(struct mdesc_handle *hp) 723 + static void __cpuinit set_proc_ids(struct mdesc_handle *hp) 721 724 { 722 725 __set_proc_ids(hp, "exec_unit"); 723 726 __set_proc_ids(hp, "exec-unit"); 724 727 } 725 728 726 - static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask, 729 + static void __cpuinit get_one_mondo_bits(const u64 *p, unsigned int *mask, 727 730 unsigned char def) 728 731 { 729 732 u64 val; ··· 742 745 *mask = ((1U << def) * 64U) - 1U; 743 746 } 744 747 745 - static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp, 748 + static void __cpuinit get_mondo_data(struct mdesc_handle *hp, u64 mp, 746 749 struct trap_per_cpu *tb) 747 750 { 748 751 const u64 *val; ··· 760 763 get_one_mondo_bits(val, &tb->nonresum_qmask, 2); 761 764 } 762 765 763 - void __cpuinit mdesc_fill_in_cpu_data(cpumask_t mask) 766 + static void * __cpuinit mdesc_iterate_over_cpus(void *(*func)(struct mdesc_handle *, u64, int, void *), void *arg, cpumask_t *mask) 764 767 { 765 768 struct mdesc_handle *hp = mdesc_grab(); 769 + void *ret = NULL; 766 770 u64 mp; 767 771 768 - ncpus_probed = 0; 769 772 mdesc_for_each_node_by_name(hp, mp, "cpu") { 770 773 const u64 *id = mdesc_get_property(hp, mp, "id", NULL); 771 - const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); 772 - struct trap_per_cpu *tb; 773 - cpuinfo_sparc *c; 774 - int cpuid; 775 - u64 a; 776 - 777 - ncpus_probed++; 778 - 779 - cpuid = *id; 774 + int cpuid = *id; 780 775 781 776 #ifdef CONFIG_SMP 782 777 if (cpuid >= NR_CPUS) { ··· 777 788 cpuid, NR_CPUS); 778 789 continue; 779 790 } 780 - if (!cpu_isset(cpuid, mask)) 791 + if (!cpu_isset(cpuid, *mask)) 781 792 continue; 782 - #else 783 - /* On uniprocessor we only want the values for the 784 - * real physical cpu the kernel booted onto, however 785 - * cpu_data() only has one entry at index 0. 786 - */ 787 - if (cpuid != real_hard_smp_processor_id()) 788 - continue; 789 - cpuid = 0; 790 793 #endif 791 794 792 - c = &cpu_data(cpuid); 793 - c->clock_tick = *cfreq; 795 + ret = func(hp, mp, cpuid, arg); 796 + if (ret) 797 + goto out; 798 + } 799 + out: 800 + mdesc_release(hp); 801 + return ret; 802 + } 794 803 795 - tb = &trap_block[cpuid]; 796 - get_mondo_data(hp, mp, tb); 804 + static void * __cpuinit record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg) 805 + { 806 + ncpus_probed++; 807 + #ifdef CONFIG_SMP 808 + set_cpu_present(cpuid, true); 809 + #endif 810 + return NULL; 811 + } 797 812 798 - mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { 799 - u64 j, t = mdesc_arc_target(hp, a); 800 - const char *t_name; 813 + void __cpuinit mdesc_populate_present_mask(cpumask_t *mask) 814 + { 815 + if (tlb_type != hypervisor) 816 + return; 801 817 802 - t_name = mdesc_node_name(hp, t); 803 - if (!strcmp(t_name, "cache")) { 804 - fill_in_one_cache(c, hp, t); 805 - continue; 806 - } 818 + ncpus_probed = 0; 819 + mdesc_iterate_over_cpus(record_one_cpu, NULL, mask); 820 + } 807 821 808 - mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { 809 - u64 n = mdesc_arc_target(hp, j); 810 - const char *n_name; 822 + static void * __cpuinit fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg) 823 + { 824 + const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); 825 + struct trap_per_cpu *tb; 826 + cpuinfo_sparc *c; 827 + u64 a; 811 828 812 - n_name = mdesc_node_name(hp, n); 813 - if (!strcmp(n_name, "cache")) 814 - fill_in_one_cache(c, hp, n); 815 - } 829 + #ifndef CONFIG_SMP 830 + /* On uniprocessor we only want the values for the 831 + * real physical cpu the kernel booted onto, however 832 + * cpu_data() only has one entry at index 0. 833 + */ 834 + if (cpuid != real_hard_smp_processor_id()) 835 + return NULL; 836 + cpuid = 0; 837 + #endif 838 + 839 + c = &cpu_data(cpuid); 840 + c->clock_tick = *cfreq; 841 + 842 + tb = &trap_block[cpuid]; 843 + get_mondo_data(hp, mp, tb); 844 + 845 + mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { 846 + u64 j, t = mdesc_arc_target(hp, a); 847 + const char *t_name; 848 + 849 + t_name = mdesc_node_name(hp, t); 850 + if (!strcmp(t_name, "cache")) { 851 + fill_in_one_cache(c, hp, t); 852 + continue; 816 853 } 817 854 818 - #ifdef CONFIG_SMP 819 - cpu_set(cpuid, cpu_present_map); 820 - #endif 855 + mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { 856 + u64 n = mdesc_arc_target(hp, j); 857 + const char *n_name; 821 858 822 - c->core_id = 0; 823 - c->proc_id = -1; 859 + n_name = mdesc_node_name(hp, n); 860 + if (!strcmp(n_name, "cache")) 861 + fill_in_one_cache(c, hp, n); 862 + } 824 863 } 864 + 865 + c->core_id = 0; 866 + c->proc_id = -1; 867 + 868 + return NULL; 869 + } 870 + 871 + void __cpuinit mdesc_fill_in_cpu_data(cpumask_t mask) 872 + { 873 + struct mdesc_handle *hp; 874 + 875 + mdesc_populate_present_mask(&mask); 876 + mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, &mask); 825 877 826 878 #ifdef CONFIG_SMP 827 879 sparc64_multi_core = 1; 828 880 #endif 829 881 882 + hp = mdesc_grab(); 883 + 830 884 set_core_ids(hp); 831 885 set_proc_ids(hp); 832 886 833 - smp_fill_in_sib_core_maps(); 834 - 835 887 mdesc_release(hp); 888 + 889 + smp_fill_in_sib_core_maps(); 836 890 } 837 891 838 892 static ssize_t mdesc_read(struct file *file, char __user *buf,