From nobody Thu Dec 18 14:46:03 2025 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D4C8299AAC for ; Mon, 15 Dec 2025 03:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765770174; cv=none; b=QrV5M9jFKu6XEx7saSPmgxm+k6uBYylfCZAArJ3hB8kDKDnDLmuOjLoYatuNgFTFlyGXfAX3w9j1jF5KDncRm19G52yTYXYf2mXz3UdOlhYU81FaRO3V3tDcQ9/0IRzHktnC2a0vyXHTU6v0E4Os/ncwoVgorWcW6e4wGXHdSIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765770174; c=relaxed/simple; bh=l38H3vsBTdrEgWUMkEZiNVCzoEObSKrQ0jGhEvBuLdE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XKqDnFLVy0WmaTXuV8BFueU87XsQnfDx0eh7AZWQ+3F+ZVMsTEaN+jOadepOH5ejrBZy9tb+RPitQ+YPldOT+J4MX0cDzy3ys8BxHuoFA4jZ7BrcX9TO112EZCs8DYnuQWxgHtlDFdm+VfiHvKDvfpCR22Goh9oaUQvvDpyJxLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aIAfC/8w; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aIAfC/8w" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-34c708702dfso709420a91.1 for ; Sun, 14 Dec 2025 19:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765770171; x=1766374971; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zodsawp9MT0zFDRA0UB83iWzeQZFAUerG70qGUpiRMU=; b=aIAfC/8w4T/cAr7zcvewSyDbm3lxXGhQbtW3U2NuXS6TqiZ7A248Rde2tl40fliGPh CKvYNGCPUrgUvh+DbWEsW9mBPj2iutjpOazoqlRHPuy54znqfxQuhZffZFYQTfywVlWP OhBYcAh10DXsU2SOLlHd0g5PnXOTc7yyQQSJ6nHvNW9PCX5tVacq2shA17kIPUJtvzhI ftZLeY1/SoeUq/ptlJoT4/1dBhU0MJDyEM8Z2gpdWiP3GyQKTXUzmcpUK8Sfc3DU/sja aS6jyaI9IWu6d8SEkfNsbsTj0NP/5qIxMHZwDr7FDp/rIPmv5wvi3+Jv+sjQXD3yQ1z8 o1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765770171; x=1766374971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zodsawp9MT0zFDRA0UB83iWzeQZFAUerG70qGUpiRMU=; b=Gt+Wo8Kqhd39kpsyRrUtw3n+c2j0PvAzEYB7CEMEgFv5OuCepzVPRD5XZ2vRDoE6ZI gzhCj0u+jyZW3R7HXs3zXezhkYpQol+Ofs4usE4ClsBrxT3+2pN0GtC64RU22mZDxdbG /yUFQCJe7mm9t+QNJDheTBMJrE7/PrfEe9jaI8hkqyLaGsj2/uOrmf00moGd6yArwgC6 iQQ4IdeTZYf3+SvtsGhdpgZ48WaftWjTRu7/c31/XLoad7nybkGpjUhi7K/46tCMDPxR mdB+6JiJzFjycCC/0G9vHv4gsdmKGf11CGMA+f6D7kd2ZcU76O8bKZA2s5iXYtsCpLI/ s+xA== X-Forwarded-Encrypted: i=1; AJvYcCXYZJYHJw5bWYeiSnej0TJ+1uN0oA0s22KQ+ZaWybGRZPbxSItgBYtVE2z8rE2fqq3JEKTKqGoUmjY+UbQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyM9ovYKt4ER+RPh1prA2UxRMYxPVhjoNU3bkoRfXpwWsUb2hEm x7FDXrmE2Ye1TZijqQhou8+g/QMidnknrc73u3Zjgz6OXlJA3mGfvHAj X-Gm-Gg: AY/fxX4ONa5SzvjqBVrSvR2CpSefqjbKOwahYsSBT/5sz+L046f1liWoqhBCHCAmuS1 DvDEloQpcE42Nn3XRWKVsqYz4UZa9JEh52/nznK2vGewe5JJumIH1PinJGEspghK9AFabQ7JB8Y HV7oCZvZHMe8GA/LQQqYTYdblRJTDlfhamkA92JpoPoeoKy+fj2PNkyK4G+9FKKjhrxIZdTMKcA yxU5Akl0HtrhG8A9tXONQMJzAxD4NKdlThGPy7P+BfWJTZXLdtU0pa4usN/2cZi8uzpjiwv4Hqn dYxmqIDNhbGEZhSj20di9+8bDZVAzxdEu0TvPBOBeSN6QtpjKfUf1k7zXRGLAtdtMvcpCTUweoa VJdCBBbXSuxS0zkEbhEDLsiCObD/Zasp3YjsHj/r/1y+6Jh45O5RW23rGTeUsGsyXMt0PuaFQgm AdUw7TCOaB5k5PPTdG4kuRhQKntFw= X-Google-Smtp-Source: AGHT+IFV0mk8C23ZddCTFMGBb6EW5vJkKKe/Id/7ooCo0G5hzTqwU+bujzLDeHuF/5cfsXslbYpfpg== X-Received: by 2002:a17:90b:3c4f:b0:340:c179:3666 with SMTP id 98e67ed59e1d1-34abd6c02cfmr7561102a91.8.1765770169907; Sun, 14 Dec 2025 19:42:49 -0800 (PST) Received: from pengdl-pc.mioffice.cn ([43.224.245.249]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34abe23a207sm3420562a91.1.2025.12.14.19.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Dec 2025 19:42:48 -0800 (PST) From: Donglin Peng To: rostedt@goodmis.org Cc: mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, pengdonglin , Xiaoqin Zhang Subject: [PATCH v4 3/3] tracing: Update funcgraph-retval documentation Date: Mon, 15 Dec 2025 11:41:53 +0800 Message-Id: <20251215034153.2367756-4-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251215034153.2367756-1-dolinux.peng@gmail.com> References: <20251215034153.2367756-1-dolinux.peng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: pengdonglin The existing documentation for funcgraph-retval is outdated and partially incorrect, as it describes limitations that have now been resolved. Recent changes (e.g., using BTF to obtain function return types) have addressed key issues: 1. Return values are now printed only for non-void functions. 2. Values are trimmed to the correct width of the return type, avoiding garbage data from high bits. Cc: Steven Rostedt (Google) Cc: Masami Hiramatsu Cc: Xiaoqin Zhang Signed-off-by: pengdonglin --- Documentation/trace/ftrace.rst | 88 +++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst index d1f313a5f4ad..b231e80e6a4f 100644 --- a/Documentation/trace/ftrace.rst +++ b/Documentation/trace/ftrace.rst @@ -1454,6 +1454,10 @@ Options for function_graph tracer: printed in hexadecimal format. By default, this option is off. =20 + funcgraph-retaddr + When set, the return address will always be printed. + By default, this option is off. + sleep-time When running function graph tracer, to include the time a task schedules out in its function. @@ -2800,7 +2804,7 @@ It is default disabled. 0) 2.861 us | } /* putname() */ =20 The return value of each traced function can be displayed after -an equal sign "=3D". When encountering system call failures, it +an equal sign "ret =3D". When encountering system call failures, it can be very helpful to quickly locate the function that first returns an error code. =20 @@ -2810,16 +2814,16 @@ returns an error code. Example with funcgraph-retval:: =20 1) | cgroup_migrate() { - 1) 0.651 us | cgroup_migrate_add_task(); /* =3D 0xffff93fcfd= 346c00 */ + 1) 0.651 us | cgroup_migrate_add_task(); /* ret=3D0xffff93fc= fd346c00 */ 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { - 1) 0.732 us | cgroup_taskset_next(); /* =3D 0xffff93fc= 8fb20000 */ - 1) 1.232 us | } /* cgroup_taskset_first =3D 0xffff93fc8f= b20000 */ - 1) 0.380 us | sched_rt_can_attach(); /* =3D 0x0 */ - 1) 2.335 us | } /* cpu_cgroup_can_attach =3D -22 */ - 1) 4.369 us | } /* cgroup_migrate_execute =3D -22 */ - 1) 7.143 us | } /* cgroup_migrate =3D -22 */ + 1) 0.732 us | cgroup_taskset_next(); /* ret=3D0xffff93= fc8fb20000 */ + 1) 1.232 us | } /* cgroup_taskset_first ret=3D0xffff93fc= 8fb20000 */ + 1) 0.380 us | sched_rt_can_attach(); /* ret=3D0x0 */ + 1) 2.335 us | } /* cpu_cgroup_can_attach ret=3D-22 */ + 1) 4.369 us | } /* cgroup_migrate_execute ret=3D-22 */ + 1) 7.143 us | } /* cgroup_migrate ret=3D-22 */ =20 The above example shows that the function cpu_cgroup_can_attach returned the error code -22 firstly, then we can read the code @@ -2836,37 +2840,41 @@ printed in hexadecimal format. Example with funcgraph-retval-hex:: =20 1) | cgroup_migrate() { - 1) 0.651 us | cgroup_migrate_add_task(); /* =3D 0xffff93fc= fd346c00 */ + 1) 0.651 us | cgroup_migrate_add_task(); /* ret=3D0xffff93= fcfd346c00 */ 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { - 1) 0.732 us | cgroup_taskset_next(); /* =3D 0xffff93= fc8fb20000 */ - 1) 1.232 us | } /* cgroup_taskset_first =3D 0xffff93fc= 8fb20000 */ - 1) 0.380 us | sched_rt_can_attach(); /* =3D 0x0 */ - 1) 2.335 us | } /* cpu_cgroup_can_attach =3D 0xffffffea = */ - 1) 4.369 us | } /* cgroup_migrate_execute =3D 0xffffffea */ - 1) 7.143 us | } /* cgroup_migrate =3D 0xffffffea */ - -At present, there are some limitations when using the funcgraph-retval -option, and these limitations will be eliminated in the future: - -- Even if the function return type is void, a return value will still - be printed, and you can just ignore it. - -- Even if return values are stored in multiple registers, only the - value contained in the first register will be recorded and printed. - To illustrate, in the x86 architecture, eax and edx are used to store - a 64-bit return value, with the lower 32 bits saved in eax and the - upper 32 bits saved in edx. However, only the value stored in eax - will be recorded and printed. - -- In certain procedure call standards, such as arm64's AAPCS64, when a - type is smaller than a GPR, it is the responsibility of the consumer - to perform the narrowing, and the upper bits may contain UNKNOWN values. - Therefore, it is advisable to check the code for such cases. For instanc= e, - when using a u8 in a 64-bit GPR, bits [63:8] may contain arbitrary value= s, - especially when larger types are truncated, whether explicitly or implic= itly. - Here are some specific cases to illustrate this point: + 1) 0.732 us | cgroup_taskset_next(); /* ret=3D0xffff= 93fc8fb20000 */ + 1) 1.232 us | } /* cgroup_taskset_first ret=3D0xffff93= fc8fb20000 */ + 1) 0.380 us | sched_rt_can_attach(); /* ret=3D0x0 */ + 1) 2.335 us | } /* cpu_cgroup_can_attach ret=3D0xffffffe= a */ + 1) 4.369 us | } /* cgroup_migrate_execute ret=3D0xffffffea= */ + 1) 7.143 us | } /* cgroup_migrate ret=3D0xffffffea */ + +Note that there are some limitations when using the funcgraph-retval +option: + +- If CONFIG_DEBUG_INFO_BTF is disabled (n), a return value is printed even= for + functions with a void return type. When CONFIG_DEBUG_INFO_BTF is enabled= (y), + the return value is printed only for non-void functions. + +- If a return value occupies multiple registers, only the value in the fir= st + register is recorded and printed. For example, on the x86 architecture, a + 64-bit return value is stored across eax (lower 32 bits) and edx (upper = 32 bits), + but only the contents of eax are captured. If CONFIG_DEBUG_INFO_BTF is e= nabled, + the suffix "(trunc)" is appended to the printed value to indicate that t= he + output may be truncated because high-order register contents are omitted. + +- Under certain procedure-call standards (e.g., arm64's AAPCS64), when the= return + type is smaller than a general-purpose register (GPR), the caller is res= ponsible + for narrowing the value; the upper bits of the register may contain unde= fined data. + For instance, when a u8 is returned in 64-bit GPR, bits [63:8] can hold = arbitrary + values, especially when larger types are truncated (explicitly or implic= itly). It + is therefore advisable to inspect the code in such cases. If CONFIG_DEBU= G_INFO_BTF + is enabled (y), the return value is automatically trimmed to the width o= f the return + type. + + The following examples illustrate the behavior: =20 **Case One**: =20 @@ -2885,7 +2893,9 @@ option, and these limitations will be eliminated in t= he future: RET =20 If you pass 0x123456789abcdef to this function and want to narrow it, - it may be recorded as 0x123456789abcdef instead of 0xef. + it may be recorded as 0x123456789abcdef instead of 0xef. When + CONFIG_DEBUG_INFO_BTF is enabled, the value will be correctly truncated + to 0xef based on the size constraints of the u8 type. =20 **Case Two**: =20 @@ -2910,7 +2920,9 @@ option, and these limitations will be eliminated in t= he future: RET =20 When passing 0x2_0000_0000 to it, the return value may be recorded as - 0x2_0000_0000 instead of 0. + 0x2_0000_0000 instead of 0. When CONFIG_DEBUG_INFO_BTF is enabled, the + value will be correctly truncated to 0 based on the size constraints of + the int type. =20 You can put some comments on specific functions by using trace_printk() For example, if you want to put a comment inside --=20 2.34.1