Lines Matching +full:record +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0
15 * --------------
21 * the record and logical positions specifying where in the other
27 * string of the record.
33 * --------------
38 * essential meta data to track the data of a printk record using
49 * A writer is modifying the record.
52 * The record and all its data are written. A writer can reopen the
57 * The record and all its data are complete and available for reading. A
61 * The record exists, but its text and/or meta data may no longer be
64 * Querying the @state_var of a record requires providing the ID of the
87 * When a writer calls the commit function prb_commit(), record data is
89 * reopen that record, claiming exclusive access (as with prb_reserve()), and
90 * modify that record. When finished, the writer must again commit the record.
92 * In order for a record to be made available to readers (and also become
93 * recyclable for writers), it must be finalized. A finalized record cannot be
94 * reopened and can never become "unfinalized". Record finalization can occur
97 * 1) A writer can simultaneously commit and finalize its record by calling
100 * 2) When a new record is reserved and the previous record has been
101 * committed via prb_commit(), that previous record is automatically
104 * 3) When a record is committed via prb_commit() and a newer record
105 * already exists, the record being committed is automatically finalized.
155 * -----
162 * This ringbuffer allows up to 32768 records (2 ^ 15) and has a size of
177 * r.info->text_len = strlen(textstr);
178 * r.info->ts_nsec = local_clock();
179 * r.info->caller_id = printk_caller_id();
181 * // commit and finalize the record
185 * Note that additional writer functions are available to extend a record
189 * Sample writer code (record extending)::
193 * r.info->text_len = strlen(textstr);
194 * r.info->ts_nsec = local_clock();
195 * r.info->caller_id = printk_caller_id();
197 * // commit the record (but do not finalize yet)
208 * snprintf(&r.text_buf[r.info->text_len],
209 * r.text_buf_size - r.info->text_len, "hello");
211 * r.info->text_len += 5;
213 * // commit and finalize the record
228 * pr_warn("lost %llu records\n", info.seq - seq);
231 * pr_warn("record %llu text truncated\n", info.seq);
232 * text_buf[r.text_buf_size - 1] = 0;
240 * allow complex record access.
247 * bits counting array wraps). However, on 32-bit systems the number of
250 * printk messages were to occur in NMI context on a 32-bit system, the
251 * interrupted context would not be able to recognize that the 32-bit integer
258 * a 32-bit system might experience.
309 * store finalized record, then set new highest finalized sequence number
312 #define DATA_SIZE(data_ring) _DATA_SIZE((data_ring)->size_bits)
313 #define DATA_SIZE_MASK(data_ring) (DATA_SIZE(data_ring) - 1)
315 #define DESCS_COUNT(desc_ring) _DESCS_COUNT((desc_ring)->count_bits)
316 #define DESCS_COUNT_MASK(desc_ring) (DESCS_COUNT(desc_ring) - 1)
325 #define DATA_WRAPS(data_ring, lpos) ((lpos) >> (data_ring)->size_bits)
327 /* Determine if a logical position refers to a data-less block. */
329 #define BLK_DATALESS(blk) (LPOS_DATALESS((blk)->begin) && \
330 LPOS_DATALESS((blk)->next))
338 DESC_ID((id) - DESCS_COUNT(desc_ring))
347 * Note that the size of a data block is only known by its associated
361 return &desc_ring->descs[DESC_INDEX(desc_ring, n)]; in to_desc()
370 return &desc_ring->infos[DESC_INDEX(desc_ring, n)]; in to_info()
376 return (void *)&data_ring->data[DATA_INDEX(data_ring, begin_lpos)]; in to_block()
380 * Increase the data size to account for data block meta data plus any
381 * padding so that the adjacent data block is aligned on the ID size.
383 static unsigned int to_blk_size(unsigned int size) in to_blk_size() argument
387 size += sizeof(*db); in to_blk_size()
388 size = ALIGN(size, sizeof(db->id)); in to_blk_size()
389 return size; in to_blk_size()
393 * Sanity checker for reserve size. The ringbuffer code assumes that a data
394 * block does not exceed the maximum possible size that could fit within the
395 * ringbuffer. This function provides that basic size check so that the
398 static bool data_check_size(struct prb_data_ring *data_ring, unsigned int size) in data_check_size() argument
402 if (size == 0) in data_check_size()
406 * Ensure the alignment padded size could possibly fit in the data in data_check_size()
410 size = to_blk_size(size); in data_check_size()
411 if (size > DATA_SIZE(data_ring) - sizeof(db->id)) in data_check_size()
433 * non-state_var data, they are only valid if the descriptor is in a
442 atomic_long_t *state_var = &desc->state_var; in desc_read()
478 * state has been re-checked. A memcpy() for all of @desc in desc_read()
482 memcpy(&desc_out->text_blk_lpos, &desc->text_blk_lpos, in desc_read()
483 sizeof(desc_out->text_blk_lpos)); /* LMM(desc_read:C) */ in desc_read()
486 *seq_out = info->seq; /* also part of desc_read:C */ in desc_read()
488 *caller_id_out = info->caller_id; /* also part of desc_read:C */ in desc_read()
491 * 1. Guarantee the descriptor content is loaded before re-checking in desc_read()
507 * 2. Guarantee the record data is loaded before re-checking the in desc_read()
538 atomic_long_set(&desc_out->state_var, state_val); in desc_read()
553 atomic_long_t *state_var = &desc->state_var; in desc_make_reusable()
566 * on error the caller can re-load the tail lpos to determine the situation.
574 struct prb_data_ring *data_ring = &rb->text_data_ring; in data_make_reusable()
575 struct prb_desc_ring *desc_ring = &rb->desc_ring; in data_make_reusable()
583 while ((lpos_end - lpos_begin) - 1 < DATA_SIZE(data_ring)) { in data_make_reusable()
594 id = blk->id; /* LMM(data_make_reusable:A) */ in data_make_reusable()
609 if (blk_lpos->begin != lpos_begin) in data_make_reusable()
618 if (blk_lpos->begin != lpos_begin) in data_make_reusable()
624 lpos_begin = blk_lpos->next; in data_make_reusable()
638 struct prb_data_ring *data_ring = &rb->text_data_ring; in data_push_tail()
643 /* If @lpos is from a data-less block, there is nothing to do. */ in data_push_tail()
665 tail_lpos = atomic_long_read(&data_ring->tail_lpos); /* LMM(data_push_tail:A) */ in data_push_tail()
674 while ((lpos - tail_lpos) - 1 < DATA_SIZE(data_ring)) { in data_push_tail()
737 tail_lpos_new = atomic_long_read(&data_ring->tail_lpos in data_push_tail()
754 if (atomic_long_try_cmpxchg(&data_ring->tail_lpos, &tail_lpos, in data_push_tail()
774 struct prb_desc_ring *desc_ring = &rb->desc_ring; in desc_push_tail()
839 atomic_long_cmpxchg(&desc_ring->tail_id, tail_id, in desc_push_tail()
867 * Re-check the tail ID. The descriptor following @tail_id is in desc_push_tail()
871 if (atomic_long_read(&desc_ring->tail_id) == tail_id) /* LMM(desc_push_tail:D) */ in desc_push_tail()
881 struct prb_desc_ring *desc_ring = &rb->desc_ring; in desc_reserve()
888 head_id = atomic_long_read(&desc_ring->head_id); /* LMM(desc_reserve:A) */ in desc_reserve()
918 if (id_prev_wrap == atomic_long_read(&desc_ring->tail_id in desc_reserve()
954 * happen via desc_push_tail()->data_push_tail(). A full in desc_reserve()
969 } while (!atomic_long_try_cmpxchg(&desc_ring->head_id, &head_id, in desc_reserve()
978 prev_state_val = atomic_long_read(&desc->state_var); /* LMM(desc_reserve:E) */ in desc_reserve()
993 if (!atomic_long_try_cmpxchg(&desc->state_var, &prev_state_val, in desc_reserve()
1007 unsigned long lpos, unsigned int size) in get_next_lpos() argument
1013 next_lpos = lpos + size; in get_next_lpos()
1020 return (DATA_THIS_WRAP_START_LPOS(data_ring, next_lpos) + size); in get_next_lpos()
1028 static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size, in data_alloc() argument
1031 struct prb_data_ring *data_ring = &rb->text_data_ring; in data_alloc()
1036 if (size == 0) { in data_alloc()
1042 blk_lpos->begin = EMPTY_LINE_LPOS; in data_alloc()
1043 blk_lpos->next = EMPTY_LINE_LPOS; in data_alloc()
1047 size = to_blk_size(size); in data_alloc()
1049 begin_lpos = atomic_long_read(&data_ring->head_lpos); in data_alloc()
1052 next_lpos = get_next_lpos(data_ring, begin_lpos, size); in data_alloc()
1054 if (!data_push_tail(rb, next_lpos - DATA_SIZE(data_ring))) { in data_alloc()
1055 /* Failed to allocate, specify a data-less block. */ in data_alloc()
1056 blk_lpos->begin = FAILED_LPOS; in data_alloc()
1057 blk_lpos->next = FAILED_LPOS; in data_alloc()
1078 } while (!atomic_long_try_cmpxchg(&data_ring->head_lpos, &begin_lpos, in data_alloc()
1082 blk->id = id; /* LMM(data_alloc:B) */ in data_alloc()
1092 blk->id = id; in data_alloc()
1095 blk_lpos->begin = begin_lpos; in data_alloc()
1096 blk_lpos->next = next_lpos; in data_alloc()
1098 return &blk->data[0]; in data_alloc()
1104 * copies the old data to the new data block. If @size yields a data block
1105 * with the same or less size, the data block is left as is.
1113 static char *data_realloc(struct printk_ringbuffer *rb, unsigned int size, in data_realloc() argument
1116 struct prb_data_ring *data_ring = &rb->text_data_ring; in data_realloc()
1123 head_lpos = atomic_long_read(&data_ring->head_lpos); in data_realloc()
1124 if (head_lpos != blk_lpos->next) in data_realloc()
1128 wrapped = (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, blk_lpos->next)); in data_realloc()
1130 size = to_blk_size(size); in data_realloc()
1132 next_lpos = get_next_lpos(data_ring, blk_lpos->begin, size); in data_realloc()
1135 if (head_lpos - next_lpos < DATA_SIZE(data_ring)) { in data_realloc()
1139 blk = to_block(data_ring, blk_lpos->begin); in data_realloc()
1140 return &blk->data[0]; in data_realloc()
1143 if (!data_push_tail(rb, next_lpos - DATA_SIZE(data_ring))) in data_realloc()
1147 if (!atomic_long_try_cmpxchg(&data_ring->head_lpos, &head_lpos, in data_realloc()
1152 blk = to_block(data_ring, blk_lpos->begin); in data_realloc()
1154 if (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, next_lpos)) { in data_realloc()
1164 blk->id = id; in data_realloc()
1172 memcpy(&blk->data[0], &old_blk->data[0], in data_realloc()
1173 (blk_lpos->next - blk_lpos->begin) - sizeof(blk->id)); in data_realloc()
1177 blk_lpos->next = next_lpos; in data_realloc()
1179 return &blk->data[0]; in data_realloc()
1186 /* Data-less blocks take no space. */ in space_used()
1190 if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next)) { in space_used()
1192 return (DATA_INDEX(data_ring, blk_lpos->next) - in space_used()
1193 DATA_INDEX(data_ring, blk_lpos->begin)); in space_used()
1200 return (DATA_INDEX(data_ring, blk_lpos->next) + in space_used()
1201 DATA_SIZE(data_ring) - DATA_INDEX(data_ring, blk_lpos->begin)); in space_used()
1206 * and calculate the size of the data part. A NULL pointer is returned if
1219 /* Data-less data block description. */ in get_data()
1226 if (blk_lpos->begin == EMPTY_LINE_LPOS && in get_data()
1227 blk_lpos->next == EMPTY_LINE_LPOS) { in get_data()
1237 if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next) && in get_data()
1238 blk_lpos->begin < blk_lpos->next) { in get_data()
1239 db = to_block(data_ring, blk_lpos->begin); in get_data()
1240 *data_size = blk_lpos->next - blk_lpos->begin; in get_data()
1243 } else if (DATA_WRAPS(data_ring, blk_lpos->begin + DATA_SIZE(data_ring)) == in get_data()
1244 DATA_WRAPS(data_ring, blk_lpos->next)) { in get_data()
1246 *data_size = DATA_INDEX(data_ring, blk_lpos->next); in get_data()
1254 /* A valid data block will always be aligned to the ID size. */ in get_data()
1255 if (WARN_ON_ONCE(blk_lpos->begin != ALIGN(blk_lpos->begin, sizeof(db->id))) || in get_data()
1256 WARN_ON_ONCE(blk_lpos->next != ALIGN(blk_lpos->next, sizeof(db->id)))) { in get_data()
1261 if (WARN_ON_ONCE(*data_size < sizeof(db->id))) in get_data()
1264 /* Subtract block ID space from size to reflect data size. */ in get_data()
1265 *data_size -= sizeof(db->id); in get_data()
1267 return &db->data[0]; in get_data()
1272 * so that the record can be modified by a writer again. This is only possible
1285 id = atomic_long_read(&desc_ring->head_id); in desc_reopen_last()
1301 * record data. A full memory barrier is needed because @state_var in desc_reopen_last()
1315 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, in desc_reopen_last()
1325 * prb_reserve_in_last() - Re-reserve and extend the space in the ringbuffer
1326 * used by the newest record.
1329 * @rb: The ringbuffer to re-reserve and extend data in.
1330 * @r: The record structure to allocate buffers for.
1332 * @max_size: Fail if the extended size would be greater than this.
1334 * This is the public function available to writers to re-reserve and extend
1337 * The writer specifies the text size to extend (not the new total size) by
1342 * newest record. In that case the caller must reserve new data using
1350 * - @r->text_buf points to the beginning of the entire text buffer.
1352 * - @r->text_buf_size is set to the new total size of the buffer.
1354 * - @r->info is not touched so that @r->info->text_len could be used
1357 * - prb_record_text_space() can be used on @e to query the new
1360 * Important: All @r->info fields will already be set with the current values
1361 * for the record. I.e. @r->info->text_len will be less than
1362 * @text_buf_size. Writers can use @r->info->text_len to know
1364 * @r->info->text_len after concatenating.
1369 struct prb_desc_ring *desc_ring = &rb->desc_ring; in prb_reserve_in_last()
1375 local_irq_save(e->irqflags); in prb_reserve_in_last()
1380 local_irq_restore(e->irqflags); in prb_reserve_in_last()
1392 e->rb = rb; in prb_reserve_in_last()
1393 e->id = id; in prb_reserve_in_last()
1400 if (caller_id != info->caller_id) in prb_reserve_in_last()
1403 if (BLK_DATALESS(&d->text_blk_lpos)) { in prb_reserve_in_last()
1404 if (WARN_ON_ONCE(info->text_len != 0)) { in prb_reserve_in_last()
1406 info->text_len); in prb_reserve_in_last()
1407 info->text_len = 0; in prb_reserve_in_last()
1410 if (!data_check_size(&rb->text_data_ring, r->text_buf_size)) in prb_reserve_in_last()
1413 if (r->text_buf_size > max_size) in prb_reserve_in_last()
1416 r->text_buf = data_alloc(rb, r->text_buf_size, in prb_reserve_in_last()
1417 &d->text_blk_lpos, id); in prb_reserve_in_last()
1419 if (!get_data(&rb->text_data_ring, &d->text_blk_lpos, &data_size)) in prb_reserve_in_last()
1423 * Increase the buffer size to include the original size. If in prb_reserve_in_last()
1425 * block size. in prb_reserve_in_last()
1427 if (WARN_ON_ONCE(info->text_len > data_size)) { in prb_reserve_in_last()
1429 info->text_len, data_size); in prb_reserve_in_last()
1430 info->text_len = data_size; in prb_reserve_in_last()
1432 r->text_buf_size += info->text_len; in prb_reserve_in_last()
1434 if (!data_check_size(&rb->text_data_ring, r->text_buf_size)) in prb_reserve_in_last()
1437 if (r->text_buf_size > max_size) in prb_reserve_in_last()
1440 r->text_buf = data_realloc(rb, r->text_buf_size, in prb_reserve_in_last()
1441 &d->text_blk_lpos, id); in prb_reserve_in_last()
1443 if (r->text_buf_size && !r->text_buf) in prb_reserve_in_last()
1446 r->info = info; in prb_reserve_in_last()
1448 e->text_space = space_used(&rb->text_data_ring, &d->text_blk_lpos); in prb_reserve_in_last()
1453 /* prb_commit() re-enabled interrupts. */ in prb_reserve_in_last()
1455 /* Make it clear to the caller that the re-reserve failed. */ in prb_reserve_in_last()
1467 * Be aware that finalized records following non-finalized records are not
1469 * a new record stored via printk() will not be available to a printer if
1470 * it follows a record that has not been finalized yet. However, once that
1471 * non-finalized record becomes finalized, @last_finalized_seq will be
1479 struct prb_desc_ring *desc_ring = &rb->desc_ring; in desc_last_finalized_seq()
1484 * associated record in order to guarantee that the record can be in desc_last_finalized_seq()
1487 ulseq = atomic_long_read_acquire(&desc_ring->last_finalized_seq in desc_last_finalized_seq()
1503 struct prb_desc_ring *desc_ring = &rb->desc_ring; in desc_update_last_finalized()
1520 /* No update needed if no later finalized record was found. */ in desc_update_last_finalized()
1528 * Set the sequence number of a later finalized record that has been in desc_update_last_finalized()
1531 * Guarantee the record data is visible to other CPUs before storing in desc_update_last_finalized()
1551 if (!atomic_long_try_cmpxchg_release(&desc_ring->last_finalized_seq, in desc_update_last_finalized()
1564 struct prb_desc_ring *desc_ring = &rb->desc_ring; in desc_make_final()
1568 if (atomic_long_try_cmpxchg_relaxed(&d->state_var, &prev_state_val, in desc_make_final()
1575 * prb_reserve() - Reserve space in the ringbuffer.
1579 * @r: The record structure to allocate buffers for.
1583 * The writer specifies the text size to reserve by setting the
1595 * Important: @info->text_len needs to be set correctly by the writer in
1602 struct prb_desc_ring *desc_ring = &rb->desc_ring; in prb_reserve()
1608 if (!data_check_size(&rb->text_data_ring, r->text_buf_size)) in prb_reserve()
1617 local_irq_save(e->irqflags); in prb_reserve()
1621 atomic_long_inc(&rb->fail); in prb_reserve()
1622 local_irq_restore(e->irqflags); in prb_reserve()
1634 seq = info->seq; in prb_reserve()
1641 e->rb = rb; in prb_reserve()
1642 e->id = id; in prb_reserve()
1656 info->seq = DESC_INDEX(desc_ring, id); in prb_reserve()
1658 info->seq = seq + DESCS_COUNT(desc_ring); in prb_reserve()
1666 if (info->seq > 0) in prb_reserve()
1667 desc_make_final(rb, DESC_ID(id - 1)); in prb_reserve()
1669 r->text_buf = data_alloc(rb, r->text_buf_size, &d->text_blk_lpos, id); in prb_reserve()
1670 /* If text data allocation fails, a data-less record is committed. */ in prb_reserve()
1671 if (r->text_buf_size && !r->text_buf) { in prb_reserve()
1673 /* prb_commit() re-enabled interrupts. */ in prb_reserve()
1677 r->info = info; in prb_reserve()
1679 /* Record full text space used by record. */ in prb_reserve()
1680 e->text_space = space_used(&rb->text_data_ring, &d->text_blk_lpos); in prb_reserve()
1692 struct prb_desc_ring *desc_ring = &e->rb->desc_ring; in _prb_commit()
1693 struct prb_desc *d = to_desc(desc_ring, e->id); in _prb_commit()
1694 unsigned long prev_state_val = DESC_SV(e->id, desc_reserved); in _prb_commit()
1702 * 1 Guarantee all record data is stored before the descriptor state in _prb_commit()
1707 * re-checking the head ID in order to possibly finalize this in _prb_commit()
1721 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, in _prb_commit()
1722 DESC_SV(e->id, state_val))) { /* LMM(_prb_commit:B) */ in _prb_commit()
1727 local_irq_restore(e->irqflags); in _prb_commit()
1731 * prb_commit() - Commit (previously reserved) data to the ringbuffer.
1738 * Finalizing happens automatically when space for the next record is
1748 struct prb_desc_ring *desc_ring = &e->rb->desc_ring; in prb_commit()
1754 * If this descriptor is no longer the head (i.e. a new record has in prb_commit()
1755 * been allocated), extending the data for this record is no longer in prb_commit()
1758 head_id = atomic_long_read(&desc_ring->head_id); /* LMM(prb_commit:A) */ in prb_commit()
1759 if (head_id != e->id) in prb_commit()
1760 desc_make_final(e->rb, e->id); in prb_commit()
1764 * prb_final_commit() - Commit and finalize (previously reserved) data to
1782 desc_update_last_finalized(e->rb); in prb_final_commit()
1802 next_size = text_size - (next - text); in count_lines()
1813 * size to possibly detect bugs in the writer code. A WARN_ON_ONCE() is
1857 * descriptor. However, it also verifies that the record is finalized and has
1861 * -EINVAL: A finalized record with sequence number @seq does not exist.
1862 * -ENOENT: A finalized record with sequence number @seq exists, but its data
1863 * is not available. This is a valid record, so readers should
1864 * continue with the next record.
1870 struct prb_data_blk_lpos *blk_lpos = &desc_out->text_blk_lpos; in desc_read_finalized_seq()
1877 * An unexpected @id (desc_miss) or @seq mismatch means the record in desc_read_finalized_seq()
1879 * means the record does not yet exist for the reader. in desc_read_finalized_seq()
1885 return -EINVAL; in desc_read_finalized_seq()
1890 * available; report it as existing but with lost data. Or the record in desc_read_finalized_seq()
1891 * may actually be a record with lost data. in desc_read_finalized_seq()
1894 (blk_lpos->begin == FAILED_LPOS && blk_lpos->next == FAILED_LPOS)) { in desc_read_finalized_seq()
1895 return -ENOENT; in desc_read_finalized_seq()
1902 * Copy the ringbuffer data from the record with @seq to the provided
1910 struct prb_desc_ring *desc_ring = &rb->desc_ring; in prb_read()
1913 atomic_long_t *state_var = &rdesc->state_var; in prb_read()
1926 * of the record. in prb_read()
1932 if (r->info) in prb_read()
1933 memcpy(r->info, info, sizeof(*(r->info))); in prb_read()
1935 /* Copy text data. If it fails, this is a data-less record. */ in prb_read()
1936 if (!copy_data(&rb->text_data_ring, &desc.text_blk_lpos, info->text_len, in prb_read()
1937 r->text_buf, r->text_buf_size, line_count)) { in prb_read()
1938 return -ENOENT; in prb_read()
1941 /* Ensure the record is still finalized and has the same @seq. */ in prb_read()
1948 struct prb_desc_ring *desc_ring = &rb->desc_ring; in prb_first_seq()
1955 id = atomic_long_read(&rb->desc_ring.tail_id); /* LMM(prb_first_seq:A) */ in prb_first_seq()
1990 * prb_next_reserve_seq() - Get the sequence number after the most recently
1991 * reserved record.
1996 * number will be assigned to the next reserved record.
2002 * Return: The sequence number that will be assigned to the next record
2007 struct prb_desc_ring *desc_ring = &rb->desc_ring; in prb_next_reserve_seq()
2028 * it points to the record with @last_finalized_seq or newer. in prb_next_reserve_seq()
2047 head_id = atomic_long_read(&desc_ring->head_id); /* LMM(prb_next_reserve_seq:A) */ in prb_next_reserve_seq()
2050 state_var = &d->state_var; in prb_next_reserve_seq()
2058 if (err == -EINVAL) { in prb_next_reserve_seq()
2061 * No record has been finalized or even reserved yet. in prb_next_reserve_seq()
2064 * increment will yield the first record (seq=0). in prb_next_reserve_seq()
2068 if (head_id == DESC0_ID(desc_ring->count_bits)) in prb_next_reserve_seq()
2076 last_finalized_id = DESC0_ID(desc_ring->count_bits) + 1; in prb_next_reserve_seq()
2078 /* Record must have been overwritten. Try again. */ in prb_next_reserve_seq()
2084 diff = head_id - last_finalized_id; in prb_next_reserve_seq()
2087 * @head_id points to the most recently reserved record, but this in prb_next_reserve_seq()
2089 * next (not yet reserved) record. Thus +1 is needed. in prb_next_reserve_seq()
2095 * Non-blocking read of a record.
2097 * On success @seq is updated to the record that was read and (if provided)
2100 * On failure @seq is updated to a record that is not yet available to the
2101 * reader, but it will be the next record available to the reader.
2104 * non-existent/non-finalized records in order to allow the panic CPU
2119 * can happen for -ENOENT and -EINVAL cases. in _prb_read_valid()
2123 } else if (err == -ENOENT) { in _prb_read_valid()
2124 /* Record exists, but the data was lost. Skip. */ in _prb_read_valid()
2129 * Non-existent/non-finalized record. Must stop. in _prb_read_valid()
2132 * non-finalized records will become finalized. But in _prb_read_valid()
2136 * non-existent/non-finalized record unless non-panic in _prb_read_valid()
2144 * by "prb_next_reserve_seq() - 1". in _prb_read_valid()
2160 * prb_read_valid() - Non-blocking read of a requested record or (if gone)
2161 * the next available record.
2164 * @seq: The sequence number of the record to read.
2165 * @r: A record data buffer to store the read record to.
2167 * This is the public function available to readers to read a record.
2175 * Return: true if a record was read, otherwise false.
2177 * On success, the reader must check r->info.seq to see which record was
2180 * Failure means @seq refers to a record not yet available to the reader.
2189 * prb_read_valid_info() - Non-blocking read of meta data for a requested
2190 * record or (if gone) the next available record.
2193 * @seq: The sequence number of the record to read.
2194 * @info: A buffer to store the read record meta data to.
2195 * @line_count: A buffer to store the number of lines in the record text.
2198 * meta data of a record.
2205 * Return: true if a record's meta data was read, otherwise false.
2207 * On success, the reader must check info->seq to see which record meta data
2210 * Failure means @seq refers to a record not yet available to the reader.
2223 * prb_first_valid_seq() - Get the sequence number of the oldest available
2224 * record.
2234 * Return: The sequence number of the first/oldest record or, if the
2248 * prb_next_seq() - Get the sequence number after the last available record.
2261 * Return: The sequence number of the next newest (not yet available) record
2271 * Begin searching after the last finalized record. in prb_next_seq()
2275 * record at index 0 exists. in prb_next_seq()
2291 * prb_init() - Initialize a ringbuffer to use provided external buffers.
2295 * @textbits: The size of @text_buf as a power-of-2 value.
2297 * @descbits: The count of @descs items as a power-of-2 value.
2315 rb->desc_ring.count_bits = descbits; in prb_init()
2316 rb->desc_ring.descs = descs; in prb_init()
2317 rb->desc_ring.infos = infos; in prb_init()
2318 atomic_long_set(&rb->desc_ring.head_id, DESC0_ID(descbits)); in prb_init()
2319 atomic_long_set(&rb->desc_ring.tail_id, DESC0_ID(descbits)); in prb_init()
2320 atomic_long_set(&rb->desc_ring.last_finalized_seq, 0); in prb_init()
2322 rb->text_data_ring.size_bits = textbits; in prb_init()
2323 rb->text_data_ring.data = text_buf; in prb_init()
2324 atomic_long_set(&rb->text_data_ring.head_lpos, BLK0_LPOS(textbits)); in prb_init()
2325 atomic_long_set(&rb->text_data_ring.tail_lpos, BLK0_LPOS(textbits)); in prb_init()
2327 atomic_long_set(&rb->fail, 0); in prb_init()
2329 atomic_long_set(&(descs[_DESCS_COUNT(descbits) - 1].state_var), DESC0_SV(descbits)); in prb_init()
2330 descs[_DESCS_COUNT(descbits) - 1].text_blk_lpos.begin = FAILED_LPOS; in prb_init()
2331 descs[_DESCS_COUNT(descbits) - 1].text_blk_lpos.next = FAILED_LPOS; in prb_init()
2333 infos[0].seq = -(u64)_DESCS_COUNT(descbits); in prb_init()
2334 infos[_DESCS_COUNT(descbits) - 1].seq = 0; in prb_init()
2338 * prb_record_text_space() - Query the full actual used ringbuffer space for
2351 * Return: The size in bytes used by the text data of the associated record.
2355 return e->text_space; in prb_record_text_space()