Commit | Line | Data |
---|---|---|
aa5d4c0d JD |
1 | #ifndef LTTNG_TP_MEMPOOL_H |
2 | #define LTTNG_TP_MEMPOOL_H | |
3 | ||
4 | /* | |
5 | * lttng-tp-mempool.h | |
6 | * | |
7 | * Copyright (C) 2018 Julien Desfossez <jdesfossez@efficios.com> | |
8 | * | |
9 | * This library is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License as published by the Free Software Foundation; only | |
12 | * version 2.1 of the License. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Lesser General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Lesser General Public | |
20 | * License along with this library; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 | */ | |
23 | ||
24 | #include <linux/percpu.h> | |
25 | ||
26 | #define LTTNG_TP_MEMPOOL_NR_BUF_PER_CPU 4 | |
27 | #define LTTNG_TP_MEMPOOL_BUF_SIZE 4096 | |
28 | ||
29 | /* | |
30 | * Initialize the pool, only performed once. The pool is a set of | |
31 | * LTTNG_TP_MEMPOOL_NR_BUF_PER_CPU buffers of size LTTNG_TP_MEMPOOL_BUF_SIZE | |
32 | * per-cpu. | |
33 | * | |
34 | * Returns 0 on success, a negative value on error. | |
35 | */ | |
36 | int lttng_tp_mempool_init(void); | |
37 | ||
38 | /* | |
39 | * Destroy the pool and free all the memory allocated. | |
40 | */ | |
41 | void lttng_tp_mempool_destroy(void); | |
42 | ||
43 | /* | |
44 | * Ask for a buffer on the current cpu. | |
45 | * | |
46 | * The pool is per-cpu, but there is no exclusive access guarantee on the | |
47 | * per-cpu free-list, the caller needs to ensure it cannot get preempted or | |
48 | * interrupted while performing the allocation. | |
49 | * | |
50 | * The maximum size that can be allocated is LTTNG_TP_MEMPOOL_BUF_SIZE, and the | |
51 | * maximum number of buffers allocated simultaneously on the same CPU is | |
52 | * LTTNG_TP_MEMPOOL_NR_BUF_PER_CPU. | |
53 | * | |
54 | * Return a pointer to a buffer on success, NULL on error. | |
55 | */ | |
56 | void *lttng_tp_mempool_alloc(size_t size); | |
57 | ||
58 | /* | |
59 | * Release the memory reserved. Same concurrency limitations as the allocation. | |
60 | */ | |
61 | void lttng_tp_mempool_free(void *ptr); | |
62 | ||
63 | #endif /* LTTNG_TP_MEMPOOL_H */ |