diff options
author | John Ogness <john.ogness@linutronix.de> | 2020-09-19 00:40:21 +0206 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2020-09-22 11:39:18 +0200 |
commit | f35efc78add6439a9fbe611f2dd517641e82d067 (patch) | |
tree | 736e3e46f7f8bf4c54d9fb671267391df6fa4b9f /kernel/printk/printk_ringbuffer.c | |
parent | 74caba7f2a0685575b3ee5330a118f5922485e02 (diff) |
printk: remove dict ring
Since there is no code that will ever store anything into the dict
ring, remove it. If any future dictionary properties are to be
added, these should be added to the struct printk_info.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200918223421.21621-4-john.ogness@linutronix.de
Diffstat (limited to 'kernel/printk/printk_ringbuffer.c')
-rw-r--r-- | kernel/printk/printk_ringbuffer.c | 155 |
1 files changed, 37 insertions, 118 deletions
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index de4b10a98623..13b94b92342e 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -18,18 +18,13 @@ * A ring of descriptors and their meta data (such as sequence number, * timestamp, loglevel, etc.) as well as internal state information about * the record and logical positions specifying where in the other - * ringbuffers the text and dictionary strings are located. + * ringbuffer the text strings are located. * * text_data_ring * A ring of data blocks. A data block consists of an unsigned long * integer (ID) that maps to a desc_ring index followed by the text * string of the record. * - * dict_data_ring - * A ring of data blocks. A data block consists of an unsigned long - * integer (ID) that maps to a desc_ring index followed by the dictionary - * string of the record. - * * The internal state information of a descriptor is the key element to allow * readers and writers to locklessly synchronize access to the data. * @@ -40,8 +35,8 @@ * ~~~~~~~~~~~~~~~ * The descriptor ring is an array of descriptors. A descriptor contains * essential meta data to track the data of a printk record using - * blk_lpos structs pointing to associated text and dictionary data blocks - * (see "Data Rings" below). Each descriptor is assigned an ID that maps + * blk_lpos structs pointing to associated text data blocks (see + * "Data Rings" below). Each descriptor is assigned an ID that maps * directly to index values of the descriptor array and has a state. The ID * and the state are bitwise combined into a single descriptor field named * @state_var, allowing ID and state to be synchronously and atomically @@ -62,8 +57,8 @@ * writer cannot reopen the descriptor. * * reusable - * The record exists, but its text and/or dictionary data may no longer - * be available. + * The record exists, but its text and/or meta data may no longer be + * available. * * Querying the @state_var of a record requires providing the ID of the * descriptor to query. This can yield a possible fifth (pseudo) state: @@ -77,7 +72,7 @@ * When a new descriptor should be created (and the ring is full), the tail * descriptor is invalidated by first transitioning to the reusable state and * then invalidating all tail data blocks up to and including the data blocks - * associated with the tail descriptor (for text and dictionary rings). Then + * associated with the tail descriptor (for the text ring). Then * @tail_id is advanced, followed by advancing @head_id. And finally the * @state_var of the new descriptor is initialized to the new ID and reserved * state. @@ -108,13 +103,9 @@ * 3) When a record is committed via prb_commit() and a newer record * already exists, the record being committed is automatically finalized. * - * Data Rings - * ~~~~~~~~~~ - * The two data rings (text and dictionary) function identically. They exist - * separately so that their buffer sizes can be individually set and they do - * not affect one another. - * - * Data rings are byte arrays composed of data blocks. Data blocks are + * Data Ring + * ~~~~~~~~~ + * The text data ring is a byte array composed of data blocks. Data blocks are * referenced by blk_lpos structs that point to the logical position of the * beginning of a data block and the beginning of the next adjacent data * block. Logical positions are mapped directly to index values of the byte @@ -165,34 +156,28 @@ * examples a global ringbuffer (test_rb) is available (which is not the * actual ringbuffer used by printk):: * - * DEFINE_PRINTKRB(test_rb, 15, 5, 3); + * DEFINE_PRINTKRB(test_rb, 15, 5); * * This ringbuffer allows up to 32768 records (2 ^ 15) and has a size of - * 1 MiB (2 ^ (15 + 5)) for text data and 256 KiB (2 ^ (15 + 3)) for - * dictionary data. + * 1 MiB (2 ^ (15 + 5)) for text data. * * Sample writer code:: * - * const char *dictstr = "dictionary text"; * const char *textstr = "message text"; * struct prb_reserved_entry e; * struct printk_record r; * * // specify how much to allocate - * prb_rec_init_wr(&r, strlen(textstr) + 1, strlen(dictstr) + 1); + * prb_rec_init_wr(&r, strlen(textstr) + 1); * * if (prb_reserve(&e, &test_rb, &r)) { * snprintf(r.text_buf, r.text_buf_size, "%s", textstr); - * r.info->text_len = strlen(textstr); - * - * // dictionary allocation may have failed - * if (r.dict_buf) { - * snprintf(r.dict_buf, r.dict_buf_size, "%s", dictstr); - * r.info->dict_len = strlen(dictstr); - * } * + * r.info->text_len = strlen(textstr); * r.info->ts_nsec = local_clock(); + * r.info->caller_id = printk_caller_id(); * + * // commit and finalize the record * prb_final_commit(&e); * } * @@ -203,8 +188,9 @@ * Sample writer code (record extending):: * * // alternate rest of previous example - * r.info->ts_nsec = local_clock(); + * * r.info->text_len = strlen(textstr); + * r.info->ts_nsec = local_clock(); * r.info->caller_id = printk_caller_id(); * * // commit the record (but do not finalize yet) @@ -214,7 +200,7 @@ * ... * * // specify additional 5 bytes text space to extend - * prb_rec_init_wr(&r, 5, 0); + * prb_rec_init_wr(&r, 5); * * if (prb_reserve_in_last(&e, &test_rb, &r, printk_caller_id())) { * snprintf(&r.text_buf[r.info->text_len], @@ -222,6 +208,7 @@ * * r.info->text_len += 5; * + * // commit and finalize the record * prb_final_commit(&e); * } * @@ -230,11 +217,9 @@ * struct printk_info info; * struct printk_record r; * char text_buf[32]; - * char dict_buf[32]; * u64 seq; * - * prb_rec_init_rd(&r, &info, &text_buf[0], sizeof(text_buf), - * &dict_buf[0], sizeof(dict_buf)); + * prb_rec_init_rd(&r, &info, &text_buf[0], sizeof(text_buf)); * * prb_for_each_record(0, &test_rb, &seq, &r) { * if (info.seq != seq) @@ -245,13 +230,8 @@ * text_buf[r.text_buf_size - 1] = 0; * } * - * if (info.dict_len > r.dict_buf_size) { - * pr_warn("record %llu dict truncated\n", info.seq); - * dict_buf[r.dict_buf_size - 1] = 0; - * } - * - * pr_info("%llu: %llu: %s;%s\n", info.seq, info.ts_nsec, - * &text_buf[0], info.dict_len ? &dict_buf[0] : ""); + * pr_info("%llu: %llu: %s\n", info.seq, info.ts_nsec, + * &text_buf[0]); * } * * Note that additional less convenient reader functions are available to @@ -495,8 +475,6 @@ static enum desc_state desc_read(struct prb_desc_ring *desc_ring, */ memcpy(&desc_out->text_blk_lpos, &desc->text_blk_lpos, sizeof(desc_out->text_blk_lpos)); /* LMM(desc_read:C) */ - memcpy(&desc_out->dict_blk_lpos, &desc->dict_blk_lpos, - sizeof(desc_out->dict_blk_lpos)); /* also part of desc_read:C */ if (seq_out) *seq_out = info->seq; /* also part of desc_read:C */ if (caller_id_out) @@ -571,7 +549,7 @@ static void desc_make_reusable(struct prb_desc_ring *desc_ring, } /* - * Given a data ring (text or dict), put the associated descriptor of each + * Given the text data ring, put the associated descriptor of each * data block from @lpos_begin until @lpos_end into the reusable state. * * If there is any problem making the associated descriptor reusable, either @@ -586,21 +564,12 @@ static bool data_make_reusable(struct printk_ringbuffer *rb, unsigned long *lpos_out) { struct prb_desc_ring *desc_ring = &rb->desc_ring; - struct prb_data_blk_lpos *blk_lpos; struct prb_data_block *blk; enum desc_state d_state; struct prb_desc desc; + struct prb_data_blk_lpos *blk_lpos = &desc.text_blk_lpos; unsigned long id; - /* - * Using the provided @data_ring, point @blk_lpos to the correct - * blk_lpos within the local copy of the descriptor. - */ - if (data_ring == &rb->text_data_ring) - blk_lpos = &desc.text_blk_lpos; - else - blk_lpos = &desc.dict_blk_lpos; - /* Loop until @lpos_begin has advanced to or beyond @lpos_end. */ while ((lpos_end - lpos_begin) - 1 < DATA_SIZE(data_ring)) { blk = to_block(data_ring, lpos_begin); @@ -839,8 +808,6 @@ static bool desc_push_tail(struct printk_ringbuffer *rb, if (!data_push_tail(rb, &rb->text_data_ring, desc.text_blk_lpos.next)) return false; - if (!data_push_tail(rb, &rb->dict_data_ring, desc.dict_blk_lpos.next)) - return false; /* * Check the next descriptor after @tail_id before pushing the tail @@ -1347,9 +1314,8 @@ static struct prb_desc *desc_reopen_last(struct prb_desc_ring *desc_ring, * data. * * The writer specifies the text size to extend (not the new total size) by - * setting the @text_buf_size field of @r. Extending dictionaries is not - * supported, so @dict_buf_size of @r should be set to 0. To ensure proper - * initialization of @r, prb_rec_init_wr() should be used. + * setting the @text_buf_size field of @r. To ensure proper initialization + * of @r, prb_rec_init_wr() should be used. * * This function will fail if @caller_id does not match the caller ID of the * newest record. In that case the caller must reserve new data using @@ -1364,9 +1330,6 @@ static struct prb_desc *desc_reopen_last(struct prb_desc_ring *desc_ring, * * - @r->text_buf_size is set to the new total size of the buffer. * - * - @r->dict_buf and @r->dict_buf_size are cleared because extending - * the dict buffer is not supported. - * * - @r->info is not touched so that @r->info->text_len could be used * to append the text. * @@ -1375,8 +1338,7 @@ static struct prb_desc *desc_reopen_last(struct prb_desc_ring *desc_ring, * * Important: All @r->info fields will already be set with the current values * for the record. I.e. @r->info->text_len will be less than - * @text_buf_size and @r->info->dict_len may be set, even though - * @dict_buf_size is 0. Writers can use @r->info->text_len to know + * @text_buf_size. Writers can use @r->info->text_len to know * where concatenation begins and writers should update * @r->info->text_len after concatenating. */ @@ -1454,10 +1416,6 @@ bool prb_reserve_in_last(struct prb_reserved_entry *e, struct printk_ringbuffer if (r->text_buf_size && !r->text_buf) goto fail; - /* Although dictionary data may be in use, it cannot be extended. */ - r->dict_buf = NULL; - r->dict_buf_size = 0; - r->info = info; e->text_space = space_used(&rb->text_data_ring, &d->text_blk_lpos); @@ -1494,27 +1452,21 @@ static void desc_make_final(struct prb_desc_ring *desc_ring, unsigned long id) * * This is the public function available to writers to reserve data. * - * The writer specifies the text and dict sizes to reserve by setting the - * @text_buf_size and @dict_buf_size fields of @r, respectively. Dictionaries - * are optional, so @dict_buf_size is allowed to be 0. To ensure proper - * initialization of @r, prb_rec_init_wr() should be used. + * The writer specifies the text size to reserve by setting the + * @text_buf_size field of @r. To ensure proper initialization of @r, + * prb_rec_init_wr() should be used. * * Context: Any context. Disables local interrupts on success. * Return: true if at least text data could be allocated, otherwise false. * - * On success, the fields @info, @text_buf, @dict_buf of @r will be set by - * this function and should be filled in by the writer before committing. Also + * On success, the fields @info and @text_buf of @r will be set by this + * function and should be filled in by the writer before committing. Also * on success, prb_record_text_space() can be used on @e to query the actual * space used for the text data block. * - * If the function fails to reserve dictionary space (but all else succeeded), - * it will still report success. In that case @dict_buf is set to NULL and - * @dict_buf_size is set to 0. Writers must check this before writing to - * dictionary space. - * - * Important: @info->text_len and @info->dict_len need to be set correctly by - * the writer in order for data to be readable and/or extended. - * Their values are initialized to 0. + * Important: @info->text_len needs to be set correctly by the writer in + * order for data to be readable and/or extended. Its value + * is initialized to 0. */ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, struct printk_record *r) @@ -1528,9 +1480,6 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, if (!data_check_size(&rb->text_data_ring, r->text_buf_size)) goto fail; - if (!data_check_size(&rb->dict_data_ring, r->dict_buf_size)) - goto fail; - /* * Descriptors in the reserved state act as blockers to all further * reservations once the desc_ring has fully wrapped. Disable @@ -1598,15 +1547,6 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, goto fail; } - r->dict_buf = data_alloc(rb, &rb->dict_data_ring, r->dict_buf_size, - &d->dict_blk_lpos, id); - /* - * If dict data allocation fails, the caller can still commit - * text. But dictionary information will not be available. - */ - if (r->dict_buf_size && !r->dict_buf) - r->dict_buf_size = 0; - r->info = info; /* Record full text space used by record. */ @@ -1869,17 +1809,6 @@ static int prb_read(struct printk_ringbuffer *rb, u64 seq, return -ENOENT; } - /* - * Copy dict data. Although this should not fail, dict data is not - * important. So if it fails, modify the copied meta data to report - * that there is no dict data, thus silently dropping the dict data. - */ - if (!copy_data(&rb->dict_data_ring, &desc.dict_blk_lpos, info->dict_len, - r->dict_buf, r->dict_buf_size, NULL)) { - if (r->info) - r->info->dict_len = 0; - } - /* Ensure the record is still finalized and has the same @seq. */ return desc_read_finalized_seq(desc_ring, id, seq, &desc); } @@ -1974,7 +1903,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, * * This is the public function available to readers to read a record. * - * The reader provides the @info, @text_buf, @dict_buf buffers of @r to be + * The reader provides the @info and @text_buf buffers of @r to be * filled in. Any of the buffer pointers can be set to NULL if the reader * is not interested in that data. To ensure proper initialization of @r, * prb_rec_init_rd() should be used. @@ -2022,7 +1951,7 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, { struct printk_record r; - prb_rec_init_rd(&r, info, NULL, 0, NULL, 0); + prb_rec_init_rd(&r, info, NULL, 0); return _prb_read_valid(rb, &seq, &r, line_count); } @@ -2084,8 +2013,6 @@ u64 prb_next_seq(struct printk_ringbuffer *rb) * @rb: The ringbuffer to initialize. * @text_buf: The data buffer for text data. * @textbits: The size of @text_buf as a power-of-2 value. - * @dict_buf: The data buffer for dictionary data. - * @dictbits: The size of @dict_buf as a power-of-2 value. * @descs: The descriptor buffer for ringbuffer records. * @descbits: The count of @descs items as a power-of-2 value. * @infos: The printk_info buffer for ringbuffer records. @@ -2099,7 +2026,6 @@ u64 prb_next_seq(struct printk_ringbuffer *rb) */ void prb_init(struct printk_ringbuffer *rb, char *text_buf, unsigned int textbits, - char *dict_buf, unsigned int dictbits, struct prb_desc *descs, unsigned int descbits, struct printk_info *infos) { @@ -2117,18 +2043,11 @@ void prb_init(struct printk_ringbuffer *rb, atomic_long_set(&rb->text_data_ring.head_lpos, BLK0_LPOS(textbits)); atomic_long_set(&rb->text_data_ring.tail_lpos, BLK0_LPOS(textbits)); - rb->dict_data_ring.size_bits = dictbits; - rb->dict_data_ring.data = dict_buf; - atomic_long_set(&rb->dict_data_ring.head_lpos, BLK0_LPOS(dictbits)); - atomic_long_set(&rb->dict_data_ring.tail_lpos, BLK0_LPOS(dictbits)); - atomic_long_set(&rb->fail, 0); atomic_long_set(&(descs[_DESCS_COUNT(descbits) - 1].state_var), DESC0_SV(descbits)); descs[_DESCS_COUNT(descbits) - 1].text_blk_lpos.begin = FAILED_LPOS; descs[_DESCS_COUNT(descbits) - 1].text_blk_lpos.next = FAILED_LPOS; - descs[_DESCS_COUNT(descbits) - 1].dict_blk_lpos.begin = FAILED_LPOS; - descs[_DESCS_COUNT(descbits) - 1].dict_blk_lpos.next = FAILED_LPOS; infos[0].seq = -(u64)_DESCS_COUNT(descbits); infos[_DESCS_COUNT(descbits) - 1].seq = 0; |