Hi Pierrick,

May 13, 2025 at 12:45 AM, Pierrick Bouvier wrote:
> On 5/11/25 6:13 AM, Julian Ganz wrote:
> 
> > 
> > We recently introduced new plugin API for registration of discontinuity
> >  related callbacks. This change introduces a minimal plugin showcasing
> >  the new API. It simply counts the occurances of interrupts, exceptions
> >  and host calls per CPU and reports the counts when exitting.
> >  Signed-off-by: Julian Ganz <neither@nut.email>
> >  ---
> >  contrib/plugins/meson.build | 3 +-
> >  contrib/plugins/traps.c | 100 ++++++++++++++++++++++++++++++++++++
> >  docs/about/emulation.rst | 8 +++
> >  3 files changed, 110 insertions(+), 1 deletion(-)
> >  create mode 100644 contrib/plugins/traps.c
> >  +typedef struct {
> >  + uint64_t interrupts;
> >  + uint64_t exceptions;
> >  + uint64_t hostcalls;
> >  + bool active;
> > 
> The scoreboard is automatically resized only when a new vcpu is initialized, 
> so if an entry is present, it means it's present by definition.
> Thus, you can remove the active field.

In plugin_exit we iterate over all VCPUs and retrieve the corresponding
entry via qemu_plugin_scoreboard_find, which will initialize a new
entry if one didn't exist at that point. We used the active field to
distinguish between entries we created and those created while printing
the results.

Using qemu_plugin_num_vcpus instead of storing max_vcpus will
(probably) solve this issue. I'll check to make sure and then remove
this field.

> > +} TrapCounters;
> >  +
> >  +static struct qemu_plugin_scoreboard *traps;
> >  +static size_t max_vcpus;
> >  +
> > 
> You can use qemu_plugin_num_vcpus() instead of keeping a copy of max_vcpus. 
> It returns the number of vcpus started, which guarantees you'll find 
> associated entries in any scoreboard.

Thanks, I must have missed that function.

Regards,
Julian

Reply via email to