aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2009-08-14 02:00:51 -0400
committerTejun Heo <tj@kernel.org>2009-08-14 02:00:51 -0400
commitfd1e8a1fe2b54df6c185b4fa65f181f50b9c4d4e (patch)
treed4411507baacaa33c68be7813ad6f9e0d93a74e2 /arch
parent033e48fb82958053113178264ddb9d5038d5e38b (diff)
percpu: introduce pcpu_alloc_info and pcpu_group_info
Till now, non-linear cpu->unit map was expressed using an integer array which maps each cpu to a unit and used only by lpage allocator. Although how many units have been placed in a single contiguos area (group) is known while building unit_map, the information is lost when the result is recorded into the unit_map array. For lpage allocator, as all allocations are done by lpages and whether two adjacent lpages are in the same group or not is irrelevant, this didn't cause any problem. Non-linear cpu->unit mapping will be used for sparse embedding and this grouping information is necessary for that. This patch introduces pcpu_alloc_info which contains all the information necessary for initializing percpu allocator. pcpu_alloc_info contains array of pcpu_group_info which describes how units are grouped and mapped to cpus. pcpu_group_info also has base_offset field to specify its offset from the chunk's base address. pcpu_build_alloc_info() initializes this field as if all groups are allocated back-to-back as is currently done but this will be used to sparsely place groups. pcpu_alloc_info is a rather complex data structure which contains a flexible array which in turn points to nested cpu_map arrays. * pcpu_alloc_alloc_info() and pcpu_free_alloc_info() are provided to help dealing with pcpu_alloc_info. * pcpu_lpage_build_unit_map() is updated to build pcpu_alloc_info, generalized and renamed to pcpu_build_alloc_info(). @cpu_distance_fn may be NULL indicating that all cpus are of LOCAL_DISTANCE. * pcpul_lpage_dump_cfg() is updated to process pcpu_alloc_info, generalized and renamed to pcpu_dump_alloc_info(). It now also prints which group each alloc unit belongs to. * pcpu_setup_first_chunk() now takes pcpu_alloc_info instead of the separate parameters. All first chunk allocators are updated to use pcpu_build_alloc_info() to build alloc_info and call pcpu_setup_first_chunk() with it. This has the side effect of packing units for sparse possible cpus. ie. if cpus 0, 2 and 4 are possible, they'll be assigned unit 0, 1 and 2 instead of 0, 2 and 4. * x86 setup_pcpu_lpage() is updated to deal with alloc_info. * sparc64 setup_per_cpu_areas() is updated to build alloc_info. Although the changes made by this patch are pretty pervasive, it doesn't cause any behavior difference other than packing of sparse cpus. It mostly changes how information is passed among initialization functions and makes room for more flexibility. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: David Miller <davem@davemloft.net>
Diffstat (limited to 'arch')
-rw-r--r--arch/sparc/kernel/smp_64.c24
-rw-r--r--arch/x86/kernel/setup_percpu.c38
2 files changed, 32 insertions, 30 deletions
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index 9856d866b77b..a42a4a744d14 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -1475,17 +1475,29 @@ static void __init pcpu_map_range(unsigned long start, unsigned long end,
1475 1475
1476void __init setup_per_cpu_areas(void) 1476void __init setup_per_cpu_areas(void)
1477{ 1477{
1478 size_t dyn_size, static_size = __per_cpu_end - __per_cpu_start;
1479 static struct vm_struct vm; 1478 static struct vm_struct vm;
1479 struct pcpu_alloc_info *ai;
1480 unsigned long delta, cpu; 1480 unsigned long delta, cpu;
1481 size_t size_sum, pcpu_unit_size; 1481 size_t size_sum, pcpu_unit_size;
1482 size_t ptrs_size; 1482 size_t ptrs_size;
1483 void **ptrs; 1483 void **ptrs;
1484 1484
1485 size_sum = PFN_ALIGN(static_size + PERCPU_MODULE_RESERVE + 1485 ai = pcpu_alloc_alloc_info(1, nr_cpu_ids);
1486
1487 ai->static_size = __per_cpu_end - __per_cpu_start;
1488 ai->reserved_size = PERCPU_MODULE_RESERVE;
1489
1490 size_sum = PFN_ALIGN(ai->static_size + ai->reserved_size +
1486 PERCPU_DYNAMIC_RESERVE); 1491 PERCPU_DYNAMIC_RESERVE);
1487 dyn_size = size_sum - static_size - PERCPU_MODULE_RESERVE;
1488 1492
1493 ai->dyn_size = size_sum - ai->static_size - ai->reserved_size;
1494 ai->unit_size = PCPU_CHUNK_SIZE;
1495 ai->atom_size = PCPU_CHUNK_SIZE;
1496 ai->alloc_size = PCPU_CHUNK_SIZE;
1497 ai->groups[0].nr_units = nr_cpu_ids;
1498
1499 for_each_possible_cpu(cpu)
1500 ai->groups[0].cpu_map[cpu] = cpu;
1489 1501
1490 ptrs_size = PFN_ALIGN(nr_cpu_ids * sizeof(ptrs[0])); 1502 ptrs_size = PFN_ALIGN(nr_cpu_ids * sizeof(ptrs[0]));
1491 ptrs = alloc_bootmem(ptrs_size); 1503 ptrs = alloc_bootmem(ptrs_size);
@@ -1497,7 +1509,7 @@ void __init setup_per_cpu_areas(void)
1497 free_bootmem(__pa(ptrs[cpu] + size_sum), 1509 free_bootmem(__pa(ptrs[cpu] + size_sum),
1498 PCPU_CHUNK_SIZE - size_sum); 1510 PCPU_CHUNK_SIZE - size_sum);
1499 1511
1500 memcpy(ptrs[cpu], __per_cpu_load, static_size); 1512 memcpy(ptrs[cpu], __per_cpu_load, ai->static_size);
1501 } 1513 }
1502 1514
1503 /* allocate address and map */ 1515 /* allocate address and map */
@@ -1514,9 +1526,7 @@ void __init setup_per_cpu_areas(void)
1514 pcpu_map_range(start, end, virt_to_page(ptrs[cpu])); 1526 pcpu_map_range(start, end, virt_to_page(ptrs[cpu]));
1515 } 1527 }
1516 1528
1517 pcpu_unit_size = pcpu_setup_first_chunk(static_size, 1529 pcpu_unit_size = pcpu_setup_first_chunk(ai, vm.addr);
1518 PERCPU_MODULE_RESERVE, dyn_size,
1519 PCPU_CHUNK_SIZE, vm.addr, NULL);
1520 1530
1521 free_bootmem(__pa(ptrs), ptrs_size); 1531 free_bootmem(__pa(ptrs), ptrs_size);
1522 1532
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index 660cde133141..db5f9c49fec5 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -161,9 +161,7 @@ static ssize_t __init setup_pcpu_lpage(bool chosen)
161{ 161{
162 size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; 162 size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
163 size_t dyn_size = reserve - PERCPU_FIRST_CHUNK_RESERVE; 163 size_t dyn_size = reserve - PERCPU_FIRST_CHUNK_RESERVE;
164 size_t unit_map_size, unit_size; 164 struct pcpu_alloc_info *ai;
165 int *unit_map;
166 int nr_units;
167 ssize_t ret; 165 ssize_t ret;
168 166
169 /* on non-NUMA, embedding is better */ 167 /* on non-NUMA, embedding is better */
@@ -177,26 +175,22 @@ static ssize_t __init setup_pcpu_lpage(bool chosen)
177 } 175 }
178 176
179 /* allocate and build unit_map */ 177 /* allocate and build unit_map */
180 unit_map_size = nr_cpu_ids * sizeof(int); 178 ai = pcpu_build_alloc_info(PERCPU_FIRST_CHUNK_RESERVE, dyn_size,
181 unit_map = alloc_bootmem_nopanic(unit_map_size); 179 PMD_SIZE, pcpu_lpage_cpu_distance);
182 if (!unit_map) { 180 if (IS_ERR(ai)) {
183 pr_warning("PERCPU: failed to allocate unit_map\n"); 181 pr_warning("PERCPU: failed to build unit_map (%ld)\n",
184 return -ENOMEM; 182 PTR_ERR(ai));
183 return PTR_ERR(ai);
185 } 184 }
186 185
187 ret = pcpu_lpage_build_unit_map(PERCPU_FIRST_CHUNK_RESERVE,
188 &dyn_size, &unit_size, PMD_SIZE,
189 unit_map, pcpu_lpage_cpu_distance);
190 if (ret < 0) {
191 pr_warning("PERCPU: failed to build unit_map\n");
192 goto out_free;
193 }
194 nr_units = ret;
195
196 /* do the parameters look okay? */ 186 /* do the parameters look okay? */
197 if (!chosen) { 187 if (!chosen) {
198 size_t vm_size = VMALLOC_END - VMALLOC_START; 188 size_t vm_size = VMALLOC_END - VMALLOC_START;
199 size_t tot_size = nr_units * unit_size; 189 size_t tot_size = 0;
190 int group;
191
192 for (group = 0; group < ai->nr_groups; group++)
193 tot_size += ai->unit_size * ai->groups[group].nr_units;
200 194
201 /* don't consume more than 20% of vmalloc area */ 195 /* don't consume more than 20% of vmalloc area */
202 if (tot_size > vm_size / 5) { 196 if (tot_size > vm_size / 5) {
@@ -207,12 +201,10 @@ static ssize_t __init setup_pcpu_lpage(bool chosen)
207 } 201 }
208 } 202 }
209 203
210 ret = pcpu_lpage_first_chunk(PERCPU_FIRST_CHUNK_RESERVE, dyn_size, 204 ret = pcpu_lpage_first_chunk(ai, pcpu_fc_alloc, pcpu_fc_free,
211 unit_size, PMD_SIZE, unit_map, nr_units, 205 pcpul_map);
212 pcpu_fc_alloc, pcpu_fc_free, pcpul_map);
213out_free: 206out_free:
214 if (ret < 0) 207 pcpu_free_alloc_info(ai);
215 free_bootmem(__pa(unit_map), unit_map_size);
216 return ret; 208 return ret;
217} 209}
218#else 210#else