numa.c (72cdd117c449896c707fc6cfe5b90978160697d0) | numa.c (c9118e6c37bff9ade90b638207a6e0db676ee6a9) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * pSeries NUMA support 4 * 5 * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM 6 */ 7#define pr_fmt(fmt) "numa: " fmt 8 --- 416 unchanged lines hidden (view full) --- 425 aa->arrays = prop; 426 return 0; 427} 428 429/* 430 * This is like of_node_to_nid_single() for memory represented in the 431 * ibm,dynamic-reconfiguration-memory node. 432 */ | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * pSeries NUMA support 4 * 5 * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM 6 */ 7#define pr_fmt(fmt) "numa: " fmt 8 --- 416 unchanged lines hidden (view full) --- 425 aa->arrays = prop; 426 return 0; 427} 428 429/* 430 * This is like of_node_to_nid_single() for memory represented in the 431 * ibm,dynamic-reconfiguration-memory node. 432 */ |
433int of_drconf_to_nid_single(struct drmem_lmb *lmb) | 433static int of_drconf_to_nid_single(struct drmem_lmb *lmb) |
434{ 435 struct assoc_arrays aa = { .arrays = NULL }; 436 int default_nid = NUMA_NO_NODE; 437 int nid = default_nid; 438 int rc, index; 439 440 if ((min_common_depth < 0) || !numa_enabled) 441 return default_nid; --- 60 unchanged lines hidden (view full) --- 502 * Return the id of the domain used. 503 */ 504static int numa_setup_cpu(unsigned long lcpu) 505{ 506 struct device_node *cpu; 507 int fcpu = cpu_first_thread_sibling(lcpu); 508 int nid = NUMA_NO_NODE; 509 | 434{ 435 struct assoc_arrays aa = { .arrays = NULL }; 436 int default_nid = NUMA_NO_NODE; 437 int nid = default_nid; 438 int rc, index; 439 440 if ((min_common_depth < 0) || !numa_enabled) 441 return default_nid; --- 60 unchanged lines hidden (view full) --- 502 * Return the id of the domain used. 503 */ 504static int numa_setup_cpu(unsigned long lcpu) 505{ 506 struct device_node *cpu; 507 int fcpu = cpu_first_thread_sibling(lcpu); 508 int nid = NUMA_NO_NODE; 509 |
510 if (!cpu_present(lcpu)) { 511 set_cpu_numa_node(lcpu, first_online_node); 512 return first_online_node; 513 } 514 | |
515 /* 516 * If a valid cpu-to-node mapping is already available, use it 517 * directly instead of querying the firmware, since it represents 518 * the most recent mapping notified to us by the platform (eg: VPHN). 519 * Since cpu_to_node binding remains the same for all threads in the 520 * core. If a valid cpu-to-node mapping is already available, for 521 * the first thread in the core, use it. 522 */ --- 200 unchanged lines hidden (view full) --- 723 724 /* 725 * Even though we connect cpus to numa domains later in SMP 726 * init, we need to know the node ids now. This is because 727 * each node to be onlined must have NODE_DATA etc backing it. 728 */ 729 for_each_present_cpu(i) { 730 struct device_node *cpu; | 510 /* 511 * If a valid cpu-to-node mapping is already available, use it 512 * directly instead of querying the firmware, since it represents 513 * the most recent mapping notified to us by the platform (eg: VPHN). 514 * Since cpu_to_node binding remains the same for all threads in the 515 * core. If a valid cpu-to-node mapping is already available, for 516 * the first thread in the core, use it. 517 */ --- 200 unchanged lines hidden (view full) --- 718 719 /* 720 * Even though we connect cpus to numa domains later in SMP 721 * init, we need to know the node ids now. This is because 722 * each node to be onlined must have NODE_DATA etc backing it. 723 */ 724 for_each_present_cpu(i) { 725 struct device_node *cpu; |
731 int nid = vphn_get_nid(i); | 726 int nid; |
732 | 727 |
728 cpu = of_get_cpu_node(i, NULL); 729 BUG_ON(!cpu); 730 nid = of_node_to_nid_single(cpu); 731 of_node_put(cpu); 732 |
|
733 /* 734 * Don't fall back to default_nid yet -- we will plug 735 * cpus into nodes once the memory scan has discovered 736 * the topology. 737 */ | 733 /* 734 * Don't fall back to default_nid yet -- we will plug 735 * cpus into nodes once the memory scan has discovered 736 * the topology. 737 */ |
738 if (nid == NUMA_NO_NODE) { 739 cpu = of_get_cpu_node(i, NULL); 740 BUG_ON(!cpu); 741 nid = of_node_to_nid_single(cpu); 742 of_node_put(cpu); 743 } 744 745 if (likely(nid > 0)) 746 node_set_online(nid); | 738 if (nid < 0) 739 continue; 740 node_set_online(nid); |
747 } 748 749 get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells); 750 751 for_each_node_by_type(memory, "memory") { 752 unsigned long start; 753 unsigned long size; 754 int nid; --- 50 unchanged lines hidden (view full) --- 805} 806 807static void __init setup_nonnuma(void) 808{ 809 unsigned long top_of_ram = memblock_end_of_DRAM(); 810 unsigned long total_ram = memblock_phys_mem_size(); 811 unsigned long start_pfn, end_pfn; 812 unsigned int nid = 0; | 741 } 742 743 get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells); 744 745 for_each_node_by_type(memory, "memory") { 746 unsigned long start; 747 unsigned long size; 748 int nid; --- 50 unchanged lines hidden (view full) --- 799} 800 801static void __init setup_nonnuma(void) 802{ 803 unsigned long top_of_ram = memblock_end_of_DRAM(); 804 unsigned long total_ram = memblock_phys_mem_size(); 805 unsigned long start_pfn, end_pfn; 806 unsigned int nid = 0; |
813 struct memblock_region *reg; | 807 int i; |
814 815 printk(KERN_DEBUG "Top of RAM: 0x%lx, Total RAM: 0x%lx\n", 816 top_of_ram, total_ram); 817 printk(KERN_DEBUG "Memory hole size: %ldMB\n", 818 (top_of_ram - total_ram) >> 20); 819 | 808 809 printk(KERN_DEBUG "Top of RAM: 0x%lx, Total RAM: 0x%lx\n", 810 top_of_ram, total_ram); 811 printk(KERN_DEBUG "Memory hole size: %ldMB\n", 812 (top_of_ram - total_ram) >> 20); 813 |
820 for_each_memblock(memory, reg) { 821 start_pfn = memblock_region_memory_base_pfn(reg); 822 end_pfn = memblock_region_memory_end_pfn(reg); 823 | 814 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL) { |
824 fake_numa_create_new_node(end_pfn, &nid); 825 memblock_set_node(PFN_PHYS(start_pfn), 826 PFN_PHYS(end_pfn - start_pfn), 827 &memblock.memory, nid); 828 node_set_online(nid); 829 } 830} 831 --- 60 unchanged lines hidden (view full) --- 892 NODE_DATA(nid)->node_id = nid; 893 NODE_DATA(nid)->node_start_pfn = start_pfn; 894 NODE_DATA(nid)->node_spanned_pages = spanned_pages; 895} 896 897static void __init find_possible_nodes(void) 898{ 899 struct device_node *rtas; | 815 fake_numa_create_new_node(end_pfn, &nid); 816 memblock_set_node(PFN_PHYS(start_pfn), 817 PFN_PHYS(end_pfn - start_pfn), 818 &memblock.memory, nid); 819 node_set_online(nid); 820 } 821} 822 --- 60 unchanged lines hidden (view full) --- 883 NODE_DATA(nid)->node_id = nid; 884 NODE_DATA(nid)->node_start_pfn = start_pfn; 885 NODE_DATA(nid)->node_spanned_pages = spanned_pages; 886} 887 888static void __init find_possible_nodes(void) 889{ 890 struct device_node *rtas; |
900 const __be32 *domains; 901 int prop_length, max_nodes; 902 u32 i; | 891 u32 numnodes, i; |
903 904 if (!numa_enabled) 905 return; 906 907 rtas = of_find_node_by_path("/rtas"); 908 if (!rtas) 909 return; 910 | 892 893 if (!numa_enabled) 894 return; 895 896 rtas = of_find_node_by_path("/rtas"); 897 if (!rtas) 898 return; 899 |
911 /* 912 * ibm,current-associativity-domains is a fairly recent property. If 913 * it doesn't exist, then fallback on ibm,max-associativity-domains. 914 * Current denotes what the platform can support compared to max 915 * which denotes what the Hypervisor can support. 916 */ 917 domains = of_get_property(rtas, "ibm,current-associativity-domains", 918 &prop_length); 919 if (!domains) { 920 domains = of_get_property(rtas, "ibm,max-associativity-domains", 921 &prop_length); 922 if (!domains) 923 goto out; 924 } | 900 if (of_property_read_u32_index(rtas, 901 "ibm,max-associativity-domains", 902 min_common_depth, &numnodes)) 903 goto out; |
925 | 904 |
926 max_nodes = of_read_number(&domains[min_common_depth], 1); 927 for (i = 0; i < max_nodes; i++) { | 905 for (i = 0; i < numnodes; i++) { |
928 if (!node_possible(i)) 929 node_set(i, node_possible_map); 930 } 931 | 906 if (!node_possible(i)) 907 node_set(i, node_possible_map); 908 } 909 |
932 prop_length /= sizeof(int); 933 if (prop_length > min_common_depth + 2) 934 coregroup_enabled = 1; 935 | |
936out: 937 of_node_put(rtas); 938} 939 940void __init mem_topology_setup(void) 941{ 942 int cpu; 943 | 910out: 911 of_node_put(rtas); 912} 913 914void __init mem_topology_setup(void) 915{ 916 int cpu; 917 |
944 /* 945 * Linux/mm assumes node 0 to be online at boot. However this is not 946 * true on PowerPC, where node 0 is similar to any other node, it 947 * could be cpuless, memoryless node. So force node 0 to be offline 948 * for now. This will prevent cpuless, memoryless node 0 showing up 949 * unnecessarily as online. If a node has cpus or memory that need 950 * to be online, then node will anyway be marked online. 951 */ 952 node_set_offline(0); 953 | |
954 if (parse_numa_properties()) 955 setup_nonnuma(); 956 957 /* 958 * Modify the set of possible NUMA nodes to reflect information 959 * available about the set of online nodes, and the set of nodes 960 * that we expect to make use of for this platform's affinity 961 * calculations. 962 */ 963 nodes_and(node_possible_map, node_possible_map, node_online_map); 964 965 find_possible_nodes(); 966 967 setup_node_to_cpumask_map(); 968 969 reset_numa_cpu_lookup_table(); 970 | 918 if (parse_numa_properties()) 919 setup_nonnuma(); 920 921 /* 922 * Modify the set of possible NUMA nodes to reflect information 923 * available about the set of online nodes, and the set of nodes 924 * that we expect to make use of for this platform's affinity 925 * calculations. 926 */ 927 nodes_and(node_possible_map, node_possible_map, node_online_map); 928 929 find_possible_nodes(); 930 931 setup_node_to_cpumask_map(); 932 933 reset_numa_cpu_lookup_table(); 934 |
971 for_each_possible_cpu(cpu) { 972 /* 973 * Powerpc with CONFIG_NUMA always used to have a node 0, 974 * even if it was memoryless or cpuless. For all cpus that 975 * are possible but not present, cpu_to_node() would point 976 * to node 0. To remove a cpuless, memoryless dummy node, 977 * powerpc need to make sure all possible but not present 978 * cpu_to_node are set to a proper node. 979 */ | 935 for_each_present_cpu(cpu) |
980 numa_setup_cpu(cpu); | 936 numa_setup_cpu(cpu); |
981 } | |
982} 983 984void __init initmem_init(void) 985{ 986 int nid; 987 988 max_low_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT; 989 max_pfn = max_low_pfn; --- 250 unchanged lines hidden (view full) --- 1240#endif 1241 } 1242 1243 pr_debug("%s:%d cpu %d nid %d\n", __FUNCTION__, __LINE__, 1244 cpu, new_nid); 1245 return new_nid; 1246} 1247 | 937} 938 939void __init initmem_init(void) 940{ 941 int nid; 942 943 max_low_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT; 944 max_pfn = max_low_pfn; --- 250 unchanged lines hidden (view full) --- 1195#endif 1196 } 1197 1198 pr_debug("%s:%d cpu %d nid %d\n", __FUNCTION__, __LINE__, 1199 cpu, new_nid); 1200 return new_nid; 1201} 1202 |
1248int cpu_to_coregroup_id(int cpu) 1249{ 1250 __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0}; 1251 int index; 1252 1253 if (cpu < 0 || cpu > nr_cpu_ids) 1254 return -1; 1255 1256 if (!coregroup_enabled) 1257 goto out; 1258 1259 if (!firmware_has_feature(FW_FEATURE_VPHN)) 1260 goto out; 1261 1262 if (vphn_get_associativity(cpu, associativity)) 1263 goto out; 1264 1265 index = of_read_number(associativity, 1); 1266 if (index > min_common_depth + 1) 1267 return of_read_number(&associativity[index - 1], 1); 1268 1269out: 1270 return cpu_to_core_id(cpu); 1271} 1272 | |
1273static int topology_update_init(void) 1274{ 1275 topology_inited = 1; 1276 return 0; 1277} 1278device_initcall(topology_update_init); 1279#endif /* CONFIG_PPC_SPLPAR */ | 1203static int topology_update_init(void) 1204{ 1205 topology_inited = 1; 1206 return 0; 1207} 1208device_initcall(topology_update_init); 1209#endif /* CONFIG_PPC_SPLPAR */ |