[PATCH 14/24] exec: Declare tlb_init/destroy() in 'exec/cputlb.h'

Philippe Mathieu-Daudé posted 24 patches 1 week, 2 days ago
[PATCH 14/24] exec: Declare tlb_init/destroy() in 'exec/cputlb.h'
Posted by Philippe Mathieu-Daudé 1 week, 2 days ago
Move CPU TLB related methods to "exec/cputlb.h".

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/cputlb.h   | 28 +++++++++++++++++++++++-----
 include/exec/exec-all.h | 17 -----------------
 accel/tcg/cpu-exec.c    |  1 +
 3 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h
index 6cac7d530f..5386e53806 100644
--- a/include/exec/cputlb.h
+++ b/include/exec/cputlb.h
@@ -22,15 +22,33 @@
 
 #include "exec/cpu-common.h"
 
-#ifdef CONFIG_TCG
+#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
+
+/**
+ * tlb_init - initialize a CPU's TLB
+ * @cpu: CPU whose TLB should be initialized
+ */
+void tlb_init(CPUState *cpu);
+
+/**
+ * tlb_destroy - destroy a CPU's TLB
+ * @cpu: CPU whose TLB should be destroyed
+ */
+void tlb_destroy(CPUState *cpu);
 
-#if !defined(CONFIG_USER_ONLY)
-/* cputlb.c */
 void tlb_protect_code(ram_addr_t ram_addr);
 void tlb_unprotect_code(ram_addr_t ram_addr);
-#endif
 
-#endif /* CONFIG_TCG */
+#else
+
+static inline void tlb_init(CPUState *cpu)
+{
+}
+static inline void tlb_destroy(CPUState *cpu)
+{
+}
+
+#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
 
 #ifndef CONFIG_USER_ONLY
 
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 2c06e54387..d792203773 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -47,17 +47,6 @@ static inline bool cpu_loop_exit_requested(CPUState *cpu)
 }
 
 #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
