All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [PATCH v5 09/10] qmp: add filtering of statistics by name
Date: Wed, 8 Jun 2022 14:36:16 +0100	[thread overview]
Message-ID: <YqCl0D0ZHaFZR9mM@work-vm> (raw)
In-Reply-To: <20220530150714.756954-10-pbonzini@redhat.com>

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> Allow retrieving only a subset of statistics.  This can be useful
> for example in order to plot a subset of the statistics many times
> a second.
> 
> KVM publishes ~40 statistics for each vCPU on x86; retrieving and
> serializing all of them would be useless
> 
> Another use will be in HMP in the following patch; implementing the
> filter in the backend is easy enough that it was deemed okay to make
> this a public interface.
> 
> Example:
> 
> { "execute": "query-stats",
>   "arguments": {
>     "target": "vcpu",
>     "vcpus": [ "/machine/unattached/device[2]",
>                "/machine/unattached/device[4]" ],
>     "providers": [
>       { "provider": "kvm",
>         "names": [ "l1d_flush", "exits" ] } } }
> 
> { "return": {
>     "vcpus": [
>       { "path": "/machine/unattached/device[2]"
>         "providers": [
>           { "provider": "kvm",
>             "stats": [ { "name": "l1d_flush", "value": 41213 },
>                        { "name": "exits", "value": 74291 } ] } ] },
>       { "path": "/machine/unattached/device[4]"
>         "providers": [
>           { "provider": "kvm",
>             "stats": [ { "name": "l1d_flush", "value": 16132 },
>                        { "name": "exits", "value": 57922 } ] } ] } ] } }
> 
> Extracted from a patch by Mark Kanda.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  accel/kvm/kvm-all.c     | 17 +++++++++++------
>  include/monitor/stats.h |  2 +-
>  monitor/qmp-cmds.c      |  7 ++++++-
>  qapi/stats.json         |  6 +++++-
>  4 files changed, 23 insertions(+), 9 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 66c4ac1ac6..f90f0602bc 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2312,7 +2312,7 @@ bool kvm_dirty_ring_enabled(void)
>  }
>  
>  static void query_stats_cb(StatsResultList **result, StatsTarget target,
> -                           strList *targets, Error **errp);
> +                           strList *names, strList *targets, Error **errp);
>  static void query_stats_schemas_cb(StatsSchemaList **result, Error **errp);
>  
>  static int kvm_init(MachineState *ms)
> @@ -3713,6 +3713,7 @@ typedef struct StatsArgs {
>          StatsResultList **stats;
>          StatsSchemaList **schema;
>      } result;
> +    strList *names;
>      Error **errp;
>  } StatsArgs;
>  
> @@ -3921,7 +3922,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
>  }
>  
>  static void query_stats(StatsResultList **result, StatsTarget target,
> -                        int stats_fd, Error **errp)
> +                        strList *names, int stats_fd, Error **errp)
>  {
>      struct kvm_stats_desc *kvm_stats_desc;
>      struct kvm_stats_header *kvm_stats_header;
> @@ -3963,6 +3964,9 @@ static void query_stats(StatsResultList **result, StatsTarget target,
>  
>          /* Add entry to the list */
>          stats = (void *)stats_data + pdesc->offset;
> +        if (!apply_str_list_filter(pdesc->name, names)) {
> +            continue;
> +        }
>          stats_list = add_kvmstat_entry(pdesc, stats, stats_list, errp);
>      }
>  
> @@ -4024,8 +4028,8 @@ static void query_stats_vcpu(CPUState *cpu, run_on_cpu_data data)
>          error_propagate(kvm_stats_args->errp, local_err);
>          return;
>      }
> -    query_stats(kvm_stats_args->result.stats, STATS_TARGET_VCPU, stats_fd,
> -                kvm_stats_args->errp);
> +    query_stats(kvm_stats_args->result.stats, STATS_TARGET_VCPU,
> +                kvm_stats_args->names, stats_fd, kvm_stats_args->errp);
>      close(stats_fd);
>  }
>  
> @@ -4046,7 +4050,7 @@ static void query_stats_schema_vcpu(CPUState *cpu, run_on_cpu_data data)
>  }
>  
>  static void query_stats_cb(StatsResultList **result, StatsTarget target,
> -                           strList *targets, Error **errp)
> +                           strList *names, strList *targets, Error **errp)
>  {
>      KVMState *s = kvm_state;
>      CPUState *cpu;
> @@ -4060,7 +4064,7 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target,
>              error_setg_errno(errp, errno, "KVM errno, stats: ioctl failed");
>              return;
>          }
> -        query_stats(result, target, stats_fd, errp);
> +        query_stats(result, target, names, stats_fd, errp);
>          close(stats_fd);
>          break;
>      }
> @@ -4068,6 +4072,7 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target,
>      {
>          StatsArgs stats_args;
>          stats_args.result.stats = result;
> +        stats_args.names = names;
>          stats_args.errp = errp;
>          CPU_FOREACH(cpu) {
>              if (!apply_str_list_filter(cpu->parent_obj.canonical_path, targets)) {
> diff --git a/include/monitor/stats.h b/include/monitor/stats.h
> index 80a523dd29..fcf0983154 100644
> --- a/include/monitor/stats.h
> +++ b/include/monitor/stats.h
> @@ -11,7 +11,7 @@
>  #include "qapi/qapi-types-stats.h"
>  
>  typedef void StatRetrieveFunc(StatsResultList **result, StatsTarget target,
> -                              strList *targets, Error **errp);
> +                              strList *names, strList *targets, Error **errp);
>  typedef void SchemaRetrieveFunc(StatsSchemaList **result, Error **errp);
>  
>  /*
> diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
> index e49ab345d7..7314cd813d 100644
> --- a/monitor/qmp-cmds.c
> +++ b/monitor/qmp-cmds.c
> @@ -472,12 +472,17 @@ static bool invoke_stats_cb(StatsCallbacks *entry,
>                              Error **errp)
>  {
>      strList *targets = NULL;
> +    strList *names = NULL;
>      ERRP_GUARD();
>  
>      if (request) {
>          if (request->provider != entry->provider) {
>              return true;
>          }
> +        if (request->has_names && !request->names) {
> +            return true;
> +        }
> +        names = request->has_names ? request->names : NULL;
>      }
>  
>      switch (filter->target) {
> @@ -496,7 +501,7 @@ static bool invoke_stats_cb(StatsCallbacks *entry,
>          abort();
>      }
>  
> -    entry->stats_cb(stats_results, filter->target, targets, errp);
> +    entry->stats_cb(stats_results, filter->target, names, targets, errp);
>      if (*errp) {
>          qapi_free_StatsResultList(*stats_results);
>          *stats_results = NULL;
> diff --git a/qapi/stats.json b/qapi/stats.json
> index 503918ea4c..2f8bfe8fdb 100644
> --- a/qapi/stats.json
> +++ b/qapi/stats.json
> @@ -75,11 +75,14 @@
>  # Indicates a set of statistics that should be returned by query-stats.
>  #
>  # @provider: provider for which to return statistics.
> +
> +# @names: statistics to be returned (all if omitted).
>  #
>  # Since: 7.1
>  ##
>  { 'struct': 'StatsRequest',
> -  'data': { 'provider': 'StatsProvider' } }
> +  'data': { 'provider': 'StatsProvider',
> +            '*names': [ 'str' ] } }
>  
>  ##
>  # @StatsVCPUFilter:
> @@ -99,6 +102,7 @@
>  # that target:
>  # - which vCPUs to request statistics for
>  # - which providers to request statistics from
> +# - which named values to return within each provider
>  #
>  # Since: 7.1
>  ##
> -- 
> 2.36.1
> 
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2022-06-08 13:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 15:07 [PATCH v5 00/10] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 01/10] qmp: Support for querying stats Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 02/10] kvm: Support for querying fd-based stats Paolo Bonzini
2022-06-07 17:44   ` Dr. David Alan Gilbert
2022-06-08 14:13     ` Paolo Bonzini
2022-06-08 14:52       ` Dr. David Alan Gilbert
2022-06-08 15:58         ` Paolo Bonzini
2022-06-08 16:01           ` Dr. David Alan Gilbert
2022-06-08 16:10             ` Paolo Bonzini
2022-06-08 16:17               ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 03/10] qmp: add filtering of statistics by target vCPU Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 04/10] cutils: fix case for "kilo" and "kibi" Paolo Bonzini
2022-05-30 21:56   ` Philippe Mathieu-Daudé via
2022-05-30 15:07 ` [PATCH v5 05/10] cutils: add functions for IEC and SI prefixes Paolo Bonzini
2022-05-30 21:59   ` Philippe Mathieu-Daudé via
2022-05-31 10:28     ` Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 06/10] hmp: add basic "info stats" implementation Paolo Bonzini
2022-06-07 18:35   ` Dr. David Alan Gilbert
2022-06-08 14:27     ` Paolo Bonzini
2022-06-08 15:23       ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 07/10] qmp: add filtering of statistics by provider Paolo Bonzini
2022-06-08 11:52   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 08/10] hmp: " Paolo Bonzini
2022-06-08 12:06   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 09/10] qmp: add filtering of statistics by name Paolo Bonzini
2022-06-08 13:36   ` Dr. David Alan Gilbert [this message]
2022-05-30 15:07 ` [PATCH v5 10/10] hmp: " Paolo Bonzini
2022-06-08 13:40   ` Dr. David Alan Gilbert

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=YqCl0D0ZHaFZR9mM@work-vm \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.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.