The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jinchao Wang <wangjinchao600@gmail.com>
To: "H. Peter Anvin" <hpa@zytor.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall
Date: Thu, 11 Sep 2025 08:42:03 +0800	[thread overview]
Message-ID: <81669788-9661-40fb-9cbc-c9fb44970c3c@gmail.com> (raw)
In-Reply-To: <332DA932-2A5A-48B1-AEF6-84D4CCDB7BA1@zytor.com>


On 9/10/25 22:56, H. Peter Anvin wrote:
> On September 10, 2025 7:47:06 AM PDT, Dave Hansen <dave.hansen@intel.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@gmail.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


  reply	other threads:[~2025-09-11  0:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-10  9:39 [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall Jinchao Wang
2025-09-10  9:39 ` [PATCH 2/2] x86/hw_breakpoint: Add arch_reinstall_hw_breakpoint Jinchao Wang
2025-09-11 10:16   ` Masami Hiramatsu
2025-09-10 14:47 ` [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall Dave Hansen
2025-09-10 14:56   ` H. Peter Anvin
2025-09-11  0:42     ` Jinchao Wang [this message]
2025-09-11  8:03 ` Masami Hiramatsu
2025-09-12  1:05   ` Jinchao Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81669788-9661-40fb-9cbc-c9fb44970c3c@gmail.com \
    --to=wangjinchao600@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox