| 1 | /* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) |
| 2 | * |
| 3 | * ringbuffer/backend_types.h |
| 4 | * |
| 5 | * Ring buffer backend (types). |
| 6 | * |
| 7 | * Copyright (C) 2008-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | */ |
| 9 | |
| 10 | #ifndef _LIB_RING_BUFFER_BACKEND_TYPES_H |
| 11 | #define _LIB_RING_BUFFER_BACKEND_TYPES_H |
| 12 | |
| 13 | #include <linux/cpumask.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <lttng/kernel-version.h> |
| 16 | #include <lttng/cpuhotplug.h> |
| 17 | |
| 18 | struct lib_ring_buffer_backend_page { |
| 19 | void *virt; /* page virtual address (cached) */ |
| 20 | unsigned long pfn; /* page frame number */ |
| 21 | }; |
| 22 | |
| 23 | struct lib_ring_buffer_backend_pages { |
| 24 | unsigned long mmap_offset; /* offset of the subbuffer in mmap */ |
| 25 | union v_atomic records_commit; /* current records committed count */ |
| 26 | union v_atomic records_unread; /* records to read */ |
| 27 | unsigned long data_size; /* Amount of data to read from subbuf */ |
| 28 | struct lib_ring_buffer_backend_page p[]; |
| 29 | }; |
| 30 | |
| 31 | struct lib_ring_buffer_backend_subbuffer { |
| 32 | /* Identifier for subbuf backend pages. Exchanged atomically. */ |
| 33 | unsigned long id; /* backend subbuffer identifier */ |
| 34 | }; |
| 35 | |
| 36 | struct lib_ring_buffer_backend_counts { |
| 37 | /* |
| 38 | * Counter specific to the sub-buffer location within the ring buffer. |
| 39 | * The actual sequence number of the packet within the entire ring |
| 40 | * buffer can be derived from the formula nr_subbuffers * seq_cnt + |
| 41 | * subbuf_idx. |
| 42 | */ |
| 43 | uint64_t seq_cnt; /* packet sequence number */ |
| 44 | }; |
| 45 | |
| 46 | /* |
| 47 | * Forward declaration of frontend-specific channel and ring_buffer. |
| 48 | */ |
| 49 | struct channel; |
| 50 | struct lib_ring_buffer; |
| 51 | |
| 52 | struct lib_ring_buffer_backend { |
| 53 | /* Array of ring_buffer_backend_subbuffer for writer */ |
| 54 | struct lib_ring_buffer_backend_subbuffer *buf_wsb; |
| 55 | /* ring_buffer_backend_subbuffer for reader */ |
| 56 | struct lib_ring_buffer_backend_subbuffer buf_rsb; |
| 57 | /* Array of lib_ring_buffer_backend_counts for the packet counter */ |
| 58 | struct lib_ring_buffer_backend_counts *buf_cnt; |
| 59 | /* |
| 60 | * Pointer array of backend pages, for whole buffer. |
| 61 | * Indexed by ring_buffer_backend_subbuffer identifier (id) index. |
| 62 | */ |
| 63 | struct lib_ring_buffer_backend_pages **array; |
| 64 | unsigned int num_pages_per_subbuf; |
| 65 | |
| 66 | struct channel *chan; /* Associated channel */ |
| 67 | int cpu; /* This buffer's cpu. -1 if global. */ |
| 68 | union v_atomic records_read; /* Number of records read */ |
| 69 | unsigned int allocated:1; /* is buffer allocated ? */ |
| 70 | }; |
| 71 | |
| 72 | struct channel_backend { |
| 73 | unsigned long buf_size; /* Size of the buffer */ |
| 74 | unsigned long subbuf_size; /* Sub-buffer size */ |
| 75 | unsigned int subbuf_size_order; /* Order of sub-buffer size */ |
| 76 | unsigned int num_subbuf_order; /* |
| 77 | * Order of number of sub-buffers/buffer |
| 78 | * for writer. |
| 79 | */ |
| 80 | unsigned int buf_size_order; /* Order of buffer size */ |
| 81 | unsigned int extra_reader_sb:1; /* has extra reader subbuffer ? */ |
| 82 | struct lib_ring_buffer *buf; /* Channel per-cpu buffers */ |
| 83 | |
| 84 | unsigned long num_subbuf; /* Number of sub-buffers for writer */ |
| 85 | u64 start_tsc; /* Channel creation TSC value */ |
| 86 | void *priv; /* Client-specific information */ |
| 87 | void *priv_ops; /* Client-specific ops pointer */ |
| 88 | void (*release_priv_ops)(void *priv_ops); |
| 89 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) |
| 90 | struct lttng_cpuhp_node cpuhp_prepare; /* CPU hotplug prepare */ |
| 91 | #else |
| 92 | struct notifier_block cpu_hp_notifier; /* CPU hotplug notifier */ |
| 93 | #endif |
| 94 | /* |
| 95 | * We need to copy config because the module containing the |
| 96 | * source config can vanish before the last reference to this |
| 97 | * channel's streams is released. |
| 98 | */ |
| 99 | struct lib_ring_buffer_config config; /* Ring buffer configuration */ |
| 100 | cpumask_var_t cpumask; /* Allocated per-cpu buffers cpumask */ |
| 101 | char name[NAME_MAX]; /* Channel name */ |
| 102 | }; |
| 103 | |
| 104 | #endif /* _LIB_RING_BUFFER_BACKEND_TYPES_H */ |