All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/10] tracing: remove dynamic vcpu state
@ 2023-05-05 15:53 Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 01/10] *-user: remove the guest_user_syscall tracepoints Alex Bennée
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

Hi Stefan,

The references dynamic vcpu tracing support was removed when the
original TCG trace points where removed. However there was still a
legacy of dynamic trace state to track this in cpu.h and extra hash
variables to track TBs. While the removed vcpu tracepoints are not in
generated code (or helpers) they still bring in a bunch of machinery
to manage the state so I've pulled them out. We keep and rename one
(cpu_reset) to a static trace points which dump vcpu->index as it is
useful to f4bug.

v3 fixes some minor comments and instead of simplifying to
qemu_xxhash6 we extend to qemu_xxhash8 so we can include cs_base. I've
added some initial benchmarks to the comments but you might want to
drop the last patch and leave it up to Richard to queue via his tree
once you've merged.

Please queue into your tree.

Alex Bennée (10):
  *-user: remove the guest_user_syscall tracepoints
  trace-events: remove the remaining vcpu trace events
  trace: remove vcpu_id from the TraceEvent structure
  scripts/qapi: document the tool that generated the file
  qapi: make the vcpu parameters deprecated for 8.1
  trace: remove code that depends on setting vcpu
  trace: remove control-vcpu.h
  tcg: remove the final vestiges of dstate
  hw/9pfs: use qemu_xxhash4
  accel/tcg: include cs_base in our hash calculations

 qapi/trace.json               |  22 +++----
 accel/tcg/tb-hash.h           |   7 ++-
 include/exec/exec-all.h       |   3 -
 include/hw/core/cpu.h         |   5 --
 include/qemu/xxhash.h         |  21 +++++--
 include/user/syscall-trace.h  |   4 --
 trace/control-internal.h      |  10 ---
 trace/control-vcpu.h          |  63 -------------------
 trace/control.h               |  48 ---------------
 trace/event-internal.h        |   2 -
 accel/tcg/cpu-exec.c          |   7 +--
 accel/tcg/tb-maint.c          |   5 +-
 accel/tcg/translate-all.c     |   6 --
 bsd-user/freebsd/os-syscall.c |   2 -
 hw/9pfs/9p.c                  |   5 +-
 hw/core/cpu-common.c          |   6 +-
 stubs/trace-control.c         |  13 ----
 trace/control-target.c        | 111 +++-------------------------------
 trace/control.c               |  28 ---------
 trace/qmp.c                   |  76 +++--------------------
 trace/trace-hmp-cmds.c        |  17 +-----
 hw/core/trace-events          |   3 +
 scripts/qapi/gen.py           |   4 +-
 scripts/tracetool/format/c.py |   6 --
 scripts/tracetool/format/h.py |  16 +----
 trace-events                  |  50 ---------------
 26 files changed, 60 insertions(+), 480 deletions(-)
 delete mode 100644 trace/control-vcpu.h

-- 
2.39.2



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

* [PATCH v3 01/10] *-user: remove the guest_user_syscall tracepoints
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 02/10] trace-events: remove the remaining vcpu trace events Alex Bennée
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

This is pure duplication now. Both bsd-user and linux-user have
builtin strace support and we can also track syscalls via the plugins
system.

Message-Id: <20230420150009.1675181-2-alex.bennee@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-2-alex.bennee@linaro.org>
---
 include/user/syscall-trace.h  |  4 ----
 bsd-user/freebsd/os-syscall.c |  2 --
 trace-events                  | 19 -------------------
 3 files changed, 25 deletions(-)

diff --git a/include/user/syscall-trace.h b/include/user/syscall-trace.h
index 90bda7631c..557f881a79 100644
--- a/include/user/syscall-trace.h
+++ b/include/user/syscall-trace.h
@@ -26,9 +26,6 @@ static inline void record_syscall_start(void *cpu, int num,
                                         abi_long arg5, abi_long arg6,
                                         abi_long arg7, abi_long arg8)
 {
-    trace_guest_user_syscall(cpu, num,
-                             arg1, arg2, arg3, arg4,
-                             arg5, arg6, arg7, arg8);
     qemu_plugin_vcpu_syscall(cpu, num,
                              arg1, arg2, arg3, arg4,
                              arg5, arg6, arg7, arg8);
@@ -36,7 +33,6 @@ static inline void record_syscall_start(void *cpu, int num,
 
 static inline void record_syscall_return(void *cpu, int num, abi_long ret)
 {
-    trace_guest_user_syscall_ret(cpu, num, ret);
     qemu_plugin_vcpu_syscall_ret(cpu, num, ret);
 }
 
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index c8f998ecec..b0ae43766f 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -531,7 +531,6 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
     CPUState *cpu = env_cpu(cpu_env);
     abi_long ret;
 
-    trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
     if (do_strace) {
         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
     }
@@ -541,7 +540,6 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
     if (do_strace) {
         print_freebsd_syscall_ret(num, ret);
     }
-    trace_guest_user_syscall_ret(cpu, num, ret);
 
     return ret;
 }
diff --git a/trace-events b/trace-events
index b6b84b175e..691c3533e4 100644
--- a/trace-events
+++ b/trace-events
@@ -85,22 +85,3 @@ vcpu guest_cpu_exit(void)
 # Targets: all
 vcpu guest_cpu_reset(void)
 
-# include/user/syscall-trace.h
-
-# @num: System call number.
-# @arg*: System call argument value.
-#
-# Start executing a guest system call in syscall emulation mode.
-#
-# Mode: user
-# Targets: TCG(all)
-vcpu guest_user_syscall(uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8) "num=0x%016"PRIx64" arg1=0x%016"PRIx64" arg2=0x%016"PRIx64" arg3=0x%016"PRIx64" arg4=0x%016"PRIx64" arg5=0x%016"PRIx64" arg6=0x%016"PRIx64" arg7=0x%016"PRIx64" arg8=0x%016"PRIx64
-
-# @num: System call number.
-# @ret: System call result value.
-#
-# Finish executing a guest system call in syscall emulation mode.
-#
-# Mode: user
-# Targets: TCG(all)
-vcpu guest_user_syscall_ret(uint64_t num, uint64_t ret) "num=0x%016"PRIx64" ret=0x%016"PRIx64
-- 
2.39.2



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

* [PATCH v3 02/10] trace-events: remove the remaining vcpu trace events
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 01/10] *-user: remove the guest_user_syscall tracepoints Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 03/10] trace: remove vcpu_id from the TraceEvent structure Alex Bennée
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

While these are all in helper functions being designated vcpu events
complicates the removal of the dynamic vcpu state code. TCG plugins
allow you to instrument vcpu_[init|exit|idle].

We rename cpu_reset and make it a normal trace point.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-3-alex.bennee@linaro.org>

---
v3
  - s/watch/trace/ in commit msg
---
 hw/core/cpu-common.c   |  4 ++--
 trace/control-target.c |  1 -
 trace/control.c        |  2 --
 hw/core/trace-events   |  3 +++
 trace-events           | 31 -------------------------------
 5 files changed, 5 insertions(+), 36 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 5ccc3837b6..951477a7fd 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -32,7 +32,7 @@
 #include "sysemu/tcg.h"
 #include "hw/boards.h"
 #include "hw/qdev-properties.h"
-#include "trace/trace-root.h"
+#include "trace.h"
 #include "qemu/plugin.h"
 
 CPUState *cpu_by_arch_id(int64_t id)
@@ -113,7 +113,7 @@ void cpu_reset(CPUState *cpu)
 {
     device_cold_reset(DEVICE(cpu));
 
-    trace_guest_cpu_reset(cpu);
+    trace_cpu_reset(cpu->cpu_index);
 }
 
 static void cpu_common_reset_hold(Object *obj)
diff --git a/trace/control-target.c b/trace/control-target.c
index 232c97a4a1..c6132f243f 100644
--- a/trace/control-target.c
+++ b/trace/control-target.c
@@ -145,5 +145,4 @@ void trace_init_vcpu(CPUState *vcpu)
             }
         }
     }
-    trace_guest_cpu_enter(vcpu);
 }
diff --git a/trace/control.c b/trace/control.c
index 6c77cc6318..d24af91004 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -277,8 +277,6 @@ void trace_fini_vcpu(CPUState *vcpu)
     TraceEventIter iter;
     TraceEvent *ev;
 
