Re: [PATCH v1] LoongArch: Use current_stack_pointer in current_pt_regs()
Huacai Chen <[email protected]>
| Newsgroups | dev.linux.lists.loongarch,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAAhV-H4zep4eLMhgvy4W94L=yv0_L4Okx2NTYiza8Z_uaTj5pQ@mail.gmail.com> |
On Thu, Aug 13, 2026 at 5:55 PM Tiezhu Yang <[email protected]> wrote: > > On 2026/8/13 下午5:32, Huacai Chen wrote: > > Hi, Tiezhu, > > > > On Thu, Aug 13, 2026 at 5:05 PM Tiezhu Yang <[email protected]> wrote: > >> > >> The current implementation of current_pt_regs() relies on the compiler > >> __builtin_frame_address(0). This introduces an unnecessary dependency > >> on the frame pointer register, which forces the compiler to generate > >> redundant prologue and epilogue code, create a larger stack frame, and > >> perform redundant memory operations to preserve the frame pointer even > >> in functions where it is otherwise unnecessary. > >> > >> Optimize this by switching to current_stack_pointer, which explicitly > >> maps to the hardware stack pointer register. This allows the compiler > >> to compute the stack alignment directly from the natively maintained > >> $sp register, completely eliminating the overhead of preserving and > >> restoring the frame pointer on the stack memory. > >> > >> As a prominent example, this optimization significantly improves the > >> hot-path function copy_thread(). A localized disassembly comparison > >> of copy_thread() illustrates the elimination of the frame pointer, > >> the reduction of stack frame size from 48 bytes down to 32 bytes, > >> and a more compact epilogue path: > > 3 instructions and 16 bytes stack space. There is improvement, but not > > "significantly". > > I used "significantly" from the perspective of hot-path sensitivity, > but I agree that 3 instructions and 16 bytes might be inaccurate. > > If the code itself looks good to you, please feel free to update the > commit message as you see fit when applying. > > Alternatively, let me know if you prefer me to send a v2 with a more > accurate description. Unnecessary, I will modify it. Huacai > > Thanks, > Tiezhu >