diff options
Diffstat (limited to 'kernel/bpf/percpu_freelist.c')
| -rw-r--r-- | kernel/bpf/percpu_freelist.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/kernel/bpf/percpu_freelist.c b/kernel/bpf/percpu_freelist.c index 673fa6fe2d73..0c1b4ba9e90e 100644 --- a/kernel/bpf/percpu_freelist.c +++ b/kernel/bpf/percpu_freelist.c | |||
| @@ -28,8 +28,8 @@ void pcpu_freelist_destroy(struct pcpu_freelist *s) | |||
| 28 | free_percpu(s->freelist); | 28 | free_percpu(s->freelist); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | static inline void __pcpu_freelist_push(struct pcpu_freelist_head *head, | 31 | static inline void ___pcpu_freelist_push(struct pcpu_freelist_head *head, |
| 32 | struct pcpu_freelist_node *node) | 32 | struct pcpu_freelist_node *node) |
| 33 | { | 33 | { |
| 34 | raw_spin_lock(&head->lock); | 34 | raw_spin_lock(&head->lock); |
| 35 | node->next = head->first; | 35 | node->next = head->first; |
| @@ -37,12 +37,22 @@ static inline void __pcpu_freelist_push(struct pcpu_freelist_head *head, | |||
| 37 | raw_spin_unlock(&head->lock); | 37 | raw_spin_unlock(&head->lock); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void pcpu_freelist_push(struct pcpu_freelist *s, | 40 | void __pcpu_freelist_push(struct pcpu_freelist *s, |
| 41 | struct pcpu_freelist_node *node) | 41 | struct pcpu_freelist_node *node) |
| 42 | { | 42 | { |
| 43 | struct pcpu_freelist_head *head = this_cpu_ptr(s->freelist); | 43 | struct pcpu_freelist_head *head = this_cpu_ptr(s->freelist); |
| 44 | 44 | ||
| 45 | __pcpu_freelist_push(head, node); | 45 | ___pcpu_freelist_push(head, node); |
| 46 | } | ||
| 47 | |||
| 48 | void pcpu_freelist_push(struct pcpu_freelist *s, | ||
| 49 | struct pcpu_freelist_node *node) | ||
| 50 | { | ||
| 51 | unsigned long flags; | ||
| 52 | |||
| 53 | local_irq_save(flags); | ||
| 54 | __pcpu_freelist_push(s, node); | ||
| 55 | local_irq_restore(flags); | ||
| 46 | } | 56 | } |
| 47 | 57 | ||
| 48 | void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size, | 58 | void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size, |
| @@ -63,7 +73,7 @@ void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size, | |||
| 63 | for_each_possible_cpu(cpu) { | 73 | for_each_possible_cpu(cpu) { |
| 64 | again: | 74 | again: |
| 65 | head = per_cpu_ptr(s->freelist, cpu); | 75 | head = per_cpu_ptr(s->freelist, cpu); |
| 66 | __pcpu_freelist_push(head, buf); | 76 | ___pcpu_freelist_push(head, buf); |
| 67 | i++; | 77 | i++; |
| 68 | buf += elem_size; | 78 | buf += elem_size; |
| 69 | if (i == nr_elems) | 79 | if (i == nr_elems) |
| @@ -74,14 +84,12 @@ again: | |||
| 74 | local_irq_restore(flags); | 84 | local_irq_restore(flags); |
| 75 | } | 85 | } |
| 76 | 86 | ||
| 77 | struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *s) | 87 | struct pcpu_freelist_node *__pcpu_freelist_pop(struct pcpu_freelist *s) |
| 78 | { | 88 | { |
| 79 | struct pcpu_freelist_head *head; | 89 | struct pcpu_freelist_head *head; |
| 80 | struct pcpu_freelist_node *node; | 90 | struct pcpu_freelist_node *node; |
| 81 | unsigned long flags; | ||
| 82 | int orig_cpu, cpu; | 91 | int orig_cpu, cpu; |
| 83 | 92 | ||
| 84 | local_irq_save(flags); | ||
| 85 | orig_cpu = cpu = raw_smp_processor_id(); | 93 | orig_cpu = cpu = raw_smp_processor_id(); |
| 86 | while (1) { | 94 | while (1) { |
| 87 | head = per_cpu_ptr(s->freelist, cpu); | 95 | head = per_cpu_ptr(s->freelist, cpu); |
| @@ -89,16 +97,25 @@ struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *s) | |||
| 89 | node = head->first; | 97 | node = head->first; |
| 90 | if (node) { | 98 | if (node) { |
| 91 | head->first = node->next; | 99 | head->first = node->next; |
| 92 | raw_spin_unlock_irqrestore(&head->lock, flags); | 100 | raw_spin_unlock(&head->lock); |
| 93 | return node; | 101 | return node; |
| 94 | } | 102 | } |
| 95 | raw_spin_unlock(&head->lock); | 103 | raw_spin_unlock(&head->lock); |
| 96 | cpu = cpumask_next(cpu, cpu_possible_mask); | 104 | cpu = cpumask_next(cpu, cpu_possible_mask); |
| 97 | if (cpu >= nr_cpu_ids) | 105 | if (cpu >= nr_cpu_ids) |
| 98 | cpu = 0; | 106 | cpu = 0; |
| 99 | if (cpu == orig_cpu) { | 107 | if (cpu == orig_cpu) |
| 100 | local_irq_restore(flags); | ||
| 101 | return NULL; | 108 | return NULL; |
| 102 | } | ||
| 103 | } | 109 | } |
| 104 | } | 110 | } |
| 111 | |||
| 112 | struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *s) | ||
| 113 | { | ||
| 114 | struct pcpu_freelist_node *ret; | ||
| 115 | unsigned long flags; | ||
| 116 | |||
| 117 | local_irq_save(flags); | ||
| 118 | ret = __pcpu_freelist_pop(s); | ||
| 119 | local_irq_restore(flags); | ||
| 120 | return ret; | ||
| 121 | } | ||
