Skip to contentSkip to conversation

try fix tracing for modules

RFC PATCH Superseded Gerd Hoffmann 5 participants 21 messages Nov 19, 2020 – Nov 23, 2020 Arm/Amlogic Meson SoC support

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover try fix tracing for modules

Problem only partly solved so far.
Building separate object files for modules works. Actually linking those to the module not yet. See last patch of the series for my not working approach.

More context:
https://bugzilla.redhat.com/show_bug.cgi?id=1898700
https://bugzilla.redhat.com/show_bug.cgi?id=1869642

take care,
Gerd

Gerd Hoffmann (4):
meson: add trace_events_config[]
meson: move up hw subdir (specifically before trace subdir)
meson: move qxl trace events to separate file [broken] meson: try link tracepoints to module

 hw/display/qxl-render.c     |  1 +
 hw/display/qxl.c            |  1 +
 hw/display/meson.build      |  5 +++
 hw/display/trace-events     | 67 -------------------------------------
 hw/display/trace-events-qxl | 66 ++++++++++++++++++++++++++++++++++++
 meson.build                 |  4 ++-
 trace/meson.build           | 30 ++++++++++++-----
 7 files changed, 97 insertions(+), 77 deletions(-)
 create mode 100644 hw/display/trace-events-qxl
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/4 meson: add trace_events_config[]

It's an array of dicts, where each dict holds the configuration for one trace-events file. For now just fill it from trace_events_subdirs.

---
 meson.build       |  1 +
 trace/meson.build | 21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)
meson.build +1 -0
index 132bc4978242..04bd9b57e401 100644
@@ -1365,6 +1365,7 @@ target_softmmu_arch = {}
 
 # TODO: add each directory to the subdirs from its own meson.build, once
 # we have those
+trace_events_config = []
 trace_events_subdirs = [
   'accel/kvm',
   'accel/tcg',
trace/meson.build +16 -5
index d5fc45c628d4..66395d3e2ba7 100644
@@ -1,12 +1,23 @@
 specific_ss.add(files('control-target.c'))
 
 trace_events_files = []
-foreach dir : [ '.' ] + trace_events_subdirs
-  trace_events_file = meson.source_root() / dir / 'trace-events'
+
+trace_events_config += {
+  'file'  : meson.source_root() / 'trace-events',
+  'group' : 'root',
+}
+foreach dir : trace_events_subdirs
+  trace_events_config += {
+    'file'  : meson.source_root() / dir / 'trace-events',
+    'group' : dir.underscorify(),
+  }
+endforeach
+
+foreach c : trace_events_config
+  trace_events_file = c.get('file')
   trace_events_files += [ trace_events_file ]
-  group_name = dir == '.' ? 'root' : dir.underscorify()
-  group = '--group=' + group_name
-  fmt = '@0@-' + group_name + '.@1@'
+  group = '--group=' + c.get('group')
+  fmt = '@0@-' + c.get('group') + '.@1@'
 
   trace_h = custom_target(fmt.format('trace', 'h'),
                           output: fmt.format('trace', 'h'),
Signature · 1 line
2.27.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] meson: add trace_events_config[]

Quoted 8 lines · Gerd Hoffmann

It's an array of dicts, where each dict holds the configuration for one trace-events file. For now just fill it from trace_events_subdirs.

---
 meson.build       |  1 +
 trace/meson.build | 21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)
#3 lore raw

PATCH 2/4 meson: move up hw subdir (specifically before trace subdir)

In reply to Gerd Hoffmann

Needed so trace/meson.build can see
stuff done in hw/*/meson.build.

---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -1
index 04bd9b57e401..41009b9685de 100644
@@ -1456,6 +1456,8 @@ trace_events_subdirs += [
   'util',
 ]
 
+subdir('hw')
+
 subdir('contrib/libvhost-user')
 subdir('qapi')
 subdir('qobject')
@@ -1543,7 +1545,6 @@ subdir('migration')
 subdir('monitor')
 subdir('net')
 subdir('replay')
-subdir('hw')
 subdir('accel')
 subdir('plugins')
 subdir('bsd-user')
Signature · 1 line
2.27.0
#4 lore raw

Re: [PATCH 2/4] meson: move up hw subdir (specifically before trace subdir)

Quoted 22 lines · Gerd Hoffmann

Needed so trace/meson.build can see
stuff done in hw/*/meson.build.

---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -0
index 04bd9b57e401..41009b9685de 100644
@@ -1456,6 +1456,8 @@ trace_events_subdirs += [
   'util',
 ]
 
+subdir('hw')
+
 subdir('contrib/libvhost-user')
 subdir('qapi')
 subdir('qobject')

meson.build subdir('migration') · line 1550

Quoted 7 lines
meson.build +0 -1
@@ -1543,7 +1545,6 @@ subdir('migration')
 subdir('monitor')
 subdir('net')
 subdir('replay')
-subdir('hw')
 subdir('accel')
 subdir('plugins')
 subdir('bsd-user')

This is unmaintainable because someone reading the code won't be aware of the ordering constraint. A comment is needed.

I wonder if anyone has suggestions for meson best practices? Relying on ordering of subdirs is awkward, but so is moving the code into the top-level meson.build file.

Stefan

#5 lore raw

PATCH 3/4 meson: move qxl trace events to separate file

In reply to Gerd Hoffmann

Move qxl trace events to separate trace-events-qxl file.

---
 hw/display/qxl-render.c     |  1 +
 hw/display/qxl.c            |  1 +
 hw/display/meson.build      |  4 +++
 hw/display/trace-events     | 67 -------------------------------------
 hw/display/trace-events-qxl | 66 ++++++++++++++++++++++++++++++++++++
 5 files changed, 72 insertions(+), 67 deletions(-)
 create mode 100644 hw/display/trace-events-qxl
hw/display/qxl-render.c +1 -0
index 3ce2e57b8feb..cc4862e26eb6 100644
@@ -23,6 +23,7 @@
 #include "qxl.h"
 #include "sysemu/runstate.h"
 #include "trace.h"
+#include "trace/trace-hw_display_qxl.h"
 
 static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
 {
hw/display/qxl.c +1 -0
index 431c1070967a..4e8d1bb8d77b 100644
@@ -33,6 +33,7 @@
 #include "migration/blocker.h"
 #include "migration/vmstate.h"
 #include "trace.h"
+#include "trace/trace-hw_display_qxl.h"
 
 #include "qxl.h"
 
hw/display/meson.build +4 -0
index dad3bd2b414b..c2fc36e19d3e 100644
@@ -43,6 +43,10 @@ if config_all_devices.has_key('CONFIG_QXL')
   qxl_ss = ss.source_set()
   qxl_ss.add(when: 'CONFIG_QXL', if_true: [files('qxl.c', 'qxl-logger.c', 'qxl-render.c'),
                                            pixman, spice])
+  trace_events_config += {
+    'file'  : meson.source_root() / 'hw' / 'display' / 'trace-events-qxl',
+    'group' : 'hw_display_qxl',
+  }
   hw_display_modules += {'qxl': qxl_ss}
 endif
 
hw/display/trace-events +0 -67

73 lines not on this page · raw message

hw/display/trace-events-qxl new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.27.0
#6 lore raw

Re: [PATCH 3/4] meson: move qxl trace events to separate file

Quoted 9 lines · Gerd Hoffmann

Move qxl trace events to separate trace-events-qxl file.

---
 hw/display/qxl-render.c     |  1 +
 hw/display/qxl.c            |  1 +
 hw/display/meson.build      |  4 +++
 hw/display/trace-events     | 67 -------------------------------------
 hw/display/trace-events-qxl | 66 ++++++++++++++++++++++++++++++++++++

FWIW, I think we should name the files to match the source prefix, such as 'qxl.trace-events', so that a simple glob hw/display/qxl* will match everything for the MAINTAINERS file assignments.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH 3/4] meson: move qxl trace events to separate file

In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Move qxl trace events to separate trace-events-qxl file.

Can we put modules into their own subdirs so that the existing meson and tracing infrastructure (e.g. scripts/cleanup-trace-events.pl) can handle them without modifications?

#8 lore raw

Re: [PATCH 3/4] meson: move qxl trace events to separate file

Quoted 8 lines · Stefan Hajnoczi
Quoted 3 lines · Gerd Hoffmann

Move qxl trace events to separate trace-events-qxl file.

Can we put modules into their own subdirs so that the existing meson and tracing infrastructure (e.g. scripts/cleanup-trace-events.pl) can handle them without modifications?

Would probably work too.

But before bikeshedding on those details we need a workable overall approach. I have no idea why 4/4 is not working. Possibly the approach I'm trying to take is completely wrong ...

take care,
Gerd

#9 lore raw

PATCH 4/4 meson: try link tracepoints to module

In reply to Gerd Hoffmann

Add source set to trace_events_config, use it in trace/meson.build so the trace objects are linked to the module not core qemu.

Not working as intended.
/me looks puzzled.

---
 hw/display/meson.build | 1 +
 trace/meson.build      | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
hw/display/meson.build +1 -0
index c2fc36e19d3e..94e355ac1e81 100644
@@ -46,6 +46,7 @@ if config_all_devices.has_key('CONFIG_QXL')
   trace_events_config += {
     'file'  : meson.source_root() / 'hw' / 'display' / 'trace-events-qxl',
     'group' : 'hw_display_qxl',
+    'ss'    : qxl_ss,
   }
   hw_display_modules += {'qxl': qxl_ss}
 endif
trace/meson.build +5 -4
index 66395d3e2ba7..3f0fe7b7b74c 100644
@@ -18,6 +18,7 @@ foreach c : trace_events_config
   trace_events_files += [ trace_events_file ]
   group = '--group=' + c.get('group')
   fmt = '@0@-' + c.get('group') + '.@1@'
+  module_ss = c.get('ss', trace_ss)
 
   trace_h = custom_target(fmt.format('trace', 'h'),
                           output: fmt.format('trace', 'h'),
@@ -36,10 +37,10 @@ foreach c : trace_events_config
                                 input: trace_events_file,
                                 command: [ tracetool, group, '--format=ust-events-h', '@INPUT@' ],
                                 capture: true)
-    trace_ss.add(trace_ust_h, lttng, urcubp)
+    module_ss.add(trace_ust_h, lttng, urcubp)
     genh += trace_ust_h
   endif
-  trace_ss.add(trace_h, trace_c)
+  module_ss.add(trace_h, trace_c)
   if 'CONFIG_TRACE_DTRACE' in config_host
     trace_dtrace = custom_target(fmt.format('trace-dtrace', 'dtrace'),
                                  output: fmt.format('trace-dtrace', 'dtrace'),
@@ -50,13 +51,13 @@ foreach c : trace_events_config
                                    output: fmt.format('trace-dtrace', 'h'),
                                    input: trace_dtrace,
                                    command: [ 'dtrace', '-o', '@OUTPUT@', '-h', '-s', '@INPUT@' ])
-    trace_ss.add(trace_dtrace_h)
+    module_ss.add(trace_dtrace_h)
     if host_machine.system() != 'darwin'
       trace_dtrace_o = custom_target(fmt.format('trace-dtrace', 'o'),
                                      output: fmt.format('trace-dtrace', 'o'),
                                      input: trace_dtrace,
                                      command: [ 'dtrace', '-o', '@OUTPUT@', '-G', '-s', '@INPUT@' ])
-      trace_ss.add(trace_dtrace_o)
+      module_ss.add(trace_dtrace_o)
     endif
 
     genh += trace_dtrace_h
Signature · 1 line
2.27.0
#10 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 29 lines · Gerd Hoffmann

Add source set to trace_events_config, use it in trace/meson.build so the trace objects are linked to the module not core qemu.

Not working as intended.
/me looks puzzled.

---
 hw/display/meson.build | 1 +
 trace/meson.build      | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
hw/display/meson.build +1 -0
index c2fc36e19d3e..94e355ac1e81 100644
@@ -46,6 +46,7 @@ if config_all_devices.has_key('CONFIG_QXL')
   trace_events_config += {
     'file'  : meson.source_root() / 'hw' / 'display' / 'trace-events-qxl',
     'group' : 'hw_display_qxl',
+    'ss'    : qxl_ss,
   }
   hw_display_modules += {'qxl': qxl_ss}
 endif
trace/meson.build +0 -0
index 66395d3e2ba7..3f0fe7b7b74c 100644

trace/meson.build foreach c : trace_events_config · line 21

Quoted 4 lines
trace/meson.build +1 -0
@@ -18,6 +18,7 @@ foreach c : trace_events_config
   trace_events_files += [ trace_events_file ]
   group = '--group=' + c.get('group')
   fmt = '@0@-' + c.get('group') + '.@1@'
+  module_ss = c.get('ss', trace_ss)

One idea: module_ss is already used in other files. Are you sure there isn't an identifier naming conflict?

#11 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Hi,

Quoted 4 lines
Quoted 4 lines
trace/meson.build +0 -0
index 66395d3e2ba7..3f0fe7b7b74c 100644
Quoted 8 lines

trace/meson.build foreach c : trace_events_config · line 21

Quoted 5 lines
trace/meson.build +1 -0
@@ -18,6 +18,7 @@ foreach c : trace_events_config
   trace_events_files += [ trace_events_file ]
   group = '--group=' + c.get('group')
   fmt = '@0@-' + c.get('group') + '.@1@'
+  module_ss = c.get('ss', trace_ss)

One idea: module_ss is already used in other files. Are you sure there isn't an identifier naming conflict?

Nope. Tried s/module_ss/kraxel_ss/, still not working.

I get tons of "undefined reference to `_TRACE_something'" errors (*not* qxl). Seems trace_ss is not updated as intended.

take care,
Gerd

#12 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 15 lines · Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 4 lines
trace/meson.build +0 -0
index 66395d3e2ba7..3f0fe7b7b74c 100644
Quoted 8 lines

trace/meson.build foreach c : trace_events_config · line 21

Quoted 5 lines
trace/meson.build +1 -0
@@ -18,6 +18,7 @@ foreach c : trace_events_config
   trace_events_files += [ trace_events_file ]
   group = '--group=' + c.get('group')
   fmt = '@0@-' + c.get('group') + '.@1@'
+  module_ss = c.get('ss', trace_ss)

One idea: module_ss is already used in other files. Are you sure there isn't an identifier naming conflict?

Quoted 4 lines

Nope. Tried s/module_ss/kraxel_ss/, still not working.

I get tons of "undefined reference to `_TRACE_something'" errors (*not* qxl). Seems trace_ss is not updated as intended.

Okay. There is a workaround available:
[PATCH v2] trace: use STAP_SDT_V2 to work around symbol visibility

We can take time to figure out how to extend the build system to handle modules.

Would you like me to try to debug this?

I'm also on #qemu IRC if you want to discuss.

Stefan

#13 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Hi,

Quoted 10 lines
Quoted 4 lines

Nope. Tried s/module_ss/kraxel_ss/, still not working.

I get tons of "undefined reference to `_TRACE_something'" errors (*not* qxl). Seems trace_ss is not updated as intended.

Okay. There is a workaround available:
[PATCH v2] trace: use STAP_SDT_V2 to work around symbol visibility

We can take time to figure out how to extend the build system to handle modules.

IMHO it isn't 5.2 material anyway.

Quoted 1 line

Would you like me to try to debug this?

Guess I'll go dig into the meson documentation, this looks more like a build system than a tracing problem to me.

Nevertheless any ideas/hints are welcome of course.

take care,
Gerd

#14 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Hi,

Quoted 2 lines

Guess I'll go dig into the meson documentation, this looks more like a build system than a tracing problem to me.

Looking at https://mesonbuild.com/Syntax.html ...

"all objects are immutable".

So "var2 = var1" creates a copy not a reference I guess?

Which implies that ...

foo_ss.add(something)

... is different from ...

bar_ss = foo_ss
bar_ss.add(something)

... which in turn explains why the patch doesn't work at all.

Now I'm wondering how I can make trace/meson.build add the trace objects to the module source sets if I can't pass around references to the module source sets?

Paolo? Any hints how to tackle this the meson way?

thanks,
Gerd

#15 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 20 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

Guess I'll go dig into the meson documentation, this looks more like a build system than a tracing problem to me.

Looking at https://mesonbuild.com/Syntax.html ...

"all objects are immutable".

So "var2 = var1" creates a copy not a reference I guess?

Which implies that ...

foo_ss.add(something)

... is different from ...

bar_ss = foo_ss
bar_ss.add(something)

Quoted 7 lines

... which in turn explains why the patch doesn't work at all.

Now I'm wondering how I can make trace/meson.build add the trace objects to the module source sets if I can't pass around references to the module source sets?

Paolo? Any hints how to tackle this the meson way?

Maybe managing it all in the main meson.build, like the e28ab096bf8..da33fc09873 cleanup?
("Move the creation of the library to the main meson.build")

Quoted 5 lines

thanks,
Gerd

#16 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 3 lines · Philippe Mathieu-Daudé

Maybe managing it all in the main meson.build, like the e28ab096bf8..da33fc09873 cleanup?
("Move the creation of the library to the main meson.build")

That was a different issue due to variables being defined in many different meson.build files. But I think in this case the ordering is not an issue, and that's actually because of your patch. :)

Paolo

#17 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

In reply to Philippe Mathieu-Daudé
Quoted 17 lines
Quoted 17 lines

So "var2 = var1" creates a copy not a reference I guess?

Which implies that ...

foo_ss.add(something)

... is different from ...

bar_ss = foo_ss
bar_ss.add(something)

... which in turn explains why the patch doesn't work at all.

Now I'm wondering how I can make trace/meson.build add the trace objects to the module source sets if I can't pass around references to the module source sets?

Quoted 5 lines
Quoted 1 line

Paolo? Any hints how to tackle this the meson way?

Maybe managing it all in the main meson.build, like the e28ab096bf8..da33fc09873 cleanup?
("Move the creation of the library to the main meson.build")

I don't see how that'll help.

The fundamental idea is hw/*/meson.build stores the source set in the new trace_events_config, then trace/meson.build can pick it up there when it loops over the trace_events_config array, adding the generated trace source files to the correct source set.

Whenever that loop is in trace/meson.build or the toplevel meson.build doesn't make much of a difference I think.

I think the problem is meson stores a copy not a reference so the trace_events_config loop doesn't update the original source set. When meson loops over the module source sets it doesn't see the updates because those changes where done on a throw-away copy.

I don't see an easy way out :(

take care,
Gerd

#18 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

In reply to Gerd Hoffmann
Quoted 20 lines · Gerd Hoffmann
   Hi,
Quoted 2 lines

Guess I'll go dig into the meson documentation, this looks more like a build system than a tracing problem to me.

Looking at https://mesonbuild.com/Syntax.html ...

"all objects are immutable".

So "var2 = var1" creates a copy not a reference I guess?

Which implies that ...

foo_ss.add(something)

... is different from ...

bar_ss = foo_ss
bar_ss.add(something)

Quoted 7 lines

... which in turn explains why the patch doesn't work at all.

Now I'm wondering how I can make trace/meson.build add the trace objects to the module source sets if I can't pass around references to the module source sets?

Paolo? Any hints how to tackle this the meson way?

You could build a separate dictionary in trace/meson.build. Instead of using the 'hw_display_qxl' group, you use the module name i.e. 'hw-display-qxl'. trace/meson.build does:

module_trace = {}

and in trace/meson.build

module_trace_src = []
foreach c : ...

    ...
    group = '--group=' + c['name'].underscorify()
    module_trace_src += [trace_h, trace_c]
    ...
    module_trace += { c['name']: module_trace_src }

endforeach

Then when building the shared_module you add the trace files to the sources, like

module_trace_src = module_trace.get(d + '-' + m, [])
sl = static_library(d + '-' + m,
[genh, module_ss.sources(), module_trace_src],
dependencies: ...)

Paolo

#19 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 17 lines

You could build a separate dictionary in trace/meson.build. Instead of using the 'hw_display_qxl' group, you use the module name i.e. 'hw-display-qxl'. trace/meson.build does:

module_trace = {}

and in trace/meson.build

module_trace_src = []
foreach c : ...

    ...
    group = '--group=' + c['name'].underscorify()
    module_trace_src += [trace_h, trace_c]
    ...
    module_trace += { c['name']: module_trace_src }

endforeach

Quoted 7 lines

Then when building the shared_module you add the trace files to the sources, like

   module_trace_src = module_trace.get(d + '-' + m, [])
   sl = static_library(d + '-' + m,
                       [genh, module_ss.sources(), module_trace_src],
                       dependencies: ...)

So basically keep track of the objects separately. Got that working for the modular builds. Progress!!!

Non-modular builds fail due to missing qxl tracepoints. Tried to fix that with a simple 'softmmu_ss.add(module_trace_src)'. Now I get:

../../meson.build:1802:2: ERROR: Object extraction arguments must be strings or Files.

/me looks surprised. Doing trace_ss.add(module_trace_src) in trace/meson.buikd works just fine ...

Branch available at git://git.kraxel.org/qemu sirius/trace-modules

Running "qemu -device qxl" segfaults. Not investigated yet, but I guess this is just modular tracepoint not being properly initialized. Will check later, have to run pick up my daughter now.

take care,
Gerd

#20 lore raw

Re: [PATCH 4/4] [broken] meson: try link tracepoints to module

Quoted 5 lines · Gerd Hoffmann

So basically keep track of the objects separately. Got that working for the modular builds. Progress!!!

Non-modular builds fail due to missing qxl tracepoints. Tried to fix that with a simple 'softmmu_ss.add(module_trace_src)'.

Mentioned in https://wiki.qemu.org/Features/Meson#Pending_Meson_changes as "extract_objects does not support generated file (not needed yet but could be surprising)".

Just use util_ss instead, confirming both points in the parentheses.

Paolo