qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate
@ 2020-06-29 16:05 Wentong Wu
  2020-06-29 16:05 ` [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets Wentong Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Wentong Wu @ 2020-06-29 16:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, marex, crwulff, Wentong Wu, peter.maydell

Add DISAS_NORETURN case for nothing more to generate because at runtime
execution will never return from some helper call. And at the same time
replace DISAS_UPDATE in t_gen_helper_raise_exception and gen_exception
with the newly added DISAS_NORETURN.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
---
 target/nios2/translate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index e17656e6..b052be85 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -149,7 +149,7 @@ static void t_gen_helper_raise_exception(DisasContext *dc,
     tcg_gen_movi_tl(dc->cpu_R[R_PC], dc->pc);
     gen_helper_raise_exception(dc->cpu_env, tmp);
     tcg_temp_free_i32(tmp);
-    dc->is_jmp = DISAS_UPDATE;
+    dc->is_jmp = DISAS_NORETURN;
 }
 
 static bool use_goto_tb(DisasContext *dc, uint32_t dest)
@@ -802,7 +802,7 @@ static void gen_exception(DisasContext *dc, uint32_t excp)
     tcg_gen_movi_tl(cpu_R[R_PC], dc->pc);
     gen_helper_raise_exception(cpu_env, tmp);
     tcg_temp_free_i32(tmp);
-    dc->is_jmp = DISAS_UPDATE;
+    dc->is_jmp = DISAS_NORETURN;
 }
 
 /* generate intermediate code for basic block 'tb'.  */
@@ -877,6 +877,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
         tcg_gen_exit_tb(NULL, 0);
         break;
 
+    case DISAS_NORETURN:
     case DISAS_TB_JUMP:
         /* nothing more to generate */
         break;
-- 
2.21.3



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

* [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets
  2020-06-29 16:05 [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Wentong Wu
@ 2020-06-29 16:05 ` Wentong Wu
  2020-07-02 18:14   ` Richard Henderson
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
  2020-07-02 18:12 ` [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Richard Henderson
  2 siblings, 1 reply; 21+ messages in thread
From: Wentong Wu @ 2020-06-29 16:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, marex, crwulff, Wentong Wu, peter.maydell

In line the semantics of DISAS_UPDATE on nios2 target with other targets
which is to explicitly write the PC back into the cpu state before doing
a tcg_gen_exit_tb().

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
---
 target/nios2/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index b052be85..83c10eb2 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -865,6 +865,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
     /* Indicate where the next block should start */
     switch (dc->is_jmp) {
     case DISAS_NEXT:
+    case DISAS_UPDATE:
         /* Save the current PC back into the CPU register */
         tcg_gen_movi_tl(cpu_R[R_PC], dc->pc);
         tcg_gen_exit_tb(NULL, 0);
@@ -872,7 +873,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
 
     default:
     case DISAS_JUMP:
-    case DISAS_UPDATE:
         /* The jump will already have updated the PC register */
         tcg_gen_exit_tb(NULL, 0);
         break;
-- 
2.21.3



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

* [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-06-29 16:05 [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Wentong Wu
  2020-06-29 16:05 ` [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets Wentong Wu
@ 2020-06-29 16:05 ` Wentong Wu
  2020-07-01 13:26   ` Wu, Wentong
                     ` (3 more replies)
  2020-07-02 18:12 ` [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Richard Henderson
  2 siblings, 4 replies; 21+ messages in thread
From: Wentong Wu @ 2020-06-29 16:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, marex, crwulff, Wentong Wu, peter.maydell

wrctl instruction on nios2 target will cause checking cpu
interrupt but tcg_handle_interrupt() will call cpu_abort()
if the CPU gets an interrupt while it's not in 'can do IO'
state, so add gen_io_start around wrctl instruction. Also
at the same time, end the onging TB with DISAS_UPDATE.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
---
 target/nios2/translate.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 83c10eb2..51347ada 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -32,6 +32,7 @@
 #include "exec/cpu_ldst.h"
 #include "exec/translator.h"
 #include "qemu/qemu-print.h"
+#include "exec/gen-icount.h"
 
 /* is_jmp field values */
 #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
@@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
     /* If interrupts were enabled using WRCTL, trigger them. */
 #if !defined(CONFIG_USER_ONLY)
     if ((instr.imm5 + CR_BASE) == CR_STATUS) {
+        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_helper_check_interrupts(dc->cpu_env);
+        dc->is_jmp = DISAS_UPDATE;
     }
 #endif
 }
-- 
2.21.3



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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
@ 2020-07-01 13:26   ` Wu, Wentong
  2020-07-02 18:53   ` Richard Henderson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-01 13:26 UTC (permalink / raw)
  To: qemu-devel, peter.maydell; +Cc: qemu-trivial

Hi,
Could you please take a look the new patch?

Thanks

> -----Original Message-----
> Subject: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
> wrctl instruction on nios2 target will cause checking cpu interrupt but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an interrupt while it's not in 'can do IO'
> state, so add gen_io_start around wrctl instruction. Also at the same time, end the onging TB with DISAS_UPDATE.

> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
> target/nios2/translate.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 83c10eb2..51347ada 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
> #include "exec/cpu_ldst.h"
> #include "exec/translator.h"
> #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
 
>  /* is_jmp field values */
> #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
>     /* If interrupts were enabled using WRCTL, trigger them. */  #if !defined(CONFIG_USER_ONLY)
>    if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        dc->is_jmp = DISAS_UPDATE;
>    }
> #endif
> }
> --
> 2.21.3



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

* Re: [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate
  2020-06-29 16:05 [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Wentong Wu
  2020-06-29 16:05 ` [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets Wentong Wu
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
@ 2020-07-02 18:12 ` Richard Henderson
  2 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2020-07-02 18:12 UTC (permalink / raw)
  To: Wentong Wu, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

On 6/29/20 9:05 AM, Wentong Wu wrote:
> Add DISAS_NORETURN case for nothing more to generate because at runtime
> execution will never return from some helper call. And at the same time
> replace DISAS_UPDATE in t_gen_helper_raise_exception and gen_exception
> with the newly added DISAS_NORETURN.
> 
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

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

r~


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

* Re: [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets
  2020-06-29 16:05 ` [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets Wentong Wu
@ 2020-07-02 18:14   ` Richard Henderson
  2020-07-02 18:25     ` Richard Henderson
  0 siblings, 1 reply; 21+ messages in thread
From: Richard Henderson @ 2020-07-02 18:14 UTC (permalink / raw)
  To: Wentong Wu, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

On 6/29/20 9:05 AM, Wentong Wu wrote:
> In line the semantics of DISAS_UPDATE on nios2 target with other targets
> which is to explicitly write the PC back into the cpu state before doing
> a tcg_gen_exit_tb().
> 
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Or simply remove it as unused, now that you've replaced the existing users with
DISAS_NORETURN.


r~


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

* Re: [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets
  2020-07-02 18:14   ` Richard Henderson
@ 2020-07-02 18:25     ` Richard Henderson
  0 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2020-07-02 18:25 UTC (permalink / raw)
  To: Wentong Wu, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

On 7/2/20 11:14 AM, Richard Henderson wrote:
> On 6/29/20 9:05 AM, Wentong Wu wrote:
>> In line the semantics of DISAS_UPDATE on nios2 target with other targets
>> which is to explicitly write the PC back into the cpu state before doing
>> a tcg_gen_exit_tb().
>>
>> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
>> ---
>>  target/nios2/translate.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Or simply remove it as unused, now that you've replaced the existing users with
> DISAS_NORETURN.

Nevermind, you're using it in the next patch.

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

r~


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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
  2020-07-01 13:26   ` Wu, Wentong
@ 2020-07-02 18:53   ` Richard Henderson
  2020-07-03 13:22     ` Wu, Wentong
                       ` (4 more replies)
  2020-07-03 15:14   ` Wu, Wentong
  2020-07-05 17:10   ` Peter Maydell
  3 siblings, 5 replies; 21+ messages in thread
From: Richard Henderson @ 2020-07-02 18:53 UTC (permalink / raw)
  To: Wentong Wu, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

On 6/29/20 9:05 AM, Wentong Wu wrote:
> wrctl instruction on nios2 target will cause checking cpu
> interrupt but tcg_handle_interrupt() will call cpu_abort()
> if the CPU gets an interrupt while it's not in 'can do IO'
> state, so add gen_io_start around wrctl instruction. Also
> at the same time, end the onging TB with DISAS_UPDATE.
> 
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index 83c10eb2..51347ada 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
>  #include "exec/cpu_ldst.h"
>  #include "exec/translator.h"
>  #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
>  
>  /* is_jmp field values */
>  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
>      /* If interrupts were enabled using WRCTL, trigger them. */
>  #if !defined(CONFIG_USER_ONLY)
>      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        dc->is_jmp = DISAS_UPDATE;
>      }
>  #endif

This isn't right.  Not so much the gen_io_start portion, but the entire
existence of helper_check_interrupt.

The correct way to acknowledge interrupts after changing an interrupt mask bit
is to exit the TB back to the cpu main loop.
Which you are doing here with DISAS_UPDATE, so that part is fine.  (Although
you could merge that into the switch statement above.)

Looking at nios_pic_cpu_handler, there are two other bugs:

1) Get rid of env->irq_pending and use cpu_interrupt/cpu_reset_interrupt instead.

2) Do not check env->regs[CR_STATUS] & CR_STATUS_PIE.  That variable does not
belong to the pic and should not be checked there.  The check belongs in
nios2_cpu_exec_interrupt, and is in fact already there.


r~


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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-02 18:53   ` Richard Henderson
@ 2020-07-03 13:22     ` Wu, Wentong
  2020-07-05 13:22     ` Wu, Wentong
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-03 13:22 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

[-- Attachment #1: Type: text/plain, Size: 3094 bytes --]



      -----Original Message-----
      From: Richard Henderson
      Sent: Friday, July 3, 2020 2:54 AM
      To: Wu, Wentong <wentong.wu@intel.com>; qemu-devel@nongnu.org
      Cc: qemu-trivial@nongnu.org; marex@denx.de; crwulff@gmail.com; peter.maydell@linaro.org
      Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction

      On 6/29/20 9:05 AM, Wentong Wu wrote:
      > wrctl instruction on nios2 target will cause checking cpu interrupt
      > but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an
      > interrupt while it's not in 'can do IO'
      > state, so add gen_io_start around wrctl instruction. Also at the same
      > time, end the onging TB with DISAS_UPDATE.
      >
      > Signed-off-by: Wentong Wu <wentong.wu@intel.com<mailto:wentong.wu@intel.com>>
      > ---
      >  target/nios2/translate.c | 5 +++++
      >  1 file changed, 5 insertions(+)
      >
      > diff --git a/target/nios2/translate.c b/target/nios2/translate.c index
      > 83c10eb2..51347ada 100644
      > --- a/target/nios2/translate.c
      > +++ b/target/nios2/translate.c
      > @@ -32,6 +32,7 @@
      >  #include "exec/cpu_ldst.h"
      >  #include "exec/translator.h"
      >  #include "qemu/qemu-print.h"
      > +#include "exec/gen-icount.h"
      >
      >  /* is_jmp field values */
      >  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
      > @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
      >      /* If interrupts were enabled using WRCTL, trigger them. */  #if
      > !defined(CONFIG_USER_ONLY)
      >      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
      > +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
      > +            gen_io_start();
      > +        }
      >          gen_helper_check_interrupts(dc->cpu_env);
      > +        dc->is_jmp = DISAS_UPDATE;
      >      }
      >  #endif

      This isn't right.  Not so much the gen_io_start portion, but the entire existence of helper_check_interrupt.

      The correct way to acknowledge interrupts after changing an interrupt mask bit is to exit the TB back to the cpu main loop.
      Which you are doing here with DISAS_UPDATE, so that part is fine.  (Although you could merge that into the switch statement above.)

      Looking at nios_pic_cpu_handler, there are two other bugs:

      1) Get rid of env->irq_pending and use cpu_interrupt/cpu_reset_interrupt instead

IMHO, we need env->irq_pending, because if ((env->regs[CR_STATUS] & CR_STATUS_PIE) == False), it can indicate there is interrupt pending, we can exit to main loop to handle the interrupt at once if guest code enable irq later.

      2) Do not check env->regs[CR_STATUS] & CR_STATUS_PIE.  That variable does not belong to the pic and should not be checked there.  The check belongs in nios2_cpu_exec_interrupt, and is in fact already there.
But that will cause some assert happen if device trigger irq with env->regs[CR_STATUS] & CR_STATUS_PIE = False

BR


[-- Attachment #2: Type: text/html, Size: 7362 bytes --]

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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
  2020-07-01 13:26   ` Wu, Wentong
  2020-07-02 18:53   ` Richard Henderson
@ 2020-07-03 15:14   ` Wu, Wentong
  2020-07-05 17:10   ` Peter Maydell
  3 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-03 15:14 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-trivial, marex, crwulff, qemu-devel

HI Peter,
Could you please take a look at this patch which is following your pervious suggestion?

Thanks

-----Original Message-----
From: Wu, Wentong <wentong.wu@intel.com> 
Sent: Tuesday, June 30, 2020 12:06 AM
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org; crwulff@gmail.com; marex@denx.de; peter.maydell@linaro.org; Wu, Wentong <wentong.wu@intel.com>
Subject: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction

wrctl instruction on nios2 target will cause checking cpu interrupt but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an interrupt while it's not in 'can do IO'
state, so add gen_io_start around wrctl instruction. Also at the same time, end the onging TB with DISAS_UPDATE.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
---
 target/nios2/translate.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 83c10eb2..51347ada 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -32,6 +32,7 @@
 #include "exec/cpu_ldst.h"
 #include "exec/translator.h"
 #include "qemu/qemu-print.h"
+#include "exec/gen-icount.h"
 
 /* is_jmp field values */
 #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
@@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
     /* If interrupts were enabled using WRCTL, trigger them. */  #if !defined(CONFIG_USER_ONLY)
     if ((instr.imm5 + CR_BASE) == CR_STATUS) {
+        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_helper_check_interrupts(dc->cpu_env);
+        dc->is_jmp = DISAS_UPDATE;
     }
 #endif
 }
--
2.21.3



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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-02 18:53   ` Richard Henderson
  2020-07-03 13:22     ` Wu, Wentong
@ 2020-07-05 13:22     ` Wu, Wentong
  2020-07-05 13:24     ` Wu, Wentong
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-05 13:22 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

Correct the format

> -----Original Message-----
> From: Richard Henderson <richard.henderson@linaro.org> 
> Sent: Friday, July 3, 2020 2:54 AM
> To: Wu, Wentong <wentong.wu@intel.com>; qemu-devel@nongnu.org
> Cc: qemu-trivial@nongnu.org; marex@denx.de; crwulff@gmail.com; peter.maydell@linaro.org
> Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
> 
> On 6/29/20 9:05 AM, Wentong Wu wrote:
> > wrctl instruction on nios2 target will cause checking cpu interrupt 
> > but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an 
> > interrupt while it's not in 'can do IO'
> > state, so add gen_io_start around wrctl instruction. Also at the same 
> > time, end the onging TB with DISAS_UPDATE.
> > 
> > Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> > ---
> >  target/nios2/translate.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 
> > 83c10eb2..51347ada 100644
> > --- a/target/nios2/translate.c
> > +++ b/target/nios2/translate.c
> > @@ -32,6 +32,7 @@
> >  #include "exec/cpu_ldst.h"
> >  #include "exec/translator.h"
> >  #include "qemu/qemu-print.h"
> > +#include "exec/gen-icount.h"
> >  
> >  /* is_jmp field values */
> >  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> > @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
> >      /* If interrupts were enabled using WRCTL, trigger them. */  #if 
> > !defined(CONFIG_USER_ONLY)
> >      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> > +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> > +            gen_io_start();
> > +        }
> >          gen_helper_check_interrupts(dc->cpu_env);
> > +        dc->is_jmp = DISAS_UPDATE;
> >      }
> >  #endif
> 
> This isn't right.  Not so much the gen_io_start portion, but the entire existence of helper_check_interrupt.
> 
> The correct way to acknowledge interrupts after changing an interrupt mask bit is to exit the TB back to the cpu main loop.
> Which you are doing here with DISAS_UPDATE, so that part is fine.  (Although you could merge that into the switch statement above.)
> 
> Looking at nios_pic_cpu_handler, there are two other bugs:
> 
> 1) Get rid of env->irq_pending and use cpu_interrupt/cpu_reset_interrupt instead.

IMHO, we need env->irq_pending, because if ((env->regs[CR_STATUS] & CR_STATUS_PIE) == False), it can indicate there is interrupt pending, we can exit to main loop to handle the interrupt at once if guest code enable irq later.

> 2) Do not check env->regs[CR_STATUS] & CR_STATUS_PIE.  That variable does not belong to the pic and should not be checked there.  The check belongs in nios2_cpu_exec_interrupt, and is in fact already there.

But that will cause some assert happen if device trigger irq with env->regs[CR_STATUS] & CR_STATUS_PIE = False

BR

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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-02 18:53   ` Richard Henderson
  2020-07-03 13:22     ` Wu, Wentong
  2020-07-05 13:22     ` Wu, Wentong
@ 2020-07-05 13:24     ` Wu, Wentong
  2020-07-05 17:08     ` Peter Maydell
  2020-07-06  0:56     ` Wu, Wentong
  4 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-05 13:24 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

Correct the format

> -----Original Message-----
> From: Richard Henderson <richard.henderson@linaro.org> 
> Sent: Friday, July 3, 2020 2:54 AM
> To: Wu, Wentong <wentong.wu@intel.com>; qemu-devel@nongnu.org
> Cc: qemu-trivial@nongnu.org; marex@denx.de; crwulff@gmail.com; peter.maydell@linaro.org
> Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
> 
> On 6/29/20 9:05 AM, Wentong Wu wrote:
> > wrctl instruction on nios2 target will cause checking cpu interrupt 
> > but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an 
> > interrupt while it's not in 'can do IO'
> > state, so add gen_io_start around wrctl instruction. Also at the same 
> > time, end the onging TB with DISAS_UPDATE.
> > 
> > Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> > ---
> >  target/nios2/translate.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 
> > 83c10eb2..51347ada 100644
> > --- a/target/nios2/translate.c
> > +++ b/target/nios2/translate.c
> > @@ -32,6 +32,7 @@
> >  #include "exec/cpu_ldst.h"
> >  #include "exec/translator.h"
> >  #include "qemu/qemu-print.h"
> > +#include "exec/gen-icount.h"
> >  
> >  /* is_jmp field values */
> >  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> > @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
> >      /* If interrupts were enabled using WRCTL, trigger them. */  #if 
> > !defined(CONFIG_USER_ONLY)
> >      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> > +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> > +            gen_io_start();
> > +        }
> >          gen_helper_check_interrupts(dc->cpu_env);
> > +        dc->is_jmp = DISAS_UPDATE;
> >      }
> >  #endif
> 
> This isn't right.  Not so much the gen_io_start portion, but the entire existence of helper_check_interrupt.
> 
> The correct way to acknowledge interrupts after changing an interrupt mask bit is to exit the TB back to the cpu main loop.
> Which you are doing here with DISAS_UPDATE, so that part is fine.  (Although you could merge that into the switch statement above.)
> 
> Looking at nios_pic_cpu_handler, there are two other bugs:
> 
> 1) Get rid of env->irq_pending and use cpu_interrupt/cpu_reset_interrupt instead.

IMHO, we need env->irq_pending, because if ((env->regs[CR_STATUS] & CR_STATUS_PIE) == False), it can indicate there is interrupt pending, we can exit to main loop to handle the interrupt at once if guest code enable irq later.

> 2) Do not check env->regs[CR_STATUS] & CR_STATUS_PIE.  That variable does not belong to the pic and should not be checked there.  The check belongs in nios2_cpu_exec_interrupt, and is in fact already there.

But that will cause some assert happen if device trigger irq with env->regs[CR_STATUS] & CR_STATUS_PIE = False

BR

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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-02 18:53   ` Richard Henderson
                       ` (2 preceding siblings ...)
  2020-07-05 13:24     ` Wu, Wentong
@ 2020-07-05 17:08     ` Peter Maydell
  2020-07-05 18:16       ` Max Filippov
  2020-07-06  0:56     ` Wu, Wentong
  4 siblings, 1 reply; 21+ messages in thread
From: Peter Maydell @ 2020-07-05 17:08 UTC (permalink / raw)
  To: Richard Henderson
  Cc: QEMU Trivial, Marek Vasut, Wentong Wu, QEMU Developers, Chris Wulff

On Thu, 2 Jul 2020 at 19:53, Richard Henderson
<richard.henderson@linaro.org> wrote:
> This isn't right.  Not so much the gen_io_start portion, but the entire
> existence of helper_check_interrupt.

I agree that it looks bogus (xtensa has a similar helper as well, incidentally),
but fixing all that stuff up is more effort than the relatively small job
of getting the icount handling right for the code we have today, which
is why I suggested to Wentong that we could just do this bit for now.

thanks
-- PMM


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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
                     ` (2 preceding siblings ...)
  2020-07-03 15:14   ` Wu, Wentong
@ 2020-07-05 17:10   ` Peter Maydell
  2020-07-06  0:30     ` Wu, Wentong
  2020-07-07  2:41     ` Wu, Wentong
  3 siblings, 2 replies; 21+ messages in thread
From: Peter Maydell @ 2020-07-05 17:10 UTC (permalink / raw)
  To: Wentong Wu; +Cc: QEMU Trivial, Marek Vasut, Chris Wulff, QEMU Developers

On Mon, 29 Jun 2020 at 09:17, Wentong Wu <wentong.wu@intel.com> wrote:
>
> wrctl instruction on nios2 target will cause checking cpu
> interrupt but tcg_handle_interrupt() will call cpu_abort()
> if the CPU gets an interrupt while it's not in 'can do IO'
> state, so add gen_io_start around wrctl instruction. Also
> at the same time, end the onging TB with DISAS_UPDATE.
>
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index 83c10eb2..51347ada 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
>  #include "exec/cpu_ldst.h"
>  #include "exec/translator.h"
>  #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
>
>  /* is_jmp field values */
>  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
>      /* If interrupts were enabled using WRCTL, trigger them. */
>  #if !defined(CONFIG_USER_ONLY)
>      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        dc->is_jmp = DISAS_UPDATE;
>      }
>  #endif
>  }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

though as Richard notes ideally the interrupt handling code here should
be rewritten because the check_interrupts helper is a very weird way
to implement things.

thanks
-- PMM


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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-05 17:08     ` Peter Maydell
@ 2020-07-05 18:16       ` Max Filippov
  2020-07-05 20:53         ` Max Filippov
  0 siblings, 1 reply; 21+ messages in thread
From: Max Filippov @ 2020-07-05 18:16 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Marek Vasut, Chris Wulff, QEMU Trivial, Wentong Wu,
	Richard Henderson, QEMU Developers

On Sun, Jul 5, 2020 at 10:09 AM Peter Maydell <peter.maydell@linaro.org> wrote:
> On Thu, 2 Jul 2020 at 19:53, Richard Henderson
> <richard.henderson@linaro.org> wrote:
> > This isn't right.  Not so much the gen_io_start portion, but the entire
> > existence of helper_check_interrupt.
>
> I agree that it looks bogus (xtensa has a similar helper as well, incidentally),

I think there was a reason for it. According to Richard

> The correct way to acknowledge interrupts after changing an interrupt mask bit
> is to exit the TB back to the cpu main loop.

But if I do this change for Xtensa I get a bunch of test_interrupt failures
that indicate that the interrupt that should have been taken wasn't taken.
FTR here's the change that I tested, did I miss something?

diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
index fdf47642e6f1..85e8d65f169d 100644
--- a/target/xtensa/translate.c
+++ b/target/xtensa/translate.c
@@ -631,18 +631,10 @@ static int gen_postprocess(DisasContext *dc, int slot)
 {
     uint32_t op_flags = dc->op_flags;

-#ifndef CONFIG_USER_ONLY
-    if (op_flags & XTENSA_OP_CHECK_INTERRUPTS) {
-        if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) {
-            gen_io_start();
-        }
-        gen_helper_check_interrupts(cpu_env);
-    }
-#endif
     if (op_flags & XTENSA_OP_SYNC_REGISTER_WINDOW) {
         gen_helper_sync_windowbase(cpu_env);
     }
-    if (op_flags & XTENSA_OP_EXIT_TB_M1) {
+    if (op_flags & (XTENSA_OP_EXIT_TB_M1 | XTENSA_OP_CHECK_INTERRUPTS)) {
         slot = -1;
     }
     return slot;
@@ -1175,7 +1167,7 @@ static void disas_xtensa_insn(CPUXtensaState
*env, DisasContext *dc)
     if (dc->base.is_jmp == DISAS_NEXT) {
         gen_postprocess(dc, 0);
         dc->op_flags = 0;
-        if (op_flags & XTENSA_OP_EXIT_TB_M1) {
+        if (op_flags & (XTENSA_OP_EXIT_TB_M1 | XTENSA_OP_CHECK_INTERRUPTS)) {
             /* Change in mmu index, memory mapping or tb->flags; exit tb */
             gen_jumpi_check_loop_end(dc, -1);
         } else if (op_flags & XTENSA_OP_EXIT_TB_0) {


-- 
Thanks.
-- Max


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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-05 18:16       ` Max Filippov
@ 2020-07-05 20:53         ` Max Filippov
  2020-07-06  8:55           ` Peter Maydell
  0 siblings, 1 reply; 21+ messages in thread
From: Max Filippov @ 2020-07-05 20:53 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Marek Vasut, Chris Wulff, QEMU Trivial, Wentong Wu,
	Richard Henderson, QEMU Developers

On Sun, Jul 5, 2020 at 11:16 AM Max Filippov <jcmvbkbc@gmail.com> wrote:
> On Sun, Jul 5, 2020 at 10:09 AM Peter Maydell <peter.maydell@linaro.org> wrote:
> > On Thu, 2 Jul 2020 at 19:53, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> > > This isn't right.  Not so much the gen_io_start portion, but the entire
> > > existence of helper_check_interrupt.
> > I agree that it looks bogus (xtensa has a similar helper as well, incidentally),
> I think there was a reason for it.

...and the reason is that this helper calls cpu_[re]set_interrupt
to update CPU_INTERRUPT_HARD, which makes exit to the
main CPU loop do something to handle IRQ.
Maybe 'check_interrupt' is not a good name for that, but the
action taken there seems right to me.

-- 
Thanks.
-- Max


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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-05 17:10   ` Peter Maydell
@ 2020-07-06  0:30     ` Wu, Wentong
  2020-07-07  2:41     ` Wu, Wentong
  1 sibling, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-06  0:30 UTC (permalink / raw)
  To: Peter Maydell, QEMU Trivial, QEMU Developers; +Cc: Marek Vasut, Chris Wulff

Thanks, I think we can get this series merged currently.

-----Original Message-----
From: Peter Maydell <peter.maydell@linaro.org> 
Sent: Monday, July 6, 2020 1:10 AM
To: Wu, Wentong <wentong.wu@intel.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>; QEMU Trivial <qemu-trivial@nongnu.org>; Chris Wulff <crwulff@gmail.com>; Marek Vasut <marex@denx.de>
Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction

On Mon, 29 Jun 2020 at 09:17, Wentong Wu <wentong.wu@intel.com> wrote:
>
> wrctl instruction on nios2 target will cause checking cpu interrupt 
> but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an 
> interrupt while it's not in 'can do IO'
> state, so add gen_io_start around wrctl instruction. Also at the same 
> time, end the onging TB with DISAS_UPDATE.
>
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 
> 83c10eb2..51347ada 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
>  #include "exec/cpu_ldst.h"
>  #include "exec/translator.h"
>  #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
>
>  /* is_jmp field values */
>  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
>      /* If interrupts were enabled using WRCTL, trigger them. */  #if 
> !defined(CONFIG_USER_ONLY)
>      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        dc->is_jmp = DISAS_UPDATE;
>      }
>  #endif
>  }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

though as Richard notes ideally the interrupt handling code here should be rewritten because the check_interrupts helper is a very weird way to implement things.

thanks
-- PMM

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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-02 18:53   ` Richard Henderson
                       ` (3 preceding siblings ...)
  2020-07-05 17:08     ` Peter Maydell
@ 2020-07-06  0:56     ` Wu, Wentong
  4 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-06  0:56 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: qemu-trivial, marex, crwulff, peter.maydell

Maybe below patch will reduce some overhead, because currently it will exit to main loop to handle interrupt but if with (env->regs[CR_STATUS] & CR_STATUS_PIE) = False, it does nothing except set env->irq_pending again.

diff --git a/hw/nios2/cpu_pic.c b/hw/nios2/cpu_pic.c
index 1c1989d5..5ea7e52a 100644
--- a/hw/nios2/cpu_pic.c
+++ b/hw/nios2/cpu_pic.c
@@ -54,7 +54,8 @@ static void nios2_pic_cpu_handler(void *opaque, int irq, int level)

 void nios2_check_interrupts(CPUNios2State *env)
 {
-    if (env->irq_pending) {
+    if (env->irq_pending &&
+        (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
         env->irq_pending = 0;
         cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD);
     }

-----Original Message-----
From: Richard Henderson <richard.henderson@linaro.org> 
Sent: Friday, July 3, 2020 2:54 AM
To: Wu, Wentong <wentong.wu@intel.com>; qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org; marex@denx.de; crwulff@gmail.com; peter.maydell@linaro.org
Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction

On 6/29/20 9:05 AM, Wentong Wu wrote:
> wrctl instruction on nios2 target will cause checking cpu interrupt 
> but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an 
> interrupt while it's not in 'can do IO'
> state, so add gen_io_start around wrctl instruction. Also at the same 
> time, end the onging TB with DISAS_UPDATE.
> 
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 
> 83c10eb2..51347ada 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
>  #include "exec/cpu_ldst.h"
>  #include "exec/translator.h"
>  #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
>  
>  /* is_jmp field values */
>  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
>      /* If interrupts were enabled using WRCTL, trigger them. */  #if 
> !defined(CONFIG_USER_ONLY)
>      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        dc->is_jmp = DISAS_UPDATE;
>      }
>  #endif

This isn't right.  Not so much the gen_io_start portion, but the entire existence of helper_check_interrupt.

The correct way to acknowledge interrupts after changing an interrupt mask bit is to exit the TB back to the cpu main loop.
Which you are doing here with DISAS_UPDATE, so that part is fine.  (Although you could merge that into the switch statement above.)

Looking at nios_pic_cpu_handler, there are two other bugs:

1) Get rid of env->irq_pending and use cpu_interrupt/cpu_reset_interrupt instead.

2) Do not check env->regs[CR_STATUS] & CR_STATUS_PIE.  That variable does not belong to the pic and should not be checked there.  The check belongs in nios2_cpu_exec_interrupt, and is in fact already there.


r~

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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-05 20:53         ` Max Filippov
@ 2020-07-06  8:55           ` Peter Maydell
  0 siblings, 0 replies; 21+ messages in thread
From: Peter Maydell @ 2020-07-06  8:55 UTC (permalink / raw)
  To: Max Filippov
  Cc: Marek Vasut, Chris Wulff, QEMU Trivial, Wentong Wu,
	Richard Henderson, QEMU Developers

On Sun, 5 Jul 2020 at 21:54, Max Filippov <jcmvbkbc@gmail.com> wrote:
>
> On Sun, Jul 5, 2020 at 11:16 AM Max Filippov <jcmvbkbc@gmail.com> wrote:
> > On Sun, Jul 5, 2020 at 10:09 AM Peter Maydell <peter.maydell@linaro.org> wrote:
> > > On Thu, 2 Jul 2020 at 19:53, Richard Henderson
> > > <richard.henderson@linaro.org> wrote:
> > > > This isn't right.  Not so much the gen_io_start portion, but the entire
> > > > existence of helper_check_interrupt.
> > > I agree that it looks bogus (xtensa has a similar helper as well, incidentally),
> > I think there was a reason for it.
>
> ...and the reason is that this helper calls cpu_[re]set_interrupt
> to update CPU_INTERRUPT_HARD, which makes exit to the
> main CPU loop do something to handle IRQ.
> Maybe 'check_interrupt' is not a good name for that, but the
> action taken there seems right to me.

Usually I would expect that CPU_INTERRUPT_HARD would be
set by whatever was setting the interrupt (often a handler
for an inbound qemu_irq line to the CPU). Then the
cpu_exec_interrupt hook only actually does something if
both the INTERRUPT_HARD bit is set and the CPU register
says "and interrupts are unmasked". If you have a design
like that then "unmasking interrupts just means going out
to the main loop" will work.

thanks
-- PMM


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

* RE: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
  2020-07-05 17:10   ` Peter Maydell
  2020-07-06  0:30     ` Wu, Wentong
@ 2020-07-07  2:41     ` Wu, Wentong
  1 sibling, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-07  2:41 UTC (permalink / raw)
  To: Peter Maydell, Richard Henderson, Max Filippov, thuth
  Cc: QEMU Trivial, Marek Vasut, Chris Wulff, QEMU Developers

Hi,
I think we can get this patch series merged first in order to get qemu_nios2 working with icount, actually we are blocked by it for some time. 
BTW if maintainers(Chris Wulff and Marek Vasut) don't have time for the re-work, I'd like to take it.

Thanks
> -----Original Message-----
> From: Peter Maydell <peter.maydell@linaro.org> 
> Sent: Monday, July 6, 2020 1:10 AM
> To: Wu, Wentong <wentong.wu@intel.com>
> Cc: QEMU Developers <qemu-devel@nongnu.org>; QEMU Trivial <qemu-trivial@nongnu.org>; Chris Wulff <crwulff@gmail.com>; Marek Vasut <marex@denx.de>
> Subject: Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
>
> On Mon, 29 Jun 2020 at 09:17, Wentong Wu <wentong.wu@intel.com> wrote:
> >
> > wrctl instruction on nios2 target will cause checking cpu interrupt 
> > but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an 
> > interrupt while it's not in 'can do IO'
> > state, so add gen_io_start around wrctl instruction. Also at the same 
> > time, end the onging TB with DISAS_UPDATE.
> >
> > Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> > ---
> >  target/nios2/translate.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 
> > 83c10eb2..51347ada 100644
> > --- a/target/nios2/translate.c
> > +++ b/target/nios2/translate.c
> > @@ -32,6 +32,7 @@
> >  #include "exec/cpu_ldst.h"
> >  #include "exec/translator.h"
> >  #include "qemu/qemu-print.h"
> > +#include "exec/gen-icount.h"
> >
> >  /* is_jmp field values */
> >  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> > @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
> >      /* If interrupts were enabled using WRCTL, trigger them. */  #if 
> > !defined(CONFIG_USER_ONLY)
> >      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> > +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> > +            gen_io_start();
> > +        }
> >          gen_helper_check_interrupts(dc->cpu_env);
> > +        dc->is_jmp = DISAS_UPDATE;
> >      }
> >  #endif
> >  }
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> though as Richard notes ideally the interrupt handling code here should be rewritten because the check_interrupts helper is a very weird way to implement things.
>
> thanks
> -- PMM

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

