All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] icount: improve exec nocache usage
@ 2020-12-08  9:10 Pavel Dovgalyuk
  2020-12-11 20:55 ` Paolo Bonzini
  2020-12-11 21:41 ` Richard Henderson
  0 siblings, 2 replies; 6+ messages in thread
From: Pavel Dovgalyuk @ 2020-12-08  9:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, pbonzini, pavel.dovgalyuk

cpu-exec tries to execute TB without caching when current
icount budget is over. But sometimes refilled budget is big
enough to try executing cached blocks.
This patch checks that instruction budget is big enough
for next block execution instead of just running cpu_exec_nocache.
It halves the number of calls of cpu_exec_nocache function
during tested OS boot scenario.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
---
 accel/tcg/cpu-exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 58aea605d8..251b340fb9 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -685,7 +685,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
     insns_left = MIN(0xffff, cpu->icount_budget);
     cpu_neg(cpu)->icount_decr.u16.low = insns_left;
     cpu->icount_extra = cpu->icount_budget - insns_left;
-    if (!cpu->icount_extra) {
+    if (!cpu->icount_extra && insns_left < tb->icount) {
         /* Execute any remaining instructions, then let the main loop
          * handle the next event.
          */



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

* Re: [PATCH] icount: improve exec nocache usage
  2020-12-08  9:10 [PATCH] icount: improve exec nocache usage Pavel Dovgalyuk
@ 2020-12-11 20:55 ` Paolo Bonzini
  2020-12-11 21:41 ` Richard Henderson
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2020-12-11 20:55 UTC (permalink / raw)
  To: Pavel Dovgalyuk, qemu-devel; +Cc: alex.bennee

On 08/12/20 10:10, Pavel Dovgalyuk wrote:
> cpu-exec tries to execute TB without caching when current
> icount budget is over. But sometimes refilled budget is big
> enough to try executing cached blocks.
> This patch checks that instruction budget is big enough
> for next block execution instead of just running cpu_exec_nocache.
> It halves the number of calls of cpu_exec_nocache function
> during tested OS boot scenario.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
> ---
>   accel/tcg/cpu-exec.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 58aea605d8..251b340fb9 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -685,7 +685,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
>       insns_left = MIN(0xffff, cpu->icount_budget);
>       cpu_neg(cpu)->icount_decr.u16.low = insns_left;
>       cpu->icount_extra = cpu->icount_budget - insns_left;
> -    if (!cpu->icount_extra) {
> +    if (!cpu->icount_extra && insns_left < tb->icount) {
>           /* Execute any remaining instructions, then let the main loop
>            * handle the next event.
>            */
> 

Queued, thanks.

Paolo



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

* Re: [PATCH] icount: improve exec nocache usage
  2020-12-08  9:10 [PATCH] icount: improve exec nocache usage Pavel Dovgalyuk
  2020-12-11 20:55 ` Paolo Bonzini
@ 2020-12-11 21:41 ` Richard Henderson
  2020-12-12  6:22   ` Pavel Dovgalyuk
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2020-12-11 21:41 UTC (permalink / raw)
  To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee

On 12/8/20 3:10 AM, Pavel Dovgalyuk wrote:
> cpu-exec tries to execute TB without caching when current
> icount budget is over. But sometimes refilled budget is big
> enough to try executing cached blocks.
> This patch checks that instruction budget is big enough
> for next block execution instead of just running cpu_exec_nocache.
> It halves the number of calls of cpu_exec_nocache function
> during tested OS boot scenario.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
> ---
>  accel/tcg/cpu-exec.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 58aea605d8..251b340fb9 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -685,7 +685,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
>      insns_left = MIN(0xffff, cpu->icount_budget);
>      cpu_neg(cpu)->icount_decr.u16.low = insns_left;
>      cpu->icount_extra = cpu->icount_budget - insns_left;
> -    if (!cpu->icount_extra) {
> +    if (!cpu->icount_extra && insns_left < tb->icount) {

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

I also wonder if we should really be not caching these.  Ever since MTTCG, we
have not actually been reusing the memory.  We're simply removing the TB from
the hash table.  I think we should be remembering these just in case we can in
fact reuse them.


r~



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

* Re: [PATCH] icount: improve exec nocache usage
  2020-12-11 21:41 ` Richard Henderson
@ 2020-12-12  6:22   ` Pavel Dovgalyuk
  2020-12-12 14:31     ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Dovgalyuk @ 2020-12-12  6:22 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: pbonzini, alex.bennee

On 12.12.2020 00:41, Richard Henderson wrote:
> On 12/8/20 3:10 AM, Pavel Dovgalyuk wrote:
>> cpu-exec tries to execute TB without caching when current
>> icount budget is over. But sometimes refilled budget is big
>> enough to try executing cached blocks.
>> This patch checks that instruction budget is big enough
>> for next block execution instead of just running cpu_exec_nocache.
>> It halves the number of calls of cpu_exec_nocache function
>> during tested OS boot scenario.
>>
>> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
>> ---
>>   accel/tcg/cpu-exec.c |    2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
>> index 58aea605d8..251b340fb9 100644
>> --- a/accel/tcg/cpu-exec.c
>> +++ b/accel/tcg/cpu-exec.c
>> @@ -685,7 +685,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
>>       insns_left = MIN(0xffff, cpu->icount_budget);
>>       cpu_neg(cpu)->icount_decr.u16.low = insns_left;
>>       cpu->icount_extra = cpu->icount_budget - insns_left;
>> -    if (!cpu->icount_extra) {
>> +    if (!cpu->icount_extra && insns_left < tb->icount) {
> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks.

> 
> I also wonder if we should really be not caching these.  Ever since MTTCG, we
> have not actually been reusing the memory.  We're simply removing the TB from
> the hash table.  I think we should be remembering these just in case we can in
> fact reuse them.

I'm still thinking about reusing these blocks. Sometimes there are 
loops, where blocks of small sizes like 1..3 are translated for many times.

However, we can't cache them directly, because hash table can include 
only one block with the specific pc.

Pavel Dovgalyuk


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

* Re: [PATCH] icount: improve exec nocache usage
  2020-12-12  6:22   ` Pavel Dovgalyuk
@ 2020-12-12 14:31     ` Richard Henderson
  2020-12-14  6:33       ` Pavel Dovgalyuk
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2020-12-12 14:31 UTC (permalink / raw)
  To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee

On 12/12/20 12:22 AM, Pavel Dovgalyuk wrote:
> However, we can't cache them directly, because hash table can include only one
> block with the specific pc.

That's not true at all.


r~


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

* Re: [PATCH] icount: improve exec nocache usage
  2020-12-12 14:31     ` Richard Henderson
@ 2020-12-14  6:33       ` Pavel Dovgalyuk
  0 siblings, 0 replies; 6+ messages in thread
From: Pavel Dovgalyuk @ 2020-12-14  6:33 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: pbonzini, alex.bennee

On 12.12.2020 17:31, Richard Henderson wrote:
> On 12/12/20 12:22 AM, Pavel Dovgalyuk wrote:
>> However, we can't cache them directly, because hash table can include only one
>> block with the specific pc.
> 
> That's not true at all.

Thanks, I missed, that icount is used for TB comparison in hash container.

Pavel Dovgalyuk


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

end of thread, other threads:[~2020-12-14  6:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08  9:10 [PATCH] icount: improve exec nocache usage Pavel Dovgalyuk
2020-12-11 20:55 ` Paolo Bonzini
2020-12-11 21:41 ` Richard Henderson
2020-12-12  6:22   ` Pavel Dovgalyuk
2020-12-12 14:31     ` Richard Henderson
2020-12-14  6:33       ` Pavel Dovgalyuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.