Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_PERCPU_H |
| 2 | #define __LINUX_PERCPU_H |
Martin Peschke | 7ff6f08 | 2006-09-25 23:31:21 -0700 | [diff] [blame] | 3 | |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 4 | #include <linux/mmdebug.h> |
Robert P. J. Day | 0a3021f | 2007-07-15 23:39:57 -0700 | [diff] [blame] | 5 | #include <linux/preempt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/smp.h> |
Martin Peschke | 7ff6f08 | 2006-09-25 23:31:21 -0700 | [diff] [blame] | 7 | #include <linux/cpumask.h> |
Steven Rostedt (Red Hat) | 04b74b2 | 2014-11-21 09:16:58 -0500 | [diff] [blame] | 8 | #include <linux/printk.h> |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 9 | #include <linux/pfn.h> |
Tejun Heo | de380b5 | 2010-03-24 17:06:43 +0900 | [diff] [blame] | 10 | #include <linux/init.h> |
Martin Peschke | 7ff6f08 | 2006-09-25 23:31:21 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/percpu.h> |
| 13 | |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 14 | /* enough to cover all DEFINE_PER_CPUs in modules */ |
Jeremy Fitzhardinge | b00742d3 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 15 | #ifdef CONFIG_MODULES |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 16 | #define PERCPU_MODULE_RESERVE (8 << 10) |
Jeremy Fitzhardinge | b00742d3 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 17 | #else |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 18 | #define PERCPU_MODULE_RESERVE 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #endif |
| 20 | |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 21 | #ifndef PERCPU_ENOUGH_ROOM |
Jeremy Fitzhardinge | b00742d3 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 22 | #define PERCPU_ENOUGH_ROOM \ |
Tejun Heo | 6a24290 | 2009-03-06 14:33:58 +0900 | [diff] [blame] | 23 | (ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES) + \ |
| 24 | PERCPU_MODULE_RESERVE) |
| 25 | #endif |
Jeremy Fitzhardinge | b00742d3 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 26 | |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 27 | /* minimum unit size, also is the maximum supported allocation size */ |
Tejun Heo | 6abad5a | 2010-09-03 18:22:47 +0200 | [diff] [blame] | 28 | #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10) |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 29 | |
| 30 | /* |
Tejun Heo | 099a19d | 2010-06-27 18:50:00 +0200 | [diff] [blame] | 31 | * Percpu allocator can serve percpu allocations before slab is |
| 32 | * initialized which allows slab to depend on the percpu allocator. |
| 33 | * The following two parameters decide how much resource to |
| 34 | * preallocate for this. Keep PERCPU_DYNAMIC_RESERVE equal to or |
| 35 | * larger than PERCPU_DYNAMIC_EARLY_SIZE. |
| 36 | */ |
| 37 | #define PERCPU_DYNAMIC_EARLY_SLOTS 128 |
| 38 | #define PERCPU_DYNAMIC_EARLY_SIZE (12 << 10) |
| 39 | |
| 40 | /* |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 41 | * PERCPU_DYNAMIC_RESERVE indicates the amount of free area to piggy |
Tejun Heo | 6b19b0c | 2009-03-06 14:33:59 +0900 | [diff] [blame] | 42 | * back on the first chunk for dynamic percpu allocation if arch is |
| 43 | * manually allocating and mapping it for faster access (as a part of |
| 44 | * large page mapping for example). |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 45 | * |
Tejun Heo | 6b19b0c | 2009-03-06 14:33:59 +0900 | [diff] [blame] | 46 | * The following values give between one and two pages of free space |
| 47 | * after typical minimal boot (2-way SMP, single disk and NIC) with |
| 48 | * both defconfig and a distro config on x86_64 and 32. More |
| 49 | * intelligent way to determine this would be nice. |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 50 | */ |
Tejun Heo | 6b19b0c | 2009-03-06 14:33:59 +0900 | [diff] [blame] | 51 | #if BITS_PER_LONG > 32 |
Tejun Heo | 1a4d760 | 2014-09-02 14:46:05 -0400 | [diff] [blame] | 52 | #define PERCPU_DYNAMIC_RESERVE (28 << 10) |
Tejun Heo | 6b19b0c | 2009-03-06 14:33:59 +0900 | [diff] [blame] | 53 | #else |
Tejun Heo | 1a4d760 | 2014-09-02 14:46:05 -0400 | [diff] [blame] | 54 | #define PERCPU_DYNAMIC_RESERVE (20 << 10) |
Tejun Heo | 6b19b0c | 2009-03-06 14:33:59 +0900 | [diff] [blame] | 55 | #endif |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 56 | |
Tejun Heo | fbf59bc | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 57 | extern void *pcpu_base_addr; |
Tejun Heo | fb435d5 | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 58 | extern const unsigned long *pcpu_unit_offsets; |
Tejun Heo | fbf59bc | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 59 | |
Tejun Heo | fd1e8a1 | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 60 | struct pcpu_group_info { |
| 61 | int nr_units; /* aligned # of units */ |
| 62 | unsigned long base_offset; /* base address offset */ |
| 63 | unsigned int *cpu_map; /* unit->cpu map, empty |
| 64 | * entries contain NR_CPUS */ |
| 65 | }; |
| 66 | |
| 67 | struct pcpu_alloc_info { |
| 68 | size_t static_size; |
| 69 | size_t reserved_size; |
| 70 | size_t dyn_size; |
| 71 | size_t unit_size; |
| 72 | size_t atom_size; |
| 73 | size_t alloc_size; |
| 74 | size_t __ai_size; /* internal, don't use */ |
| 75 | int nr_groups; /* 0 if grouping unnecessary */ |
| 76 | struct pcpu_group_info groups[]; |
| 77 | }; |
| 78 | |
Tejun Heo | f58dc01 | 2009-08-14 15:00:50 +0900 | [diff] [blame] | 79 | enum pcpu_fc { |
| 80 | PCPU_FC_AUTO, |
| 81 | PCPU_FC_EMBED, |
| 82 | PCPU_FC_PAGE, |
Tejun Heo | f58dc01 | 2009-08-14 15:00:50 +0900 | [diff] [blame] | 83 | |
| 84 | PCPU_FC_NR, |
| 85 | }; |
Andi Kleen | 17f3609 | 2012-10-04 17:12:07 -0700 | [diff] [blame] | 86 | extern const char * const pcpu_fc_names[PCPU_FC_NR]; |
Tejun Heo | f58dc01 | 2009-08-14 15:00:50 +0900 | [diff] [blame] | 87 | |
| 88 | extern enum pcpu_fc pcpu_chosen_fc; |
| 89 | |
Tejun Heo | 3cbc856 | 2009-08-14 15:00:50 +0900 | [diff] [blame] | 90 | typedef void * (*pcpu_fc_alloc_fn_t)(unsigned int cpu, size_t size, |
| 91 | size_t align); |
Tejun Heo | d4b95f8 | 2009-07-04 08:10:59 +0900 | [diff] [blame] | 92 | typedef void (*pcpu_fc_free_fn_t)(void *ptr, size_t size); |
| 93 | typedef void (*pcpu_fc_populate_pte_fn_t)(unsigned long addr); |
Tejun Heo | a530b79 | 2009-07-04 08:11:00 +0900 | [diff] [blame] | 94 | typedef int (pcpu_fc_cpu_distance_fn_t)(unsigned int from, unsigned int to); |
Tejun Heo | fbf59bc | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 95 | |
Tejun Heo | fd1e8a1 | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 96 | extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups, |
| 97 | int nr_units); |
| 98 | extern void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai); |
Tejun Heo | 033e48f | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 99 | |
Tejun Heo | fb435d5 | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 100 | extern int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, |
| 101 | void *base_addr); |
Tejun Heo | 8d408b4 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 102 | |
Tejun Heo | 08fc458 | 2009-08-14 15:00:49 +0900 | [diff] [blame] | 103 | #ifdef CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK |
Tejun Heo | 4ba6ce2 | 2010-06-27 18:49:59 +0200 | [diff] [blame] | 104 | extern int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, |
Tejun Heo | c8826dd | 2009-08-14 15:00:52 +0900 | [diff] [blame] | 105 | size_t atom_size, |
| 106 | pcpu_fc_cpu_distance_fn_t cpu_distance_fn, |
| 107 | pcpu_fc_alloc_fn_t alloc_fn, |
| 108 | pcpu_fc_free_fn_t free_fn); |
Tejun Heo | 08fc458 | 2009-08-14 15:00:49 +0900 | [diff] [blame] | 109 | #endif |
Tejun Heo | 66c3a75 | 2009-03-10 16:27:48 +0900 | [diff] [blame] | 110 | |
Tejun Heo | 08fc458 | 2009-08-14 15:00:49 +0900 | [diff] [blame] | 111 | #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK |
Tejun Heo | fb435d5 | 2009-08-14 15:00:51 +0900 | [diff] [blame] | 112 | extern int __init pcpu_page_first_chunk(size_t reserved_size, |
Tejun Heo | d4b95f8 | 2009-07-04 08:10:59 +0900 | [diff] [blame] | 113 | pcpu_fc_alloc_fn_t alloc_fn, |
| 114 | pcpu_fc_free_fn_t free_fn, |
| 115 | pcpu_fc_populate_pte_fn_t populate_pte_fn); |
Tejun Heo | 08fc458 | 2009-08-14 15:00:49 +0900 | [diff] [blame] | 116 | #endif |
Tejun Heo | d4b95f8 | 2009-07-04 08:10:59 +0900 | [diff] [blame] | 117 | |
Rusty Russell | e0fdb0e | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 118 | extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align); |
Tejun Heo | 10fad5e | 2010-03-10 18:57:54 +0900 | [diff] [blame] | 119 | extern bool is_kernel_percpu_address(unsigned long addr); |
Tejun Heo | f2a8205 | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 120 | |
Tejun Heo | bbddff0 | 2010-09-03 18:22:48 +0200 | [diff] [blame] | 121 | #if !defined(CONFIG_SMP) || !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) |
Tejun Heo | e74e396 | 2009-03-30 19:07:44 +0900 | [diff] [blame] | 122 | extern void __init setup_per_cpu_areas(void); |
| 123 | #endif |
Tejun Heo | 099a19d | 2010-06-27 18:50:00 +0200 | [diff] [blame] | 124 | extern void __init percpu_init_late(void); |
Tejun Heo | e74e396 | 2009-03-30 19:07:44 +0900 | [diff] [blame] | 125 | |
Tejun Heo | 5835d96 | 2014-09-02 14:46:04 -0400 | [diff] [blame] | 126 | extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp); |
Tejun Heo | de380b5 | 2010-03-24 17:06:43 +0900 | [diff] [blame] | 127 | extern void __percpu *__alloc_percpu(size_t size, size_t align); |
| 128 | extern void free_percpu(void __percpu *__pdata); |
| 129 | extern phys_addr_t per_cpu_ptr_to_phys(void *addr); |
| 130 | |
Tejun Heo | 5835d96 | 2014-09-02 14:46:04 -0400 | [diff] [blame] | 131 | #define alloc_percpu_gfp(type, gfp) \ |
| 132 | (typeof(type) __percpu *)__alloc_percpu_gfp(sizeof(type), \ |
| 133 | __alignof__(type), gfp) |
| 134 | #define alloc_percpu(type) \ |
| 135 | (typeof(type) __percpu *)__alloc_percpu(sizeof(type), \ |
| 136 | __alignof__(type)) |
Tejun Heo | f2a8205 | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 137 | |
Steven Rostedt (Red Hat) | afdc34a | 2014-06-19 17:33:31 -0400 | [diff] [blame] | 138 | /* To avoid include hell, as printk can not declare this, we declare it here */ |
| 139 | DECLARE_PER_CPU(printk_func_t, printk_func); |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #endif /* __LINUX_PERCPU_H */ |