* Re: [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction
@ 2020-07-09 11:58 Wu, Wentong
  0 siblings, 0 replies; 21+ messages in thread
From: Wu, Wentong @ 2020-07-09 11:58 UTC (permalink / raw)
  To: peter.maydell; +Cc: QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 1861 bytes --]

> >On Mon, 29 Jun 2020 at 09:17, Wentong Wu <wentong.wu@intel.com> wrote:
> >
> > wrctl instruction on nios2 target will cause checking cpu
> > interrupt but tcg_handle_interrupt() will call cpu_abort()
> > if the CPU gets an interrupt while it's not in 'can do IO'
> > state, so add gen_io_start around wrctl instruction. Also
> > at the same time, end the onging TB with DISAS_UPDATE.
> >
> > Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> > ---
> >  target/nios2/translate.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> > index 83c10eb2..51347ada 100644
> > --- a/target/nios2/translate.c
> > +++ b/target/nios2/translate.c
> > @@ -32,6 +32,7 @@
> >  #include "exec/cpu_ldst.h"
> >  #include "exec/translator.h"
> >  #include "qemu/qemu-print.h"
> > +#include "exec/gen-icount.h"
> >
> >  /* is_jmp field values */
> >  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> > @@ -518,7 +519,11 @@ static void wrctl(DisasContext *dc, uint32_t code,
> > uint32_t flags)
> >      /* If interrupts were enabled using WRCTL, trigger them. */
> >  #if !defined(CONFIG_USER_ONLY)
> >      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> > +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> > +            gen_io_start();
> > +        }
> >          gen_helper_check_interrupts(dc->cpu_env);
> > +        dc->is_jmp = DISAS_UPDATE;
> >      }
> >  #endif
> >  }
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Hi Peter,

