Thomas Gleixner | 25763b3 | 2019-05-28 10:10:09 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Alexei Starovoitov | e19494e | 2016-03-07 21:57:14 -0800 | [diff] [blame] | 2 | /* Copyright (c) 2016 Facebook |
Alexei Starovoitov | e19494e | 2016-03-07 21:57:14 -0800 | [diff] [blame] | 3 | */ |
| 4 | #ifndef __PERCPU_FREELIST_H__ |
| 5 | #define __PERCPU_FREELIST_H__ |
| 6 | #include <linux/spinlock.h> |
| 7 | #include <linux/percpu.h> |
| 8 | |
| 9 | struct pcpu_freelist_head { |
| 10 | struct pcpu_freelist_node *first; |
| 11 | raw_spinlock_t lock; |
| 12 | }; |
| 13 | |
| 14 | struct pcpu_freelist { |
| 15 | struct pcpu_freelist_head __percpu *freelist; |
Song Liu | 39d8f0d | 2020-10-05 09:58:38 -0700 | [diff] [blame] | 16 | struct pcpu_freelist_head extralist; |
Alexei Starovoitov | e19494e | 2016-03-07 21:57:14 -0800 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | struct pcpu_freelist_node { |
| 20 | struct pcpu_freelist_node *next; |
| 21 | }; |
| 22 | |
Alexei Starovoitov | a89fac5 | 2019-01-30 18:12:43 -0800 | [diff] [blame] | 23 | /* pcpu_freelist_* do spin_lock_irqsave. */ |
Alexei Starovoitov | e19494e | 2016-03-07 21:57:14 -0800 | [diff] [blame] | 24 | void pcpu_freelist_push(struct pcpu_freelist *, struct pcpu_freelist_node *); |
| 25 | struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *); |
Alexei Starovoitov | a89fac5 | 2019-01-30 18:12:43 -0800 | [diff] [blame] | 26 | /* __pcpu_freelist_* do spin_lock only. caller must disable irqs. */ |
| 27 | void __pcpu_freelist_push(struct pcpu_freelist *, struct pcpu_freelist_node *); |
| 28 | struct pcpu_freelist_node *__pcpu_freelist_pop(struct pcpu_freelist *); |
Alexei Starovoitov | e19494e | 2016-03-07 21:57:14 -0800 | [diff] [blame] | 29 | void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size, |
| 30 | u32 nr_elems); |
| 31 | int pcpu_freelist_init(struct pcpu_freelist *); |
| 32 | void pcpu_freelist_destroy(struct pcpu_freelist *s); |
| 33 | #endif |