| 1 | #ifndef _LIB_RING_BUFFER_BACKEND_TYPES_H |
| 2 | #define _LIB_RING_BUFFER_BACKEND_TYPES_H |
| 3 | |
| 4 | /* |
| 5 | * lib/ringbuffer/backend_types.h |
| 6 | * |
| 7 | * Ring buffer backend (types). |
| 8 | * |
| 9 | * Copyright (C) 2008-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; only |
| 14 | * version 2.1 of the License. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Lesser General Public |
| 22 | * License along with this library; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | #include <linux/cpumask.h> |
| 27 | #include <linux/types.h> |
| 28 | |
| 29 | struct lib_ring_buffer_backend_page { |
| 30 | void *virt; /* page virtual address (cached) */ |
| 31 | unsigned long pfn; /* page frame number */ |
| 32 | }; |
| 33 | |
| 34 | struct lib_ring_buffer_backend_pages { |
| 35 | unsigned long mmap_offset; /* offset of the subbuffer in mmap */ |
| 36 | union v_atomic records_commit; /* current records committed count */ |
| 37 | union v_atomic records_unread; /* records to read */ |
| 38 | unsigned long data_size; /* Amount of data to read from subbuf */ |
| 39 | struct lib_ring_buffer_backend_page p[]; |
| 40 | }; |
| 41 | |
| 42 | struct lib_ring_buffer_backend_subbuffer { |
| 43 | /* Identifier for subbuf backend pages. Exchanged atomically. */ |
| 44 | unsigned long id; /* backend subbuffer identifier */ |
| 45 | }; |
| 46 | |
| 47 | struct lib_ring_buffer_backend_counts { |
| 48 | /* |
| 49 | * Counter specific to the sub-buffer location within the ring buffer. |
| 50 | * The actual sequence number of the packet within the entire ring |
| 51 | * buffer can be derived from the formula nr_subbuffers * seq_cnt + |
| 52 | * subbuf_idx. |
| 53 | */ |
| 54 | uint64_t seq_cnt; /* packet sequence number */ |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | * Forward declaration of frontend-specific channel and ring_buffer. |
| 59 | */ |
| 60 | struct channel; |
| 61 | struct lib_ring_buffer; |
| 62 | |
| 63 | struct lib_ring_buffer_backend { |
| 64 | /* Array of ring_buffer_backend_subbuffer for writer */ |
| 65 | struct lib_ring_buffer_backend_subbuffer *buf_wsb; |
| 66 | /* ring_buffer_backend_subbuffer for reader */ |
| 67 | struct lib_ring_buffer_backend_subbuffer buf_rsb; |
| 68 | /* Array of lib_ring_buffer_backend_counts for the packet counter */ |
| 69 | struct lib_ring_buffer_backend_counts *buf_cnt; |
| 70 | /* |
| 71 | * Pointer array of backend pages, for whole buffer. |
| 72 | * Indexed by ring_buffer_backend_subbuffer identifier (id) index. |
| 73 | */ |
| 74 | struct lib_ring_buffer_backend_pages **array; |
| 75 | unsigned int num_pages_per_subbuf; |
| 76 | |
| 77 | struct channel *chan; /* Associated channel */ |
| 78 | int cpu; /* This buffer's cpu. -1 if global. */ |
| 79 | union v_atomic records_read; /* Number of records read */ |
| 80 | unsigned int allocated:1; /* is buffer allocated ? */ |
| 81 | }; |
| 82 | |
| 83 | struct channel_backend { |
| 84 | unsigned long buf_size; /* Size of the buffer */ |
| 85 | unsigned long subbuf_size; /* Sub-buffer size */ |
| 86 | unsigned int subbuf_size_order; /* Order of sub-buffer size */ |
| 87 | unsigned int num_subbuf_order; /* |
| 88 | * Order of number of sub-buffers/buffer |
| 89 | * for writer. |
| 90 | */ |
| 91 | unsigned int buf_size_order; /* Order of buffer size */ |
| 92 | unsigned int extra_reader_sb:1; /* has extra reader subbuffer ? */ |
| 93 | struct lib_ring_buffer *buf; /* Channel per-cpu buffers */ |
| 94 | |
| 95 | unsigned long num_subbuf; /* Number of sub-buffers for writer */ |
| 96 | u64 start_tsc; /* Channel creation TSC value */ |
| 97 | void *priv; /* Client-specific information */ |
| 98 | void *priv_ops; /* Client-specific ops pointer */ |
| 99 | void (*release_priv_ops)(void *priv_ops); |
| 100 | struct notifier_block cpu_hp_notifier; /* CPU hotplug notifier */ |
| 101 | /* |
| 102 | * We need to copy config because the module containing the |
| 103 | * source config can vanish before the last reference to this |
| 104 | * channel's streams is released. |
| 105 | */ |
| 106 | struct lib_ring_buffer_config config; /* Ring buffer configuration */ |
| 107 | cpumask_var_t cpumask; /* Allocated per-cpu buffers cpumask */ |
| 108 | char name[NAME_MAX]; /* Channel name */ |
| 109 | }; |
| 110 | |
| 111 | #endif /* _LIB_RING_BUFFER_BACKEND_TYPES_H */ |