1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: Change the ringbuffer sub-buffer size 4# requires: buffer_subbuf_size_kb 5# flags: instance 6 7get_buffer_data_size() { 8 sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page 9} 10 11get_buffer_data_offset() { 12 sed -ne 's/^.*data.*offset:\([0-9][0-9]*\).*/\1/p' events/header_page 13} 14 15get_event_header_size() { 16 type_len=`sed -ne 's/^.*type_len.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` 17 time_len=`sed -ne 's/^.*time_delta.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` 18 array_len=`sed -ne 's/^.*array.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` 19 total_bits=$((type_len+time_len+array_len)) 20 total_bits=$((total_bits+7)) 21 echo $((total_bits/8)) 22} 23 24get_print_event_buf_offset() { 25 sed -ne 's/^.*buf.*offset:\([0-9][0-9]*\).*/\1/p' events/ftrace/print/format 26} 27 28event_header_size=`get_event_header_size` 29print_header_size=`get_print_event_buf_offset` 30 31data_offset=`get_buffer_data_offset` 32 33marker_meta=$((event_header_size+print_header_size)) 34 35make_str() { 36 cnt=$1 37 printf -- 'X%.0s' $(seq $cnt) 38} 39 40write_buffer() { 41 size=$1 42 43 str=`make_str $size` 44 45 # clear the buffer 46 echo > trace 47 48 # write the string into the marker 49 echo $str > trace_marker 50 51 echo $str 52} 53 54test_buffer() { 55 size_kb=$1 56 page_size=$((size_kb*1024)) 57 58 size=`get_buffer_data_size` 59 60 # the size must be greater than or equal to page_size - data_offset 61 page_size=$((page_size-data_offset)) 62 if [ $size -lt $page_size ]; then 63 exit fail 64 fi 65 66 # Now add a little more the meta data overhead will overflow 67 68 str=`write_buffer $size` 69 70 # Make sure the line was broken 71 new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; exit}' trace` 72 73 if [ "$new_str" = "$str" ]; then 74 exit fail; 75 fi 76 77 # Make sure the entire line can be found 78 new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; }' trace` 79 80 if [ "$new_str" != "$str" ]; then 81 exit fail; 82 fi 83} 84 85ORIG=`cat buffer_subbuf_size_kb` 86 87# Could test bigger sizes than 32K, but then creating the string 88# to write into the ring buffer takes too long 89for a in 4 8 16 32 ; do 90 echo $a > buffer_subbuf_size_kb 91 test_buffer $a 92done 93 94echo $ORIG > buffer_subbuf_size_kb 95 96