[PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails

Richard Henderson posted 3 patches 1 week, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260813005031.518387-1-richard.henderson@linaro.org
Maintainers: Richard Henderson <richard.henderson@linaro.org>
tcg/tcg-internal.h |  2 +-
tcg/region.c       | 40 ++++++++++++++++++++++++++++++----------
tcg/tcg.c          | 24 +++++++++++++++---------
3 files changed, 46 insertions(+), 20 deletions(-)
[PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Richard Henderson 1 week, 6 days ago
Hi Yogesh,

The main problem with your patch is where you've placed the change:
tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
used by tb_flush.  Along that path, we really can't have a failure.
The path on which we can defer allocation is via tcg_register_thread.

The second change I made is to use code_buf_ptr == NULL to signal
reallocation is required.  In addition, tcg_tb_alloc doesn't need
to immediately fail: in the interim since thread creation, we may
well have performed a tb_flush already.

Please have a try vs your hotplug test case.


r~


Richard Henderson (3):
  tcg: Return success from tcg_region_alloc__locked
  tcg: Return success from tcg_region_alloc
  tcg: Defer tb_flush when initial thread region alloc fails

 tcg/tcg-internal.h |  2 +-
 tcg/region.c       | 40 ++++++++++++++++++++++++++++++----------
 tcg/tcg.c          | 24 +++++++++++++++---------
 3 files changed, 46 insertions(+), 20 deletions(-)

-- 
2.43.0
Re: [PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Michael Tokarev 5 days, 14 hours ago
On 8/13/26 03:50, Richard Henderson wrote:
> Hi Yogesh,
> 
> The main problem with your patch is where you've placed the change:
> tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
> used by tb_flush.  Along that path, we really can't have a failure.
> The path on which we can defer allocation is via tcg_register_thread.
> 
> The second change I made is to use code_buf_ptr == NULL to signal
> reallocation is required.  In addition, tcg_tb_alloc doesn't need
> to immediately fail: in the interim since thread creation, we may
> well have performed a tb_flush already.
> 
> Please have a try vs your hotplug test case.

Hi!

Is this a qemu-stable material?

I'm not picking it up, but it feels I should :)

Thanks,

/mjt

> Richard Henderson (3):
>    tcg: Return success from tcg_region_alloc__locked
>    tcg: Return success from tcg_region_alloc
>    tcg: Defer tb_flush when initial thread region alloc fails
> 
>   tcg/tcg-internal.h |  2 +-
>   tcg/region.c       | 40 ++++++++++++++++++++++++++++++----------
>   tcg/tcg.c          | 24 +++++++++++++++---------
>   3 files changed, 46 insertions(+), 20 deletions(-)
>
Re: [PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Richard Henderson 5 days, 7 hours ago
On 8/20/26 09:45, Michael Tokarev wrote:
> On 8/13/26 03:50, Richard Henderson wrote:
>> Hi Yogesh,
>>
>> The main problem with your patch is where you've placed the change:
>> tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
>> used by tb_flush.  Along that path, we really can't have a failure.
>> The path on which we can defer allocation is via tcg_register_thread.
>>
>> The second change I made is to use code_buf_ptr == NULL to signal
>> reallocation is required.  In addition, tcg_tb_alloc doesn't need
>> to immediately fail: in the interim since thread creation, we may
>> well have performed a tb_flush already.
>>
>> Please have a try vs your hotplug test case.
> 
> Hi!
> 
> Is this a qemu-stable material?
> 
> I'm not picking it up, but it feels I should :)
Yes, I think it could be trivially picked up.  I don't think any of this code has changed 
in years.

r~

Re: [PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Yogesh Vyas 1 week, 2 days ago
Hi Richard,
Thank you for improvising on the initial patch shared.

On Thu, Aug 13, 2026 at 6:20 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> Hi Yogesh,
>
> The main problem with your patch is where you've placed the change:
> tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
> used by tb_flush.  Along that path, we really can't have a failure.
> The path on which we can defer allocation is via tcg_register_thread.
>
> The second change I made is to use code_buf_ptr == NULL to signal
> reallocation is required.  In addition, tcg_tb_alloc doesn't need
> to immediately fail: in the interim since thread creation, we may
> well have performed a tb_flush already.
>
> Please have a try vs your hotplug test case.
>
I tried testing these patches on my x86 host running qemu-system-ppc64 by
initially hotpluging 400 vCPUs.
While the response was relatively slower than the initial patch that I had
shared, I also observed the VM is as slow as stuck when I retried
hotplugging upto 1024.
I will share more feedback if I have any.

Regards,
Yogesh


>
> r~
>
>
> Richard Henderson (3):
>   tcg: Return success from tcg_region_alloc__locked
>   tcg: Return success from tcg_region_alloc
>   tcg: Defer tb_flush when initial thread region alloc fails
>
>  tcg/tcg-internal.h |  2 +-
>  tcg/region.c       | 40 ++++++++++++++++++++++++++++++----------
>  tcg/tcg.c          | 24 +++++++++++++++---------
>  3 files changed, 46 insertions(+), 20 deletions(-)
>
> --
> 2.43.0
>
>
Re: [PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Yogesh Vyas 1 week ago
Hi Richard,

On Sun, Aug 16, 2026 at 10:38 PM Yogesh Vyas <yvyas1991@gmail.com> wrote:

> Hi Richard,
> Thank you for improvising on the initial patch shared.
>
> On Thu, Aug 13, 2026 at 6:20 AM Richard Henderson <
> richard.henderson@linaro.org> wrote:
>
>> Hi Yogesh,
>>
>> The main problem with your patch is where you've placed the change:
>> tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
>> used by tb_flush.  Along that path, we really can't have a failure.
>> The path on which we can defer allocation is via tcg_register_thread.
>>
>> The second change I made is to use code_buf_ptr == NULL to signal
>> reallocation is required.  In addition, tcg_tb_alloc doesn't need
>> to immediately fail: in the interim since thread creation, we may
>> well have performed a tb_flush already.
>>
>> Please have a try vs your hotplug test case.
>>
> I tried testing these patches on my x86 host running qemu-system-ppc64 by
> initially hotpluging 400 vCPUs.
> While the response was relatively slower than the initial patch that I had
> shared, I also observed the VM is as slow as stuck when I retried
> hotplugging upto 1024.
> I will share more feedback if I have any.
>

I have shared one minor comment on patch 2/3, with that:

Reviewed-by: Yogesh Vyas <yvyas1991@gmail.com>
Tested-by: Yogesh Vyas <yvyas1991@gmail.com>


> Regards,
> Yogesh
>
>
>>
>> r~
>>
>>
>> Richard Henderson (3):
>>   tcg: Return success from tcg_region_alloc__locked
>>   tcg: Return success from tcg_region_alloc
>>   tcg: Defer tb_flush when initial thread region alloc fails
>>
>>  tcg/tcg-internal.h |  2 +-
>>  tcg/region.c       | 40 ++++++++++++++++++++++++++++++----------
>>  tcg/tcg.c          | 24 +++++++++++++++---------
>>  3 files changed, 46 insertions(+), 20 deletions(-)
>>
>> --
>> 2.43.0
>>
>>
Re: [PATCH v2 0/3] tcg: Defer tb_flush when initial thread region alloc fails
Posted by Richard Henderson 1 week ago
On 8/18/26 10:07, Yogesh Vyas wrote:
> 
> Hi Richard,
> 
> On Sun, Aug 16, 2026 at 10:38 PM Yogesh Vyas <yvyas1991@gmail.com 
> <mailto:yvyas1991@gmail.com>> wrote:
> 
>     Hi Richard,
>     Thank you for improvising on the initial patch shared.
> 
>     On Thu, Aug 13, 2026 at 6:20 AM Richard Henderson <richard.henderson@linaro.org
>     <mailto:richard.henderson@linaro.org>> wrote:
> 
>         Hi Yogesh,
> 
>         The main problem with your patch is where you've placed the change:
>         tcg_region_initial_alloc__locked is also used by tcg_region_reset_all,
>         used by tb_flush.  Along that path, we really can't have a failure.
>         The path on which we can defer allocation is via tcg_register_thread.
> 
>         The second change I made is to use code_buf_ptr == NULL to signal
>         reallocation is required.  In addition, tcg_tb_alloc doesn't need
>         to immediately fail: in the interim since thread creation, we may
>         well have performed a tb_flush already.
> 
>         Please have a try vs your hotplug test case.
> 
>     I tried testing these patches on my x86 host running qemu-system-ppc64 by initially
>     hotpluging 400 vCPUs.
>     While the response was relatively slower than the initial patch that I had shared, I
>     also observed the VM is as slow as stuck when I retried hotplugging upto 1024.
>     I will share more feedback if I have any.
> 
> 
> I have shared one minor comment on patch 2/3, with that:
> 
> Reviewed-by: Yogesh Vyas <yvyas1991@gmail.com <mailto:yvyas1991@gmail.com>>
> Tested-by: Yogesh Vyas <yvyas1991@gmail.com <mailto:yvyas1991@gmail.com>>
Thanks.

r`