-    trace_guest_cpu_exit(vcpu);
-
     trace_event_iter_init_all(&iter);
     while ((ev = trace_event_iter_next(&iter)) != NULL) {
         if (trace_event_is_vcpu(ev) &&
diff --git a/hw/core/trace-events b/hw/core/trace-events
index 56da55bd71..2cf085ac66 100644
--- a/hw/core/trace-events
+++ b/hw/core/trace-events
@@ -29,3 +29,6 @@ clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRI
 clock_propagate(const char *clk) "'%s'"
 clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d"
 clock_set_mul_div(const char *clk, uint32_t oldmul, uint32_t mul, uint32_t olddiv, uint32_t div) "'%s', mul: %u -> %u, div: %u -> %u"
+
+# cpu-common.c
+cpu_reset(int cpu_index) "%d"
diff --git a/trace-events b/trace-events
index 691c3533e4..dd318ed1af 100644
--- a/trace-events
+++ b/trace-events
@@ -54,34 +54,3 @@ qmp_job_resume(void *job) "job %p"
 qmp_job_complete(void *job) "job %p"
 qmp_job_finalize(void *job) "job %p"
 qmp_job_dismiss(void *job) "job %p"
-
-
-### Guest events, keep at bottom
-
-
-## vCPU
-
-# trace/control-target.c
-
-# Hot-plug a new virtual (guest) CPU
-#
-# Mode: user, softmmu
-# Targets: all
-vcpu guest_cpu_enter(void)
-
-# trace/control.c
-
-# Hot-unplug a virtual (guest) CPU
-#
-# Mode: user, softmmu
-# Targets: all
-vcpu guest_cpu_exit(void)
-
-# hw/core/cpu.c
-
-# Reset the state of a virtual (guest) CPU
-#
-# Mode: user, softmmu
-# Targets: all
-vcpu guest_cpu_reset(void)
-
-- 
2.39.2



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

* [PATCH v3 03/10] trace: remove vcpu_id from the TraceEvent structure
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 01/10] *-user: remove the guest_user_syscall tracepoints Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 02/10] trace-events: remove the remaining vcpu trace events Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 04/10] scripts/qapi: document the tool that generated the file Alex Bennée
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

This does involve temporarily stubbing out some helper functions
before we excise the rest of the code.

Message-Id: <20230420150009.1675181-4-alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-4-alex.bennee@linaro.org>
---
 trace/control-internal.h      |  4 ++--
 trace/event-internal.h        |  2 --
 trace/control.c               | 10 ----------
 scripts/tracetool/format/c.py |  6 ------
 scripts/tracetool/format/h.py | 11 +----------
 5 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/trace/control-internal.h b/trace/control-internal.h
index 8b2b50a7cf..0178121720 100644
--- a/trace/control-internal.h
+++ b/trace/control-internal.h
@@ -27,12 +27,12 @@ static inline uint32_t trace_event_get_id(TraceEvent *ev)
 
 static inline uint32_t trace_event_get_vcpu_id(TraceEvent *ev)
 {
-    return ev->vcpu_id;
+    return 0;
 }
 
 static inline bool trace_event_is_vcpu(TraceEvent *ev)
 {
-    return ev->vcpu_id != TRACE_VCPU_EVENT_NONE;
+    return false;
 }
 
 static inline const char * trace_event_get_name(TraceEvent *ev)
