Fix: Argument with 'nonnull' attribute passed null
[lttng-ust.git] / libringbuffer / ring_buffer_backend.c
CommitLineData
852c2936
MD
1/*
2 * ring_buffer_backend.c
3 *
e92f3e28 4 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
852c2936 5 *
e92f3e28
MD
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
852c2936
MD
19 */
20
5ad63a16 21#define _GNU_SOURCE
8ed89704 22#include <unistd.h>
14641deb 23#include <urcu/arch.h>
96e80018 24#include <limits.h>
14641deb 25
4318ae1b 26#include <lttng/ringbuffer-config.h>
2fed87ae 27#include "vatomic.h"
4931a13e
MD
28#include "backend.h"
29#include "frontend.h"
a6352fd4 30#include "smp.h"
431d5cf0 31#include "shm.h"
852c2936
MD
32
33/**
34 * lib_ring_buffer_backend_allocate - allocate a channel buffer
35 * @config: ring buffer instance configuration
36 * @buf: the buffer struct
37 * @size: total size of the buffer
38 * @num_subbuf: number of subbuffers
39 * @extra_reader_sb: need extra subbuffer for reader
40 */
41static
4cfec15c
MD
42int lib_ring_buffer_backend_allocate(const struct lttng_ust_lib_ring_buffer_config *config,
43 struct lttng_ust_lib_ring_buffer_backend *bufb,
852c2936 44 size_t size, size_t num_subbuf,
a6352fd4 45 int extra_reader_sb,
38fae1d3 46 struct lttng_ust_shm_handle *handle,
1d498196 47 struct shm_object *shmobj)
852c2936 48{
1d498196 49 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
852c2936
MD
50 unsigned long subbuf_size, mmap_offset = 0;
51 unsigned long num_subbuf_alloc;
852c2936 52 unsigned long i;
8ed89704 53 long page_size;
852c2936 54
852c2936
MD
55 subbuf_size = chanb->subbuf_size;
56 num_subbuf_alloc = num_subbuf;
57
a6352fd4 58 if (extra_reader_sb)
852c2936 59 num_subbuf_alloc++;
852c2936 60
8ed89704
MD
61 page_size = sysconf(_SC_PAGE_SIZE);
62 if (page_size <= 0) {
63 goto page_size_error;
64 }
65
4cfec15c 66 align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages_shmp));
1d498196 67 set_shmp(bufb->array, zalloc_shm(shmobj,
4cfec15c 68 sizeof(struct lttng_ust_lib_ring_buffer_backend_pages_shmp) * num_subbuf_alloc));
b5a3dfa5 69 if (caa_unlikely(!shmp(handle, bufb->array)))
852c2936
MD
70 goto array_error;
71
431d5cf0
MD
72 /*
73 * This is the largest element (the buffer pages) which needs to
8ed89704 74 * be aligned on page size.
431d5cf0 75 */
8ed89704 76 align_shm(shmobj, page_size);
1d498196 77 set_shmp(bufb->memory_map, zalloc_shm(shmobj,
a6352fd4 78 subbuf_size * num_subbuf_alloc));
b5a3dfa5 79 if (caa_unlikely(!shmp(handle, bufb->memory_map)))
a6352fd4 80 goto memory_map_error;
852c2936
MD
81
82 /* Allocate backend pages array elements */
83 for (i = 0; i < num_subbuf_alloc; i++) {
4cfec15c 84 align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages));
aead2025 85 set_shmp(shmp_index(handle, bufb->array, i)->shmp,
1d498196 86 zalloc_shm(shmobj,
4cfec15c 87 sizeof(struct lttng_ust_lib_ring_buffer_backend_pages)));
4746ae29 88 if (!shmp(handle, shmp_index(handle, bufb->array, i)->shmp))
852c2936
MD
89 goto free_array;
90 }
91
92 /* Allocate write-side subbuffer table */
4cfec15c 93 align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer_backend_subbuffer));
1d498196 94 set_shmp(bufb->buf_wsb, zalloc_shm(shmobj,
4cfec15c 95 sizeof(struct lttng_ust_lib_ring_buffer_backend_subbuffer)
1d498196 96 * num_subbuf));
b5a3dfa5 97 if (caa_unlikely(!shmp(handle, bufb->buf_wsb)))
852c2936
MD
98 goto free_array;
99
100 for (i = 0; i < num_subbuf; i++)
4746ae29 101 shmp_index(handle, bufb->buf_wsb, i)->id = subbuffer_id(config, 0, 1, i);
852c2936
MD
102
103 /* Assign read-side subbuffer table */
104 if (extra_reader_sb)
105 bufb->buf_rsb.id = subbuffer_id(config, 0, 1,
106 num_subbuf_alloc - 1);
107 else
108 bufb->buf_rsb.id = subbuffer_id(config, 0, 1, 0);
109
110 /* Assign pages to page index */
111 for (i = 0; i < num_subbuf_alloc; i++) {
1d498196
MD
112 struct shm_ref ref;
113
114 ref.index = bufb->memory_map._ref.index;
115 ref.offset = bufb->memory_map._ref.offset;
116 ref.offset += i * subbuf_size;
117
4746ae29 118 set_shmp(shmp(handle, shmp_index(handle, bufb->array, i)->shmp)->p,
1d498196 119 ref);
852c2936 120 if (config->output == RING_BUFFER_MMAP) {
4746ae29 121 shmp(handle, shmp_index(handle, bufb->array, i)->shmp)->mmap_offset = mmap_offset;
852c2936
MD
122 mmap_offset += subbuf_size;
123 }
124 }
125
852c2936
MD
126 return 0;
127
128free_array:
a6352fd4
MD
129 /* bufb->array[i] will be freed by shm teardown */
130memory_map_error:
131 /* bufb->array will be freed by shm teardown */
852c2936 132array_error:
8ed89704 133page_size_error:
852c2936
MD
134 return -ENOMEM;
135}
136
4cfec15c 137int lib_ring_buffer_backend_create(struct lttng_ust_lib_ring_buffer_backend *bufb,
a6352fd4 138 struct channel_backend *chanb, int cpu,
38fae1d3 139 struct lttng_ust_shm_handle *handle,
1d498196 140 struct shm_object *shmobj)
852c2936 141{
4cfec15c 142 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
852c2936 143
1d498196 144 set_shmp(bufb->chan, handle->chan._ref);
852c2936
MD
145 bufb->cpu = cpu;
146
147 return lib_ring_buffer_backend_allocate(config, bufb, chanb->buf_size,
148 chanb->num_subbuf,
a6352fd4 149 chanb->extra_reader_sb,
1d498196 150 handle, shmobj);
852c2936
MD
151}
152
4cfec15c 153void lib_ring_buffer_backend_reset(struct lttng_ust_lib_ring_buffer_backend *bufb,
38fae1d3 154 struct lttng_ust_shm_handle *handle)
852c2936 155{
1d498196 156 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
4cfec15c 157 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
852c2936
MD
158 unsigned long num_subbuf_alloc;
159 unsigned int i;
160
161 num_subbuf_alloc = chanb->num_subbuf;
162 if (chanb->extra_reader_sb)
163 num_subbuf_alloc++;
164
165 for (i = 0; i < chanb->num_subbuf; i++)
4746ae29 166 shmp_index(handle, bufb->buf_wsb, i)->id = subbuffer_id(config, 0, 1, i);
852c2936
MD
167 if (chanb->extra_reader_sb)
168 bufb->buf_rsb.id = subbuffer_id(config, 0, 1,
169 num_subbuf_alloc - 1);
170 else
171 bufb->buf_rsb.id = subbuffer_id(config, 0, 1, 0);
172
173 for (i = 0; i < num_subbuf_alloc; i++) {
174 /* Don't reset mmap_offset */
4746ae29
MD
175 v_set(config, &shmp(handle, shmp_index(handle, bufb->array, i)->shmp)->records_commit, 0);
176 v_set(config, &shmp(handle, shmp_index(handle, bufb->array, i)->shmp)->records_unread, 0);
177 shmp(handle, shmp_index(handle, bufb->array, i)->shmp)->data_size = 0;
852c2936
MD
178 /* Don't reset backend page and virt addresses */
179 }
180 /* Don't reset num_pages_per_subbuf, cpu, allocated */
181 v_set(config, &bufb->records_read, 0);
182}
183
184/*
185 * The frontend is responsible for also calling ring_buffer_backend_reset for
186 * each buffer when calling channel_backend_reset.
187 */
188void channel_backend_reset(struct channel_backend *chanb)
189{
14641deb 190 struct channel *chan = caa_container_of(chanb, struct channel, backend);
4cfec15c 191 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
852c2936
MD
192
193 /*
194 * Don't reset buf_size, subbuf_size, subbuf_size_order,
195 * num_subbuf_order, buf_size_order, extra_reader_sb, num_subbuf,
196 * priv, notifiers, config, cpumask and name.
197 */
198 chanb->start_tsc = config->cb.ring_buffer_clock_read(chan);
199}
200
852c2936
MD
201/**
202 * channel_backend_init - initialize a channel backend
203 * @chanb: channel backend
204 * @name: channel name
205 * @config: client ring buffer configuration
852c2936 206 * @parent: dentry of parent directory, %NULL for root directory
8ed89704 207 * @subbuf_size: size of sub-buffers (> page size, power of 2)
852c2936 208 * @num_subbuf: number of sub-buffers (power of 2)
38fae1d3 209 * @lttng_ust_shm_handle: shared memory handle
852c2936
MD
210 *
211 * Returns channel pointer if successful, %NULL otherwise.
212 *
213 * Creates per-cpu channel buffers using the sizes and attributes
214 * specified. The created channel buffer files will be named
215 * name_0...name_N-1. File permissions will be %S_IRUSR.
216 *
217 * Called with CPU hotplug disabled.
218 */
219int channel_backend_init(struct channel_backend *chanb,
220 const char *name,
4cfec15c 221 const struct lttng_ust_lib_ring_buffer_config *config,
a3f61e7f 222 size_t subbuf_size, size_t num_subbuf,
38fae1d3 223 struct lttng_ust_shm_handle *handle)
852c2936 224{
14641deb 225 struct channel *chan = caa_container_of(chanb, struct channel, backend);
852c2936
MD
226 unsigned int i;
227 int ret;
6c1f7d8b 228 size_t shmsize = 0, num_subbuf_alloc;
8ed89704 229 long page_size;
852c2936
MD
230
231 if (!name)
232 return -EPERM;
233
8ed89704
MD
234 page_size = sysconf(_SC_PAGE_SIZE);
235 if (page_size <= 0) {
236 return -ENOMEM;
237 }
852c2936 238 /* Check that the subbuffer size is larger than a page. */
8ed89704 239 if (subbuf_size < page_size)
852c2936
MD
240 return -EINVAL;
241
242 /*
12bcbbdb
MD
243 * Make sure the number of subbuffers and subbuffer size are
244 * power of 2, and nonzero.
852c2936 245 */
12bcbbdb 246 if (!subbuf_size || (subbuf_size & (subbuf_size - 1)))
e52b0723 247 return -EINVAL;
12bcbbdb 248 if (!num_subbuf || (num_subbuf & (num_subbuf - 1)))
e52b0723 249 return -EINVAL;
3d8e9399
MD
250 /*
251 * Overwrite mode buffers require at least 2 subbuffers per
252 * buffer.
253 */
254 if (config->mode == RING_BUFFER_OVERWRITE && num_subbuf < 2)
255 return -EINVAL;
852c2936
MD
256
257 ret = subbuffer_id_check_index(config, num_subbuf);
258 if (ret)
259 return ret;
260
852c2936
MD
261 chanb->buf_size = num_subbuf * subbuf_size;
262 chanb->subbuf_size = subbuf_size;
263 chanb->buf_size_order = get_count_order(chanb->buf_size);
264 chanb->subbuf_size_order = get_count_order(subbuf_size);
265 chanb->num_subbuf_order = get_count_order(num_subbuf);
266 chanb->extra_reader_sb =
267 (config->mode == RING_BUFFER_OVERWRITE) ? 1 : 0;
268 chanb->num_subbuf = num_subbuf;
a6352fd4
MD
269 strncpy(chanb->name, name, NAME_MAX);
270 chanb->name[NAME_MAX - 1] = '\0';
193183fb 271 memcpy(&chanb->config, config, sizeof(*config));
852c2936 272
1d498196 273 /* Per-cpu buffer size: control (prior to backend) */
4cfec15c
MD
274 shmsize = offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer));
275 shmsize += sizeof(struct lttng_ust_lib_ring_buffer);
1d498196
MD
276
277 /* Per-cpu buffer size: backend */
278 /* num_subbuf + 1 is the worse case */
279 num_subbuf_alloc = num_subbuf + 1;
4cfec15c
MD
280 shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages_shmp));
281 shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_pages_shmp) * num_subbuf_alloc;
8ed89704 282 shmsize += offset_align(shmsize, page_size);
1d498196 283 shmsize += subbuf_size * num_subbuf_alloc;
4cfec15c
MD
284 shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages));
285 shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_pages) * num_subbuf_alloc;
286 shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_subbuffer));
287 shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_subbuffer) * num_subbuf;
1d498196
MD
288 /* Per-cpu buffer size: control (after backend) */
289 shmsize += offset_align(shmsize, __alignof__(struct commit_counters_hot));
290 shmsize += sizeof(struct commit_counters_hot) * num_subbuf;
291 shmsize += offset_align(shmsize, __alignof__(struct commit_counters_cold));
292 shmsize += sizeof(struct commit_counters_cold) * num_subbuf;
293
852c2936 294 if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
4cfec15c 295 struct lttng_ust_lib_ring_buffer *buf;
852c2936 296 /*
a6352fd4 297 * We need to allocate for all possible cpus.
852c2936 298 */
852c2936 299 for_each_possible_cpu(i) {
1d498196
MD
300 struct shm_object *shmobj;
301
74d81a6c
MD
302 shmobj = shm_object_table_alloc(handle->table, shmsize,
303 SHM_OBJECT_SHM);
afdf9825
MD
304 if (!shmobj)
305 goto end;
4cfec15c
MD
306 align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer));
307 set_shmp(chanb->buf[i].shmp, zalloc_shm(shmobj, sizeof(struct lttng_ust_lib_ring_buffer)));
1d498196
MD
308 buf = shmp(handle, chanb->buf[i].shmp);
309 if (!buf)
310 goto end;
5d61a504 311 set_shmp(buf->self, chanb->buf[i].shmp._ref);
1d498196
MD
312 ret = lib_ring_buffer_create(buf, chanb, i,
313 handle, shmobj);
852c2936
MD
314 if (ret)
315 goto free_bufs; /* cpu hotplug locked */
316 }
852c2936 317 } else {
1d498196 318 struct shm_object *shmobj;
4cfec15c 319 struct lttng_ust_lib_ring_buffer *buf;
a6352fd4 320
74d81a6c
MD
321 shmobj = shm_object_table_alloc(handle->table, shmsize,
322 SHM_OBJECT_SHM);
afdf9825
MD
323 if (!shmobj)
324 goto end;
4cfec15c
MD
325 align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer));
326 set_shmp(chanb->buf[0].shmp, zalloc_shm(shmobj, sizeof(struct lttng_ust_lib_ring_buffer)));
1d498196 327 buf = shmp(handle, chanb->buf[0].shmp);
a6352fd4
MD
328 if (!buf)
329 goto end;
cb14bae9 330 set_shmp(buf->self, chanb->buf[0].shmp._ref);
1d498196
MD
331 ret = lib_ring_buffer_create(buf, chanb, -1,
332 handle, shmobj);
852c2936
MD
333 if (ret)
334 goto free_bufs;
335 }
336 chanb->start_tsc = config->cb.ring_buffer_clock_read(chan);
337
338 return 0;
339
340free_bufs:
a6352fd4
MD
341 /* We only free the buffer data upon shm teardown */
342end:
852c2936
MD
343 return -ENOMEM;
344}
345
852c2936
MD
346/**
347 * channel_backend_free - destroy the channel
348 * @chan: the channel
349 *
350 * Destroy all channel buffers and frees the channel.
351 */
1d498196 352void channel_backend_free(struct channel_backend *chanb,
38fae1d3 353 struct lttng_ust_shm_handle *handle)
852c2936 354{
45e9e699 355 /* SHM teardown takes care of everything */
852c2936
MD
356}
357
852c2936
MD
358/**
359 * lib_ring_buffer_read - read data from ring_buffer_buffer.
360 * @bufb : buffer backend
361 * @offset : offset within the buffer
362 * @dest : destination address
363 * @len : length to copy to destination
364 *
365 * Should be protected by get_subbuf/put_subbuf.
366 * Returns the length copied.
367 */
4cfec15c 368size_t lib_ring_buffer_read(struct lttng_ust_lib_ring_buffer_backend *bufb, size_t offset,
38fae1d3 369 void *dest, size_t len, struct lttng_ust_shm_handle *handle)
852c2936 370{
1d498196 371 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
4cfec15c 372 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
a6352fd4 373 ssize_t orig_len;
4cfec15c 374 struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages;
852c2936 375 unsigned long sb_bindex, id;
10a92ba8 376 void *src;
852c2936
MD
377
378 orig_len = len;
379 offset &= chanb->buf_size - 1;
a6352fd4 380
b5a3dfa5 381 if (caa_unlikely(!len))
852c2936 382 return 0;
a6352fd4
MD
383 id = bufb->buf_rsb.id;
384 sb_bindex = subbuffer_id_get_index(config, id);
4746ae29 385 rpages = shmp_index(handle, bufb->array, sb_bindex);
a6352fd4
MD
386 /*
387 * Underlying layer should never ask for reads across
388 * subbuffers.
389 */
390 CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
391 CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
392 && subbuffer_id_is_noref(config, id));
10a92ba8
MD
393 src = shmp_index(handle, shmp(handle, rpages->shmp)->p,
394 offset & (chanb->subbuf_size - 1));
395 if (caa_unlikely(!src))
396 return 0;
397 memcpy(dest, src, len);
852c2936
MD
398 return orig_len;
399}
852c2936 400
852c2936
MD
401/**
402 * lib_ring_buffer_read_cstr - read a C-style string from ring_buffer.
403 * @bufb : buffer backend
404 * @offset : offset within the buffer
405 * @dest : destination address
406 * @len : destination's length
407 *
0bf3c920 408 * Return string's length, or -EINVAL on error.
852c2936 409 * Should be protected by get_subbuf/put_subbuf.
0bf3c920 410 * Destination length should be at least 1 to hold '\0'.
852c2936 411 */
4cfec15c 412int lib_ring_buffer_read_cstr(struct lttng_ust_lib_ring_buffer_backend *bufb, size_t offset,
38fae1d3 413 void *dest, size_t len, struct lttng_ust_shm_handle *handle)
852c2936 414{
1d498196 415 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
4cfec15c 416 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
a6352fd4 417 ssize_t string_len, orig_offset;
852c2936 418 char *str;
4cfec15c 419 struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages;
852c2936
MD
420 unsigned long sb_bindex, id;
421
0bf3c920
MD
422 if (caa_unlikely(!len))
423 return -EINVAL;
852c2936 424 offset &= chanb->buf_size - 1;
852c2936 425 orig_offset = offset;
852c2936
MD
426 id = bufb->buf_rsb.id;
427 sb_bindex = subbuffer_id_get_index(config, id);
4746ae29 428 rpages = shmp_index(handle, bufb->array, sb_bindex);
a6352fd4
MD
429 /*
430 * Underlying layer should never ask for reads across
431 * subbuffers.
432 */
433 CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
852c2936
MD
434 CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
435 && subbuffer_id_is_noref(config, id));
aead2025 436 str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
10a92ba8
MD
437 if (caa_unlikely(!str))
438 return -EINVAL;
a6352fd4
MD
439 string_len = strnlen(str, len);
440 if (dest && len) {
441 memcpy(dest, str, string_len);
442 ((char *)dest)[0] = 0;
443 }
444 return offset - orig_offset;
852c2936 445}
852c2936
MD
446
447/**
448 * lib_ring_buffer_read_offset_address - get address of a buffer location
449 * @bufb : buffer backend
450 * @offset : offset within the buffer.
451 *
452 * Return the address where a given offset is located (for read).
453 * Should be used to get the current subbuffer header pointer. Given we know
22b22ce9
MD
454 * it's never on a page boundary, it's safe to read/write directly
455 * from/to this address, as long as the read/write is never bigger than
456 * a page size.
852c2936 457 */
4cfec15c 458void *lib_ring_buffer_read_offset_address(struct lttng_ust_lib_ring_buffer_backend *bufb,
1d498196 459 size_t offset,
38fae1d3 460 struct lttng_ust_shm_handle *handle)
852c2936 461{
4cfec15c 462 struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages;
1d498196 463 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
4cfec15c 464 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
852c2936
MD
465 unsigned long sb_bindex, id;
466
467 offset &= chanb->buf_size - 1;
852c2936
MD
468 id = bufb->buf_rsb.id;
469 sb_bindex = subbuffer_id_get_index(config, id);
4746ae29 470 rpages = shmp_index(handle, bufb->array, sb_bindex);
852c2936
MD
471 CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
472 && subbuffer_id_is_noref(config, id));
aead2025 473 return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
852c2936 474}
852c2936
MD
475
476/**
477 * lib_ring_buffer_offset_address - get address of a location within the buffer
478 * @bufb : buffer backend
479 * @offset : offset within the buffer.
480 *
481 * Return the address where a given offset is located.
482 * Should be used to get the current subbuffer header pointer. Given we know
483 * it's always at the beginning of a page, it's safe to write directly to this
484 * address, as long as the write is never bigger than a page size.
485 */
4cfec15c 486void *lib_ring_buffer_offset_address(struct lttng_ust_lib_ring_buffer_backend *bufb,
1d498196 487 size_t offset,
38fae1d3 488 struct lttng_ust_shm_handle *handle)
852c2936 489{
a6352fd4 490 size_t sbidx;
4cfec15c 491 struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages;
1d498196 492 struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
4cfec15c 493 const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
852c2936
MD
494 unsigned long sb_bindex, id;
495
496 offset &= chanb->buf_size - 1;
497 sbidx = offset >> chanb->subbuf_size_order;
4746ae29 498 id = shmp_index(handle, bufb->buf_wsb, sbidx)->id;
852c2936 499 sb_bindex = subbuffer_id_get_index(config, id);
4746ae29 500 rpages = shmp_index(handle, bufb->array, sb_bindex);
852c2936
MD
501 CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
502 && subbuffer_id_is_noref(config, id));
aead2025 503 return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
852c2936 504}
This page took 0.053017 seconds and 4 git commands to generate.