Lines Matching +full:data +full:- +full:size

1 // SPDX-License-Identifier: LGPL-2.1
15 #define COMMIT_MASK ((1 << 27) - 1)
27 * @timestamp - timestamp of current event
28 * @lost_events - # of lost events between this subbuffer and previous
29 * @flags - special flags of the kbuffer
30 * @subbuffer - pointer to the sub-buffer page
31 * @data - pointer to the start of data on the sub-buffer page
32 * @index - index from @data to the @curr event data
33 * @curr - offset from @data to the start of current event
35 * @next - offset from @data to the start of next event
36 * @size - The size of data on @data
37 * @start - The offset from @subbuffer where @data lives
39 * @read_4 - Function to read 4 raw bytes (may swap)
40 * @read_8 - Function to read 8 raw bytes (may swap)
41 * @read_long - Function to read a long word (4 or 8 bytes with needed swap)
48 void *data; member
52 unsigned int size; member
61 static void *zmalloc(size_t size) in zmalloc() argument
63 return calloc(1, size); in zmalloc()
77 return ((kbuf->flags & KBUFFER_FL_HOST_BIG_ENDIAN) + kbuf->flags) & in do_swap()
83 unsigned long long data = *(unsigned long long *)ptr; in __read_8() local
85 return data; in __read_8()
90 unsigned long long data = *(unsigned long long *)ptr; in __read_8_sw() local
93 swap = ((data & 0xffULL) << 56) | in __read_8_sw()
94 ((data & (0xffULL << 8)) << 40) | in __read_8_sw()
95 ((data & (0xffULL << 16)) << 24) | in __read_8_sw()
96 ((data & (0xffULL << 24)) << 8) | in __read_8_sw()
97 ((data & (0xffULL << 32)) >> 8) | in __read_8_sw()
98 ((data & (0xffULL << 40)) >> 24) | in __read_8_sw()
99 ((data & (0xffULL << 48)) >> 40) | in __read_8_sw()
100 ((data & (0xffULL << 56)) >> 56); in __read_8_sw()
107 unsigned int data = *(unsigned int *)ptr; in __read_4() local
109 return data; in __read_4()
114 unsigned int data = *(unsigned int *)ptr; in __read_4_sw() local
117 swap = ((data & 0xffULL) << 24) | in __read_4_sw()
118 ((data & (0xffULL << 8)) << 8) | in __read_4_sw()
119 ((data & (0xffULL << 16)) >> 8) | in __read_4_sw()
120 ((data & (0xffULL << 24)) >> 24); in __read_4_sw()
127 return kbuf->read_8(ptr); in read_8()
132 return kbuf->read_4(ptr); in read_4()
137 return kbuf->read_8(ptr); in __read_long_8()
142 return kbuf->read_4(ptr); in __read_long_4()
147 return kbuf->read_long(kbuf, ptr); in read_long()
152 return (unsigned long)ptr - (unsigned long)kbuf->data; in calc_index()
158 * kbuffer_alloc - allocat a new kbuffer
159 * @size; enum to denote size of word
165 kbuffer_alloc(enum kbuffer_long_size size, enum kbuffer_endian endian) in kbuffer_alloc() argument
170 switch (size) { in kbuffer_alloc()
194 kbuf->flags = flags; in kbuffer_alloc()
197 kbuf->flags |= KBUFFER_FL_HOST_BIG_ENDIAN; in kbuffer_alloc()
200 kbuf->read_8 = __read_8_sw; in kbuffer_alloc()
201 kbuf->read_4 = __read_4_sw; in kbuffer_alloc()
203 kbuf->read_8 = __read_8; in kbuffer_alloc()
204 kbuf->read_4 = __read_4; in kbuffer_alloc()
207 if (kbuf->flags & KBUFFER_FL_LONG_8) in kbuffer_alloc()
208 kbuf->read_long = __read_long_8; in kbuffer_alloc()
210 kbuf->read_long = __read_long_4; in kbuffer_alloc()
213 kbuf->next_event = __next_event; in kbuffer_alloc()
218 /** kbuffer_free - free an allocated kbuffer
231 if (kbuf->flags & KBUFFER_FL_BIG_ENDIAN) in type4host()
240 if (kbuf->flags & KBUFFER_FL_BIG_ENDIAN) in len4host()
249 if (kbuf->flags & KBUFFER_FL_BIG_ENDIAN) in type_len4host()
250 return (type_len_ts >> 27) & ((1 << 5) - 1); in type_len4host()
252 return type_len_ts & ((1 << 5) - 1); in type_len4host()
258 if (kbuf->flags & KBUFFER_FL_BIG_ENDIAN) in ts4host()
259 return type_len_ts & ((1 << 27) - 1); in ts4host()
283 void *ptr = kbuf->data + kbuf->curr; in old_update_pointers()
294 kbuf->next = kbuf->size; in old_update_pointers()
308 kbuf->curr = kbuf->size; in old_update_pointers()
309 kbuf->next = kbuf->size; in old_update_pointers()
310 kbuf->index = kbuf->size; in old_update_pointers()
311 return -1; in old_update_pointers()
317 length -= 4; in old_update_pointers()
323 kbuf->timestamp += delta; in old_update_pointers()
324 kbuf->index = calc_index(kbuf, ptr); in old_update_pointers()
325 kbuf->next = kbuf->index + length; in old_update_pointers()
335 kbuf->curr = kbuf->next; in __old_next_event()
336 if (kbuf->next >= kbuf->size) in __old_next_event()
337 return -1; in __old_next_event()
345 translate_data(struct kbuffer *kbuf, void *data, void **rptr, in translate_data() argument
352 type_len_ts = read_4(kbuf, data); in translate_data()
353 data += 4; in translate_data()
360 *length = read_4(kbuf, data); in translate_data()
365 extend = read_4(kbuf, data); in translate_data()
366 data += 4; in translate_data()
374 *length = read_4(kbuf, data) - 4; in translate_data()
376 data += 4; in translate_data()
383 *rptr = data; in translate_data()
393 void *ptr = kbuf->data + kbuf->curr; in update_pointers()
398 kbuf->timestamp = delta; in update_pointers()
400 kbuf->timestamp += delta; in update_pointers()
402 kbuf->index = calc_index(kbuf, ptr); in update_pointers()
403 kbuf->next = kbuf->index + length; in update_pointers()
409 * kbuffer_translate_data - read raw data to get a record
411 * @data: The raw data to read
412 * @size: Address to store the size of the event data.
414 * Returns a pointer to the event data. To determine the entire
415 * record size (record metadata + data) just add the difference between
416 * @data and the returned value to @size.
418 void *kbuffer_translate_data(int swap, void *data, unsigned int *size) in kbuffer_translate_data() argument
436 type_len = translate_data(&kbuf, data, &ptr, &delta, &length); in kbuffer_translate_data()
444 *size = length; in kbuffer_translate_data()
454 kbuf->curr = kbuf->next; in __next_event()
455 if (kbuf->next >= kbuf->size) in __next_event()
456 return -1; in __next_event()
467 return kbuf->next_event(kbuf); in next_event()
471 * kbuffer_next_event - increment the current pointer
479 * Returns the data of the next event if a new event exists on the subbuffer,
486 if (!kbuf || !kbuf->subbuffer) in kbuffer_next_event()
494 *ts = kbuf->timestamp; in kbuffer_next_event()
496 return kbuf->data + kbuf->index; in kbuffer_next_event()
500 * kbuffer_load_subbuffer - load a new subbuffer into the kbuffer
508 * Returns 0 on succes, -1 otherwise.
516 return -1; in kbuffer_load_subbuffer()
518 kbuf->subbuffer = subbuffer; in kbuffer_load_subbuffer()
520 kbuf->timestamp = read_8(kbuf, ptr); in kbuffer_load_subbuffer()
523 kbuf->curr = 0; in kbuffer_load_subbuffer()
525 if (kbuf->flags & KBUFFER_FL_LONG_8) in kbuffer_load_subbuffer()
526 kbuf->start = 16; in kbuffer_load_subbuffer()
528 kbuf->start = 12; in kbuffer_load_subbuffer()
530 kbuf->data = subbuffer + kbuf->start; in kbuffer_load_subbuffer()
533 kbuf->size = (unsigned int)flags & COMMIT_MASK; in kbuffer_load_subbuffer()
537 ptr = kbuf->data + kbuf->size; in kbuffer_load_subbuffer()
538 kbuf->lost_events = read_long(kbuf, ptr); in kbuffer_load_subbuffer()
540 kbuf->lost_events = -1; in kbuffer_load_subbuffer()
542 kbuf->lost_events = 0; in kbuffer_load_subbuffer()
544 kbuf->index = 0; in kbuffer_load_subbuffer()
545 kbuf->next = 0; in kbuffer_load_subbuffer()
553 * kbuffer_subbuf_timestamp - read the timestamp from a sub buffer
561 return kbuf->read_8(subbuf); in kbuffer_subbuf_timestamp()
565 * kbuffer_ptr_delta - read the delta field from a record
581 * kbuffer_read_event - read the next event in the kbuffer subbuffer
585 * Returns a pointer to the data part of the current event.
590 if (!kbuf || !kbuf->subbuffer) in kbuffer_read_event()
593 if (kbuf->curr >= kbuf->size) in kbuffer_read_event()
597 *ts = kbuf->timestamp; in kbuffer_read_event()
598 return kbuf->data + kbuf->index; in kbuffer_read_event()
602 * kbuffer_timestamp - Return the timestamp of the current event
609 return kbuf->timestamp; in kbuffer_timestamp()
613 * kbuffer_read_at_offset - read the event that is at offset
621 * Returns the data of the record that is at @offset. Note, @offset does
627 * data and timestamp, and kbuffer_next_event() will increment from
633 void *data; in kbuffer_read_at_offset() local
635 if (offset < kbuf->start) in kbuffer_read_at_offset()
638 offset -= kbuf->start; in kbuffer_read_at_offset()
641 kbuffer_load_subbuffer(kbuf, kbuf->subbuffer); in kbuffer_read_at_offset()
642 data = kbuffer_read_event(kbuf, ts); in kbuffer_read_at_offset()
644 while (kbuf->curr < offset) { in kbuffer_read_at_offset()
645 data = kbuffer_next_event(kbuf, ts); in kbuffer_read_at_offset()
646 if (!data) in kbuffer_read_at_offset()
650 return data; in kbuffer_read_at_offset()
654 * kbuffer_subbuffer_size - the size of the loaded subbuffer
657 * Returns the size of the subbuffer. Note, this size is
663 return kbuf->size; in kbuffer_subbuffer_size()
667 * kbuffer_curr_index - Return the index of the record
670 * Returns the index from the start of the data part of
678 return kbuf->curr; in kbuffer_curr_index()
682 * kbuffer_curr_offset - Return the offset of the record
690 return kbuf->curr + kbuf->start; in kbuffer_curr_offset()
694 * kbuffer_event_size - return the size of the event data
697 * Returns the size of the event data (the payload not counting
698 * the meta data of the record) of the current event.
702 return kbuf->next - kbuf->index; in kbuffer_event_size()
706 * kbuffer_curr_size - return the size of the entire record
709 * Returns the size of the entire record (meta data and payload)
714 return kbuf->next - kbuf->curr; in kbuffer_curr_size()
718 * kbuffer_missed_events - return the # of missed events from last event.
729 if (kbuf->curr) in kbuffer_missed_events()
732 return kbuf->lost_events; in kbuffer_missed_events()
736 * kbuffer_set_old_forma - set the kbuffer to use the old format parsing
746 kbuf->flags |= KBUFFER_FL_OLD_FORMAT; in kbuffer_set_old_format()
748 kbuf->next_event = __old_next_event; in kbuffer_set_old_format()
752 * kbuffer_start_of_data - return offset of where data starts on subbuffer
755 * Returns the location on the subbuffer where the data starts.
759 return kbuf->start; in kbuffer_start_of_data()
763 * kbuffer_raw_get - get raw buffer info
769 * Expects to have info->next set to what it will read.
771 * @info->next will be updated to the next element.
773 * data and NULL will be returned if it is.
781 unsigned int size; in kbuffer_raw_get() local
784 void *ptr = info->next; in kbuffer_raw_get()
789 if (kbuf->flags & KBUFFER_FL_LONG_8) in kbuffer_raw_get()
795 size = (unsigned int)flags & COMMIT_MASK; in kbuffer_raw_get()
797 if (ptr < subbuf || ptr >= subbuf + start + size) in kbuffer_raw_get()
802 info->next = ptr + length; in kbuffer_raw_get()
804 info->type = type_len; in kbuffer_raw_get()
805 info->delta = delta; in kbuffer_raw_get()
806 info->length = length; in kbuffer_raw_get()