diff mbox series

[v2,38/42] include/exec: Protect icount_enabled from poisoned symbols

Message ID 20250318213209.2579218-39-richard.henderson@linaro.org (mailing list archive)
State New
Headers show
Series accel/tcg, codebase: Build once patches | expand

Commit Message

Richard Henderson March 18, 2025, 9:32 p.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/icount.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Pierrick Bouvier March 19, 2025, 12:42 a.m. UTC | #1
On 3/18/25 14:32, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   include/exec/icount.h | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/include/exec/icount.h b/include/exec/icount.h
> index 4964987ae4..7a26b40084 100644
> --- a/include/exec/icount.h
> +++ b/include/exec/icount.h
> @@ -22,13 +22,21 @@ typedef enum {
>       ICOUNT_ADAPTATIVE,
>   } ICountMode;
>   
> -#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
> +#ifdef CONFIG_TCG
>   extern ICountMode use_icount;
>   #define icount_enabled() (use_icount)
>   #else
>   #define icount_enabled() ICOUNT_DISABLED
>   #endif
>   
> +/* Protect the CONFIG_USER_ONLY test vs poisoning. */
> +#if defined(COMPILING_PER_TARGET) || defined(COMPILING_SYSTEM_VS_USER)
> +# ifdef CONFIG_USER_ONLY
> +#  undef  icount_enabled
> +#  define icount_enabled() ICOUNT_DISABLED
> +# endif
> +#endif
> +
>   /*
>    * Update the icount with the executed instructions. Called by
>    * cpus-tcg vCPU thread so the main-loop can see time has moved forward.

I understand the shortcut taken here, but I'm not sure we want to start 
having specifics for COMPILING_SYSTEM_VS_USER, out of the poison file.

In this case, we can change icount_enabled() to a function, implement it 
in accel/tcg/icount-common.c (which is system only), and add a stub for 
user mode in accel/tcg/icount-user.c (or common-user/icount.c), 
returning ICOUNT_DISABLED, or 0, more simply.
Richard Henderson March 19, 2025, 1:41 a.m. UTC | #2
On 3/18/25 17:42, Pierrick Bouvier wrote:
> On 3/18/25 14:32, Richard Henderson wrote:
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   include/exec/icount.h | 10 +++++++++-
>>   1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/exec/icount.h b/include/exec/icount.h
>> index 4964987ae4..7a26b40084 100644
>> --- a/include/exec/icount.h
>> +++ b/include/exec/icount.h
>> @@ -22,13 +22,21 @@ typedef enum {
>>       ICOUNT_ADAPTATIVE,
>>   } ICountMode;
>> -#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
>> +#ifdef CONFIG_TCG
>>   extern ICountMode use_icount;
>>   #define icount_enabled() (use_icount)
>>   #else
>>   #define icount_enabled() ICOUNT_DISABLED
>>   #endif
>> +/* Protect the CONFIG_USER_ONLY test vs poisoning. */
>> +#if defined(COMPILING_PER_TARGET) || defined(COMPILING_SYSTEM_VS_USER)
>> +# ifdef CONFIG_USER_ONLY
>> +#  undef  icount_enabled
>> +#  define icount_enabled() ICOUNT_DISABLED
>> +# endif
>> +#endif
>> +
>>   /*
>>    * Update the icount with the executed instructions. Called by
>>    * cpus-tcg vCPU thread so the main-loop can see time has moved forward.
> 
> I understand the shortcut taken here, but I'm not sure we want to start having specifics 
> for COMPILING_SYSTEM_VS_USER, out of the poison file.
> 
> In this case, we can change icount_enabled() to a function, implement it in accel/tcg/ 
> icount-common.c (which is system only), and add a stub for user mode in accel/tcg/icount- 
> user.c (or common-user/icount.c), returning ICOUNT_DISABLED, or 0, more simply.

(1) If I were to do anything it would not be adding a function, but
     making use_icount a universal variable.

(2) There are a few uses where if (!icount_enabled()) needs to
     evaluate to false for user-mode, so that dead code elimination happens.
     Otherwise we then have to introduce extra stubs, etc, etc, etc.


r~
diff mbox series

Patch

diff --git a/include/exec/icount.h b/include/exec/icount.h
index 4964987ae4..7a26b40084 100644
--- a/include/exec/icount.h
+++ b/include/exec/icount.h
@@ -22,13 +22,21 @@  typedef enum {
     ICOUNT_ADAPTATIVE,
 } ICountMode;
 
-#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
+#ifdef CONFIG_TCG
 extern ICountMode use_icount;
 #define icount_enabled() (use_icount)
 #else
 #define icount_enabled() ICOUNT_DISABLED
 #endif
 
+/* Protect the CONFIG_USER_ONLY test vs poisoning. */
+#if defined(COMPILING_PER_TARGET) || defined(COMPILING_SYSTEM_VS_USER)
+# ifdef CONFIG_USER_ONLY
+#  undef  icount_enabled
+#  define icount_enabled() ICOUNT_DISABLED
+# endif
+#endif
+
 /*
  * Update the icount with the executed instructions. Called by
  * cpus-tcg vCPU thread so the main-loop can see time has moved forward.