본문 바로가기

Core BSP 분석/리눅스 커널 핵심 분석

[리눅스커널] tracing: 부팅 과정에서 ftrace ring-buffer 늘리기

<커널: v5.10>
 
부팅 과정에서 ftrace 로깅이 될 때 ftrace ring-buffer 사이즈가 충분해야 부팅 과정의 
메시지를 ftrace에 저장할 수 있습니다. ring-buffer 사이즈가 작으면 메시지가 overwritten됩니다. 
 
본 페이지에 소개된 패치를 적용하면 부팅 과정에서 ftracing ring-buffer 사이즈를 키울 수 있습니다.
 
commit 0deada593566918d6ac4a3e8df7bca8584fd83e1 (HEAD -> rpi-5.10.y)
Author: Austin Kim <austindh.kim@gmail.com>
Date:   Mon Sep 20 14:52:54 2021 +0900
 
    tracing: increase ftrace ring-buffer size
 
    In case ftrace ring-buffer size is small,
    ftrace message could be overwritten. As a result of this,
    the useful ftrace message can be lost.
 
    With this commit, we could increase ftrace ring-buffer size.
 
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
old mode 100644
new mode 100755
index b09c59806..8cb872543
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6541,6 +6541,8 @@ tracing_entries_read(struct file *filp, char __user *ubuf,
        return ret;
 }
 
+#define TRACING_FTRACE_MAX_BUFFER_SIZE (4096 * 2)
+
 static ssize_t
 tracing_entries_write(struct file *filp, const char __user *ubuf,
                      size_t cnt, loff_t *ppos)
@@ -6558,6 +6560,10 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
        if (!val)
                return -EINVAL;
 
+       if( val < TRACING_FTRACE_MAX_BUFFER_SIZE ) {
+               val = TRACING_FTRACE_MAX_BUFFER_SIZE;
+       }
+
        /* value is in KB */
        val <<= 10;
        ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode));