target/ppc: Expose the TB offset of the guest in QEMU monitor
PATCH 1/1 target/ppc: Expose the TB offset of the guest in QEMU monitor
When debugging issues in KVM guests, it is sometimes helpful to have a unified trace log of both guest and host to see where things are going wrong. Expose the TB (timebase) offset through QEMU monitor to enable capturing of unified log.
The below steps can be then used to get a unified log:
1. In host
trace-cmd record -e kvm_hv:kvm_guest_enter -e kvm_hv:kvm_guest_exit \
-C ppc-tb -o trace_host.dat
2. In guest
trace-cmd record -e powerpc:hcall_entry -e powerpc:hcall_exit -C ppc-tb \
--ts-offset <TB offset from QEMU monitor> -o trace_guest.dat
3. Transfer the guest logs to the host with scp/rsync
4. Unify the logs
trace-cmd report -i trace_host.dat -i trace_guest.dat > combined_log
--- hw/ppc/ppc.c | 5 +++++ target/ppc/cpu.h | 1 + target/ppc/cpu_init.c | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-)
hw/ppc/ppc.c +5 -0
@@ -515,6 +515,11 @@ uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset)return ns_to_tb (tb_env->tb_freq, vmclk) + tb_offset; } +int64_t cpu_ppc_load_tb_offset (CPUPPCState *env) +{ +return llabs (*(&env->tb_env->tb_offset)); +} +uint64_t cpu_ppc_load_tbl (CPUPPCState *env) {ppc_tb_t *tb_env = env->tb_env;
target/ppc/cpu.h +1 -0
@@ -1693,6 +1693,7 @@ void cpu_ppc_store_hdecr(CPUPPCState *env, target_ulong value);void cpu_ppc_store_tbu40 (CPUPPCState *env,uint64_t value);uint64_t cpu_ppc_load_purr (CPUPPCState *env);void cpu_ppc_store_purr (CPUPPCState *env,uint64_t value); +int64_t cpu_ppc_load_tb_offset (CPUPPCState *env);#if !defined(CONFIG_USER_ONLY )target_ulong load_40x_pit (CPUPPCState *env);void store_40x_pit (CPUPPCState *env,target_ulong val);
target/ppc/cpu_init.c +3 -1
@@ -7620,8 +7620,10 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)#if !defined(CONFIG_USER_ONLY )if (env->tb_env) {qemu_fprintf (f,"TB %08" PRIu32" %08" PRIu64 +" TB_OFFSET %016" PRId64" DECR " TARGET_FMT_lu"\n" ,cpu_ppc_load_tbu (env), -cpu_ppc_load_tbl (env),cpu_ppc_load_decr (env)); +cpu_ppc_load_tbl (env),cpu_ppc_load_tb_offset (env), +cpu_ppc_load_decr (env)); }#else qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 "\n", cpu_ppc_load_tbu(env),
Signature · 1 line
2.54.0
Hi Gautam,
Thanks for the patch. My review comments inline below:
Quoted 31 lines · Gautam Menghani
When debugging issues in KVM guests, it is sometimes helpful to have a unified trace log of both guest and host to see where things are going wrong. Expose the TB (timebase) offset through QEMU monitor to enable capturing of unified log.
The below steps can be then used to get a unified log:
1. In host
trace-cmd record -e kvm_hv:kvm_guest_enter -e kvm_hv:kvm_guest_exit \
-C ppc-tb -o trace_host.dat2. In guest
trace-cmd record -e powerpc:hcall_entry -e powerpc:hcall_exit -C ppc-tb \
--ts-offset <TB offset from QEMU monitor> -o trace_guest.dat3. Transfer the guest logs to the host with scp/rsync
4. Unify the logs
trace-cmd report -i trace_host.dat -i trace_guest.dat >combined_logSigned-off-by Gautam Menghani <[email protected]>--- hw/ppc/ppc.c | 5 +++++ target/ppc/cpu.h | 1 + target/ppc/cpu_init.c | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-)hw/ppc/ppc.c +0
-0
hw/ppc/ppc.c uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset) · line 520
Quoted 6 lines
hw/ppc/ppc.c +3
-0@@ -515,6 +515,11 @@ uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset)return ns_to_tb (tb_env->tb_freq, vmclk) + tb_offset; } +int64_t cpu_ppc_load_tb_offset (CPUPPCState *env) +{ +return llabs (*(&env->tb_env->tb_offset));
Why are you doing both pointer ref and deref ?
Also why llabs is needed for tb_offset. You are anyways returning signed value and printing signed value later in ppc_cpu_dump_state.
I think you can just do
return env->tb_env->tb_offset;
Quoted 22 lines
hw/ppc/ppc.c +2
-0+} +uint64_t cpu_ppc_load_tbl (CPUPPCState *env) {ppc_tb_t *tb_env = env->tb_env;target/ppc/cpu.h +1
-0@@ -1693,6 +1693,7 @@ void cpu_ppc_store_hdecr(CPUPPCState *env, target_ulong value);void cpu_ppc_store_tbu40 (CPUPPCState *env,uint64_t value);uint64_t cpu_ppc_load_purr (CPUPPCState *env);void cpu_ppc_store_purr (CPUPPCState *env,uint64_t value); +int64_t cpu_ppc_load_tb_offset (CPUPPCState *env);#if !defined(CONFIG_USER_ONLY )target_ulong load_40x_pit (CPUPPCState *env);void store_40x_pit (CPUPPCState *env,target_ulong val);target/ppc/cpu_init.c +0
-0
target/ppc/cpu_init.c void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 7623
Quoted 4 lines
target/ppc/cpu_init.c +1
-0@@ -7620,8 +7620,10 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)#if !defined(CONFIG_USER_ONLY )if (env->tb_env) {qemu_fprintf (f,"TB %08" PRIu32" %08" PRIu64 + " TB_OFFSET %016" PRId64
Minor:
There might be some userspace tooling depending on this dump format. Would prefer if you introduce the new field to the end of string.
Quoted 10 lines
target/ppc/cpu_init.c +2
-1" DECR " TARGET_FMT_lu"\n" ,cpu_ppc_load_tbu (env), - cpu_ppc_load_tbl(env), cpu_ppc_load_decr(env)); +cpu_ppc_load_tbl (env),cpu_ppc_load_tb_offset (env), + cpu_ppc_load_decr(env)); }#else qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 "\n", cpu_ppc_load_tbu(env),Signature · 1 line
2.54.0
Signature · 2 lines
Cheers ~ Vaibhav
Quoted 40 lines · Vaibhav Jain
Hi Gautam,
Thanks for the patch. My review comments inline below:
Quoted 34 lines · Gautam Menghani
When debugging issues in KVM guests, it is sometimes helpful to have a unified trace log of both guest and host to see where things are going wrong. Expose the TB (timebase) offset through QEMU monitor to enable capturing of unified log.
The below steps can be then used to get a unified log:
1. In host
trace-cmd record -e kvm_hv:kvm_guest_enter -e kvm_hv:kvm_guest_exit \
-C ppc-tb -o trace_host.dat2. In guest
trace-cmd record -e powerpc:hcall_entry -e powerpc:hcall_exit -C ppc-tb \
--ts-offset <TB offset from QEMU monitor> -o trace_guest.dat3. Transfer the guest logs to the host with scp/rsync
4. Unify the logs
trace-cmd report -i trace_host.dat -i trace_guest.dat >combined_logSigned-off-by Gautam Menghani <[email protected]>--- hw/ppc/ppc.c | 5 +++++ target/ppc/cpu.h | 1 + target/ppc/cpu_init.c | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-)hw/ppc/ppc.c +0
-0@@ -515,6 +515,11 @@ uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset)return ns_to_tb (tb_env->tb_freq, vmclk) + tb_offset; }
Quoted 6 lines
hw/ppc/ppc.c uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset) · line 520
Quoted 3 lines
hw/ppc/ppc.c +3
-0+int64_t cpu_ppc_load_tb_offset (CPUPPCState *env) +{ +return llabs (*(&env->tb_env->tb_offset));Why are you doing both pointer ref and deref ?
Also why llabs is needed fortb_offset. You are anyways returning signed value and printing signed value later inppc_cpu_dump_state.
Since tb_offset is negative, I thought it would be better from user perspective if the offset is a positive number. Copy pasting it in the trace-cmd command would be easier. But on a second thought, I think we can leave it as negative number since this is for debugging anyways, I'll update the steps to reflect this.
Quoted 4 lines
I think you can just do
return
env->tb_env->tb_offset;
Ack. Will change it in v2.
Quoted 23 lines
Quoted 23 lines
hw/ppc/ppc.c +2
-0+} +uint64_t cpu_ppc_load_tbl (CPUPPCState *env) {ppc_tb_t *tb_env = env->tb_env;target/ppc/cpu.h +1
-0@@ -1693,6 +1693,7 @@ void cpu_ppc_store_hdecr(CPUPPCState *env, target_ulong value);void cpu_ppc_store_tbu40 (CPUPPCState *env,uint64_t value);uint64_t cpu_ppc_load_purr (CPUPPCState *env);void cpu_ppc_store_purr (CPUPPCState *env,uint64_t value); +int64_t cpu_ppc_load_tb_offset (CPUPPCState *env);#if !defined(CONFIG_USER_ONLY )target_ulong load_40x_pit (CPUPPCState *env);void store_40x_pit (CPUPPCState *env,target_ulong val);target/ppc/cpu_init.c +0
-0@@ -7620,8 +7620,10 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
Quoted 8 lines
target/ppc/cpu_init.c void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 7623
Quoted 4 lines
target/ppc/cpu_init.c +1
-0#if !defined(CONFIG_USER_ONLY )if (env->tb_env) {qemu_fprintf (f,"TB %08" PRIu32" %08" PRIu64 + " TB_OFFSET %016" PRId64Minor:
There might be some userspace tooling depending on this dump format. Would prefer if you introduce the new field to the end of string.
Sure will do.
Thanks,
Gautam