loongarch.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] loongarch: kgdb: remove unnecessary init variable
@ 2025-06-04  6:56 Li Jun
  2025-06-04 14:11 ` Huacai Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Li Jun @ 2025-06-04  6:56 UTC (permalink / raw)
  To: si.yanteng, chenhuacai, kernel, loongarch, lijun01

The compiler generates initialization instructions,
which consume additional CPU cycles. the
get_step_address(regs, &addr) should assign a value
to 'error' before it is read.so the var don't need init
to 0.

Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
 arch/loongarch/kernel/kgdb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/loongarch/kernel/kgdb.c b/arch/loongarch/kernel/kgdb.c
index 7be5b4c0c900..df85d6a0dc74 100644
--- a/arch/loongarch/kernel/kgdb.c
+++ b/arch/loongarch/kernel/kgdb.c
@@ -379,10 +379,9 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
 
 static int do_single_step(struct pt_regs *regs)
 {
-	int error = 0;
 	unsigned long addr = 0; /* Determine where the target instruction will send us to */
+	int error = get_step_address(regs, &addr);
 
-	error = get_step_address(regs, &addr);
 	if (error)
 		return error;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] loongarch: kgdb: remove unnecessary init variable
  2025-06-04  6:56 [PATCH v2] loongarch: kgdb: remove unnecessary init variable Li Jun
@ 2025-06-04 14:11 ` Huacai Chen
  2025-06-05  1:30   ` Re:[PATCH " lijun
  2025-06-05  1:41   ` Re:[PATCH " lijun
  0 siblings, 2 replies; 6+ messages in thread
From: Huacai Chen @ 2025-06-04 14:11 UTC (permalink / raw)
  To: Li Jun; +Cc: si.yanteng, kernel, loongarch

On Wed, Jun 4, 2025 at 2:57 PM Li Jun <lijun01@kylinos.cn> wrote:
>
> The compiler generates initialization instructions,
> which consume additional CPU cycles. the
> get_step_address(regs, &addr) should assign a value
> to 'error' before it is read.so the var don't need init
> to 0.
Why do you think the compiler generates initialization instructions,
have you found any difference in the binary after your patch?

Huacai

>
> Signed-off-by: Li Jun <lijun01@kylinos.cn>
> ---
>  arch/loongarch/kernel/kgdb.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/kernel/kgdb.c b/arch/loongarch/kernel/kgdb.c
> index 7be5b4c0c900..df85d6a0dc74 100644
> --- a/arch/loongarch/kernel/kgdb.c
> +++ b/arch/loongarch/kernel/kgdb.c
> @@ -379,10 +379,9 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
>
>  static int do_single_step(struct pt_regs *regs)
>  {
> -       int error = 0;
>         unsigned long addr = 0; /* Determine where the target instruction will send us to */
> +       int error = get_step_address(regs, &addr);
>
> -       error = get_step_address(regs, &addr);
>         if (error)
>                 return error;
>
> --
> 2.25.1
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:[PATCH v2] loongarch: kgdb: remove unnecessary init variable
  2025-06-04 14:11 ` Huacai Chen
@ 2025-06-05  1:30   ` lijun
  2025-06-05  1:37     ` [PATCH " Huacai Chen
  2025-06-05  1:41   ` Re:[PATCH " lijun
  1 sibling, 1 reply; 6+ messages in thread
From: lijun @ 2025-06-05  1:30 UTC (permalink / raw)
  To: lijun01; +Cc: kernel, loongarch



#include<stdio.h>                                              #include
<stdio.h>
                                        
int main(int argc, const char *argv[])     int main(int argc, const
char *argv[])
{                                                                      
               {
    int
i=0;                                                                   
  int i;
                                        
                                        
    i =
3;                                                                     
    i = 3;
    printf("i = %d\n",
i);                                       printf("i = %d\n", i); 
    return
0;                                                              return
0;
}                                                                      
              }                                      
 endbr64                                                               
   endbr64
push   %rbp                                                           p
ush   %rbp
mov    %rsp,%rbp                                              mov    %r
sp,%rbp
sub    $0x20,%rsp                                                sub   
 $0x20,%rsp
mov    %edi,-0x14(%rbp)                               mov    %edi,-
0x14(%rbp)
mov    %rsi,-0x20(%rbp)                                mov    %rsi,-
0x20(%rbp)
movl   $0x0,-0x4(%rbp)                                  movl   $0x3,-
0x4(%rbp)
movl   $0x3,-0x4(%rbp)                                  mov    -
0x4(%rbp),%eax
mov    -0x4(%rbp),%eax                                mov    %eax,%esi
mov    %eax,%esi                                              mov    $0
x402004,%edi
mov    $0x402004,%edi                                  mov    $0x0,%eax
mov    $0x0,%eax                                               callq  4
01040 <printf@plt>
callq  401040 <printf@plt>

if  gcc   -O3   test2.c -o a2.out, It is possible that the
initialization is optimized by
assigning values immediately after initialization
endbr64 
sub    $0x8,%rsp
mov    $0x3,%edx
mov    $0x402004,%esi
xor    %eax,%eax
mov    $0x1,%edi
callq  401040 <__printf_chk@plt>

----------------------------------------------->
Why do you think the compiler generates initialization instructions,
have you found any difference in the binary after your patch?

Huacai




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] loongarch: kgdb: remove unnecessary init variable
  2025-06-05  1:30   ` Re:[PATCH " lijun
@ 2025-06-05  1:37     ` Huacai Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2025-06-05  1:37 UTC (permalink / raw)
  To: lijun; +Cc: kernel, loongarch

On Thu, Jun 5, 2025 at 9:31 AM lijun <lijun01@kylinos.cn> wrote:
>
>
>
> #include<stdio.h>                                              #include
> <stdio.h>
>
> int main(int argc, const char *argv[])     int main(int argc, const
> char *argv[])
> {
>                {
>     int
> i=0;
>   int i;
>
>
>     i =
> 3;
>     i = 3;
>     printf("i = %d\n",
> i);                                       printf("i = %d\n", i);
>     return
> 0;                                                              return
> 0;
> }
>               }
>  endbr64
>    endbr64
> push   %rbp                                                           p
> ush   %rbp
> mov    %rsp,%rbp                                              mov    %r
> sp,%rbp
> sub    $0x20,%rsp                                                sub
>  $0x20,%rsp
> mov    %edi,-0x14(%rbp)                               mov    %edi,-
> 0x14(%rbp)
> mov    %rsi,-0x20(%rbp)                                mov    %rsi,-
> 0x20(%rbp)
> movl   $0x0,-0x4(%rbp)                                  movl   $0x3,-
> 0x4(%rbp)
> movl   $0x3,-0x4(%rbp)                                  mov    -
> 0x4(%rbp),%eax
> mov    -0x4(%rbp),%eax                                mov    %eax,%esi
> mov    %eax,%esi                                              mov    $0
> x402004,%edi
> mov    $0x402004,%edi                                  mov    $0x0,%eax
> mov    $0x0,%eax                                               callq  4
> 01040 <printf@plt>
> callq  401040 <printf@plt>
>
> if  gcc   -O3   test2.c -o a2.out, It is possible that the
> initialization is optimized by
> assigning values immediately after initialization
> endbr64
> sub    $0x8,%rsp
> mov    $0x3,%edx
> mov    $0x402004,%esi
> xor    %eax,%eax
> mov    $0x1,%edi
> callq  401040 <__printf_chk@plt>
The format is completely unreadable here:
https://lore.kernel.org/loongarch/CAAhV-H5dmh8_rNNRAaFeFvjCtt0CCsqTxOujWFakU=RYakrpAA@mail.gmail.com/T/#t

And we are talking about the kernel of LoongArch, you provide a user
program of x86?

Huacai

>
> ----------------------------------------------->
> Why do you think the compiler generates initialization instructions,
> have you found any difference in the binary after your patch?
>
> Huacai
>
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:[PATCH v2] loongarch: kgdb: remove unnecessary init variable
  2025-06-04 14:11 ` Huacai Chen
  2025-06-05  1:30   ` Re:[PATCH " lijun
@ 2025-06-05  1:41   ` lijun
  2025-06-05  1:46     ` [PATCH " Huacai Chen
  1 sibling, 1 reply; 6+ messages in thread
From: lijun @ 2025-06-05  1:41 UTC (permalink / raw)
  To: Huacai Chen; +Cc: si.yanteng, kernel, loongarch


//test2.c
#include<stdio.h>                                                      
   
int main(int argc, const char *argv[]) 
{                                      
    int
i=0;                                                             
    i = 3;                             
    printf("i = %d\n", i);            
    return 0;                           
}   
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%esi
mov    $0x402004,%edi
mov    $0x0,%eax
callq  401040 <printf@plt>
//test.c
#include<stdio.h>                                                      
    
int main(int argc, const char *argv[]) 
{                                      
    int i;                                                          
    i = 3;                             
    printf("i = %d\n", i);            
    return 0;                           
}   
endbr64 
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%esi
mov    $0x402004,%edi
mov    $0x0,%eax
callq  401040 <printf@plt>

It is possible that the initialization is optimized by assigning values
immediately after initialization
if gcc -O3 test2.c -o ao3.out
endbr64 
sub    $0x8,%rsp
mov    $0x3,%edx
mov    $0x402004,%esi
xor    %eax,%eax
mov    $0x1,%edi
callq  401040 <__printf_chk@plt>



----------------------------------->
Why do you think the compiler generates initialization instructions,
have you found any difference in the binary after your patch?

Huacai


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] loongarch: kgdb: remove unnecessary init variable
  2025-06-05  1:41   ` Re:[PATCH " lijun
@ 2025-06-05  1:46     ` Huacai Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2025-06-05  1:46 UTC (permalink / raw)
  To: lijun; +Cc: si.yanteng, kernel, loongarch

On Thu, Jun 5, 2025 at 9:41 AM lijun <lijun01@kylinos.cn> wrote:
>
>
> //test2.c
> #include<stdio.h>
>
> int main(int argc, const char *argv[])
> {
>     int
> i=0;
>     i = 3;
>     printf("i = %d\n", i);
>     return 0;
> }
> push   %rbp
> mov    %rsp,%rbp
> sub    $0x20,%rsp
> mov    %edi,-0x14(%rbp)
> mov    %rsi,-0x20(%rbp)
> movl   $0x0,-0x4(%rbp)
> movl   $0x3,-0x4(%rbp)
> mov    -0x4(%rbp),%eax
> mov    %eax,%esi
> mov    $0x402004,%edi
> mov    $0x0,%eax
> callq  401040 <printf@plt>
> //test.c
> #include<stdio.h>
>
> int main(int argc, const char *argv[])
> {
>     int i;
>     i = 3;
>     printf("i = %d\n", i);
>     return 0;
> }
> endbr64
> push   %rbp
> mov    %rsp,%rbp
> sub    $0x20,%rsp
> mov    %edi,-0x14(%rbp)
> mov    %rsi,-0x20(%rbp)
> movl   $0x3,-0x4(%rbp)
> mov    -0x4(%rbp),%eax
> mov    %eax,%esi
> mov    $0x402004,%edi
> mov    $0x0,%eax
> callq  401040 <printf@plt>
>
> It is possible that the initialization is optimized by assigning values
> immediately after initialization
> if gcc -O3 test2.c -o ao3.out
> endbr64
> sub    $0x8,%rsp
> mov    $0x3,%edx
> mov    $0x402004,%esi
> xor    %eax,%eax
> mov    $0x1,%edi
> callq  401040 <__printf_chk@plt>
Still a user program of x86, not the kernel of LoongArch.

And top posting is strictly forbidden in the kernel community which
Yanteng has already pointed out. Don't do it again and again, and
don't always only answer part of reviewers comments.

Huacai

>
>
>
> ----------------------------------->
> Why do you think the compiler generates initialization instructions,
> have you found any difference in the binary after your patch?
>
> Huacai
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-05  1:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04  6:56 [PATCH v2] loongarch: kgdb: remove unnecessary init variable Li Jun
2025-06-04 14:11 ` Huacai Chen
2025-06-05  1:30   ` Re:[PATCH " lijun
2025-06-05  1:37     ` [PATCH " Huacai Chen
2025-06-05  1:41   ` Re:[PATCH " lijun
2025-06-05  1:46     ` [PATCH " Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).