blob: c3960118e617881644f1c726796cc1071face893 [file] [log] [blame]
Alexei Starovoitove19494e2016-03-07 21:57:14 -08001/* Copyright (c) 2016 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#ifndef __PERCPU_FREELIST_H__
8#define __PERCPU_FREELIST_H__
9#include <linux/spinlock.h>
10#include <linux/percpu.h>
11
12struct pcpu_freelist_head {
13 struct pcpu_freelist_node *first;
14 raw_spinlock_t lock;
15};
16
17struct pcpu_freelist {
18 struct pcpu_freelist_head __percpu *freelist;
19};
20
21struct pcpu_freelist_node {
22 struct pcpu_freelist_node *next;
23};
24
Alexei Starovoitova89fac52019-01-30 18:12:43 -080025/* pcpu_freelist_* do spin_lock_irqsave. */
Alexei Starovoitove19494e2016-03-07 21:57:14 -080026void pcpu_freelist_push(struct pcpu_freelist *, struct pcpu_freelist_node *);
27struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *);
Alexei Starovoitova89fac52019-01-30 18:12:43 -080028/* __pcpu_freelist_* do spin_lock only. caller must disable irqs. */
29void __pcpu_freelist_push(struct pcpu_freelist *, struct pcpu_freelist_node *);
30struct pcpu_freelist_node *__pcpu_freelist_pop(struct pcpu_freelist *);
Alexei Starovoitove19494e2016-03-07 21:57:14 -080031void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size,
32 u32 nr_elems);
33int pcpu_freelist_init(struct pcpu_freelist *);
34void pcpu_freelist_destroy(struct pcpu_freelist *s);
35#endif