[PATCH 3/3] riscv: pack rv64 thread_info better

Radim Krčmář posted 3 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH 3/3] riscv: pack rv64 thread_info better
Posted by Radim Krčmář 2 months, 2 weeks ago
On rv64, preempt_count and cpu were both 32-bit followed by 64-bit, so
placing one in the hole saves 8 bytes in the struct.

Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
---
 arch/riscv/include/asm/thread_info.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
index f5916a70879a..c267d6bd838e 100644
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -53,6 +53,7 @@
 struct thread_info {
 	unsigned long		flags;		/* low level flags */
 	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
+	int			cpu;
 	/*
 	 * These stack pointers are overwritten on every system call or
 	 * exception.  SP is also saved to the stack it can be recovered when
@@ -60,7 +61,6 @@ struct thread_info {
 	 */
 	long			kernel_sp;	/* Kernel stack pointer */
 	long			user_sp;	/* User stack pointer */
-	int			cpu;
 	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
 #ifdef CONFIG_SHADOW_CALL_STACK
 	void			*scs_base;
-- 
2.50.0

Re: [PATCH 3/3] riscv: pack rv64 thread_info better
Posted by Alexandre Ghiti 2 months, 1 week ago
On 7/22/25 18:05, Radim Krčmář wrote:
> On rv64, preempt_count and cpu were both 32-bit followed by 64-bit, so
> placing one in the hole saves 8 bytes in the struct.
>
> Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
> ---
>   arch/riscv/include/asm/thread_info.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
> index f5916a70879a..c267d6bd838e 100644
> --- a/arch/riscv/include/asm/thread_info.h
> +++ b/arch/riscv/include/asm/thread_info.h
> @@ -53,6 +53,7 @@
>   struct thread_info {
>   	unsigned long		flags;		/* low level flags */
>   	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
> +	int			cpu;
>   	/*
>   	 * These stack pointers are overwritten on every system call or
>   	 * exception.  SP is also saved to the stack it can be recovered when
> @@ -60,7 +61,6 @@ struct thread_info {
>   	 */
>   	long			kernel_sp;	/* Kernel stack pointer */
>   	long			user_sp;	/* User stack pointer */
> -	int			cpu;
>   	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
>   #ifdef CONFIG_SHADOW_CALL_STACK
>   	void			*scs_base;


Great, that now fits into a cacheline. I guess other structures would 
deserve the same attention.

You can add:

Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex