aboutsummaryrefslogtreecommitdiffstats
path: root/mm/percpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/percpu.c')
-rw-r--r--mm/percpu.c407
1 files changed, 237 insertions, 170 deletions
diff --git a/mm/percpu.c b/mm/percpu.c
index 039f51a0dc3f..efe816856a9d 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -76,6 +76,7 @@
76#define PCPU_SLOT_BASE_SHIFT 5 /* 1-31 shares the same slot */ 76#define PCPU_SLOT_BASE_SHIFT 5 /* 1-31 shares the same slot */
77#define PCPU_DFL_MAP_ALLOC 16 /* start a map with 16 ents */ 77#define PCPU_DFL_MAP_ALLOC 16 /* start a map with 16 ents */
78 78
79#ifdef CONFIG_SMP
79/* default addr <-> pcpu_ptr mapping, override in asm/percpu.h if necessary */ 80/* default addr <-> pcpu_ptr mapping, override in asm/percpu.h if necessary */
80#ifndef __addr_to_pcpu_ptr 81#ifndef __addr_to_pcpu_ptr
81#define __addr_to_pcpu_ptr(addr) \ 82#define __addr_to_pcpu_ptr(addr) \
@@ -89,6 +90,11 @@
89 (unsigned long)pcpu_base_addr - \ 90 (unsigned long)pcpu_base_addr - \
90 (unsigned long)__per_cpu_start) 91 (unsigned long)__per_cpu_start)
91#endif 92#endif
93#else /* CONFIG_SMP */
94/* on UP, it's always identity mapped */
95#define __addr_to_pcpu_ptr(addr) (void __percpu *)(addr)
96#define __pcpu_ptr_to_addr(ptr) (void __force *)(ptr)
97#endif /* CONFIG_SMP */
92 98
93struct pcpu_chunk { 99struct pcpu_chunk {
94 struct list_head list; /* linked to pcpu_slot lists */ 100 struct list_head list; /* linked to pcpu_slot lists */
@@ -393,7 +399,9 @@ static int pcpu_extend_area_map(struct pcpu_chunk *chunk, int new_alloc)
393 goto out_unlock; 399 goto out_unlock;
394 400
395 old_size = chunk->map_alloc * sizeof(chunk->map[0]); 401 old_size = chunk->map_alloc * sizeof(chunk->map[0]);
396 memcpy(new, chunk->map, old_size); 402 old = chunk->map;
403
404 memcpy(new, old, old_size);
397 405
398 chunk->map_alloc = new_alloc; 406 chunk->map_alloc = new_alloc;
399 chunk->map = new; 407 chunk->map = new;
@@ -818,8 +826,8 @@ fail_unlock_mutex:
818 * @size: size of area to allocate in bytes 826 * @size: size of area to allocate in bytes
819 * @align: alignment of area (max PAGE_SIZE) 827 * @align: alignment of area (max PAGE_SIZE)
820 * 828 *
821 * Allocate percpu area of @size bytes aligned at @align. Might 829 * Allocate zero-filled percpu area of @size bytes aligned at @align.
822 * sleep. Might trigger writeouts. 830 * Might sleep. Might trigger writeouts.
823 * 831 *
824 * CONTEXT: 832 * CONTEXT:
825 * Does GFP_KERNEL allocation. 833 * Does GFP_KERNEL allocation.
@@ -838,9 +846,10 @@ EXPORT_SYMBOL_GPL(__alloc_percpu);
838 * @size: size of area to allocate in bytes 846 * @size: size of area to allocate in bytes
839 * @align: alignment of area (max PAGE_SIZE) 847 * @align: alignment of area (max PAGE_SIZE)
840 * 848 *
841 * Allocate percpu area of @size bytes aligned at @align from reserved 849 * Allocate zero-filled percpu area of @size bytes aligned at @align
842 * percpu area if arch has set it up; otherwise, allocation is served 850 * from reserved percpu area if arch has set it up; otherwise,
843 * from the same dynamic area. Might sleep. Might trigger writeouts. 851 * allocation is served from the same dynamic area. Might sleep.
852 * Might trigger writeouts.
844 * 853 *
845 * CONTEXT: 854 * CONTEXT:
846 * Does GFP_KERNEL allocation. 855 * Does GFP_KERNEL allocation.
@@ -947,6 +956,7 @@ EXPORT_SYMBOL_GPL(free_percpu);
947 */ 956 */
948bool is_kernel_percpu_address(unsigned long addr) 957bool is_kernel_percpu_address(unsigned long addr)
949{ 958{
959#ifdef CONFIG_SMP
950 const size_t static_size = __per_cpu_end - __per_cpu_start; 960 const size_t static_size = __per_cpu_end - __per_cpu_start;
951 void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr); 961 void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr);
952 unsigned int cpu; 962 unsigned int cpu;
@@ -957,6 +967,8 @@ bool is_kernel_percpu_address(unsigned long addr)
957 if ((void *)addr >= start && (void *)addr < start + static_size) 967 if ((void *)addr >= start && (void *)addr < start + static_size)
958 return true; 968 return true;
959 } 969 }
970#endif
971 /* on UP, can't distinguish from other static vars, always false */
960 return false; 972 return false;
961} 973}
962 974
@@ -1065,161 +1077,6 @@ void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai)
1065} 1077}
1066 1078
1067/** 1079/**
1068 * pcpu_build_alloc_info - build alloc_info considering distances between CPUs
1069 * @reserved_size: the size of reserved percpu area in bytes
1070 * @dyn_size: minimum free size for dynamic allocation in bytes
1071 * @atom_size: allocation atom size
1072 * @cpu_distance_fn: callback to determine distance between cpus, optional
1073 *
1074 * This function determines grouping of units, their mappings to cpus
1075 * and other parameters considering needed percpu size, allocation
1076 * atom size and distances between CPUs.
1077 *
1078 * Groups are always mutliples of atom size and CPUs which are of
1079 * LOCAL_DISTANCE both ways are grouped together and share space for
1080 * units in the same group. The returned configuration is guaranteed
1081 * to have CPUs on different nodes on different groups and >=75% usage
1082 * of allocated virtual address space.
1083 *
1084 * RETURNS:
1085 * On success, pointer to the new allocation_info is returned. On
1086 * failure, ERR_PTR value is returned.
1087 */
1088static struct pcpu_alloc_info * __init pcpu_build_alloc_info(
1089 size_t reserved_size, size_t dyn_size,
1090 size_t atom_size,
1091 pcpu_fc_cpu_distance_fn_t cpu_distance_fn)
1092{
1093 static int group_map[NR_CPUS] __initdata;
1094 static int group_cnt[NR_CPUS] __initdata;
1095 const size_t static_size = __per_cpu_end - __per_cpu_start;
1096 int nr_groups = 1, nr_units = 0;
1097 size_t size_sum, min_unit_size, alloc_size;
1098 int upa, max_upa, uninitialized_var(best_upa); /* units_per_alloc */
1099 int last_allocs, group, unit;
1100 unsigned int cpu, tcpu;
1101 struct pcpu_alloc_info *ai;
1102 unsigned int *cpu_map;
1103
1104 /* this function may be called multiple times */
1105 memset(group_map, 0, sizeof(group_map));
1106 memset(group_cnt, 0, sizeof(group_cnt));
1107
1108 /* calculate size_sum and ensure dyn_size is enough for early alloc */
1109 size_sum = PFN_ALIGN(static_size + reserved_size +
1110 max_t(size_t, dyn_size, PERCPU_DYNAMIC_EARLY_SIZE));
1111 dyn_size = size_sum - static_size - reserved_size;
1112
1113 /*
1114 * Determine min_unit_size, alloc_size and max_upa such that
1115 * alloc_size is multiple of atom_size and is the smallest
1116 * which can accomodate 4k aligned segments which are equal to
1117 * or larger than min_unit_size.
1118 */
1119 min_unit_size = max_t(size_t, size_sum, PCPU_MIN_UNIT_SIZE);
1120
1121 alloc_size = roundup(min_unit_size, atom_size);
1122 upa = alloc_size / min_unit_size;
1123 while (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
1124 upa--;
1125 max_upa = upa;
1126
1127 /* group cpus according to their proximity */
1128 for_each_possible_cpu(cpu) {
1129 group = 0;
1130 next_group:
1131 for_each_possible_cpu(tcpu) {
1132 if (cpu == tcpu)
1133 break;
1134 if (group_map[tcpu] == group && cpu_distance_fn &&
1135 (cpu_distance_fn(cpu, tcpu) > LOCAL_DISTANCE ||
1136 cpu_distance_fn(tcpu, cpu) > LOCAL_DISTANCE)) {
1137 group++;
1138 nr_groups = max(nr_groups, group + 1);
1139 goto next_group;
1140 }
1141 }
1142 group_map[cpu] = group;
1143 group_cnt[group]++;
1144 }
1145
1146 /*
1147 * Expand unit size until address space usage goes over 75%
1148 * and then as much as possible without using more address
1149 * space.
1150 */
1151 last_allocs = INT_MAX;
1152 for (upa = max_upa; upa; upa--) {
1153 int allocs = 0, wasted = 0;
1154
1155 if (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
1156 continue;
1157
1158 for (group = 0; group < nr_groups; group++) {
1159 int this_allocs = DIV_ROUND_UP(group_cnt[group], upa);
1160 allocs += this_allocs;
1161 wasted += this_allocs * upa - group_cnt[group];
1162 }
1163
1164 /*
1165 * Don't accept if wastage is over 25%. The
1166 * greater-than comparison ensures upa==1 always
1167 * passes the following check.
1168 */
1169 if (wasted > num_possible_cpus() / 3)
1170 continue;
1171
1172 /* and then don't consume more memory */
1173 if (allocs > last_allocs)
1174 break;
1175 last_allocs = allocs;
1176 best_upa = upa;
1177 }
1178 upa = best_upa;
1179
1180 /* allocate and fill alloc_info */
1181 for (group = 0; group < nr_groups; group++)
1182 nr_units += roundup(group_cnt[group], upa);
1183
1184 ai = pcpu_alloc_alloc_info(nr_groups, nr_units);
1185 if (!ai)
1186 return ERR_PTR(-ENOMEM);
1187 cpu_map = ai->groups[0].cpu_map;
1188
1189 for (group = 0; group < nr_groups; group++) {
1190 ai->groups[group].cpu_map = cpu_map;
1191 cpu_map += roundup(group_cnt[group], upa);
1192 }
1193
1194 ai->static_size = static_size;
1195 ai->reserved_size = reserved_size;
1196 ai->dyn_size = dyn_size;
1197 ai->unit_size = alloc_size / upa;
1198 ai->atom_size = atom_size;
1199 ai->alloc_size = alloc_size;
1200
1201 for (group = 0, unit = 0; group_cnt[group]; group++) {
1202 struct pcpu_group_info *gi = &ai->groups[group];
1203
1204 /*
1205 * Initialize base_offset as if all groups are located
1206 * back-to-back. The caller should update this to
1207 * reflect actual allocation.
1208 */
1209 gi->base_offset = unit * ai->unit_size;
1210
1211 for_each_possible_cpu(cpu)
1212 if (group_map[cpu] == group)
1213 gi->cpu_map[gi->nr_units++] = cpu;
1214 gi->nr_units = roundup(gi->nr_units, upa);
1215 unit += gi->nr_units;
1216 }
1217 BUG_ON(unit != nr_units);
1218
1219 return ai;
1220}
1221
1222/**
1223 * pcpu_dump_alloc_info - print out information about pcpu_alloc_info 1080 * pcpu_dump_alloc_info - print out information about pcpu_alloc_info
1224 * @lvl: loglevel 1081 * @lvl: loglevel
1225 * @ai: allocation info to dump 1082 * @ai: allocation info to dump
@@ -1361,7 +1218,9 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
1361 1218
1362 /* sanity checks */ 1219 /* sanity checks */
1363 PCPU_SETUP_BUG_ON(ai->nr_groups <= 0); 1220 PCPU_SETUP_BUG_ON(ai->nr_groups <= 0);
1221#ifdef CONFIG_SMP
1364 PCPU_SETUP_BUG_ON(!ai->static_size); 1222 PCPU_SETUP_BUG_ON(!ai->static_size);
1223#endif
1365 PCPU_SETUP_BUG_ON(!base_addr); 1224 PCPU_SETUP_BUG_ON(!base_addr);
1366 PCPU_SETUP_BUG_ON(ai->unit_size < size_sum); 1225 PCPU_SETUP_BUG_ON(ai->unit_size < size_sum);
1367 PCPU_SETUP_BUG_ON(ai->unit_size & ~PAGE_MASK); 1226 PCPU_SETUP_BUG_ON(ai->unit_size & ~PAGE_MASK);
@@ -1399,9 +1258,9 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
1399 1258
1400 if (pcpu_first_unit_cpu == NR_CPUS) 1259 if (pcpu_first_unit_cpu == NR_CPUS)
1401 pcpu_first_unit_cpu = cpu; 1260 pcpu_first_unit_cpu = cpu;
1261 pcpu_last_unit_cpu = cpu;
1402 } 1262 }
1403 } 1263 }
1404 pcpu_last_unit_cpu = cpu;
1405 pcpu_nr_units = unit; 1264 pcpu_nr_units = unit;
1406 1265
1407 for_each_possible_cpu(cpu) 1266 for_each_possible_cpu(cpu)
@@ -1486,6 +1345,8 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
1486 return 0; 1345 return 0;
1487} 1346}
1488 1347
1348#ifdef CONFIG_SMP
1349
1489const char *pcpu_fc_names[PCPU_FC_NR] __initdata = { 1350const char *pcpu_fc_names[PCPU_FC_NR] __initdata = {
1490 [PCPU_FC_AUTO] = "auto", 1351 [PCPU_FC_AUTO] = "auto",
1491 [PCPU_FC_EMBED] = "embed", 1352 [PCPU_FC_EMBED] = "embed",
@@ -1513,8 +1374,180 @@ static int __init percpu_alloc_setup(char *str)
1513} 1374}
1514early_param("percpu_alloc", percpu_alloc_setup); 1375early_param("percpu_alloc", percpu_alloc_setup);
1515 1376
1377/*
1378 * pcpu_embed_first_chunk() is used by the generic percpu setup.
1379 * Build it if needed by the arch config or the generic setup is going
1380 * to be used.
1381 */
1516#if defined(CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK) || \ 1382#if defined(CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK) || \
1517 !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) 1383 !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA)
1384#define BUILD_EMBED_FIRST_CHUNK
1385#endif
1386
1387/* build pcpu_page_first_chunk() iff needed by the arch config */
1388#if defined(CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK)
1389#define BUILD_PAGE_FIRST_CHUNK
1390#endif
1391
1392/* pcpu_build_alloc_info() is used by both embed and page first chunk */
1393#if defined(BUILD_EMBED_FIRST_CHUNK) || defined(BUILD_PAGE_FIRST_CHUNK)
1394/**
1395 * pcpu_build_alloc_info - build alloc_info considering distances between CPUs
1396 * @reserved_size: the size of reserved percpu area in bytes
1397 * @dyn_size: minimum free size for dynamic allocation in bytes
1398 * @atom_size: allocation atom size
1399 * @cpu_distance_fn: callback to determine distance between cpus, optional
1400 *
1401 * This function determines grouping of units, their mappings to cpus
1402 * and other parameters considering needed percpu size, allocation
1403 * atom size and distances between CPUs.
1404 *
1405 * Groups are always mutliples of atom size and CPUs which are of
1406 * LOCAL_DISTANCE both ways are grouped together and share space for
1407 * units in the same group. The returned configuration is guaranteed
1408 * to have CPUs on different nodes on different groups and >=75% usage
1409 * of allocated virtual address space.
1410 *
1411 * RETURNS:
1412 * On success, pointer to the new allocation_info is returned. On
1413 * failure, ERR_PTR value is returned.
1414 */
1415static struct pcpu_alloc_info * __init pcpu_build_alloc_info(
1416 size_t reserved_size, size_t dyn_size,
1417 size_t atom_size,
1418 pcpu_fc_cpu_distance_fn_t cpu_distance_fn)
1419{
1420 static int group_map[NR_CPUS] __initdata;
1421 static int group_cnt[NR_CPUS] __initdata;
1422 const size_t static_size = __per_cpu_end - __per_cpu_start;
1423 int nr_groups = 1, nr_units = 0;
1424 size_t size_sum, min_unit_size, alloc_size;
1425 int upa, max_upa, uninitialized_var(best_upa); /* units_per_alloc */
1426 int last_allocs, group, unit;
1427 unsigned int cpu, tcpu;
1428 struct pcpu_alloc_info *ai;
1429 unsigned int *cpu_map;
1430
1431 /* this function may be called multiple times */
1432 memset(group_map, 0, sizeof(group_map));
1433 memset(group_cnt, 0, sizeof(group_cnt));
1434
1435 /* calculate size_sum and ensure dyn_size is enough for early alloc */
1436 size_sum = PFN_ALIGN(static_size + reserved_size +
1437 max_t(size_t, dyn_size, PERCPU_DYNAMIC_EARLY_SIZE));
1438 dyn_size = size_sum - static_size - reserved_size;
1439
1440 /*
1441 * Determine min_unit_size, alloc_size and max_upa such that
1442 * alloc_size is multiple of atom_size and is the smallest
1443 * which can accomodate 4k aligned segments which are equal to
1444 * or larger than min_unit_size.
1445 */
1446 min_unit_size = max_t(size_t, size_sum, PCPU_MIN_UNIT_SIZE);
1447
1448 alloc_size = roundup(min_unit_size, atom_size);
1449 upa = alloc_size / min_unit_size;
1450 while (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
1451 upa--;
1452 max_upa = upa;
1453
1454 /* group cpus according to their proximity */
1455 for_each_possible_cpu(cpu) {
1456 group = 0;
1457 next_group:
1458 for_each_possible_cpu(tcpu) {
1459 if (cpu == tcpu)
1460 break;
1461 if (group_map[tcpu] == group && cpu_distance_fn &&
1462 (cpu_distance_fn(cpu, tcpu) > LOCAL_DISTANCE ||
1463 cpu_distance_fn(tcpu, cpu) > LOCAL_DISTANCE)) {
1464 group++;
1465 nr_groups = max(nr_groups, group + 1);
1466 goto next_group;
1467 }
1468 }
1469 group_map[cpu] = group;
1470 group_cnt[group]++;
1471 }
1472
1473 /*
1474 * Expand unit size until address space usage goes over 75%
1475 * and then as much as possible without using more address
1476 * space.
1477 */
1478 last_allocs = INT_MAX;
1479 for (upa = max_upa; upa; upa--) {
1480 int allocs = 0, wasted = 0;
1481
1482 if (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
1483 continue;
1484
1485 for (group = 0; group < nr_groups; group++) {
1486 int this_allocs = DIV_ROUND_UP(group_cnt[group], upa);
1487 allocs += this_allocs;
1488 wasted += this_allocs * upa - group_cnt[group];
1489 }
1490
1491 /*
1492 * Don't accept if wastage is over 1/3. The
1493 * greater-than comparison ensures upa==1 always
1494 * passes the following check.
1495 */
1496 if (wasted > num_possible_cpus() / 3)
1497 continue;
1498
1499 /* and then don't consume more memory */
1500 if (allocs > last_allocs)
1501 break;
1502 last_allocs = allocs;
1503 best_upa = upa;
1504 }
1505 upa = best_upa;
1506
1507 /* allocate and fill alloc_info */
1508 for (group = 0; group < nr_groups; group++)
1509 nr_units += roundup(group_cnt[group], upa);
1510
1511 ai = pcpu_alloc_alloc_info(nr_groups, nr_units);
1512 if (!ai)
1513 return ERR_PTR(-ENOMEM);
1514 cpu_map = ai->groups[0].cpu_map;
1515
1516 for (group = 0; group < nr_groups; group++) {
1517 ai->groups[group].cpu_map = cpu_map;
1518 cpu_map += roundup(group_cnt[group], upa);
1519 }
1520
1521 ai->static_size = static_size;
1522 ai->reserved_size = reserved_size;
1523 ai->dyn_size = dyn_size;
1524 ai->unit_size = alloc_size / upa;
1525 ai->atom_size = atom_size;
1526 ai->alloc_size = alloc_size;
1527
1528 for (group = 0, unit = 0; group_cnt[group]; group++) {
1529 struct pcpu_group_info *gi = &ai->groups[group];
1530
1531 /*
1532 * Initialize base_offset as if all groups are located
1533 * back-to-back. The caller should update this to
1534 * reflect actual allocation.
1535 */
1536 gi->base_offset = unit * ai->unit_size;
1537
1538 for_each_possible_cpu(cpu)
1539 if (group_map[cpu] == group)
1540 gi->cpu_map[gi->nr_units++] = cpu;
1541 gi->nr_units = roundup(gi->nr_units, upa);
1542 unit += gi->nr_units;
1543 }
1544 BUG_ON(unit != nr_units);
1545
1546 return ai;
1547}
1548#endif /* BUILD_EMBED_FIRST_CHUNK || BUILD_PAGE_FIRST_CHUNK */
1549
1550#if defined(BUILD_EMBED_FIRST_CHUNK)
1518/** 1551/**
1519 * pcpu_embed_first_chunk - embed the first percpu chunk into bootmem 1552 * pcpu_embed_first_chunk - embed the first percpu chunk into bootmem
1520 * @reserved_size: the size of reserved percpu area in bytes 1553 * @reserved_size: the size of reserved percpu area in bytes
@@ -1643,10 +1676,9 @@ out_free:
1643 free_bootmem(__pa(areas), areas_size); 1676 free_bootmem(__pa(areas), areas_size);
1644 return rc; 1677 return rc;
1645} 1678}
1646#endif /* CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK || 1679#endif /* BUILD_EMBED_FIRST_CHUNK */
1647 !CONFIG_HAVE_SETUP_PER_CPU_AREA */
1648 1680
1649#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK 1681#ifdef BUILD_PAGE_FIRST_CHUNK
1650/** 1682/**
1651 * pcpu_page_first_chunk - map the first chunk using PAGE_SIZE pages 1683 * pcpu_page_first_chunk - map the first chunk using PAGE_SIZE pages
1652 * @reserved_size: the size of reserved percpu area in bytes 1684 * @reserved_size: the size of reserved percpu area in bytes
@@ -1754,10 +1786,11 @@ out_free_ar:
1754 pcpu_free_alloc_info(ai); 1786 pcpu_free_alloc_info(ai);
1755 return rc; 1787 return rc;
1756} 1788}
1757#endif /* CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK */ 1789#endif /* BUILD_PAGE_FIRST_CHUNK */
1758 1790
1791#ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
1759/* 1792/*
1760 * Generic percpu area setup. 1793 * Generic SMP percpu area setup.
1761 * 1794 *
1762 * The embedding helper is used because its behavior closely resembles 1795 * The embedding helper is used because its behavior closely resembles
1763 * the original non-dynamic generic percpu area setup. This is 1796 * the original non-dynamic generic percpu area setup. This is
@@ -1768,7 +1801,6 @@ out_free_ar:
1768 * on the physical linear memory mapping which uses large page 1801 * on the physical linear memory mapping which uses large page
1769 * mappings on applicable archs. 1802 * mappings on applicable archs.
1770 */ 1803 */
1771#ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
1772unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; 1804unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
1773EXPORT_SYMBOL(__per_cpu_offset); 1805EXPORT_SYMBOL(__per_cpu_offset);
1774 1806
@@ -1797,13 +1829,48 @@ void __init setup_per_cpu_areas(void)
1797 PERCPU_DYNAMIC_RESERVE, PAGE_SIZE, NULL, 1829 PERCPU_DYNAMIC_RESERVE, PAGE_SIZE, NULL,
1798 pcpu_dfl_fc_alloc, pcpu_dfl_fc_free); 1830 pcpu_dfl_fc_alloc, pcpu_dfl_fc_free);
1799 if (rc < 0) 1831 if (rc < 0)
1800 panic("Failed to initialized percpu areas."); 1832 panic("Failed to initialize percpu areas.");
1801 1833
1802 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start; 1834 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
1803 for_each_possible_cpu(cpu) 1835 for_each_possible_cpu(cpu)
1804 __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu]; 1836 __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
1805} 1837}
1806#endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */ 1838#endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */
1839
1840#else /* CONFIG_SMP */
1841
1842/*
1843 * UP percpu area setup.
1844 *
1845 * UP always uses km-based percpu allocator with identity mapping.
1846 * Static percpu variables are indistinguishable from the usual static
1847 * variables and don't require any special preparation.
1848 */
1849void __init setup_per_cpu_areas(void)
1850{
1851 const size_t unit_size =
1852 roundup_pow_of_two(max_t(size_t, PCPU_MIN_UNIT_SIZE,
1853 PERCPU_DYNAMIC_RESERVE));
1854 struct pcpu_alloc_info *ai;
1855 void *fc;
1856
1857 ai = pcpu_alloc_alloc_info(1, 1);
1858 fc = __alloc_bootmem(unit_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
1859 if (!ai || !fc)
1860 panic("Failed to allocate memory for percpu areas.");
1861
1862 ai->dyn_size = unit_size;
1863 ai->unit_size = unit_size;
1864 ai->atom_size = unit_size;
1865 ai->alloc_size = unit_size;
1866 ai->groups[0].nr_units = 1;
1867 ai->groups[0].cpu_map[0] = 0;
1868
1869 if (pcpu_setup_first_chunk(ai, fc) < 0)
1870 panic("Failed to initialize percpu areas.");
1871}
1872
1873#endif /* CONFIG_SMP */
1807 1874
1808/* 1875/*
1809 * First and reserved chunks are initialized with temporary allocation 1876 * First and reserved chunks are initialized with temporary allocation