[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <81669788-9661-40fb-9cbc-c9fb44970c3c@gmail.com>
Date: Thu, 11 Sep 2025 08:42:03 +0800
From: Jinchao Wang <wangjinchao600@...il.com>
To: "H. Peter Anvin" <hpa@...or.com>, Dave Hansen <dave.hansen@...el.com>,
Thomas Gleixner <tglx@...utronix.de>, Masami Hiramatsu
<mhiramat@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall
On 9/10/25 22:56, H. Peter Anvin wrote:
> On September 10, 2025 7:47:06 AM PDT, Dave Hansen <dave.hansen@...el.com> wrote:
>> On 9/10/25 02:39, Jinchao Wang wrote:
>>> Consolidate breakpoint management into a single helper function to
>>> reduce code duplication. This introduces new static helpers for
>>> slot management and debug register manipulation.
>>>
>>> Also, add `<linux/types.h>` to the header file to fix a build
>>> dependency.
>>>
>>> Signed-off-by: Jinchao Wang <wangjinchao600@...il.com>
>>> ---
>>> arch/x86/include/asm/hw_breakpoint.h | 7 +-
>>> arch/x86/kernel/hw_breakpoint.c | 151 ++++++++++++++++-----------
>>> 2 files changed, 96 insertions(+), 62 deletions(-)
>> That diffstat doesn't look like it's reducing code duplication.
> He does add a *lot* of comments.
The diffstat was misleading. My refactoring consolidated duplicated
logic into reusable functions, which reduces the final code size.
The original refactoring can be found at:
https://lore.kernel.org/lkml/20250904002126.1514566-6-wangjinchao600@gmail.com
Measurements of the `hw_breakpoint.o`file were taken with
`CONFIG_DEBUG_INFO`
enabled, using these commands:
```
objcopy --strip-debug arch/x86/kernel/hw_breakpoint.o tmp.o
du -b arch/x86/kernel/hw_breakpoint.o
du -b tmp.o
```
This table compares the code size in bytes. The `refactor`column indicates
if the refactoring was applied (`1`) or not (`0`). The `function`column
indicates if `arch_reinstall_hw_breakpoint`was included (`1`) or not (`0`).
```
+----------+------------+------------+----------+----------+
| refactor | function | unstripped | stripped | percent |
+----------+------------+------------+----------+----------+
| 0 | 0 | 275320 | 11976 | 100% |
| 1 | 0 | 275736 | 11448 | 96% |
| 0 | 1 | 278720 | 13520 | 100% |
| 1 | 1 | 276392 | 11760 | 87% |
+----------+------------+------------+----------+----------+
```
1.**Overall Refactoring Benefit**: The refactored version (`refactor 1`)
with
`arch_reinstall_hw_breakpoint`is 11760 bytes, a **13%**reduction from the
original's 13520 bytes.
2.**Unification Target**: Adding `arch_reinstall_hw_breakpoint`to the
un-refactored code increased the size by **1544 bytes**. Adding it to the
refactored code only increased the size by **312 bytes**. This demonstrates
that the refactoring makes future code additions more efficient.
--
Thanks,
Jinchao
Powered by blists - more mailing lists