Will this be merged? If not, I would like to follow any suggestions, thanks

Thanks

>
> though as Richard notes ideally the interrupt handling code here should
> be rewritten because the check_interrupts helper is a very weird way
> to implement things.
>
> thanks
> -- PMM


[-- Attachment #2: Type: text/html, Size: 11574 bytes --]

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

end of thread, other threads:[~2020-07-09 11:59 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 16:05 [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Wentong Wu
2020-06-29 16:05 ` [PATCH 2/3] target/nios2: in line the semantics of DISAS_UPDATE with other targets Wentong Wu
2020-07-02 18:14   ` Richard Henderson
2020-07-02 18:25     ` Richard Henderson
2020-06-29 16:05 ` [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wentong Wu
2020-07-01 13:26   ` Wu, Wentong
2020-07-02 18:53   ` Richard Henderson
2020-07-03 13:22     ` Wu, Wentong
2020-07-05 13:22     ` Wu, Wentong
2020-07-05 13:24     ` Wu, Wentong
2020-07-05 17:08     ` Peter Maydell
2020-07-05 18:16       ` Max Filippov
2020-07-05 20:53         ` Max Filippov
2020-07-06  8:55           ` Peter Maydell
2020-07-06  0:56     ` Wu, Wentong
2020-07-03 15:14   ` Wu, Wentong
2020-07-05 17:10   ` Peter Maydell
2020-07-06  0:30     ` Wu, Wentong
2020-07-07  2:41     ` Wu, Wentong
2020-07-02 18:12 ` [PATCH 1/3] target/nios2: add DISAS_NORETURN case for nothing more to generate Richard Henderson
2020-07-09 11:58 [PATCH 3/3] target/nios2: Use gen_io_start around wrctl instruction Wu, Wentong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).