target/riscv: Add Zihintpause support
v4 cover target/riscv: Add Zihintpause support
This patch adds RISC-V Zihintpause support. The extension is set to be enabled by default and opcode has been added to insn32.decode.
Added trans_pause to exit the TB and return to main loop.
The change can also be found in:
https://github.com/dlu42/qemu/tree/zihintpause_support_v1
Tested along with pause support added to cpu_relax function for linux, the changes I made to linux to test can be found here:
https://github.com/dlu42/linux/tree/pause_support_v1
--------
Changelog:
v1 -> v2
1. Pause now also exit the TB and return to main loop
2. Move the REQUIRE_ZIHINTPAUSE macro inside the trans_pause function
v2 -> v3
No changes, v2 was lost from the list
v3 -> v4
No longer break the reservation in trans_pause
Dao Lu (1):
Add Zihintpause support
target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
PATCH v4 1/1 target/riscv: Add Zihintpause support
Added support for RISC-V PAUSE instruction from Zihintpause extension, enabled by default.
--- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)
target/riscv/cpu.c +2 -0
@@ -825,6 +825,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zihintpause" ,RISCVCPU , cfg.ext_zihintpause, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),
@@ -996,6 +997,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zihintpause, ext_zihintpause),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),
target/riscv/cpu.h +1 -0
@@ -394,6 +394,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zihintpause;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;
target/riscv/insn32.decode +6 -1
@@ -149,7 +149,12 @@ srl 0000000 ..... ..... 101 ..... 0110011 @r sra 0100000 ..... ..... 101 ..... 0110011 @r or 0000000 ..... ..... 110 ..... 0110011 @r and 0000000 ..... ..... 111 ..... 0110011 @r -fence ---- pred:4 succ:4 ----- 000 ----- 0001111 + +{ + pause 0000 0001 0000 00000 000 00000 0001111 + fence ---- pred:4 succ:4 ----- 000 ----- 0001111 +} + fence_i ---- ---- ---- ----- 001 ----- 0001111 csrrw ............ ..... 001 ..... 1110011 @csr csrrs ............ ..... 010 ..... 1110011 @csr
target/riscv/insn_trans/trans_rvi.c.inc +16 -0
@@ -796,6 +796,22 @@ static bool trans_srad(DisasContext *ctx, arg_srad *a) return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl, NULL); } +static bool trans_pause(DisasContext *ctx, arg_pause *a) +{ + if (!ctx->cfg_ptr->ext_zihintpause) { + return false; + } + + /* + * PAUSE is a no-op in QEMU, + * end the TB and return to main loop + */ + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp = DISAS_NORETURN; + + return true; +} static bool trans_fence(DisasContext *ctx, arg_fence *a) {
Signature · 1 line
2.25.1
ping
Quoted 93 lines · Dao Lu
Added support for RISC-V PAUSE instruction from Zihintpause extension, enabled by default.
Tested-by Heiko Stuebner <[email protected]>Signed-off-by Dao Lu <[email protected]>--- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)target/riscv/cpu.c +2
-0@@ -825,6 +825,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zihintpause" ,RISCVCPU , cfg.ext_zihintpause, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),@@ -996,6 +997,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zihintpause, ext_zihintpause),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),target/riscv/cpu.h +1
-0@@ -394,6 +394,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zihintpause;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;target/riscv/insn32.decode +6
-1@@ -149,7 +149,12 @@ srl 0000000 ..... ..... 101 ..... 0110011 @r sra 0100000 ..... ..... 101 ..... 0110011 @r or 0000000 ..... ..... 110 ..... 0110011 @r and 0000000 ..... ..... 111 ..... 0110011 @r -fence ---- pred:4 succ:4 ----- 000 ----- 0001111 + +{ + pause 0000 0001 0000 00000 000 00000 0001111 + fence ---- pred:4 succ:4 ----- 000 ----- 0001111 +} + fence_i ---- ---- ---- ----- 001 ----- 0001111 csrrw ............ ..... 001 ..... 1110011 @csr csrrs ............ ..... 010 ..... 1110011 @csrtarget/riscv/insn_trans/trans_rvi.c.inc +16
-1@@ -796,6 +796,22 @@ static bool trans_srad(DisasContext *ctx, arg_srad *a) return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl, NULL); } +static bool trans_pause(DisasContext *ctx, arg_pause *a) +{ + if (!ctx->cfg_ptr->ext_zihintpause) { + return false; + } + + /* + * PAUSE is a no-op in QEMU, + * end the TB and return to main loop + */ + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp = DISAS_NORETURN; + + return true; +} static bool trans_fence(DisasContext *ctx, arg_fence *a) { --2.25.1
Quoted 2 lines · Dao Lu
ping
Sorry for the delay.
Do you mind rebasing this on
https://github.com/alistair23/qemu/tree/riscv-to-apply.next and sending a v5
Alistair
Quoted 96 lines · Dao Lu
Quoted 93 lines
Added support for RISC-V PAUSE instruction from Zihintpause extension, enabled by default.
Tested-by Heiko Stuebner <[email protected]>Signed-off-by Dao Lu <[email protected]>--- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)target/riscv/cpu.c +2
-0@@ -825,6 +825,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zihintpause" ,RISCVCPU , cfg.ext_zihintpause, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),@@ -996,6 +997,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zihintpause, ext_zihintpause),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),target/riscv/cpu.h +1
-0@@ -394,6 +394,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zihintpause;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;target/riscv/insn32.decode +6
-1@@ -149,7 +149,12 @@ srl 0000000 ..... ..... 101 ..... 0110011 @r sra 0100000 ..... ..... 101 ..... 0110011 @r or 0000000 ..... ..... 110 ..... 0110011 @r and 0000000 ..... ..... 111 ..... 0110011 @r -fence ---- pred:4 succ:4 ----- 000 ----- 0001111 + +{ + pause 0000 0001 0000 00000 000 00000 0001111 + fence ---- pred:4 succ:4 ----- 000 ----- 0001111 +} + fence_i ---- ---- ---- ----- 001 ----- 0001111 csrrw ............ ..... 001 ..... 1110011 @csr csrrs ............ ..... 010 ..... 1110011 @csrtarget/riscv/insn_trans/trans_rvi.c.inc +16
-1@@ -796,6 +796,22 @@ static bool trans_srad(DisasContext *ctx, arg_srad *a) return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl, NULL); } +static bool trans_pause(DisasContext *ctx, arg_pause *a) +{ + if (!ctx->cfg_ptr->ext_zihintpause) { + return false; + } + + /* + * PAUSE is a no-op in QEMU, + * end the TB and return to main loop + */ + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp = DISAS_NORETURN; + + return true; +} static bool trans_fence(DisasContext *ctx, arg_fence *a) { --2.25.1
Will do, thanks!
Dao
Quoted 109 lines · Alistair Francis
Quoted 2 lines · Dao Lu
ping
Sorry for the delay.
Do you mind rebasing this on
https://github.com/alistair23/qemu/tree/riscv-to-apply.next and sending a v5Alistair
Quoted 96 lines · Dao Lu
Quoted 93 lines
Added support for RISC-V PAUSE instruction from Zihintpause extension, enabled by default.
Tested-by Heiko Stuebner <[email protected]>Signed-off-by Dao Lu <[email protected]>--- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)target/riscv/cpu.c +2
-0@@ -825,6 +825,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zihintpause" ,RISCVCPU , cfg.ext_zihintpause, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),@@ -996,6 +997,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zihintpause, ext_zihintpause),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),target/riscv/cpu.h +1
-0@@ -394,6 +394,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zihintpause;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;target/riscv/insn32.decode +6
-1@@ -149,7 +149,12 @@ srl 0000000 ..... ..... 101 ..... 0110011 @r sra 0100000 ..... ..... 101 ..... 0110011 @r or 0000000 ..... ..... 110 ..... 0110011 @r and 0000000 ..... ..... 111 ..... 0110011 @r -fence ---- pred:4 succ:4 ----- 000 ----- 0001111 + +{ + pause 0000 0001 0000 00000 000 00000 0001111 + fence ---- pred:4 succ:4 ----- 000 ----- 0001111 +} + fence_i ---- ---- ---- ----- 001 ----- 0001111 csrrw ............ ..... 001 ..... 1110011 @csr csrrs ............ ..... 010 ..... 1110011 @csrtarget/riscv/insn_trans/trans_rvi.c.inc +16
-1@@ -796,6 +796,22 @@ static bool trans_srad(DisasContext *ctx, arg_srad *a) return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl, NULL); } +static bool trans_pause(DisasContext *ctx, arg_pause *a) +{ + if (!ctx->cfg_ptr->ext_zihintpause) { + return false; + } + + /* + * PAUSE is a no-op in QEMU, + * end the TB and return to main loop + */ + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp = DISAS_NORETURN; + + return true; +} static bool trans_fence(DisasContext *ctx, arg_fence *a) { --2.25.1
Quoted 6 lines · Dao Lu
Added support for RISC-V PAUSE instruction from Zihintpause extension, enabled by default.
Tested-by Heiko Stuebner <[email protected]>Signed-off-by Dao Lu <[email protected]>
Alistair
Quoted 88 lines
--- target/riscv/cpu.c | 2 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++++++- target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)target/riscv/cpu.c +2
-0@@ -825,6 +825,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true), +DEFINE_PROP_BOOL ("Zihintpause" ,RISCVCPU , cfg.ext_zihintpause, true),DEFINE_PROP_BOOL ("Zfh" ,RISCVCPU , cfg.ext_zfh, false),DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),@@ -996,6 +997,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zihintpause, ext_zihintpause),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),target/riscv/cpu.h +1
-0@@ -394,6 +394,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_zihintpause;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;target/riscv/insn32.decode +6
-1@@ -149,7 +149,12 @@ srl 0000000 ..... ..... 101 ..... 0110011 @r sra 0100000 ..... ..... 101 ..... 0110011 @r or 0000000 ..... ..... 110 ..... 0110011 @r and 0000000 ..... ..... 111 ..... 0110011 @r -fence ---- pred:4 succ:4 ----- 000 ----- 0001111 + +{ + pause 0000 0001 0000 00000 000 00000 0001111 + fence ---- pred:4 succ:4 ----- 000 ----- 0001111 +} + fence_i ---- ---- ---- ----- 001 ----- 0001111 csrrw ............ ..... 001 ..... 1110011 @csr csrrs ............ ..... 010 ..... 1110011 @csrtarget/riscv/insn_trans/trans_rvi.c.inc +16
-1@@ -796,6 +796,22 @@ static bool trans_srad(DisasContext *ctx, arg_srad *a) return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl, NULL); } +static bool trans_pause(DisasContext *ctx, arg_pause *a) +{ + if (!ctx->cfg_ptr->ext_zihintpause) { + return false; + } + + /* + * PAUSE is a no-op in QEMU, + * end the TB and return to main loop + */ + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp = DISAS_NORETURN; + + return true; +} static bool trans_fence(DisasContext *ctx, arg_fence *a) { --2.25.1