* [PATCH] accel/kvm: Turn DPRINTF macro use into tracepoints
@ 2023-11-27 19:42 Jai Arora
2023-11-28 10:24 ` Peter Maydell
0 siblings, 1 reply; 2+ messages in thread
From: Jai Arora @ 2023-11-27 19:42 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Jai Arora
To remove DPRINTF macros and use tracepoints
for logging.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1827
Signed-off-by: Jai Arora <arorajai2798@gmail.com>
---
accel/kvm/kvm-all.c | 32 ++++++++++----------------------
accel/kvm/trace-events | 2 +-
2 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index e39a810a4e..d0dd7e54c3 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -69,16 +69,6 @@
#define KVM_GUESTDBG_BLOCKIRQ 0
#endif
-//#define DEBUG_KVM
-
-#ifdef DEBUG_KVM
-#define DPRINTF(fmt, ...) \
- do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) \
- do { } while (0)
-#endif
-
struct KVMParkedVcpu {
unsigned long vcpu_id;
int kvm_fd;
@@ -331,7 +321,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
struct KVMParkedVcpu *vcpu = NULL;
int ret = 0;
- DPRINTF("kvm_destroy_vcpu\n");
+ trace_kvm_dprintf("kvm_destroy_vcpu\n");
ret = kvm_arch_destroy_vcpu(cpu);
if (ret < 0) {
@@ -341,7 +331,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
if (mmap_size < 0) {
ret = mmap_size;
- DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
+ trace_kvm_dprintf("KVM_GET_VCPU_MMAP_SIZE failed\n");
goto err;
}
@@ -443,7 +433,6 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
PAGE_SIZE * KVM_DIRTY_LOG_PAGE_OFFSET);
if (cpu->kvm_dirty_gfns == MAP_FAILED) {
ret = -errno;
- DPRINTF("mmap'ing vcpu dirty gfns failed: %d\n", ret);
goto err;
}
}
@@ -2821,7 +2810,7 @@ int kvm_cpu_exec(CPUState *cpu)
struct kvm_run *run = cpu->kvm_run;
int ret, run_ret;
- DPRINTF("kvm_cpu_exec()\n");
+ trace_kvm_dprintf("kvm_cpu_exec()\n");
if (kvm_arch_process_async_events(cpu)) {
qatomic_set(&cpu->exit_request, 0);
@@ -2848,7 +2837,7 @@ int kvm_cpu_exec(CPUState *cpu)
kvm_arch_pre_run(cpu, run);
if (qatomic_read(&cpu->exit_request)) {
- DPRINTF("interrupt exit requested\n");
+ trace_kvm_dprintf("interrupt exit requested\n");
/*
* KVM requires us to reenter the kernel after IO exits to complete
* instruction emulation. This self-signal will ensure that we
@@ -2878,7 +2867,7 @@ int kvm_cpu_exec(CPUState *cpu)
if (run_ret < 0) {
if (run_ret == -EINTR || run_ret == -EAGAIN) {
- DPRINTF("io window exit\n");
+ trace_kvm_dprintf("io window exit\n");
kvm_eat_signals(cpu);
ret = EXCP_INTERRUPT;
break;
@@ -2900,7 +2889,7 @@ int kvm_cpu_exec(CPUState *cpu)
trace_kvm_run_exit(cpu->cpu_index, run->exit_reason);
switch (run->exit_reason) {
case KVM_EXIT_IO:
- DPRINTF("handle_io\n");
+ trace_kvm_dprintf("handle_io\n");
/* Called outside BQL */
kvm_handle_io(run->io.port, attrs,
(uint8_t *)run + run->io.data_offset,
@@ -2910,7 +2899,7 @@ int kvm_cpu_exec(CPUState *cpu)
ret = 0;
break;
case KVM_EXIT_MMIO:
- DPRINTF("handle_mmio\n");
+ trace_kvm_dprintf("handle_mmio\n");
/* Called outside BQL */
address_space_rw(&address_space_memory,
run->mmio.phys_addr, attrs,
@@ -2920,11 +2909,11 @@ int kvm_cpu_exec(CPUState *cpu)
ret = 0;
break;
case KVM_EXIT_IRQ_WINDOW_OPEN:
- DPRINTF("irq_window_open\n");
+ trace_kvm_dprintf("irq_window_open\n");
ret = EXCP_INTERRUPT;
break;
case KVM_EXIT_SHUTDOWN:
- DPRINTF("shutdown\n");
+ trace_kvm_dprintf("shutdown\n");
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
ret = EXCP_INTERRUPT;
break;
@@ -2976,13 +2965,12 @@ int kvm_cpu_exec(CPUState *cpu)
ret = 0;
break;
default:
- DPRINTF("kvm_arch_handle_exit\n");
+ trace_kvm_dprintf("kvm_arch_handle_exit\n");
ret = kvm_arch_handle_exit(cpu, run);
break;
}
break;
default:
- DPRINTF("kvm_arch_handle_exit\n");
ret = kvm_arch_handle_exit(cpu, run);
break;
}
diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
index 399aaeb0ec..1754909efe 100644
--- a/accel/kvm/trace-events
+++ b/accel/kvm/trace-events
@@ -25,4 +25,4 @@ kvm_dirty_ring_reaper(const char *s) "%s"
kvm_dirty_ring_reap(uint64_t count, int64_t t) "reaped %"PRIu64" pages (took %"PRIi64" us)"
kvm_dirty_ring_reaper_kick(const char *reason) "%s"
kvm_dirty_ring_flush(int finished) "%d"
-
+kvm_dprintf(const char *s) "from KVM: %s"
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] accel/kvm: Turn DPRINTF macro use into tracepoints
2023-11-27 19:42 [PATCH] accel/kvm: Turn DPRINTF macro use into tracepoints Jai Arora
@ 2023-11-28 10:24 ` Peter Maydell
0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2023-11-28 10:24 UTC (permalink / raw)
To: Jai Arora; +Cc: qemu-devel, qemu-trivial, Paolo Bonzini
On Mon, 27 Nov 2023 at 19:44, Jai Arora <arorajai2798@gmail.com> wrote:
>
> To remove DPRINTF macros and use tracepoints
> for logging.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1827
>
> Signed-off-by: Jai Arora <arorajai2798@gmail.com>
> ---
> accel/kvm/kvm-all.c | 32 ++++++++++----------------------
> accel/kvm/trace-events | 2 +-
> 2 files changed, 11 insertions(+), 23 deletions(-)
Hi; thanks for sending in this patch.
(I've CC'd the KVM maintainer.)
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index e39a810a4e..d0dd7e54c3 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -69,16 +69,6 @@
> #define KVM_GUESTDBG_BLOCKIRQ 0
> #endif
>
> -//#define DEBUG_KVM
> -
> -#ifdef DEBUG_KVM
> -#define DPRINTF(fmt, ...) \
> - do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
> -#else
> -#define DPRINTF(fmt, ...) \
> - do { } while (0)
> -#endif
> -
> struct KVMParkedVcpu {
> unsigned long vcpu_id;
> int kvm_fd;
> @@ -331,7 +321,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
> struct KVMParkedVcpu *vcpu = NULL;
> int ret = 0;
>
> - DPRINTF("kvm_destroy_vcpu\n");
> + trace_kvm_dprintf("kvm_destroy_vcpu\n");
Rather than using a single tracepoint for every line
that was previously a DPRINTF, it's preferable to
use tracepoints whose name indicates what they're doing.
Users can turn tracepoints on and off individually, and they
might, for instance, only want to trace when the vcpu is
destroyed and not also the very large number of events
that will happen for kvm_cpu_exec entry/exits.
If you look at the current set of events in accel/kvm/trace-events
you can see the general style: the tracepoint name itself
tells you the "what has happened", the arguments provide
more info (eg which CPU did we just destroy), and it's
rarely necessary to pass a string into the tracepoint function.
thanks
-- PMM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-28 10:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-27 19:42 [PATCH] accel/kvm: Turn DPRINTF macro use into tracepoints Jai Arora
2023-11-28 10:24 ` Peter Maydell
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).