diff --git a/trace/event-internal.h b/trace/event-internal.h
index f63500b37e..0c24e01b52 100644
--- a/trace/event-internal.h
+++ b/trace/event-internal.h
@@ -19,7 +19,6 @@
 /**
  * TraceEvent:
  * @id: Unique event identifier.
- * @vcpu_id: Unique per-vCPU event identifier.
  * @name: Event name.
  * @sstate: Static tracing state.
  * @dstate: Dynamic tracing state
@@ -33,7 +32,6 @@
  */
 typedef struct TraceEvent {
     uint32_t id;
-    uint32_t vcpu_id;
     const char * name;
     const bool sstate;
     uint16_t *dstate;
diff --git a/trace/control.c b/trace/control.c
index d24af91004..5dfb609954 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -68,16 +68,6 @@ void trace_event_register_group(TraceEvent **events)
     size_t i;
     for (i = 0; events[i] != NULL; i++) {
         events[i]->id = next_id++;
-        if (events[i]->vcpu_id == TRACE_VCPU_EVENT_NONE) {
-            continue;
-        }
-
-        if (likely(next_vcpu_id < CPU_TRACE_DSTATE_MAX_EVENTS)) {
-            events[i]->vcpu_id = next_vcpu_id++;
-        } else {
-            warn_report("too many vcpu trace events; dropping '%s'",
-                        events[i]->name);
-        }
     }
     event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
     event_groups[nevent_groups].events = events;
diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py
index c390c1844a..69edf0d588 100644
--- a/scripts/tracetool/format/c.py
+++ b/scripts/tracetool/format/c.py
@@ -32,19 +32,13 @@ def generate(events, backend, group):
         out('uint16_t %s;' % e.api(e.QEMU_DSTATE))
 
     for e in events:
-        if "vcpu" in e.properties:
-            vcpu_id = 0
-        else:
-            vcpu_id = "TRACE_VCPU_EVENT_NONE"
         out('TraceEvent %(event)s = {',
             '    .id = 0,',
-            '    .vcpu_id = %(vcpu_id)s,',
             '    .name = \"%(name)s\",',
             '    .sstate = %(sstate)s,',
             '    .dstate = &%(dstate)s ',
             '};',
             event = e.api(e.QEMU_EVENT),
-            vcpu_id = vcpu_id,
             name = e.name,
             sstate = "TRACE_%s_ENABLED" % e.name.upper(),
             dstate = e.api(e.QEMU_DSTATE))
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index e94f0be7da..285d7b03a9 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -74,16 +74,7 @@ def generate(events, backend, group):
 
         out('}')
 
-        # tracer wrapper with checks (per-vCPU tracing)
-        if "vcpu" in e.properties:
-            trace_cpu = next(iter(e.args))[1]
-            cond = "trace_event_get_vcpu_state(%(cpu)s,"\
-                   " TRACE_%(id)s)"\
-                   % dict(
-                       cpu=trace_cpu,
-                       id=e.name.upper())
-        else:
-            cond = "true"
+        cond = "true"
 
         out('',
             'static inline void %(api)s(%(args)s)',
-- 
2.39.2



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

* [PATCH v3 04/10] scripts/qapi: document the tool that generated the file
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (2 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 03/10] trace: remove vcpu_id from the TraceEvent structure Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-06  7:34   ` Markus Armbruster
  2023-05-05 15:53 ` [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1 Alex Bennée
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

This makes it a little easier for developers to find where things
where being generated.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-5-alex.bennee@linaro.org>
---
 scripts/qapi/gen.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 8f8f784f4a..e724507e1a 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -162,7 +162,7 @@ def __init__(self, fname: str, blurb: str, pydoc: str):
 
     def _top(self) -> str:
         return mcgen('''
-/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
+/* AUTOMATICALLY GENERATED by QAPIGenC, DO NOT MODIFY */
 
 /*
 %(blurb)s
@@ -195,7 +195,7 @@ def _bottom(self) -> str:
 
 class QAPIGenTrace(QAPIGen):
     def _top(self) -> str:
-        return super()._top() + '# AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n'
+        return super()._top() + '# AUTOMATICALLY GENERATED by QAPIGenTrace, DO NOT MODIFY\n\n'
 
 
 @contextmanager
-- 
2.39.2



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

* [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (3 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 04/10] scripts/qapi: document the tool that generated the file Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-06  7:20   ` Markus Armbruster
  2023-05-05 15:53 ` [PATCH v3 06/10] trace: remove code that depends on setting vcpu Alex Bennée
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

I don't think I can remove the parameters directly but certainly mark
them as deprecated.

Message-Id: <20230420150009.1675181-6-alex.bennee@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-6-alex.bennee@linaro.org>
---
 qapi/trace.json | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/qapi/trace.json b/qapi/trace.json
index f425d10764..de6b1681aa 100644
--- a/qapi/trace.json
+++ b/qapi/trace.json
@@ -33,9 +33,9 @@
 #
 # @name: Event name.
 # @state: Tracing state.
-# @vcpu: Whether this is a per-vCPU event (since 2.7).
+# @vcpu: Whether this is a per-vCPU event (deprecated since 8.1).
 #
-# An event is per-vCPU if it has the "vcpu" property in the "trace-events"
+# There are no longer any events with the "vcpu" property in the "trace-events"
 # files.
 #
 # Since: 2.2
@@ -49,19 +49,15 @@
 # Query the state of events.
 #
 # @name: Event name pattern (case-sensitive glob).
-# @vcpu: The vCPU to query (any by default; since 2.7).
+# @vcpu: The vCPU to query (deprecated since 8.1).
 #
 # Returns: a list of @TraceEventInfo for the matching events
 #
 #          An event is returned if:
 #
 #          - its name matches the @name pattern, and
-#          - if @vcpu is given, the event has the "vcpu" property.
 #
-#          Therefore, if @vcpu is given, the operation will only match per-vCPU events,
-#          returning their state on the specified vCPU. Special case: if @name is an
-#          exact match, @vcpu is given and the event does not have the "vcpu" property,
-#          an error is returned.
+#          There are no longer any per-vCPU events
 #
 # Since: 2.2
 #
@@ -84,17 +80,13 @@
 # @name: Event name pattern (case-sensitive glob).
 # @enable: Whether to enable tracing.
 # @ignore-unavailable: Do not match unavailable events with @name.
-# @vcpu: The vCPU to act upon (all by default; since 2.7).
+# @vcpu: The vCPU to act upon (deprecated since 8.1).
 #
 # An event's state is modified if:
 #
-# - its name matches the @name pattern, and
-# - if @vcpu is given, the event has the "vcpu" property.
+# - its name matches the @name pattern
 #
-# Therefore, if @vcpu is given, the operation will only match per-vCPU events,
-# setting their state on the specified vCPU. Special case: if @name is an exact
-# match, @vcpu is given and the event does not have the "vcpu" property, an
-# error is returned.
+# There are no longer and per-vCPU events so specifying it will never match.
 #
 # Since: 2.2
 #
-- 
2.39.2



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

* [PATCH v3 06/10] trace: remove code that depends on setting vcpu
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (4 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1 Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-10  7:46   ` Philippe Mathieu-Daudé
  2023-05-05 15:53 ` [PATCH v3 07/10] trace: remove control-vcpu.h Alex Bennée
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

Now we no longer have any events that are for vcpus we can start
excising the code from the trace control. As the vcpu parameter is
encoded as part of QMP we just stub out the has_vcpu/vcpu parameters
rather than alter the API.

Message-Id: <20230420150009.1675181-7-alex.bennee@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-7-alex.bennee@linaro.org>
---
 trace/control-internal.h |  10 ----
 trace/control-vcpu.h     |  16 ------
 trace/control.h          |  48 -----------------
 hw/core/cpu-common.c     |   2 -
 stubs/trace-control.c    |  13 -----
 trace/control-target.c   | 110 ++++-----------------------------------
 trace/control.c          |  16 ------
 trace/qmp.c              |  74 +++-----------------------
 trace/trace-hmp-cmds.c   |  17 +-----
 9 files changed, 19 insertions(+), 287 deletions(-)

diff --git a/trace/control-internal.h b/trace/control-internal.h
index 0178121720..8d818d359b 100644
--- a/trace/control-internal.h
+++ b/trace/control-internal.h
@@ -25,16 +25,6 @@ static inline uint32_t trace_event_get_id(TraceEvent *ev)
     return ev->id;
 }
 
-static inline uint32_t trace_event_get_vcpu_id(TraceEvent *ev)
-{
-    return 0;
-}
-
-static inline bool trace_event_is_vcpu(TraceEvent *ev)
-{
-    return false;
-}
-
 static inline const char * trace_event_get_name(TraceEvent *ev)
 {
     assert(ev != NULL);
diff --git a/trace/control-vcpu.h b/trace/control-vcpu.h
index 0f98ebe7b5..800fc5a219 100644
--- a/trace/control-vcpu.h
+++ b/trace/control-vcpu.h
@@ -30,13 +30,6 @@
      trace_event_get_vcpu_state_dynamic_by_vcpu_id(                     \
          vcpu, _ ## id ## _EVENT.vcpu_id))
 
-/**
- * trace_event_get_vcpu_state_dynamic:
- *
- * Get the dynamic tracing state of an event for the given vCPU.
- */
-static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev);
-
 #include "control-internal.h"
 
 static inline bool
@@ -51,13 +44,4 @@ trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
     }
 }
 
-static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu,
-                                                      TraceEvent *ev)
-{
-    uint32_t vcpu_id;
-    assert(trace_event_is_vcpu(ev));
-    vcpu_id = trace_event_get_vcpu_id(ev);
-    return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id);
-}
-
 #endif
diff --git a/trace/control.h b/trace/control.h
index 23b8393b29..dfd209edd8 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -89,23 +89,6 @@ static bool trace_event_is_pattern(const char *str);
  */
 static uint32_t trace_event_get_id(TraceEvent *ev);
 
-/**
- * trace_event_get_vcpu_id:
- *
- * Get the per-vCPU identifier of an event.
- *
- * Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
- * (does not have the "vcpu" property).
- */
-static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);
-
-/**
- * trace_event_is_vcpu:
- *
- * Whether this is a per-vCPU event.
- */
-static bool trace_event_is_vcpu(TraceEvent *ev);
-
 /**
  * trace_event_get_name:
  *
@@ -172,21 +155,6 @@ static bool trace_event_get_state_dynamic(TraceEvent *ev);
  */
 void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
 
-/**
- * trace_event_set_vcpu_state_dynamic:
- *
- * Set the dynamic tracing state of an event for the given vCPU.
- *
- * Pre-condition: trace_event_get_vcpu_state_static(ev) == true
- *
- * Note: Changes for execution-time events with the 'tcg' property will not be
- *       propagated until the next TB is executed (iff executing in TCG mode).
- */
-void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
-                                        TraceEvent *ev, bool state);
-
-
-
 /**
  * trace_init_backends:
  *
@@ -205,22 +173,6 @@ bool trace_init_backends(void);
  */
 void trace_init_file(void);
 
-/**
- * trace_init_vcpu:
- * @vcpu: Added vCPU.
- *
- * Set initial dynamic event state for a hot-plugged vCPU.
- */
-void trace_init_vcpu(CPUState *vcpu);
-
-/**
- * trace_fini_vcpu:
- * @vcpu: Removed vCPU.
- *
- * Disable dynamic event state for a hot-unplugged vCPU.
- */
-void trace_fini_vcpu(CPUState *vcpu);
-
 /**
  * trace_list_events:
  * @f: Where to send output.
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 951477a7fd..f4e51c8a1b 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -211,7 +211,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
     }
 
     /* NOTE: latest generic point where the cpu is fully realized */
-    trace_init_vcpu(cpu);
 }
 
 static void cpu_common_unrealizefn(DeviceState *dev)
@@ -219,7 +218,6 @@ static void cpu_common_unrealizefn(DeviceState *dev)
     CPUState *cpu = CPU(dev);
 
     /* NOTE: latest generic point before the cpu is fully unrealized */
-    trace_fini_vcpu(cpu);
     cpu_exec_unrealizefn(cpu);
 }
 
diff --git a/stubs/trace-control.c b/stubs/trace-control.c
index 7f856e5c24..b428f34c87 100644
--- a/stubs/trace-control.c
+++ b/stubs/trace-control.c
@@ -36,16 +36,3 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
         }
     }
 }
-
-void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
-                                        TraceEvent *ev, bool state)
-{
-    /* should never be called on non-target binaries */
-    abort();
-}
-
-void trace_init_vcpu(CPUState *vcpu)
-{
-    /* should never be called on non-target binaries */
-    abort();
-}
diff --git a/trace/control-target.c b/trace/control-target.c
index c6132f243f..1ae582af17 100644
--- a/trace/control-target.c
+++ b/trace/control-target.c
@@ -35,114 +35,22 @@ void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
 
 void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
-    CPUState *vcpu;
     assert(trace_event_get_state_static(ev));
-    if (trace_event_is_vcpu(ev) && likely(first_cpu != NULL)) {
-        CPU_FOREACH(vcpu) {
-            trace_event_set_vcpu_state_dynamic(vcpu, ev, state);
-        }
-    } else {
-        /*
-         * Without the "vcpu" property, dstate can only be 1 or 0. With it, we
-         * haven't instantiated any vCPU yet, so we will set a global state
-         * instead, and trace_init_vcpu will reconcile it afterwards.
-         */
-        bool state_pre = *ev->dstate;
-        if (state_pre != state) {
-            if (state) {
-                trace_events_enabled_count++;
-                *ev->dstate = 1;
-            } else {
-                trace_events_enabled_count--;
-                *ev->dstate = 0;
-            }
-        }
-    }
-}
 
-static void trace_event_synchronize_vcpu_state_dynamic(
-    CPUState *vcpu, run_on_cpu_data ignored)
-{
-    bitmap_copy(vcpu->trace_dstate, vcpu->trace_dstate_delayed,
-                CPU_TRACE_DSTATE_MAX_EVENTS);
-    tcg_flush_jmp_cache(vcpu);
-}
-
-void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
-                                        TraceEvent *ev, bool state)
-{
-    uint32_t vcpu_id;
-    bool state_pre;
-    assert(trace_event_get_state_static(ev));
-    assert(trace_event_is_vcpu(ev));
-    vcpu_id = trace_event_get_vcpu_id(ev);
-    state_pre = test_bit(vcpu_id, vcpu->trace_dstate);
+    /*
+     * There is no longer a "vcpu" property, dstate can only be 1 or
+     * 0. With it, we haven't instantiated any vCPU yet, so we will
+     * set a global state instead, and trace_init_vcpu will reconcile
+     * it afterwards.
+     */
+    bool state_pre = *ev->dstate;
     if (state_pre != state) {
         if (state) {
             trace_events_enabled_count++;
-            set_bit(vcpu_id, vcpu->trace_dstate_delayed);
-            (*ev->dstate)++;
+            *ev->dstate = 1;
         } else {
             trace_events_enabled_count--;
-            clear_bit(vcpu_id, vcpu->trace_dstate_delayed);
-            (*ev->dstate)--;
-        }
-        if (vcpu->created) {
-            /*
-             * Delay changes until next TB; we want all TBs to be built from a
-             * single set of dstate values to ensure consistency of generated
-             * tracing code.
-             */
-            async_run_on_cpu(vcpu, trace_event_synchronize_vcpu_state_dynamic,
-                             RUN_ON_CPU_NULL);
-        } else {
-            trace_event_synchronize_vcpu_state_dynamic(vcpu, RUN_ON_CPU_NULL);
-        }
-    }
-}
-
-static bool adding_first_cpu1(void)
-{
-    CPUState *cpu;
-    size_t count = 0;
-    CPU_FOREACH(cpu) {
-        count++;
-        if (count > 1) {
-            return false;
-        }
-    }
-    return true;
-}
-
-static bool adding_first_cpu(void)
-{
-    bool res;
-    cpu_list_lock();
-    res = adding_first_cpu1();
-    cpu_list_unlock();
-    return res;
-}
-
-void trace_init_vcpu(CPUState *vcpu)
-{
-    TraceEventIter iter;
-    TraceEvent *ev;
-    trace_event_iter_init_all(&iter);
-    while ((ev = trace_event_iter_next(&iter)) != NULL) {
-        if (trace_event_is_vcpu(ev) &&
-            trace_event_get_state_static(ev) &&
-            trace_event_get_state_dynamic(ev)) {
-            if (adding_first_cpu()) {
-                /* check preconditions */
-                assert(*ev->dstate == 1);
-                /* disable early-init state ... */
-                *ev->dstate = 0;
-                trace_events_enabled_count--;
-                /* ... and properly re-enable */
-                trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
-            } else {
-                trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
-            }
+            *ev->dstate = 0;
         }
     }
 }
diff --git a/trace/control.c b/trace/control.c
index 5dfb609954..1a48a7e266 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -262,22 +262,6 @@ void trace_init_file(void)
 #endif
 }
 
-void trace_fini_vcpu(CPUState *vcpu)
-{
-    TraceEventIter iter;
-    TraceEvent *ev;
-
-    trace_event_iter_init_all(&iter);
-    while ((ev = trace_event_iter_next(&iter)) != NULL) {
-        if (trace_event_is_vcpu(ev) &&
-            trace_event_get_state_static(ev) &&
-            trace_event_get_vcpu_state_dynamic(vcpu, ev)) {
-            /* must disable to affect the global counter */
-            trace_event_set_vcpu_state_dynamic(vcpu, ev, false);
-        }
-    }
-}
-
 bool trace_init_backends(void)
 {
 #ifdef CONFIG_TRACE_SIMPLE
diff --git a/trace/qmp.c b/trace/qmp.c
index 3b4f4702b4..aa760f1fc4 100644
--- a/trace/qmp.c
+++ b/trace/qmp.c
@@ -13,20 +13,7 @@
 #include "control-vcpu.h"
 
 
-static CPUState *get_cpu(bool has_vcpu, int vcpu, Error **errp)
-{
-    if (has_vcpu) {
-        CPUState *cpu = qemu_get_cpu(vcpu);
-        if (cpu == NULL) {
-            error_setg(errp, "invalid vCPU index %u", vcpu);
-        }
-        return cpu;
-    } else {
-        return NULL;
-    }
-}
-
-static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern,
+static bool check_events(bool ignore_unavailable, bool is_pattern,
                          const char *name, Error **errp)
 {
     if (!is_pattern) {
@@ -38,12 +25,6 @@ static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern
             return false;
         }
 
-        /* error for non-vcpu event */
-        if (has_vcpu && !trace_event_is_vcpu(ev)) {
-            error_setg(errp, "event \"%s\" is not vCPU-specific", name);
-            return false;
-        }
-
         /* error for unavailable event */
         if (!ignore_unavailable && !trace_event_get_state_static(ev)) {
             error_setg(errp, "event \"%s\" is disabled", name);
@@ -70,22 +51,13 @@ TraceEventInfoList *qmp_trace_event_get_state(const char *name,
                                               bool has_vcpu, int64_t vcpu,
                                               Error **errp)
 {
-    Error *err = NULL;
     TraceEventInfoList *events = NULL;
     TraceEventIter iter;
     TraceEvent *ev;
     bool is_pattern = trace_event_is_pattern(name);
-    CPUState *cpu;
-
-    /* Check provided vcpu */
-    cpu = get_cpu(has_vcpu, vcpu, &err);
-    if (err) {
-        error_propagate(errp, err);
-        return NULL;
-    }
 
     /* Check events */
-    if (!check_events(has_vcpu, true, is_pattern, name, errp)) {
+    if (!check_events(true, is_pattern, name, errp)) {
         return NULL;
     }
 
@@ -93,33 +65,17 @@ TraceEventInfoList *qmp_trace_event_get_state(const char *name,
     trace_event_iter_init_pattern(&iter, name);
     while ((ev = trace_event_iter_next(&iter)) != NULL) {
         TraceEventInfo *value;
-        bool is_vcpu = trace_event_is_vcpu(ev);
-        if (has_vcpu && !is_vcpu) {
-            continue;
-        }
 
         value = g_new(TraceEventInfo, 1);
-        value->vcpu = is_vcpu;
         value->name = g_strdup(trace_event_get_name(ev));
 
         if (!trace_event_get_state_static(ev)) {
             value->state = TRACE_EVENT_STATE_UNAVAILABLE;
         } else {
-            if (has_vcpu) {
-                if (is_vcpu) {
-                    if (trace_event_get_vcpu_state_dynamic(cpu, ev)) {
-                        value->state = TRACE_EVENT_STATE_ENABLED;
-                    } else {
-                        value->state = TRACE_EVENT_STATE_DISABLED;
-                    }
-                }
-                /* else: already skipped above */
+            if (trace_event_get_state_dynamic(ev)) {
+                value->state = TRACE_EVENT_STATE_ENABLED;
             } else {
-                if (trace_event_get_state_dynamic(ev)) {
-                    value->state = TRACE_EVENT_STATE_ENABLED;
-                } else {
-                    value->state = TRACE_EVENT_STATE_DISABLED;
-                }
+                value->state = TRACE_EVENT_STATE_DISABLED;
             }
         }
         QAPI_LIST_PREPEND(events, value);
@@ -133,21 +89,12 @@ void qmp_trace_event_set_state(const char *name, bool enable,
                                bool has_vcpu, int64_t vcpu,
                                Error **errp)
 {
-    Error *err = NULL;
     TraceEventIter iter;
     TraceEvent *ev;
     bool is_pattern = trace_event_is_pattern(name);
-    CPUState *cpu;
-
-    /* Check provided vcpu */
-    cpu = get_cpu(has_vcpu, vcpu, &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
 
     /* Check events */
-    if (!check_events(has_vcpu, has_ignore_unavailable && ignore_unavailable,
+    if (!check_events(has_ignore_unavailable && ignore_unavailable,
                       is_pattern, name, errp)) {
         return;
     }
@@ -155,14 +102,9 @@ void qmp_trace_event_set_state(const char *name, bool enable,
     /* Apply changes (all errors checked above) */
     trace_event_iter_init_pattern(&iter, name);
     while ((ev = trace_event_iter_next(&iter)) != NULL) {
-        if (!trace_event_get_state_static(ev) ||
-            (has_vcpu && !trace_event_is_vcpu(ev))) {
+        if (!trace_event_get_state_static(ev)) {
             continue;
         }
-        if (has_vcpu) {
-            trace_event_set_vcpu_state_dynamic(cpu, ev, enable);
-        } else {
-            trace_event_set_state_dynamic(ev, enable);
-        }
+        trace_event_set_state_dynamic(ev, enable);
     }
 }
diff --git a/trace/trace-hmp-cmds.c b/trace/trace-hmp-cmds.c
index 792876c34a..1d07672cb2 100644
--- a/trace/trace-hmp-cmds.c
+++ b/trace/trace-hmp-cmds.c
@@ -37,16 +37,9 @@ void hmp_trace_event(Monitor *mon, const QDict *qdict)
 {
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
-    bool has_vcpu = qdict_haskey(qdict, "vcpu");
-    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
     Error *local_err = NULL;
 
-    if (vcpu < 0) {
-        monitor_printf(mon, "argument vcpu must be positive");
-        return;
-    }
-
-    qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
+    qmp_trace_event_set_state(tp_name, new_state, true, true, false, 0, &local_err);
     if (local_err) {
         error_report_err(local_err);
     }
@@ -80,8 +73,6 @@ void hmp_trace_file(Monitor *mon, const QDict *qdict)
 void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
 {
     const char *name = qdict_get_try_str(qdict, "name");
-    bool has_vcpu = qdict_haskey(qdict, "vcpu");
-    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
     TraceEventInfoList *events;
     TraceEventInfoList *elem;
     Error *local_err = NULL;
@@ -89,12 +80,8 @@ void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
     if (name == NULL) {
         name = "*";
     }
-    if (vcpu < 0) {
-        monitor_printf(mon, "argument vcpu must be positive");
-        return;
-    }
 
-    events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
+    events = qmp_trace_event_get_state(name, false, 0, &local_err);
     if (local_err) {
         error_report_err(local_err);
         return;
-- 
2.39.2



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

* [PATCH v3 07/10] trace: remove control-vcpu.h
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (5 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 06/10] trace: remove code that depends on setting vcpu Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 08/10] tcg: remove the final vestiges of dstate Alex Bennée
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

Now we no longer have vcpu controlled trace events we can excise the
code that allows us to query its status.

Message-Id: <20230420150009.1675181-8-alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-8-alex.bennee@linaro.org>
---
 trace/control-vcpu.h          | 47 -----------------------------------
 trace/qmp.c                   |  2 +-
 scripts/tracetool/format/h.py |  5 +---
 3 files changed, 2 insertions(+), 52 deletions(-)
 delete mode 100644 trace/control-vcpu.h

diff --git a/trace/control-vcpu.h b/trace/control-vcpu.h
deleted file mode 100644
index 800fc5a219..0000000000
--- a/trace/control-vcpu.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Interface for configuring and controlling the state of tracing events.
- *
- * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef TRACE__CONTROL_VCPU_H
-#define TRACE__CONTROL_VCPU_H
-
-#include "control.h"
-#include "event-internal.h"
-#include "hw/core/cpu.h"
-
-/**
- * trace_event_get_vcpu_state:
- * @vcpu: Target vCPU.
- * @id: Event identifier name.
- *
- * Get the tracing state of an event (both static and dynamic) for the given
- * vCPU.
- *
- * If the event has the disabled property, the check will have no performance
- * impact.
- */
-#define trace_event_get_vcpu_state(vcpu, id)                            \
-    ((id ##_ENABLED) &&                                                 \
-     trace_event_get_vcpu_state_dynamic_by_vcpu_id(                     \
-         vcpu, _ ## id ## _EVENT.vcpu_id))
-
-#include "control-internal.h"
-
-static inline bool
-trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
-                                              uint32_t vcpu_id)
-{
-    /* it's on fast path, avoid consistency checks (asserts) */
-    if (unlikely(trace_events_enabled_count)) {
-        return test_bit(vcpu_id, vcpu->trace_dstate);
-    } else {
-        return false;
-    }
-}
-
-#endif
diff --git a/trace/qmp.c b/trace/qmp.c
index aa760f1fc4..3e3971c6a8 100644
--- a/trace/qmp.c
+++ b/trace/qmp.c
@@ -10,7 +10,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-trace.h"
-#include "control-vcpu.h"
+#include "control.h"
 
 
 static bool check_events(bool ignore_unavailable, bool is_pattern,
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 285d7b03a9..ea126b07ea 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -16,10 +16,7 @@
 
 
 def generate(events, backend, group):
-    if group == "root":
-        header = "trace/control-vcpu.h"
-    else:
-        header = "trace/control.h"
+    header = "trace/control.h"
 
     out('/* This file is autogenerated by tracetool, do not edit. */',
         '',
-- 
2.39.2



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

* [PATCH v3 08/10] tcg: remove the final vestiges of dstate
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (6 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 07/10] trace: remove control-vcpu.h Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-10  7:48   ` Philippe Mathieu-Daudé
  2023-05-05 15:53 ` [PATCH v3 09/10] hw/9pfs: use qemu_xxhash4 Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations Alex Bennée
  9 siblings, 1 reply; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

Now we no longer have dynamic state affecting things we can remove the
additional fields in cpu.h and simplify the TB hash calculation.

For the benchmark:

    hyperfine -w 2 -m 20 \
      "./arm-softmmu/qemu-system-arm -cpu cortex-a15 \
        -machine type=virt,highmem=off \
        -display none -m 2048 \
        -serial mon:stdio \
        -netdev user,id=unet,hostfwd=tcp::2222-:22 \
        -device virtio-net-pci,netdev=unet \
        -device virtio-scsi-pci \
        -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-bullseye-armhf \
        -device scsi-hd,drive=hd -smp 4 \
        -kernel /home/alex/lsrc/linux.git/builds/arm/arch/arm/boot/zImage \
        -append 'console=ttyAMA0 root=/dev/sda2 systemd.unit=benchmark.service' \
        -snapshot"

It has a marginal effect on runtime, before:

  Time (mean ± σ):     26.279 s ±  2.438 s    [User: 41.113 s, System: 1.843 s]
  Range (min … max):   24.420 s … 32.565 s    20 runs

after:

  Time (mean ± σ):     24.440 s ±  2.885 s    [User: 34.474 s, System: 2.028 s]
  Range (min … max):   21.663 s … 29.937 s    20 runs

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1358
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-9-alex.bennee@linaro.org>
---
 accel/tcg/tb-hash.h       | 6 +++---
 include/exec/exec-all.h   | 3 ---
 include/hw/core/cpu.h     | 5 -----
 accel/tcg/cpu-exec.c      | 7 +------
 accel/tcg/tb-maint.c      | 5 ++---
 accel/tcg/translate-all.c | 6 ------
 6 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/accel/tcg/tb-hash.h b/accel/tcg/tb-hash.h
index 83dc610e4c..1d19c69caa 100644
--- a/accel/tcg/tb-hash.h
+++ b/accel/tcg/tb-hash.h
@@ -61,10 +61,10 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
 #endif /* CONFIG_SOFTMMU */
 
 static inline
-uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags,
-                      uint32_t cf_mask, uint32_t trace_vcpu_dstate)
+uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc,
+                      uint32_t flags, uint32_t cf_mask)
 {
-    return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate);
+    return qemu_xxhash6(phys_pc, pc, flags, cf_mask);
 }
 
 #endif
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index ecded1f112..3ee76af28b 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -548,9 +548,6 @@ struct TranslationBlock {
 #define CF_CLUSTER_MASK  0xff000000 /* Top 8 bits are cluster ID */
 #define CF_CLUSTER_SHIFT 24
 
-    /* Per-vCPU dynamic tracing state used to generate this TB */
-    uint32_t trace_vcpu_dstate;
-
     /*
      * Above fields used for comparing
      */
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 397fd3ac68..4b399643d0 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -262,7 +262,6 @@ typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
 struct qemu_work_item;
 
 #define CPU_UNSET_NUMA_NODE_ID -1
-#define CPU_TRACE_DSTATE_MAX_EVENTS 32
 
 /**
  * CPUState:
@@ -403,10 +402,6 @@ struct CPUState {
     /* Use by accel-block: CPU is executing an ioctl() */
     QemuLockCnt in_ioctl_lock;
 
-    /* Used for events with 'vcpu' and *without* the 'disabled' properties */
-    DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
-    DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
-
     DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX);
 
 #ifdef CONFIG_PLUGIN
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index bc0e1c3299..973da2a434 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -175,7 +175,6 @@ struct tb_desc {
     tb_page_addr_t page_addr0;
     uint32_t flags;
     uint32_t cflags;
-    uint32_t trace_vcpu_dstate;
 };
 
 static bool tb_lookup_cmp(const void *p, const void *d)
@@ -187,7 +186,6 @@ static bool tb_lookup_cmp(const void *p, const void *d)
         tb_page_addr0(tb) == desc->page_addr0 &&
         tb->cs_base == desc->cs_base &&
         tb->flags == desc->flags &&
-        tb->trace_vcpu_dstate == desc->trace_vcpu_dstate &&
         tb_cflags(tb) == desc->cflags) {
         /* check next page if needed */
         tb_page_addr_t tb_phys_page1 = tb_page_addr1(tb);
@@ -228,7 +226,6 @@ static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
     desc.cs_base = cs_base;
     desc.flags = flags;
     desc.cflags = cflags;
-    desc.trace_vcpu_dstate = *cpu->trace_dstate;
     desc.pc = pc;
     phys_pc = get_page_addr_code(desc.env, pc);
     if (phys_pc == -1) {
@@ -236,7 +233,7 @@ static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
     }
     desc.page_addr0 = phys_pc;
     h = tb_hash_func(phys_pc, (cflags & CF_PCREL ? 0 : pc),
-                     flags, cflags, *cpu->trace_dstate);
+                     flags, cflags);
     return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp);
 }
 
@@ -263,7 +260,6 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc,
                    jc->array[hash].pc == pc &&
                    tb->cs_base == cs_base &&
                    tb->flags == flags &&
-                   tb->trace_vcpu_dstate == *cpu->trace_dstate &&
                    tb_cflags(tb) == cflags)) {
             return tb;
         }
@@ -282,7 +278,6 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc,
                    tb->pc == pc &&
                    tb->cs_base == cs_base &&
                    tb->flags == flags &&
-                   tb->trace_vcpu_dstate == *cpu->trace_dstate &&
                    tb_cflags(tb) == cflags)) {
             return tb;
         }
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index cb1f806f00..432a0cffdb 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -50,7 +50,6 @@ static bool tb_cmp(const void *ap, const void *bp)
             a->cs_base == b->cs_base &&
             a->flags == b->flags &&
             (tb_cflags(a) & ~CF_INVALID) == (tb_cflags(b) & ~CF_INVALID) &&
-            a->trace_vcpu_dstate == b->trace_vcpu_dstate &&
             tb_page_addr0(a) == tb_page_addr0(b) &&
             tb_page_addr1(a) == tb_page_addr1(b));
 }
@@ -888,7 +887,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
     /* remove the TB from the hash list */
     phys_pc = tb_page_addr0(tb);
     h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc),
-                     tb->flags, orig_cflags, tb->trace_vcpu_dstate);
+                     tb->flags, orig_cflags);
     if (!qht_remove(&tb_ctx.htable, tb, h)) {
         return;
     }
@@ -969,7 +968,7 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
 
     /* add in the hash table */
     h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb->pc),
-                     tb->flags, tb->cflags, tb->trace_vcpu_dstate);
+                     tb->flags, tb->cflags);
     qht_insert(&tb_ctx.htable, tb, h, &existing_tb);
 
     /* remove TB from the page(s) if we couldn't insert it */
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 5b13281119..2ea42970e1 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -65,11 +65,6 @@
 #include "internal.h"
 #include "perf.h"
 
-/* Make sure all possible CPU event bits fit in tb->trace_vcpu_dstate */
-QEMU_BUILD_BUG_ON(CPU_TRACE_DSTATE_MAX_EVENTS >
-                  sizeof_field(TranslationBlock, trace_vcpu_dstate)
-                  * BITS_PER_BYTE);
-
 TBContext tb_ctx;
 
 /* Encode VAL as a signed leb128 sequence at P.
@@ -348,7 +343,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     tb->cs_base = cs_base;
     tb->flags = flags;
     tb->cflags = cflags;
-    tb->trace_vcpu_dstate = *cpu->trace_dstate;
     tb_set_page_addr0(tb, phys_pc);
     tb_set_page_addr1(tb, -1);
     tcg_ctx->gen_tb = tb;
-- 
2.39.2



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

* [PATCH v3 09/10] hw/9pfs: use qemu_xxhash4
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (7 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 08/10] tcg: remove the final vestiges of dstate Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 15:53 ` [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations Alex Bennée
  9 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

No need to pass zeros as we have helpers that do that for us.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230503091756.1453057-10-alex.bennee@linaro.org>

---
v3
  - remove stale comment
---
 hw/9pfs/9p.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9621ec1341..991645adca 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -738,15 +738,14 @@ static VariLenAffix affixForIndex(uint64_t index)
     return invertAffix(&prefix); /* convert prefix to suffix */
 }
 
-/* creative abuse of tb_hash_func7, which is based on xxhash */
 static uint32_t qpp_hash(QppEntry e)
 {
-    return qemu_xxhash7(e.ino_prefix, e.dev, 0, 0, 0);
+    return qemu_xxhash4(e.ino_prefix, e.dev);
 }
 
 static uint32_t qpf_hash(QpfEntry e)
 {
-    return qemu_xxhash7(e.ino, e.dev, 0, 0, 0);
+    return qemu_xxhash4(e.ino, e.dev);
 }
 
 static bool qpd_cmp_func(const void *obj, const void *userp)
-- 
2.39.2



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

* [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations
  2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
                   ` (8 preceding siblings ...)
  2023-05-05 15:53 ` [PATCH v3 09/10] hw/9pfs: use qemu_xxhash4 Alex Bennée
@ 2023-05-05 15:53 ` Alex Bennée
  2023-05-05 18:27   ` Richard Henderson
  9 siblings, 1 reply; 17+ messages in thread
From: Alex Bennée @ 2023-05-05 15:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Markus Armbruster,
	Riku Voipio, Alex Bennée

We weren't using cs_base in the hash calculations before. Since the
arm front end moved a chunk of flags in a378206a20 (target/arm: Move
mode specific TB flags to tb->cs_base) they comprise of an important
part of the execution state.

Widen the tb_hash_func to include cs_base and expand to qemu_xxhash8()
to accommodate it.

My initial benchmark run on armhf shows very little difference in the
runtime.

Before:

  Time (mean ± σ):     24.440 s ±  2.885 s    [User: 34.474 s, System: 2.028 s]
  Range (min … max):   21.663 s … 29.937 s    20 runs

After:

  Time (mean ± σ):     24.348 s ±  2.717 s    [User: 34.668 s, System: 1.859 s]
  Range (min … max):   21.830 s … 30.093 s    20 runs

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 accel/tcg/tb-hash.h   |  5 +++--
 include/qemu/xxhash.h | 21 +++++++++++++++------
 accel/tcg/cpu-exec.c  |  2 +-
 accel/tcg/tb-maint.c  |  4 ++--
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/accel/tcg/tb-hash.h b/accel/tcg/tb-hash.h
index 1d19c69caa..8cbafb5494 100644
--- a/accel/tcg/tb-hash.h
+++ b/accel/tcg/tb-hash.h
@@ -62,9 +62,10 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
 
 static inline
 uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc,
-                      uint32_t flags, uint32_t cf_mask)
+                      uint32_t flags, uint64_t flags2, uint32_t cf_mask)
 {
-    return qemu_xxhash6(phys_pc, pc, flags, cf_mask);
+    return qemu_xxhash8(phys_pc, pc, flags,
+                        flags2 & 0xffff, flags2 >> 32, cf_mask);
 }
 
 #endif
diff --git a/include/qemu/xxhash.h b/include/qemu/xxhash.h
index c2dcccadbf..cd7054f07e 100644
--- a/include/qemu/xxhash.h
+++ b/include/qemu/xxhash.h
@@ -48,8 +48,8 @@
  * xxhash32, customized for input variables that are not guaranteed to be
  * contiguous in memory.
  */
-static inline uint32_t
-qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g)
+static inline uint32_t qemu_xxhash8(uint64_t ab, uint64_t cd, uint32_t e,
+                                    uint32_t f, uint32_t g, uint32_t h)
 {
     uint32_t v1 = QEMU_XXHASH_SEED + PRIME32_1 + PRIME32_2;
     uint32_t v2 = QEMU_XXHASH_SEED + PRIME32_2;
@@ -89,6 +89,9 @@ qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g)
     h32 += g * PRIME32_3;
     h32  = rol32(h32, 17) * PRIME32_4;
 
+    h32 += h * PRIME32_3;
+    h32  = rol32(h32, 17) * PRIME32_4;
+
     h32 ^= h32 >> 15;
     h32 *= PRIME32_2;
     h32 ^= h32 >> 13;
@@ -100,23 +103,29 @@ qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g)
 
 static inline uint32_t qemu_xxhash2(uint64_t ab)
 {
-    return qemu_xxhash7(ab, 0, 0, 0, 0);
+    return qemu_xxhash8(ab, 0, 0, 0, 0, 0);
 }
 
 static inline uint32_t qemu_xxhash4(uint64_t ab, uint64_t cd)
 {
-    return qemu_xxhash7(ab, cd, 0, 0, 0);
+    return qemu_xxhash8(ab, cd, 0, 0, 0, 0);
 }
 
 static inline uint32_t qemu_xxhash5(uint64_t ab, uint64_t cd, uint32_t e)
 {
-    return qemu_xxhash7(ab, cd, e, 0, 0);
+    return qemu_xxhash8(ab, cd, e, 0, 0, 0);
 }
 
 static inline uint32_t qemu_xxhash6(uint64_t ab, uint64_t cd, uint32_t e,
                                     uint32_t f)
 {
-    return qemu_xxhash7(ab, cd, e, f, 0);
+    return qemu_xxhash8(ab, cd, e, f, 0, 0);
+}
+
+static inline uint32_t qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e,
+                                    uint32_t f, uint32_t g)
+{
+    return qemu_xxhash8(ab, cd, e, f, g, 0);
 }
 
 /*
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 973da2a434..8d67198e56 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -233,7 +233,7 @@ static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
     }
     desc.page_addr0 = phys_pc;
     h = tb_hash_func(phys_pc, (cflags & CF_PCREL ? 0 : pc),
-                     flags, cflags);
+                     flags, cs_base, cflags);
     return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp);
 }
 
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 432a0cffdb..52d17815e4 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -887,7 +887,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
     /* remove the TB from the hash list */
     phys_pc = tb_page_addr0(tb);
     h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc),
-                     tb->flags, orig_cflags);
+                     tb->flags, tb->cs_base, orig_cflags);
     if (!qht_remove(&tb_ctx.htable, tb, h)) {
         return;
     }
@@ -968,7 +968,7 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
 
     /* add in the hash table */
     h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb->pc),
-                     tb->flags, tb->cflags);
+                     tb->flags, tb->cs_base, tb->cflags);
     qht_insert(&tb_ctx.htable, tb, h, &existing_tb);
 
     /* remove TB from the page(s) if we couldn't insert it */
-- 
2.39.2



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

* Re: [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations
  2023-05-05 15:53 ` [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations Alex Bennée
@ 2023-05-05 18:27   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-05-05 18:27 UTC (permalink / raw)
  To: Alex Bennée, Stefan Hajnoczi, qemu-devel

On 5/5/23 16:53, Alex Bennée wrote:
> +                      uint32_t flags, uint64_t flags2, uint32_t cf_mask)
>   {
> -    return qemu_xxhash6(phys_pc, pc, flags, cf_mask);
> +    return qemu_xxhash8(phys_pc, pc, flags,
> +                        flags2 & 0xffff, flags2 >> 32, cf_mask);

Well not that mask, obviously.  Either pass it whole, like pc, or just let the compiler 
truncate for you without the mask.


r~


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

* Re: [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1
  2023-05-05 15:53 ` [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1 Alex Bennée
@ 2023-05-06  7:20   ` Markus Armbruster
  0 siblings, 0 replies; 17+ messages in thread
From: Markus Armbruster @ 2023-05-06  7:20 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Stefan Hajnoczi, qemu-devel, Marcel Apfelbaum,
	Christian Schoenebeck, Michael Roth, Eric Blake, Paolo Bonzini,
	Greg Kurz, Eduardo Habkost, Yanan Wang,
	Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Riku Voipio

Alex Bennée <alex.bennee@linaro.org> writes:

> I don't think I can remove the parameters directly but certainly mark
> them as deprecated.
>
> Message-Id: <20230420150009.1675181-6-alex.bennee@linaro.org>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20230503091756.1453057-6-alex.bennee@linaro.org>
> ---
>  qapi/trace.json | 22 +++++++---------------
>  1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/qapi/trace.json b/qapi/trace.json
> index f425d10764..de6b1681aa 100644
> --- a/qapi/trace.json
> +++ b/qapi/trace.json
> @@ -33,9 +33,9 @@
>  #
>  # @name: Event name.
>  # @state: Tracing state.
> -# @vcpu: Whether this is a per-vCPU event (since 2.7).
> +# @vcpu: Whether this is a per-vCPU event (deprecated since 8.1).

We don't normally replace the (since ...) when we deprecate.

>  #
> -# An event is per-vCPU if it has the "vcpu" property in the "trace-events"
> +# There are no longer any events with the "vcpu" property in the "trace-events"

Why would a user still need to know what @vcpu used to mean?  Also, long
line.  See below for a possible alternative.

>  # files.
>  #
>  # Since: 2.2

You need to make it official, like so:

   { 'struct': 'TraceEventInfo',
  -  'data': {'name': 'str', 'state': 'TraceEventState', 'vcpu': 'bool'} }
  +  'data': {'name': 'str', 'state': 'TraceEventState',
  +           'vcpu': { 'type': 'bool', 'features': ['deprecated'] } } }

And then the generator will demand you document it formally, so you also
need something like

 # @state: Tracing state.
 # @vcpu: Whether this is a per-vCPU event (since 2.7).
 #
-# An event is per-vCPU if it has the "vcpu" property in the "trace-events"
-# files.
+# Features:
+# @deprecated: Member @vcpu is deprecated, and always false.
 #
 # Since: 2.2
 ##

Additionally, update docs/about/deprecated.rst.

> @@ -49,19 +49,15 @@
>  # Query the state of events.
>  #
>  # @name: Event name pattern (case-sensitive glob).
> -# @vcpu: The vCPU to query (any by default; since 2.7).
> +# @vcpu: The vCPU to query (deprecated since 8.1).

Again, we don't normally replace the (since ...) when we deprecate.

I suggest to just drop the "any by default" part.

>  #
>  # Returns: a list of @TraceEventInfo for the matching events
>  #
>  #          An event is returned if:
>  #
>  #          - its name matches the @name pattern, and
> -#          - if @vcpu is given, the event has the "vcpu" property.
>  #
> -#          Therefore, if @vcpu is given, the operation will only match per-vCPU events,
> -#          returning their state on the specified vCPU. Special case: if @name is an
> -#          exact match, @vcpu is given and the event does not have the "vcpu" property,
> -#          an error is returned.
> +#          There are no longer any per-vCPU events
>  #
>  # Since: 2.2
>  #

Please add 'features': ['deprecated'].

> @@ -84,17 +80,13 @@
>  # @name: Event name pattern (case-sensitive glob).
>  # @enable: Whether to enable tracing.
>  # @ignore-unavailable: Do not match unavailable events with @name.
> -# @vcpu: The vCPU to act upon (all by default; since 2.7).
> +# @vcpu: The vCPU to act upon (deprecated since 8.1).

Suggest to just drop the "all by default" part.

>  #
>  # An event's state is modified if:
>  #
> -# - its name matches the @name pattern, and
> -# - if @vcpu is given, the event has the "vcpu" property.
> +# - its name matches the @name pattern
>  #
> -# Therefore, if @vcpu is given, the operation will only match per-vCPU events,
> -# setting their state on the specified vCPU. Special case: if @name is an exact
> -# match, @vcpu is given and the event does not have the "vcpu" property, an
> -# error is returned.
> +# There are no longer and per-vCPU events so specifying it will never match.
>  #
>  # Since: 2.2
>  #

Please add 'features': ['deprecated'].



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

* Re: [PATCH v3 04/10] scripts/qapi: document the tool that generated the file
  2023-05-05 15:53 ` [PATCH v3 04/10] scripts/qapi: document the tool that generated the file Alex Bennée
@ 2023-05-06  7:34   ` Markus Armbruster
  0 siblings, 0 replies; 17+ messages in thread
From: Markus Armbruster @ 2023-05-06  7:34 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Stefan Hajnoczi, qemu-devel, Marcel Apfelbaum,
	Christian Schoenebeck, Michael Roth, Eric Blake, Paolo Bonzini,
	Greg Kurz, Eduardo Habkost, Yanan Wang,
	Philippe Mathieu-Daudé,
	Kyle Evans, Warner Losh, Richard Henderson, Riku Voipio

Alex Bennée <alex.bennee@linaro.org> writes:

> This makes it a little easier for developers to find where things
> where being generated.
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20230503091756.1453057-5-alex.bennee@linaro.org>
> ---
>  scripts/qapi/gen.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
> index 8f8f784f4a..e724507e1a 100644
> --- a/scripts/qapi/gen.py
> +++ b/scripts/qapi/gen.py
> @@ -162,7 +162,7 @@ def __init__(self, fname: str, blurb: str, pydoc: str):
>  
>      def _top(self) -> str:
>          return mcgen('''
> -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
> +/* AUTOMATICALLY GENERATED by QAPIGenC, DO NOT MODIFY */
>  
>  /*
>  %(blurb)s
> @@ -195,7 +195,7 @@ def _bottom(self) -> str:
>  
>  class QAPIGenTrace(QAPIGen):
>      def _top(self) -> str:
> -        return super()._top() + '# AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n'
> +        return super()._top() + '# AUTOMATICALLY GENERATED by QAPIGenTrace, DO NOT MODIFY\n\n'
>  
>  
>  @contextmanager

Nitpicking...  would "GENERATED BY {os.path.basename(sys.argv[0])}" be
more useful?  The people who know what QAPIGenC and QAPIGenTrace mean
are probably the ones that need this warning the least :)



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

* Re: [PATCH v3 06/10] trace: remove code that depends on setting vcpu
  2023-05-05 15:53 ` [PATCH v3 06/10] trace: remove code that depends on setting vcpu Alex Bennée
@ 2023-05-10  7:46   ` Philippe Mathieu-Daudé
  2023-05-23 12:11     ` Alex Bennée
  0 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-10  7:46 UTC (permalink / raw)
  To: Alex Bennée, Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Kyle Evans, Warner Losh, Richard Henderson,
	Markus Armbruster, Riku Voipio

On 5/5/23 17:53, Alex Bennée wrote:
> Now we no longer have any events that are for vcpus we can start
> excising the code from the trace control. As the vcpu parameter is
> encoded as part of QMP we just stub out the has_vcpu/vcpu parameters
> rather than alter the API.
> 
> Message-Id: <20230420150009.1675181-7-alex.bennee@linaro.org>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20230503091756.1453057-7-alex.bennee@linaro.org>
> ---
>   trace/control-internal.h |  10 ----
>   trace/control-vcpu.h     |  16 ------
>   trace/control.h          |  48 -----------------
>   hw/core/cpu-common.c     |   2 -
>   stubs/trace-control.c    |  13 -----
>   trace/control-target.c   | 110 ++++-----------------------------------
>   trace/control.c          |  16 ------
>   trace/qmp.c              |  74 +++-----------------------
>   trace/trace-hmp-cmds.c   |  17 +-----
>   9 files changed, 19 insertions(+), 287 deletions(-)


> diff --git a/trace/trace-hmp-cmds.c b/trace/trace-hmp-cmds.c
> index 792876c34a..1d07672cb2 100644
> --- a/trace/trace-hmp-cmds.c
> +++ b/trace/trace-hmp-cmds.c
> @@ -37,16 +37,9 @@ void hmp_trace_event(Monitor *mon, const QDict *qdict)
>   {
>       const char *tp_name = qdict_get_str(qdict, "name");
>       bool new_state = qdict_get_bool(qdict, "option");
> -    bool has_vcpu = qdict_haskey(qdict, "vcpu");
> -    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
>       Error *local_err = NULL;
>   
> -    if (vcpu < 0) {
> -        monitor_printf(mon, "argument vcpu must be positive");
> -        return;
> -    }
> -
> -    qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
> +    qmp_trace_event_set_state(tp_name, new_state, true, true, false, 0, &local_err);
>       if (local_err) {
>           error_report_err(local_err);
>       }
> @@ -80,8 +73,6 @@ void hmp_trace_file(Monitor *mon, const QDict *qdict)
>   void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>   {
>       const char *name = qdict_get_try_str(qdict, "name");
> -    bool has_vcpu = qdict_haskey(qdict, "vcpu");
> -    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
>       TraceEventInfoList *events;
>       TraceEventInfoList *elem;
>       Error *local_err = NULL;
> @@ -89,12 +80,8 @@ void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>       if (name == NULL) {
>           name = "*";
>       }
> -    if (vcpu < 0) {
> -        monitor_printf(mon, "argument vcpu must be positive");
> -        return;
> -    }
>   
> -    events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
> +    events = qmp_trace_event_get_state(name, false, 0, &local_err);
>       if (local_err) {
>           error_report_err(local_err);
>           return;

We can simplify further by removing 'bool has_vcpu, int64_t vcpu' from
qmp_trace_event_set_state/qmp_trace_event_get_state, which are now
always false/0.


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

* Re: [PATCH v3 08/10] tcg: remove the final vestiges of dstate
  2023-05-05 15:53 ` [PATCH v3 08/10] tcg: remove the final vestiges of dstate Alex Bennée
@ 2023-05-10  7:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-10  7:48 UTC (permalink / raw)
  To: Alex Bennée, Stefan Hajnoczi, qemu-devel
  Cc: Marcel Apfelbaum, Christian Schoenebeck, Michael Roth,
	Eric Blake, Paolo Bonzini, Greg Kurz, Eduardo Habkost,
	Yanan Wang, Kyle Evans, Warner Losh, Richard Henderson,
	Markus Armbruster, Riku Voipio

On 5/5/23 17:53, Alex Bennée wrote:
> Now we no longer have dynamic state affecting things we can remove the
> additional fields in cpu.h and simplify the TB hash calculation.
> 
> For the benchmark:
> 
>      hyperfine -w 2 -m 20 \
>        "./arm-softmmu/qemu-system-arm -cpu cortex-a15 \
>          -machine type=virt,highmem=off \
>          -display none -m 2048 \
>          -serial mon:stdio \
>          -netdev user,id=unet,hostfwd=tcp::2222-:22 \
>          -device virtio-net-pci,netdev=unet \
>          -device virtio-scsi-pci \
>          -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-bullseye-armhf \
>          -device scsi-hd,drive=hd -smp 4 \
>          -kernel /home/alex/lsrc/linux.git/builds/arm/arch/arm/boot/zImage \
>          -append 'console=ttyAMA0 root=/dev/sda2 systemd.unit=benchmark.service' \
>          -snapshot"
> 
> It has a marginal effect on runtime, before:
> 
>    Time (mean ± σ):     26.279 s ±  2.438 s    [User: 41.113 s, System: 1.843 s]
>    Range (min … max):   24.420 s … 32.565 s    20 runs
> 
> after:
> 
>    Time (mean ± σ):     24.440 s ±  2.885 s    [User: 34.474 s, System: 2.028 s]
>    Range (min … max):   21.663 s … 29.937 s    20 runs
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1358
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20230503091756.1453057-9-alex.bennee@linaro.org>
> ---
>   accel/tcg/tb-hash.h       | 6 +++---
>   include/exec/exec-all.h   | 3 ---
>   include/hw/core/cpu.h     | 5 -----
>   accel/tcg/cpu-exec.c      | 7 +------
>   accel/tcg/tb-maint.c      | 5 ++---
>   accel/tcg/translate-all.c | 6 ------
>   6 files changed, 6 insertions(+), 26 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH v3 06/10] trace: remove code that depends on setting vcpu
  2023-05-10  7:46   ` Philippe Mathieu-Daudé
@ 2023-05-23 12:11     ` Alex Bennée
  0 siblings, 0 replies; 17+ messages in thread
From: Alex Bennée @ 2023-05-23 12:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Stefan Hajnoczi, qemu-devel, Marcel Apfelbaum,
	Christian Schoenebeck, Michael Roth, Eric Blake, Paolo Bonzini,
	Greg Kurz, Eduardo Habkost, Yanan Wang, Kyle Evans, Warner Losh,
	Richard Henderson, Markus Armbruster, Riku Voipio


Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 5/5/23 17:53, Alex Bennée wrote:
<snip>
>> --- a/trace/trace-hmp-cmds.c
>> +++ b/trace/trace-hmp-cmds.c
>> @@ -37,16 +37,9 @@ void hmp_trace_event(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *tp_name = qdict_get_str(qdict, "name");
>>       bool new_state = qdict_get_bool(qdict, "option");
>> -    bool has_vcpu = qdict_haskey(qdict, "vcpu");
>> -    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
>>       Error *local_err = NULL;
>>   -    if (vcpu < 0) {
>> -        monitor_printf(mon, "argument vcpu must be positive");
>> -        return;
>> -    }
>> -
>> -    qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
>> +    qmp_trace_event_set_state(tp_name, new_state, true, true, false, 0, &local_err);
>>       if (local_err) {
>>           error_report_err(local_err);
>>       }
>> @@ -80,8 +73,6 @@ void hmp_trace_file(Monitor *mon, const QDict *qdict)
>>   void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *name = qdict_get_try_str(qdict, "name");
>> -    bool has_vcpu = qdict_haskey(qdict, "vcpu");
>> -    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
>>       TraceEventInfoList *events;
>>       TraceEventInfoList *elem;
>>       Error *local_err = NULL;
>> @@ -89,12 +80,8 @@ void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>>       if (name == NULL) {
>>           name = "*";
>>       }
>> -    if (vcpu < 0) {
>> -        monitor_printf(mon, "argument vcpu must be positive");
>> -        return;
>> -    }
>>   -    events = qmp_trace_event_get_state(name, has_vcpu, vcpu,
>> &local_err);
>> +    events = qmp_trace_event_get_state(name, false, 0, &local_err);
>>       if (local_err) {
>>           error_report_err(local_err);
>>           return;
>
> We can simplify further by removing 'bool has_vcpu, int64_t vcpu' from
> qmp_trace_event_set_state/qmp_trace_event_get_state, which are now
> always false/0.

Isn't qmp_trace_event_get_state generated by the headers?

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


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

end of thread, other threads:[~2023-05-23 12:13 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 15:53 [PATCH v3 00/10] tracing: remove dynamic vcpu state Alex Bennée
2023-05-05 15:53 ` [PATCH v3 01/10] *-user: remove the guest_user_syscall tracepoints Alex Bennée
2023-05-05 15:53 ` [PATCH v3 02/10] trace-events: remove the remaining vcpu trace events Alex Bennée
2023-05-05 15:53 ` [PATCH v3 03/10] trace: remove vcpu_id from the TraceEvent structure Alex Bennée
2023-05-05 15:53 ` [PATCH v3 04/10] scripts/qapi: document the tool that generated the file Alex Bennée
2023-05-06  7:34   ` Markus Armbruster
2023-05-05 15:53 ` [PATCH v3 05/10] qapi: make the vcpu parameters deprecated for 8.1 Alex Bennée
2023-05-06  7:20   ` Markus Armbruster
2023-05-05 15:53 ` [PATCH v3 06/10] trace: remove code that depends on setting vcpu Alex Bennée
2023-05-10  7:46   ` Philippe Mathieu-Daudé
2023-05-23 12:11     ` Alex Bennée
2023-05-05 15:53 ` [PATCH v3 07/10] trace: remove control-vcpu.h Alex Bennée
2023-05-05 15:53 ` [PATCH v3 08/10] tcg: remove the final vestiges of dstate Alex Bennée
2023-05-10  7:48   ` Philippe Mathieu-Daudé
2023-05-05 15:53 ` [PATCH v3 09/10] hw/9pfs: use qemu_xxhash4 Alex Bennée
2023-05-05 15:53 ` [PATCH v3 10/10] accel/tcg: include cs_base in our hash calculations Alex Bennée
2023-05-05 18:27   ` Richard Henderson

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.