-/* cputlb.c */
-/**
- * tlb_init - initialize a CPU's TLB
- * @cpu: CPU whose TLB should be initialized
- */
-void tlb_init(CPUState *cpu);
-/**
- * tlb_destroy - destroy a CPU's TLB
- * @cpu: CPU whose TLB should be destroyed
- */
-void tlb_destroy(CPUState *cpu);
 /**
  * tlb_flush_page:
  * @cpu: CPU whose TLB should be flushed
@@ -242,12 +231,6 @@ void tlb_set_page(CPUState *cpu, vaddr addr,
                   hwaddr paddr, int prot,
                   int mmu_idx, vaddr size);
 #else
-static inline void tlb_init(CPUState *cpu)
-{
-}
-static inline void tlb_destroy(CPUState *cpu)
-{
-}
 static inline void tlb_flush_page(CPUState *cpu, vaddr addr)
 {
 }
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 8163295f34..8770493590 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -24,6 +24,7 @@
 #include "hw/core/tcg-cpu-ops.h"
 #include "trace.h"
 #include "disas/disas.h"
+#include "exec/cputlb.h"
 #include "exec/exec-all.h"
 #include "tcg/tcg.h"
 #include "qemu/atomic.h"
-- 
2.45.2


Re: [PATCH 14/24] exec: Declare tlb_init/destroy() in 'exec/cputlb.h'
Posted by Richard Henderson 1 week, 1 day ago
On 11/13/24 17:12, Philippe Mathieu-Daudé wrote:
> Move CPU TLB related methods to "exec/cputlb.h".
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/exec/cputlb.h   | 28 +++++++++++++++++++++++-----
>   include/exec/exec-all.h | 17 -----------------
>   accel/tcg/cpu-exec.c    |  1 +
>   3 files changed, 24 insertions(+), 22 deletions(-)

This is only within accel/tcg/.  Better to move to accel/tcg/internal-common.h.


r~

Re: [PATCH 14/24] exec: Declare tlb_init/destroy() in 'exec/cputlb.h'
Posted by Philippe Mathieu-Daudé 1 week, 1 day ago
On 14/11/24 19:21, Richard Henderson wrote:
> On 11/13/24 17:12, Philippe Mathieu-Daudé wrote:
>> Move CPU TLB related methods to "exec/cputlb.h".
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   include/exec/cputlb.h   | 28 +++++++++++++++++++++++-----
>>   include/exec/exec-all.h | 17 -----------------
>>   accel/tcg/cpu-exec.c    |  1 +
>>   3 files changed, 24 insertions(+), 22 deletions(-)
> 
> This is only within accel/tcg/.  Better to move to 
> accel/tcg/internal-common.h.

Yeah, and IIRC this is also true for some other helpers.
My thought was "better keep all the API public" but I
don't remember why I decided to go this way, since this
is of no use outside of accel/tcg/.

Re: [PATCH 14/24] exec: Declare tlb_init/destroy() in 'exec/cputlb.h'
Posted by Pierrick Bouvier 1 week, 2 days ago
On 11/13/24 17:12, Philippe Mathieu-Daudé wrote:
> Move CPU TLB related methods to "exec/cputlb.h".
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/exec/cputlb.h   | 28 +++++++++++++++++++++++-----
>   include/exec/exec-all.h | 17 -----------------
>   accel/tcg/cpu-exec.c    |  1 +
>   3 files changed, 24 insertions(+), 22 deletions(-)
> 
> diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h
> index 6cac7d530f..5386e53806 100644
> --- a/include/exec/cputlb.h
> +++ b/include/exec/cputlb.h
> @@ -22,15 +22,33 @@
>   
>   #include "exec/cpu-common.h"
>   
> -#ifdef CONFIG_TCG
> +#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
> +
> +/**
> + * tlb_init - initialize a CPU's TLB
> + * @cpu: CPU whose TLB should be initialized
> + */
> +void tlb_init(CPUState *cpu);
> +
> +/**
> + * tlb_destroy - destroy a CPU's TLB
> + * @cpu: CPU whose TLB should be destroyed
> + */
> +void tlb_destroy(CPUState *cpu);
>   
> -#if !defined(CONFIG_USER_ONLY)
> -/* cputlb.c */
>   void tlb_protect_code(ram_addr_t ram_addr);
>   void tlb_unprotect_code(ram_addr_t ram_addr);
> -#endif
>   
> -#endif /* CONFIG_TCG */
> +#else
> +
> +static inline void tlb_init(CPUState *cpu)
> +{
> +}
> +static inline void tlb_destroy(CPUState *cpu)
> +{
> +}
> +
> +#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
>   
>   #ifndef CONFIG_USER_ONLY
>   
> diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
> index 2c06e54387..d792203773 100644
> --- a/include/exec/exec-all.h
> +++ b/include/exec/exec-all.h
> @@ -47,17 +47,6 @@ static inline bool cpu_loop_exit_requested(CPUState *cpu)
>   }
>   
>   #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
> -/* cputlb.c */
> -/**
> - * tlb_init - initialize a CPU's TLB
> - * @cpu: CPU whose TLB should be initialized
> - */
> -void tlb_init(CPUState *cpu);
> -/**
> - * tlb_destroy - destroy a CPU's TLB
> - * @cpu: CPU whose TLB should be destroyed
> - */
> -void tlb_destroy(CPUState *cpu);
>   /**
>    * tlb_flush_page:
>    * @cpu: CPU whose TLB should be flushed
> @@ -242,12 +231,6 @@ void tlb_set_page(CPUState *cpu, vaddr addr,
>                     hwaddr paddr, int prot,
>                     int mmu_idx, vaddr size);
>   #else
> -static inline void tlb_init(CPUState *cpu)
> -{
> -}
> -static inline void tlb_destroy(CPUState *cpu)
> -{
> -}
>   static inline void tlb_flush_page(CPUState *cpu, vaddr addr)
>   {
>   }
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 8163295f34..8770493590 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -24,6 +24,7 @@
>   #include "hw/core/tcg-cpu-ops.h"
>   #include "trace.h"
>   #include "disas/disas.h"
> +#include "exec/cputlb.h"
>   #include "exec/exec-all.h"
>   #include "tcg/tcg.h"
>   #include "qemu/atomic.h"

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>