All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org,  armbru@redhat.com,  berrange@redhat.com,
	dgilbert@redhat.com,  Mark Kanda <mark.kanda@oracle.com>
Subject: Re: [PATCH v3 3/8] qmp: add filtering of statistics by target vCPU
Date: Mon, 16 May 2022 14:04:11 +0200	[thread overview]
Message-ID: <87lev1y98k.fsf@pond.sub.org> (raw)
In-Reply-To: <20220516090234.1195907-2-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 16 May 2022 11:02:29 +0200")

Paolo Bonzini <pbonzini@redhat.com> writes:

> Introduce a simple filtering of statistics, that allows to retrieve
> statistics for a subset of the guest vCPUs.  This will be used for
> example by the HMP monitor, in order to retrieve the statistics
> for the currently selected CPU.
>
> Example:
> { "execute": "query-stats",
>   "arguments": {
>     "target": "vcpu",
>     "vcpus": [ "/machine/unattached/device[2]",
>                "/machine/unattached/device[4]" ] } }
>
> Extracted from a patch by Mark Kanda.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  accel/kvm/kvm-all.c     |  9 +++++++--
>  include/monitor/stats.h |  9 ++++++++-
>  monitor/qmp-cmds.c      | 34 +++++++++++++++++++++++++++++++++-
>  qapi/stats.json         | 20 +++++++++++++++++---
>  4 files changed, 65 insertions(+), 7 deletions(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 6a6bbe2994..28f8a45205 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2311,7 +2311,8 @@ bool kvm_dirty_ring_enabled(void)
>      return kvm_state->kvm_dirty_ring_size ? true : false;
>  }
>  
> -static void query_stats_cb(StatsResultList **result, StatsTarget target, Error **errp);
> +static void query_stats_cb(StatsResultList **result, StatsTarget target,
> +                           strList *targets, Error **errp);
>  static void query_stats_schemas_cb(StatsSchemaList **result, Error **errp);
>  
>  static int kvm_init(MachineState *ms)
> @@ -4049,7 +4050,8 @@ static void query_stats_schema_vcpu(CPUState *cpu, run_on_cpu_data data)
>      close(stats_fd);
>  }
>  
> -static void query_stats_cb(StatsResultList **result, StatsTarget target, Error **errp)
> +static void query_stats_cb(StatsResultList **result, StatsTarget target,
> +                           strList *targets, Error **errp)
>  {
>      KVMState *s = kvm_state;
>      CPUState *cpu;
> @@ -4073,6 +4075,9 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target, Error *
>          stats_args.result.stats = result;
>          stats_args.errp = errp;
>          CPU_FOREACH(cpu) {
> +            if (!str_in_list(cpu->parent_obj.canonical_path, targets)) {
> +                continue;
> +            }
>              run_on_cpu(cpu, query_stats_vcpu, RUN_ON_CPU_HOST_PTR(&stats_args));
>          }
>          break;
> diff --git a/include/monitor/stats.h b/include/monitor/stats.h
> index 89552ab06f..92a1df3072 100644
> --- a/include/monitor/stats.h
> +++ b/include/monitor/stats.h
> @@ -10,7 +10,8 @@
>  
>  #include "qapi/qapi-types-stats.h"
>  
> -typedef void StatRetrieveFunc(StatsResultList **result, StatsTarget target, Error **errp);
> +typedef void StatRetrieveFunc(StatsResultList **result, StatsTarget target,
> +                              strList *targets, Error **errp);
>  typedef void SchemaRetrieveFunc(StatsSchemaList **result, Error **errp);
>  
>  /*
> @@ -30,4 +31,10 @@ void add_stats_entry(StatsResultList **, StatsProvider, const char *id,
>  void add_stats_schema(StatsSchemaList **, StatsProvider, StatsTarget,
>                        StatsSchemaValueList *);
>  
> +/*
> + * True if a string matches the filter passed to the stats_fn callabck,
> + * false otherwise.
> + */
> +bool str_in_list(const char *string, strList *list);
> +
>  #endif /* STATS_H */
> diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
> index d83faeca88..1ec7409bc2 100644
> --- a/monitor/qmp-cmds.c
> +++ b/monitor/qmp-cmds.c
> @@ -463,13 +463,30 @@ void add_stats_callbacks(StatRetrieveFunc *stats_fn,
>      QTAILQ_INSERT_TAIL(&stats_callbacks, entry, next);
>  }
>  
> +static strList *stats_target_filter(StatsFilter *filter)
> +{
> +    switch (filter->target) {
> +    case STATS_TARGET_VM:
> +        return NULL;
> +    case STATS_TARGET_VCPU:
> +        if (!filter->u.vcpu.has_vcpus) {
> +            return NULL;
> +        }
> +        return filter->u.vcpu.vcpus;
> +        break;
> +    default:
> +        abort();
> +    }
> +}
> +
>  StatsResultList *qmp_query_stats(StatsFilter *filter, Error **errp)
>  {
>      StatsResultList *stats_results = NULL;
> +    strList *targets = stats_target_filter(filter);
>      StatsCallbacks *entry;
>  
>      QTAILQ_FOREACH(entry, &stats_callbacks, next) {
> -        entry->stats_cb(&stats_results, filter->target, errp);
> +        entry->stats_cb(&stats_results, filter->target, targets, errp);
>      }
>  
>      return stats_results;
> @@ -512,3 +529,18 @@ void add_stats_schema(StatsSchemaList **schema_results,
>      entry->stats = stats_list;
>      QAPI_LIST_PREPEND(*schema_results, entry);
>  }
> +
> +bool str_in_list(const char *string, strList *list)
> +{
> +    strList *str_list = NULL;
> +
> +    if (!list) {
> +        return true;

Are you sure the empty list is supposed to contain any string?

> +    }
> +    for (str_list = list; str_list; str_list = str_list->next) {
> +        if (g_str_equal(string, str_list->value)) {
> +            return true;
> +        }
> +    }
> +    return false;
> +}
> diff --git a/qapi/stats.json b/qapi/stats.json
> index 382223e197..859fc0f459 100644
> --- a/qapi/stats.json
> +++ b/qapi/stats.json
> @@ -68,16 +68,30 @@
>  { 'enum': 'StatsTarget',
>    'data': [ 'vm', 'vcpu' ] }
>  
> +##
> +# @StatsVCPUFilter:
> +#
> +# @vcpus: list of QOM paths for the desired vCPU objects.
> +#
> +# Since: 7.1
> +##
> +{ 'struct': 'StatsVCPUFilter',
> +  'data': { '*vcpus': [ 'str' ] } }
> +
>  ##
>  # @StatsFilter:
>  #
>  # The arguments to the query-stats command; specifies a target for which to
> -# request statistics.
> +# request statistics and optionally the required subset of information for
> +# that target:
> +# - which vCPUs to request statistics for
>  #
>  # Since: 7.1
>  ##
> -{ 'struct': 'StatsFilter',
> -  'data': { 'target': 'StatsTarget' } }
> +{ 'union': 'StatsFilter',
> +        'base': { 'target': 'StatsTarget' },
> +  'discriminator': 'target',
> +  'data': { 'vcpu': 'StatsVCPUFilter' } }
>  
>  ##
>  # @StatsValue:



  reply	other threads:[~2022-05-16 12:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16  9:00 [PATCH v3 0/8] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-05-16  9:00 ` [PATCH v3 1/8] qmp: Support for querying stats Paolo Bonzini
2022-05-16 12:00   ` Markus Armbruster
2022-05-16 14:48     ` Paolo Bonzini
2022-05-16  9:00 ` [PATCH v3 2/8] kvm: Support for querying fd-based stats Paolo Bonzini
2022-05-24 18:44   ` Dr. David Alan Gilbert
2022-05-16  9:02 ` Paolo Bonzini
2022-05-16  9:02 ` [PATCH v3 3/8] qmp: add filtering of statistics by target vCPU Paolo Bonzini
2022-05-16 12:04   ` Markus Armbruster [this message]
2022-05-16 14:31     ` Paolo Bonzini
2022-05-16  9:02 ` [PATCH v3 4/8] hmp: add basic "info stats" implementation Paolo Bonzini
2022-05-24 19:10   ` Dr. David Alan Gilbert
2022-05-16  9:02 ` [PATCH v3 5/8] qmp: add filtering of statistics by provider Paolo Bonzini
2022-05-16  9:02 ` [PATCH v3 6/8] hmp: " Paolo Bonzini
2022-05-25 10:35   ` Dr. David Alan Gilbert
2022-05-25 14:01     ` Paolo Bonzini
2022-05-16  9:02 ` [PATCH v3 7/8] qmp: add filtering of statistics by name Paolo Bonzini
2022-05-16  9:02 ` [PATCH v3 8/8] hmp: " Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lev1y98k.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=mark.kanda@oracle.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.