Support fd-based KVM stats
v4 cover Support fd-based KVM stats
This patchset adds QEMU support for querying fd-based KVM stats. The kernel support was introduced by:
cb082bfab59a ("KVM: stats: Add fd-based API to read binary stats data")
v4:
- revise and cleanup the API [Daniel, Paolo]
- filtering for multiple providers [Daniel]
- cache KVM stat descriptors [Paolo]
- use g_autofree and other cleanup [Daniel]
v3:
- various QMP API enhancements from review [Daniel, Paolo, Igor]
- general cleanup
v2: [Paolo]
- generalize the interface
- add support for querying stat schema and instances
- add additional HMP semantic processing for a few exponent/unit combinations (related to seconds and bytes)
Mark Kanda (3):
qmp: Support for querying stats
hmp: Support for querying stats
kvm: Support for querying fd-based stats
accel/kvm/kvm-all.c | 393 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 28 +++ include/monitor/hmp.h | 2 + include/monitor/stats.h | 51 ++++++ monitor/hmp-cmds.c | 328 +++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 219 ++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 259 ++++++++++++++++++++++++++ 9 files changed, 1282 insertions(+) create mode 100644 include/monitor/stats.h create mode 100644 qapi/stats.json
Signature · 1 line
2.27.0
PATCH v4 1/3 qmp: Support for querying stats
Introduce QMP support for querying stats. Provide a framework for adding new stats and support for the following commands:
- query-stats
Returns a list of all stats per target type (only VM and vCPU to start), with additional options for specifying stat names, vCPU qom paths, and providers.
- query-stats-schemas
Returns a list of stats included in each target type, with an option for specifying the provider.
The framework provides a method to register callbacks for these QMP commands.
The first use-case will be for fd-based KVM stats (in an upcoming patch).
Examples (with fd-based KVM stats):
- Query all VM stats:
{ "execute": "query-stats", "arguments" : { "target": "vm" } }
{ "return": {
"vm": [
{ "provider": "kvm",
"stats": [
{ "name": "max_mmu_page_hash_collisions", "value": 0 },
{ "name": "max_mmu_rmap_size", "value": 0 },
{ "name": "nx_lpage_splits", "value": 148 },
...
{ "provider": "xyz",
"stats": [ ...
...] } }
- Query all vCPU stats:
{ "execute": "query-stats", "arguments" : { "target": "vcpu" } }
{ "return": {
"vcpus": [
{ "path": "/machine/unattached/device[0]"
"providers": [
{ "provider": "kvm",
"stats": [
{ "name": "guest_mode", "value": 0 },
{ "name": "directed_yield_successful", "value": 0 },
{ "name": "directed_yield_attempted", "value": 106 },
...
{ "provider": "xyz",
"stats": [ ...
...
{ "path": "/machine/unattached/device[1]"
"providers": [
{ "provider": "kvm",
"stats": [...
...
} ] } }- Query 'exits' and 'l1d_flush' KVM stats, and 'somestat' from provider 'xyz' for vCPUs '/machine/unattached/device[2]' and '/machine/unattached/device[4]':
{ "execute": "query-stats",
"arguments": {
"target": "vcpu",
"vcpus": [ "/machine/unattached/device[2]",
"/machine/unattached/device[4]" ],
"filters": [
{ "provider": "kvm",
"fields": [ "l1d_flush", "exits" ] },
{ "provider": "xyz",
"fields": [ "somestat" ] } ] } }{ "return": {
"vcpus": [
{ "path": "/machine/unattached/device[2]"
"providers": [
{ "provider": "kvm",
"stats": [ { "name": "l1d_flush", "value": 41213 },
{ "name": "exits", "value": 74291 } ] },
{ "provider": "xyz",
"stats": [ ... ] } ] },
{ "path": "/machine/unattached/device[4]"
"providers": [
{ "provider": "kvm",
"stats": [ { "name": "l1d_flush", "value": 16132 },
{ "name": "exits", "value": 57922 } ] },
{ "provider": "xyz",
"stats": [ ... ] } ] } ] } }- Query stats schemas:
{ "execute": "query-stats-schemas" }
{ "return": {
"vcpu": [
{ "provider": "kvm",
"stats": [
{ "name": "guest_mode",
"unit": "none",
"base": 10,
"exponent": 0,
"type": "instant" },
{ "name": "directed_yield_successful",
"unit": "none",
"base": 10,
"exponent": 0,
"type": "cumulative" },
...
{ "provider": "xyz",
...
"vm": [
{ "provider": "kvm",
"stats": [
{ "name": "max_mmu_page_hash_collisions",
"unit": "none",
"base": 10,
"exponent": 0,
"type": "peak" },
{ "provider": "xyz",
...--- include/monitor/stats.h | 51 ++++++++ monitor/qmp-cmds.c | 219 +++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 259 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 531 insertions(+) create mode 100644 include/monitor/stats.h create mode 100644 qapi/stats.json
include/monitor/stats.h new file +51 -0
@@ -0,0 +1,51 @@ +/* +* Copyright (c) 2022 Oracle and/or its affiliates. +* +* This work is licensed under the terms of the GNU GPL, version 2. +* See the COPYING file in the top-level directory. +*/ + +#ifndef STATS_H +#define STATS_H + +#include "qapi/qapi-types-stats.h" + +/* +* Add QMP stats callbacks to the stats_callbacks list. +* +* @provider: stats provider +* +* @stats_fn: routine to query stats: +* void (*stats_fn)(StatsResults *results, StatsFilter *filter, Error **errp) +* +* @schema_fn: routine to query stat schemas: +* void (*schemas_fn)(StatsSchemaResult *results, Error **errp) +*/ +void add_stats_callbacks (StatsProvider provider, +void (*stats_fn)(StatsResults *,StatsFilter *, +Error **), +void (*schemas_fn)(StatsSchemaResults *,Error **)); + +/* +* Helper routines for adding stats entries to the results lists. +*/ +void add_vm_stats_entry (StatsList *,StatsResults *,StatsProvider ); +void add_vcpu_stats_entry (StatsList *,StatsResults *,StatsProvider ,char *); +void add_vm_stats_schema (StatsSchemaValueList *,StatsSchemaResults *, +StatsProvider ); +void add_vcpu_stats_schema (StatsSchemaValueList *,StatsSchemaResults *, +StatsProvider ); + +/* +* True if a stat name and provider match a filter or if no corresponding +* filters are defined. False otherwise. +*/ +bool stats_requested_name (const char *,StatsProvider ,StatsFilter *); + +/* +* True if a vcpu qom path and provider match a filter or if no corresponding +* filters are defined. False otherwise. +*/ +bool stats_requested_vcpu (const char *,StatsProvider ,StatsFilter *); + +#endif /* STATS_H */
monitor/qmp-cmds.c +219 -0
234 lines not on this page · raw message
qapi/meson.build +1 -0
@@ -46,6 +46,7 @@ qapi_all_modules = [ 'replay', 'run-state', 'sockets', + 'stats', 'trace', 'transaction', 'yank',
qapi/qapi-schema.json +1 -0
@@ -93,3 +93,4 @@ { 'include': 'audio.json' } { 'include': 'acpi.json' } { 'include': 'pci.json' } +{ 'include': 'stats.json' }
qapi/stats.json new file +259 -0
259 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v4 1/3] qmp: Support for querying stats
Quoted 62 lines · Mark Kanda
Introduce QMP support for querying stats. Provide a framework for adding new stats and support for the following commands:
- query-stats
Returns a list of all stats per target type (only VM and vCPU to start), with additional options for specifying stat names, vCPU qom paths, and providers.- query-stats-schemas
Returns a list of stats included in each target type, with an option for specifying the provider.The framework provides a method to register callbacks for these QMP commands.
The first use-case will be for fd-based KVM stats (in an upcoming patch).
Examples (with fd-based KVM stats):
- Query all VM stats:
{ "execute": "query-stats", "arguments" : { "target": "vm" } }
{ "return": {
"vm": [{ "provider": "kvm", "stats": [ { "name": "max_mmu_page_hash_collisions", "value": 0 }, { "name": "max_mmu_rmap_size", "value": 0 }, { "name": "nx_lpage_splits", "value": 148 }, ... { "provider": "xyz", "stats": [ ... ...] } }
- Query all vCPU stats:
{ "execute": "query-stats", "arguments" : { "target": "vcpu" } }
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[0]" "providers": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "value": 0 }, { "name": "directed_yield_successful", "value": 0 }, { "name": "directed_yield_attempted", "value": 106 }, ... { "provider": "xyz", "stats": [ ... ... { "path": "/machine/unattached/device[1]" "providers": [ { "provider": "kvm", "stats": [... ... } ] } }- Query 'exits' and '
l1d_flush' KVM stats, and 'somestat' from provider 'xyz' for vCPUs '/machine/unattached/device[2]' and '/machine/unattached/device[4]':{ "execute": "query-stats",
Quoted 9 lines
"arguments": {
"target": "vcpu",
"vcpus": [ "/machine/unattached/device[2]",
"/machine/unattached/device[4]" ],
"filters": [
{ "provider": "kvm",
"fields": [ "l1d_flush", "exits" ] },
{ "provider": "xyz",
"fields": [ "somestat" ] } ] } }Are the stats bulky enough to justfify the extra complexity of filtering?
Quoted 41 lines
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[2]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 41213 }, { "name": "exits", "value": 74291 } ] }, { "provider": "xyz", "stats": [ ... ] } ] }, { "path": "/machine/unattached/device[4]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 16132 }, { "name": "exits", "value": 57922 } ] }, { "provider": "xyz", "stats": [ ... ] } ] } ] } }- Query stats schemas:
{ "execute": "query-stats-schemas" }
{ "return": { "vcpu": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "unit": "none", "base": 10, "exponent": 0, "type": "instant" }, { "name": "directed_yield_successful", "unit": "none", "base": 10, "exponent": 0, "type": "cumulative" }, ... { "provider": "xyz", ... "vm": [ { "provider": "kvm",
Quoted 8 lines
"stats": [
{ "name": "max_mmu_page_hash_collisions",
"unit": "none",
"base": 10,
"exponent": 0,
"type": "peak" },
{ "provider": "xyz",
...Can you give a use case for query-stats-schemas?
Quoted 8 lines
Signed-off-by Mark Kanda <[email protected]>--- include/monitor/stats.h | 51 ++++++++ monitor/qmp-cmds.c | 219 +++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 259 ++++++++++++++++++++++++++++++++++++++++
That's a lot of schema code.
How much of it is for query-stats, and how much for query-stats-schemas?
How much of the query-stats part is for filtering?
Quoted 3 lines
5 files changed, 531 insertions(+) create mode 100644 include/monitor/stats.h create mode 100644 qapi/stats.json
[...]
Quoted 14 lines
qapi/stats.json new file +8
-0@@ -0,0 +1,259 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# +# Copyright (c) 2022 Oracle and/or its affiliates. +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +#
qapi/stats.json line 18
Quoted 10 lines
qapi/stats.json new file +10
-0+# SPDX-License-Identifier: GPL-2.0-or-later + +## +# = Stats +## + +## +# @StatsType: +# +# Enumeration of stats types
We commonly put a blank line between overview and arguments.
Quoted 113 lines
qapi/stats.json new file +113
-0+# @cumulative: stat is cumulative; value can only increase. +# @instant: stat is instantaneous; value can increase or decrease. +# @peak: stat is the peak value; value can only increase. +# @linear-hist: stat is a linear histogram. +# @log-hist: stat is a logarithmic histogram. +# +# Since: 7.0 +## +{ 'enum' : 'StatsType', + 'data' : [ 'cumulative', 'instant', 'peak', 'linear-hist', 'log-hist' ] } + +## +# @StatsUnit: +# +# Enumeration of stats units +# @bytes: stat reported in bytes. +# @seconds: stat reported in seconds. +# @cycles: stat reported in clock cycles. +# @none: no unit for this stat. +# +# Since: 7.0 +## +{ 'enum' : 'StatsUnit', + 'data' : [ 'bytes', 'seconds', 'cycles', 'none' ] } + +## +# @StatsBase: +# +# Enumeration of stats base +# @pow10: scale is based on power of 10. +# @pow2: scale is based on power of 2. +# +# Since: 7.0 +## +{ 'enum' : 'StatsBase', + 'data' : [ 'pow10', 'pow2' ] } + +## +# @StatsProvider: +# +# Enumeration of stats providers. +# +# Since: 7.0 +## +{ 'enum': 'StatsProvider', + 'data': [ ] } + +## +# @StatsTarget: +# +# Enumeration of stats targets. +# @vm: stat is per vm. +# @vcpu: stat is per vcpu. +# +# Since: 7.0 +## +{ 'enum': 'StatsTarget', + 'data': [ 'vm', 'vcpu' ] } + +## +# @StatsRequest: +# +# Stats filter element. +# @provider: stat provider. +# @fields: list of stat names. +# +# Since: 7.0 +## +{ 'struct': 'StatsRequest', + 'data': { '*provider': 'StatsProvider', + '*fields': [ 'str' ] } } + +## +# @StatsRequestArray: +# +# @filters: filters for this request. +## +{ 'struct': 'StatsRequestArray', + 'data': { '*filters': [ 'StatsRequest' ] } } + +## +# @StatsVCPURequestArray: +# +# @vcpus: list of qom paths. +## +{ 'struct': 'StatsVCPURequestArray', + 'base': 'StatsRequestArray', + 'data': { '*vcpus': [ 'str' ] } } + +## +# @StatsFilter: +# +# Target specific filter. +# +# Since: 7.0 +## +{ 'union': 'StatsFilter', + 'base': { 'target': 'StatsTarget' }, + 'discriminator': 'target', + 'data': { 'vcpu': 'StatsVCPURequestArray', + 'vm': 'StatsRequestArray' } } + +## +# @StatsValueArray: +# +# @values: uint64 list. +# +# Since: 7.0 +## +{ 'struct': 'StatsValueArray', + 'data': { 'values' : [ 'uint64' ] } } + +##
qapi/stats.json line 141
Quoted 10 lines
qapi/stats.json new file +10
-0+# @StatsValue: +# +# @scalar: single uint64. +# @list: list of uint64. +# +# Since: 7.0 +## +{ 'alternate': 'StatsValue', + 'data': { 'scalar': 'uint64', + 'list': 'StatsValueArray' } }
Any particular reason for wrapping the array in a struct?
Quoted 118 lines
qapi/stats.json new file +118
-0+ +## +# @Stats: +# +# @name: name of stat. +# @value: stat value. +# +# Since: 7.0 +## +{ 'struct': 'Stats', + 'data': { 'name': 'str', + 'value' : 'StatsValue' } } + +## +# @StatsResultsEntry: +# +# @provider: stat provider. +# @stats: list of stats. +# +# Since: 7.0 +## +{ 'struct': 'StatsResultsEntry', + 'data': { 'provider': 'StatsProvider', + 'stats': [ 'Stats' ] } } + +## +# @StatsResultsVCPUEntry: +# +# @path: vCPU qom path. +# @providers: per provider results. +# +# Since: 7.0 +## +{ 'struct': 'StatsResultsVCPUEntry', + 'data': { 'path': 'str', + 'providers': [ 'StatsResultsEntry' ] } } + +## +# @StatsResults: +# +# Target specific results. +# +# Since: 7.0 +## +{ 'struct': 'StatsResults', + 'data': { + '*vcpus': [ 'StatsResultsVCPUEntry' ], + '*vm': [ 'StatsResultsEntry' ] } } + +## +# @query-stats: +# +# data: @StatsFilter. +# Returns: @StatsResults. +# +# Since: 7.0 +## +{ 'command': 'query-stats', + 'data': 'StatsFilter', + 'boxed': true, + 'returns': 'StatsResults' } + +## +# @StatsSchemaValue: +# +# Individual stat schema. +# @name: stat name. +# @type: @StatType. +# @unit: @StatUnit. +# @base: @StatBase. +# @exponent: Used together with @base. +# @bucket-size: Used with linear-hist to report bucket size +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaValue', + 'data': { 'name': 'str', + 'type': 'StatsType', + 'unit': 'StatsUnit', + 'base': 'StatsBase', + 'exponent': 'int16', + '*bucket-size': 'uint32' } } + +## +# @StatsSchemaProvider: +# +# @provider: @StatsProvider. +# @stats: list of stats. +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaProvider', + 'data': { 'provider': 'StatsProvider', + 'stats': [ 'StatsSchemaValue' ] } } + +## +# @StatsSchemaResults: +# +# @vm: vm stats schemas. +# @vcpu: vcpu stats schemas. +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaResults', + 'data': { '*vm': [ 'StatsSchemaProvider' ], + '*vcpu': [ 'StatsSchemaProvider' ] } } + +## +# @query-stats-schemas: +# +# Query Stats schemas. +# Returns @StatsSchemaResult. +# +# Since: 7.0 +## +{ 'command': 'query-stats-schemas', + 'data': { '*provider': 'StatsProvider' }, + 'returns': 'StatsSchemaResults' }
Re: [PATCH v4 1/3] qmp: Support for querying stats
Quoted 74 lines · Markus Armbruster
Quoted 62 lines · Mark Kanda
Introduce QMP support for querying stats. Provide a framework for adding new stats and support for the following commands:
- query-stats
Returns a list of all stats per target type (only VM and vCPU to start), with additional options for specifying stat names, vCPU qom paths, and providers.- query-stats-schemas
Returns a list of stats included in each target type, with an option for specifying the provider.The framework provides a method to register callbacks for these QMP commands.
The first use-case will be for fd-based KVM stats (in an upcoming patch).
Examples (with fd-based KVM stats):
- Query all VM stats:
{ "execute": "query-stats", "arguments" : { "target": "vm" } }
{ "return": {
"vm": [{ "provider": "kvm", "stats": [ { "name": "max_mmu_page_hash_collisions", "value": 0 }, { "name": "max_mmu_rmap_size", "value": 0 }, { "name": "nx_lpage_splits", "value": 148 }, ... { "provider": "xyz", "stats": [ ... ...] } }
- Query all vCPU stats:
{ "execute": "query-stats", "arguments" : { "target": "vcpu" } }
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[0]" "providers": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "value": 0 }, { "name": "directed_yield_successful", "value": 0 }, { "name": "directed_yield_attempted", "value": 106 }, ... { "provider": "xyz", "stats": [ ... ... { "path": "/machine/unattached/device[1]" "providers": [ { "provider": "kvm", "stats": [... ... } ] } }- Query 'exits' and '
l1d_flush' KVM stats, and 'somestat' from provider 'xyz' for vCPUs '/machine/unattached/device[2]' and '/machine/unattached/device[4]':{ "execute": "query-stats",
Quoted 9 lines
"arguments": { "target": "vcpu", "vcpus": [ "/machine/unattached/device[2]", "/machine/unattached/device[4]" ], "filters": [ { "provider": "kvm", "fields": [ "l1d_flush", "exits" ] }, { "provider": "xyz", "fields": [ "somestat" ] } ] } }
Quoted 2 lines
Are the stats bulky enough to justfify the extra complexity of filtering?
I viewed it more as a mechanism to cope with a scenario where some stats are expensive to query. If the mgmt app only want to get one specific cheap stat, we don't want to trigger code that does expensive queries of other stats as a side effect.
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 :|
Re: [PATCH v4 1/3] qmp: Support for querying stats
In reply to Markus ArmbrusterThank you Markus.
Quoted 73 lines · Markus Armbruster
Quoted 62 lines · Mark Kanda
Introduce QMP support for querying stats. Provide a framework for adding new stats and support for the following commands:
- query-stats
Returns a list of all stats per target type (only VM and vCPU to start), with additional options for specifying stat names, vCPU qom paths, and providers.- query-stats-schemas
Returns a list of stats included in each target type, with an option for specifying the provider.The framework provides a method to register callbacks for these QMP commands.
The first use-case will be for fd-based KVM stats (in an upcoming patch).
Examples (with fd-based KVM stats):
- Query all VM stats:
{ "execute": "query-stats", "arguments" : { "target": "vm" } }
{ "return": { "vm": [ { "provider": "kvm", "stats": [ { "name": "max_mmu_page_hash_collisions", "value": 0 }, { "name": "max_mmu_rmap_size", "value": 0 }, { "name": "nx_lpage_splits", "value": 148 }, ... { "provider": "xyz", "stats": [ ... ...] } }
- Query all vCPU stats:
{ "execute": "query-stats", "arguments" : { "target": "vcpu" } }
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[0]" "providers": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "value": 0 }, { "name": "directed_yield_successful", "value": 0 }, { "name": "directed_yield_attempted", "value": 106 }, ... { "provider": "xyz", "stats": [ ... ... { "path": "/machine/unattached/device[1]" "providers": [ { "provider": "kvm", "stats": [... ... } ] } }- Query 'exits' and '
l1d_flush' KVM stats, and 'somestat' from provider 'xyz' for vCPUs '/machine/unattached/device[2]' and '/machine/unattached/device[4]':{ "execute": "query-stats",
Quoted 9 lines
"arguments": { "target": "vcpu", "vcpus": [ "/machine/unattached/device[2]", "/machine/unattached/device[4]" ], "filters": [ { "provider": "kvm", "fields": [ "l1d_flush", "exits" ] }, { "provider": "xyz", "fields": [ "somestat" ] } ] } }
Quoted 2 lines
Are the stats bulky enough to justfify the extra complexity of filtering?
If this was only for KVM, the complexity probably isn't worth it. However, the framework is intended to support future stats with new providers and targets (there has also been mention of moving existing stats to this framework). Without some sort of filtering, I think the payload could become unmanageable.
Quoted 49 lines
Quoted 41 lines
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[2]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 41213 }, { "name": "exits", "value": 74291 } ] }, { "provider": "xyz", "stats": [ ... ] } ] }, { "path": "/machine/unattached/device[4]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 16132 }, { "name": "exits", "value": 57922 } ] }, { "provider": "xyz", "stats": [ ... ] } ] } ] } }- Query stats schemas:
{ "execute": "query-stats-schemas" }
{ "return": { "vcpu": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "unit": "none", "base": 10, "exponent": 0, "type": "instant" }, { "name": "directed_yield_successful", "unit": "none", "base": 10, "exponent": 0, "type": "cumulative" }, ... { "provider": "xyz", ... "vm": [ { "provider": "kvm",Quoted 8 lines
"stats": [ { "name": "max_mmu_page_hash_collisions", "unit": "none", "base": 10, "exponent": 0, "type": "peak" }, { "provider": "xyz", ...
Quoted 1 line
Can you give a use case for query-stats-schemas?
'query-stats-schemas' provide the the type details about each stat; such as the unit, base, etc. These details are not reported by 'query-stats' (only the stat name and raw values are returned).
Quoted 11 lines
Quoted 8 lines
Signed-off-by Mark Kanda <[email protected]>--- include/monitor/stats.h | 51 ++++++++ monitor/qmp-cmds.c | 219 +++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 259 ++++++++++++++++++++++++++++++++++++++++That's a lot of schema code.
How much of it is for query-stats, and how much for query-stats-schemas?
It's roughly 60% query-stats, 40% query-stats-schemas.
Quoted 1 line
How much of the query-stats part is for filtering?
I think filtering is about 40% of query-stats.
Quoted 23 lines
Quoted 4 lines
5 files changed, 531 insertions(+)create mode 100644
include/monitor/stats.h
create mode 100644qapi/stats.json[...]
Quoted 17 lines
qapi/stats.json new file +11
-0@@ -0,0 +1,259 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# +# Copyright (c) 2022 Oracle and/or its affiliates. +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +##
Quoted 8 lines
qapi/stats.json line 18
Quoted 7 lines
qapi/stats.json new file +7
-0+# = Stats +## + +## +# @StatsType: +# +# Enumeration of stats typesWe commonly put a blank line between overview and arguments.
Will fix.
Quoted 116 lines
Quoted 116 lines
qapi/stats.json new file +116
-0+# @cumulative: stat is cumulative; value can only increase. +# @instant: stat is instantaneous; value can increase or decrease. +# @peak: stat is the peak value; value can only increase. +# @linear-hist: stat is a linear histogram. +# @log-hist: stat is a logarithmic histogram. +# +# Since: 7.0 +## +{ 'enum' : 'StatsType', + 'data' : [ 'cumulative', 'instant', 'peak', 'linear-hist', 'log-hist' ] } + +## +# @StatsUnit: +# +# Enumeration of stats units +# @bytes: stat reported in bytes. +# @seconds: stat reported in seconds. +# @cycles: stat reported in clock cycles. +# @none: no unit for this stat. +# +# Since: 7.0 +## +{ 'enum' : 'StatsUnit', + 'data' : [ 'bytes', 'seconds', 'cycles', 'none' ] } + +## +# @StatsBase: +# +# Enumeration of stats base +# @pow10: scale is based on power of 10. +# @pow2: scale is based on power of 2. +# +# Since: 7.0 +## +{ 'enum' : 'StatsBase', + 'data' : [ 'pow10', 'pow2' ] } + +## +# @StatsProvider: +# +# Enumeration of stats providers. +# +# Since: 7.0 +## +{ 'enum': 'StatsProvider', + 'data': [ ] } + +## +# @StatsTarget: +# +# Enumeration of stats targets. +# @vm: stat is per vm. +# @vcpu: stat is per vcpu. +# +# Since: 7.0 +## +{ 'enum': 'StatsTarget', + 'data': [ 'vm', 'vcpu' ] } + +## +# @StatsRequest: +# +# Stats filter element. +# @provider: stat provider. +# @fields: list of stat names. +# +# Since: 7.0 +## +{ 'struct': 'StatsRequest', + 'data': { '*provider': 'StatsProvider', + '*fields': [ 'str' ] } } + +## +# @StatsRequestArray: +# +# @filters: filters for this request. +## +{ 'struct': 'StatsRequestArray', + 'data': { '*filters': [ 'StatsRequest' ] } } + +## +# @StatsVCPURequestArray: +# +# @vcpus: list of qom paths. +## +{ 'struct': 'StatsVCPURequestArray', + 'base': 'StatsRequestArray', + 'data': { '*vcpus': [ 'str' ] } } + +## +# @StatsFilter: +# +# Target specific filter. +# +# Since: 7.0 +## +{ 'union': 'StatsFilter', + 'base': { 'target': 'StatsTarget' }, + 'discriminator': 'target', + 'data': { 'vcpu': 'StatsVCPURequestArray', + 'vm': 'StatsRequestArray' } } + +## +# @StatsValueArray: +# +# @values: uint64 list. +# +# Since: 7.0 +## +{ 'struct': 'StatsValueArray', + 'data': { 'values' : [ 'uint64' ] } } + +## +# @StatsValue: +# +# @scalar: single uint64.
Quoted 8 lines
qapi/stats.json line 141
Quoted 7 lines
qapi/stats.json new file +7
-0+# @list: list of uint64. +# +# Since: 7.0 +## +{ 'alternate': 'StatsValue', + 'data': { 'scalar': 'uint64', + 'list': 'StatsValueArray' } }Any particular reason for wrapping the array in a struct?
Due to the limitation in the QAPI framework, I hit:../qapi/stats.json:139: 'data' member 'list' cannot be an array
I can look at adding support...
Thanks/regards,
-Mark
Quoted 118 lines
Quoted 118 lines
qapi/stats.json new file +118
-0+ +## +# @Stats: +# +# @name: name of stat. +# @value: stat value. +# +# Since: 7.0 +## +{ 'struct': 'Stats', + 'data': { 'name': 'str', + 'value' : 'StatsValue' } } + +## +# @StatsResultsEntry: +# +# @provider: stat provider. +# @stats: list of stats. +# +# Since: 7.0 +## +{ 'struct': 'StatsResultsEntry', + 'data': { 'provider': 'StatsProvider', + 'stats': [ 'Stats' ] } } + +## +# @StatsResultsVCPUEntry: +# +# @path: vCPU qom path. +# @providers: per provider results. +# +# Since: 7.0 +## +{ 'struct': 'StatsResultsVCPUEntry', + 'data': { 'path': 'str', + 'providers': [ 'StatsResultsEntry' ] } } + +## +# @StatsResults: +# +# Target specific results. +# +# Since: 7.0 +## +{ 'struct': 'StatsResults', + 'data': { + '*vcpus': [ 'StatsResultsVCPUEntry' ], + '*vm': [ 'StatsResultsEntry' ] } } + +## +# @query-stats: +# +# data: @StatsFilter. +# Returns: @StatsResults. +# +# Since: 7.0 +## +{ 'command': 'query-stats', + 'data': 'StatsFilter', + 'boxed': true, + 'returns': 'StatsResults' } + +## +# @StatsSchemaValue: +# +# Individual stat schema. +# @name: stat name. +# @type: @StatType. +# @unit: @StatUnit. +# @base: @StatBase. +# @exponent: Used together with @base. +# @bucket-size: Used with linear-hist to report bucket size +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaValue', + 'data': { 'name': 'str', + 'type': 'StatsType', + 'unit': 'StatsUnit', + 'base': 'StatsBase', + 'exponent': 'int16', + '*bucket-size': 'uint32' } } + +## +# @StatsSchemaProvider: +# +# @provider: @StatsProvider. +# @stats: list of stats. +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaProvider', + 'data': { 'provider': 'StatsProvider', + 'stats': [ 'StatsSchemaValue' ] } } + +## +# @StatsSchemaResults: +# +# @vm: vm stats schemas. +# @vcpu: vcpu stats schemas. +# +# Since: 7.0 +## +{ 'struct': 'StatsSchemaResults', + 'data': { '*vm': [ 'StatsSchemaProvider' ], + '*vcpu': [ 'StatsSchemaProvider' ] } } + +## +# @query-stats-schemas: +# +# Query Stats schemas. +# Returns @StatsSchemaResult. +# +# Since: 7.0 +## +{ 'command': 'query-stats-schemas', + 'data': { '*provider': 'StatsProvider' }, + 'returns': 'StatsSchemaResults' }
Re: [PATCH v4 1/3] qmp: Support for querying stats
First: sorry for my slow response.
Quoted 76 lines · Mark Kanda
Thank you Markus.
Quoted 73 lines · Markus Armbruster
Quoted 71 lines · Mark Kanda
Introduce QMP support for querying stats. Provide a framework for adding new stats and support for the following commands:
- query-stats
Returns a list of all stats per target type (only VM and vCPU to start), with additional options for specifying stat names, vCPU qom paths, and providers.- query-stats-schemas
Returns a list of stats included in each target type, with an option for specifying the provider.The framework provides a method to register callbacks for these QMP commands.
The first use-case will be for fd-based KVM stats (in an upcoming patch).
Examples (with fd-based KVM stats):
- Query all VM stats:
{ "execute": "query-stats", "arguments" : { "target": "vm" } }
{ "return": { "vm": [ { "provider": "kvm", "stats": [ { "name": "max_mmu_page_hash_collisions", "value": 0 }, { "name": "max_mmu_rmap_size", "value": 0 }, { "name": "nx_lpage_splits", "value": 148 }, ... { "provider": "xyz", "stats": [ ... ...] } }
- Query all vCPU stats:
{ "execute": "query-stats", "arguments" : { "target": "vcpu" } }
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[0]" "providers": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "value": 0 }, { "name": "directed_yield_successful", "value": 0 }, { "name": "directed_yield_attempted", "value": 106 }, ... { "provider": "xyz", "stats": [ ... ... { "path": "/machine/unattached/device[1]" "providers": [ { "provider": "kvm", "stats": [... ... } ] } }- Query 'exits' and '
l1d_flush' KVM stats, and 'somestat' from provider 'xyz' for vCPUs '/machine/unattached/device[2]' and '/machine/unattached/device[4]':{ "execute": "query-stats",
"arguments": { "target": "vcpu", "vcpus": [ "/machine/unattached/device[2]", "/machine/unattached/device[4]" ], "filters": [ { "provider": "kvm", "fields": [ "l1d_flush", "exits" ] }, { "provider": "xyz", "fields": [ "somestat" ] } ] } }
Quoted 7 lines
Quoted 2 lines
Are the stats bulky enough to justfify the extra complexity of filtering?
If this was only for KVM, the complexity probably isn't worth it. However, the framework is intended to support future stats with new providers and targets (there has also been mention of moving existing stats to this framework). Without some sort of filtering, I think the payload could become unmanageable.
I'm deeply wary of "may need $complexity in the future" when $complexity could be added when we actually need it :)
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
{ "return": { "vcpus": [ { "path": "/machine/unattached/device[2]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 41213 }, { "name": "exits", "value": 74291 } ] }, { "provider": "xyz", "stats": [ ... ] } ] }, { "path": "/machine/unattached/device[4]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 16132 }, { "name": "exits", "value": 57922 } ] }, { "provider": "xyz", "stats": [ ... ] } ] } ] } }- Query stats schemas:
{ "execute": "query-stats-schemas" }
{ "return": { "vcpu": [ { "provider": "kvm", "stats": [ { "name": "guest_mode", "unit": "none", "base": 10, "exponent": 0, "type": "instant" }, { "name": "directed_yield_successful", "unit": "none", "base": 10, "exponent": 0, "type": "cumulative" }, ... { "provider": "xyz", ... "vm": [ { "provider": "kvm", "stats": [ { "name": "max_mmu_page_hash_collisions", "unit": "none", "base": 10, "exponent": 0, "type": "peak" }, { "provider": "xyz", ...
Quoted 5 lines
Quoted 1 line
Can you give a use case for query-stats-schemas?
'query-stats-schemas' provide the the type details about each stat; such as the unit, base, etc. These details are not reported by 'query-stats' (only the stat name and raw values are returned).
Yes, but what is going to use these type details, and for what purpose?
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Signed-off-by Mark Kanda <[email protected]>--- include/monitor/stats.h | 51 ++++++++ monitor/qmp-cmds.c | 219 +++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 259 ++++++++++++++++++++++++++++++++++++++++That's a lot of schema code.
Quoted 7 lines
Quoted 1 line
How much of it is for query-stats, and how much for query-stats-schemas?
It's roughly 60% query-stats, 40% query-stats-schemas.
Quoted 1 line
How much of the query-stats part is for filtering?
I think filtering is about 40% of query-stats.
Have you considered splitting this up into three parts: unfiltered query-stats, filtering, and query-stats-schemas?
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
5 files changed, 531 insertions(+)create mode 100644
include/monitor/stats.h
create mode 100644qapi/stats.json[...]
Quoted 5 lines
qapi/stats.json new file +0
-0
[...]
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
qapi/stats.json new file +5
-0+## +# @StatsValue: +# +# @scalar: single uint64. +# @list: list of uint64.Quoted 8 lines
qapi/stats.json line 141
Quoted 6 lines
qapi/stats.json new file +6
-0+# +# Since: 7.0 +## +{ 'alternate': 'StatsValue', + 'data': { 'scalar': 'uint64', + 'list': 'StatsValueArray' } }Any particular reason for wrapping the array in a struct?
Quoted 4 lines
Due to the limitation in the QAPI framework, I hit:
../qapi/stats.json:139: 'data' member 'list' cannot be an arrayI can look at adding support...
That would be nice. Could you use help to get started with it?
We could perhaps merge with the current schema, then clean it up on top, both in 7.1, if that's easier for you.
Re: [PATCH v4 1/3] qmp: Support for querying stats
Quoted 6 lines · Markus Armbruster
Quoted 5 lines · Mark Kanda
Thank you Markus.
Quoted 2 lines · Markus Armbruster
Are the stats bulky enough to justfify the extra complexity of filtering?
Quoted 7 lines
Quoted 4 lines
If this was only for KVM, the complexity probably isn't worth it. However, the framework is intended to support future stats with new providers and targets (there has also been mention of moving existing stats to this framework). Without some sort of filtering, I think the payload could become unmanageable.
I'm deeply wary of "may need $complexity in the future" when $complexity could be added when we actually need it :)
I think it's better to have the filtering already. There are several uses for it.
Regarding filtering by provider, consider that a command like "info jit" should be a wrapper over
{ "execute": "query-stats", "arguments" : { "target": "vm",
"filters": [ { "provider": "tcg" } ] } }
So we have an example of the intended use already within QEMU. Yes, the usefulness depends on actually having >1 provider but I think it's pretty central to the idea of having a statistics *subsystem*.
Regarding filtering by name, query-stats mostly has two usecases. The first is retrieving all stats and publishing them up to the user, for example once per minute per VM. The second is monitoring a small number and building a relatively continuous plot (e.g. 1-10 times per second per vCPU). For the latter, not having to return hundreds of values unnecessarily (KVM has almost 60 stats, multiply by the number of vCPUs and the frequency) is worth having even just with the KVM provider.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can you give a use case for query-stats-schemas?
'query-stats-schemas' provide the the type details about each stat; such as the unit, base, etc. These details are not reported by 'query-stats' (only the stat name and raw values are returned).
Yes, but what is going to use these type details, and for what purpose?
QEMU does not know in advance which stats are provided. The types, etc. are provided by the kernel and can change by architecture and kernel version. In the case of KVM, introspection is done through a file descriptor. QEMU passes these up as QMP and in the future it could/should extend this to other providers (such as TCG) and devices (such as block devices).
See the "info stats" implementation for how it uses the schema:
vcpu (qom path: /machine/unattached/device[2])
provider: kvm
exits (cumulative): 52369
halt_wait_ns (cumulative nanoseconds): 416092704390Information such as "cumulative nanoseconds" is provided by the schema.
Quoted 2 lines
Have you considered splitting this up into three parts: unfiltered query-stats, filtering, and query-stats-schemas?
Splitting could be an idea, but I think only filtering would be a separate step. The stats are not really usable without a schema that tells you the units, or whether a number can go down or only up. (Well, a human export could use them through its intuition, but a HMP-level command could not be provided).
Quoted 2 lines
We could perhaps merge with the current schema, then clean it up on top, both in 7.1, if that's easier for you.
The serialized JSON would change, so that would be a bit worrisome (but it makes me feel a little less bad about this missing 7.0). It seems to be as easy as this, as far as alternates go:
scripts/qapi/expr.py +1 -1
@@ -554,7 +554,7 @@ def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None: check_name_lower(key, info, source) check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source) + check_type(value['type'], info, source, allow_array=True) def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None:
scripts/qapi/schema.py +4 -0
@@ -243,6 +243,7 @@ def alternate_qtype(self): 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', 'boolean': 'QTYPE_QBOOL', + 'array': 'QTYPE_QLIST', 'object': 'QTYPE_QDICT' } return json2qtype.get(self.json_type())
@@ -1069,6 +1070,9 @@ def _def_struct_type(self, expr, info, doc): None)) def _make_variant(self, case, typ, ifcond, info): + if isinstance(typ, list): + assert len(typ) == 1 + typ = self._make_array_type(typ[0], info) return QAPISchemaVariant(case, info, typ, ifcond) def _def_union_type(self, expr, info, doc):
I'll try to write some testcases and also cover other uses of _make_variant, which will undoubtedly find some issue.
Paolo
Re: [PATCH v4 1/3] qmp: Support for querying stats
Quoted 91 lines · Paolo Bonzini
Quoted 6 lines · Markus Armbruster
Quoted 5 lines · Mark Kanda
Thank you Markus.
Quoted 2 lines · Markus Armbruster
Are the stats bulky enough to justfify the extra complexity of filtering?
Quoted 7 lines
Quoted 4 lines
If this was only for KVM, the complexity probably isn't worth it. However, the framework is intended to support future stats with new providers and targets (there has also been mention of moving existing stats to this framework). Without some sort of filtering, I think the payload could become unmanageable.
I'm deeply wary of "may need $complexity in the future" when $complexity could be added when we actually need it :)
I think it's better to have the filtering already. There are several uses for it.
Regarding filtering by provider, consider that a command like "info jit" should be a wrapper over
{ "execute": "query-stats", "arguments" : { "target": "vm", "filters": [ { "provider": "tcg" } ] } }
So we have an example of the intended use already within QEMU. Yes, the usefulness depends on actually having >1 provider but I think it's pretty central to the idea of having a statistics *subsystem*.
Regarding filtering by name, query-stats mostly has two usecases. The first is retrieving all stats and publishing them up to the user, for example once per minute per VM. The second is monitoring a small number and building a relatively continuous plot (e.g. 1-10 times per second per vCPU). For the latter, not having to return hundreds of values unnecessarily (KVM has almost 60 stats, multiply by the number of vCPUs and the frequency) is worth having even just with the KVM provider.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can you give a use case for query-stats-schemas?
'query-stats-schemas' provide the the type details about each stat; such as the unit, base, etc. These details are not reported by 'query-stats' (only the stat name and raw values are returned).
Yes, but what is going to use these type details, and for what purpose?
QEMU does not know in advance which stats are provided. The types, etc. are provided by the kernel and can change by architecture and kernel version. In the case of KVM, introspection is done through a file descriptor. QEMU passes these up as QMP and in the future it could/should extend this to other providers (such as TCG) and devices (such as block devices).
See the "info stats" implementation for how it uses the schema:
vcpu (qom path: /machine/unattached/device[2])
provider: kvm
exits (cumulative): 52369
halt_wait_ns(cumulative nanoseconds): 416092704390Information such as "cumulative nanoseconds" is provided by the schema.
Quoted 2 lines
Have you considered splitting this up into three parts: unfiltered query-stats, filtering, and query-stats-schemas?
Splitting could be an idea, but I think only filtering would be a separate step. The stats are not really usable without a schema that tells you the units, or whether a number can go down or only up. (Well, a human export could use them through its intuition, but a HMP-level command could not be provided).
Quoted 2 lines
We could perhaps merge with the current schema, then clean it up on top, both in 7.1, if that's easier for you.
The serialized JSON would change, so that would be a bit worrisome (but it makes me feel a little less bad about this missing 7.0). It seems to be as easy as this, as far as alternates go:
scripts/qapi/expr.py +0
-0@@ -554,7 +554,7 @@ def check_alternate(expr: _JSONObject, info:QAPISourceInfo) -> None:
check_name_lower(key, info, source)check_keys(value, info, source, ['type'], ['if'])check_if(value, info, source)
-check_type(value['type'], info, source)
+check_type(value['type'], info, source, allow_array=True)def
check_command(expr: _JSONObject, info: QAPISourceInfo)-> None:scripts/qapi/schema.py +1
-0@@ -243,6 +243,7 @@ def alternate_qtype(self): 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', 'boolean': 'QTYPE_QBOOL', + 'array': 'QTYPE_QLIST','object': '
QTYPE_QDICT'
}
return json2qtype.get(self.json_type())scripts/qapi/schema.py +0
-0@@ -1069,6 +1070,9 @@ def _def_struct_type(self, expr, info, doc): None))def
_make_variant(self, case, typ, ifcond, info):
+ ifisinstance(typ, list):
+ assert len(typ) == 1
+ typ =self._make_array_type(typ[0], info)returnQAPISchemaVariant(case, info, typ, ifcond)
Quoted 6 lines
def
_def_union_type(self, expr, info, doc):I'll try to write some testcases and also cover other uses of
_make_variant, which will undoubtedly find some issue.
Hi Paolo,
FWIW, the attached patch adjusts some tests for alternates with arrays..
Thanks/regards,
-Mark
From 8d02b1b3cbb0dcc08875e307199d06c3995b3cf2 Mon Sep 17 00:00:00 2001
From: Mark Kanda <[email protected]>
Date: Tue, 15 Mar 2022 20:42:05 -0500
Subject: [PATCH] qapi: Add support for alternates with arrays
--- scripts/qapi/expr.py | 2 +- scripts/qapi/schema.py | 6 +++++- tests/qapi-schema/alternate-array.err | 2 -- tests/qapi-schema/alternate-array.json | 7 ------- tests/qapi-schema/alternate-array.out | 0 tests/qapi-schema/meson.build | 1 - tests/qapi-schema/qapi-schema-test.json | 6 ++++++ tests/qapi-schema/qapi-schema-test.out | 8 ++++++++ 8 files changed, 20 insertions(+), 12 deletions(-) delete mode 100644 tests/qapi-schema/alternate-array.err delete mode 100644 tests/qapi-schema/alternate-array.json delete mode 100644 tests/qapi-schema/alternate-array.out
scripts/qapi/expr.py +1 -1
@@ -554,7 +554,7 @@ def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None: check_name_lower(key, info, source) check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source) + check_type(value['type'], info, source, allow_array=True) def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None:
scripts/qapi/schema.py +5 -1
@@ -243,7 +243,8 @@ def alternate_qtype(self): 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', 'boolean': 'QTYPE_QBOOL', - 'object': 'QTYPE_QDICT' + 'object': 'QTYPE_QDICT', + 'array': 'QTYPE_QLIST' } return json2qtype.get(self.json_type())
@@ -1069,6 +1070,9 @@ def _def_struct_type(self, expr, info, doc): None)) def _make_variant(self, case, typ, ifcond, info): + if isinstance(typ, list): + assert len(typ) == 1 + typ = self._make_array_type(typ[0], info) return QAPISchemaVariant(case, info, typ, ifcond) def _def_union_type(self, expr, info, doc):
tests/qapi-schema/alternate-array.err deleted +0 -2
@@ -1,2 +0,0 @@ -alternate-array.json: In alternate 'Alt': -alternate-array.json:5: 'data' member 'two' cannot be an array
tests/qapi-schema/alternate-array.json deleted +0 -7
@@ -1,7 +0,0 @@ -# we do not allow array branches in alternates -# TODO: should we support this? -{ 'struct': 'One', - 'data': { 'name': 'str' } } -{ 'alternate': 'Alt', - 'data': { 'one': 'One', - 'two': [ 'int' ] } }
tests/qapi-schema/alternate-array.out deleted +0 -0
tests/qapi-schema/meson.build +0 -1
@@ -4,7 +4,6 @@ test_env.set('PYTHONIOENCODING', 'utf-8') schemas = [ 'alternate-any.json', - 'alternate-array.json', 'alternate-base.json', 'alternate-branch-if-invalid.json', 'alternate-clash.json',
tests/qapi-schema/qapi-schema-test.json +6 -0
@@ -123,6 +123,12 @@ # for testing use of 'str' within alternates { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } +# for testing use of an 'int' array within alternates +{ 'alternate': 'AltIntArray', 'data': { 'a': [ 'int' ], 'o': 'TestStruct' } } + +# for testing use of an 'TestStruct' array within alternates +{ 'alternate': 'AltStructArray', 'data': { 'a': [ 'TestStruct' ], 'o': 'TestStruct' } } + { 'struct': 'ArrayStruct', 'data': { 'integer': ['int'], 's8': ['int8'],
tests/qapi-schema/qapi-schema-test.out +8 -0
@@ -125,6 +125,14 @@ alternate AltStrObj tag type case s: str case o: TestStruct +alternate AltIntArray + tag type + case a: intList + case o: TestStruct +alternate AltStructArray + tag type + case a: TestStructList + case o: TestStruct object ArrayStruct member integer: intList optional=False member s8: int8List optional=False
Signature · 1 line
2.27.0
PATCH v4 2/3 hmp: Support for querying stats
In reply to Mark KandaLeverage the QMP support for querying stats. The interface supports similar arguments as the QMP interface. Wildcard char (*) is accepted for names and stats target.
Examples (with fd-based KVM stats):
- Display all stats
(qemu) info stats
vm
provider: kvm
max_mmu_page_hash_collisions (peak): 0
max_mmu_rmap_size (peak): 0
...
vcpu (qom path: /machine/unattached/device[0])
provider: kvm
guest_mode (instant): 0
directed_yield_successful (cumulative): 0
...
(qemu) info stats-schemas
vm
provider: kvm
max_mmu_page_hash_collisions (peak)
max_mmu_rmap_size (peak)
...
vcpu
provider: kvm
guest_mode (instant)
directed_yield_successful (cumulative)
- Display 'halt_wait_ns' and 'exits' for vCPUs with qom paths /machine/unattached/device[2] and /machine/unattached/device[4]:
(qemu) info stats exits,halt_wait_ns /machine/unattached/device[2], /machine/unattached/device[4]
vcpu (qom path: /machine/unattached/device[2])
provider: kvm
exits (cumulative): 52369
halt_wait_ns (cumulative nanoseconds): 416092704390
vcpu (qom path: /machine/unattached/device[4])
provider: kvm
exits (cumulative): 52550
halt_wait_ns (cumulative nanoseconds): 419637402657- Display all VM stats for provider KVM:
(qemu) info stats * vm kvm
vm
provider: kvm
max_mmu_page_hash_collisions (peak): 0
max_mmu_rmap_size (peak): 0
nx_lpage_splits (instant): 51
...
--- hmp-commands-info.hx | 28 ++++ include/monitor/hmp.h | 2 + monitor/hmp-cmds.c | 328 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 358 insertions(+)
hmp-commands-info.hx +28 -0
@@ -879,3 +879,31 @@ SRST ``info sgx`` Show intel SGX information. ERST + + { + .name = "stats", + .args_type = "names:s?,vcpus:s?,provider:s?", + .params = "[names] [vcpus] [provider]", + .help = "show statistics; optional comma separated names, " + "vcpu qom paths, and provider", + .cmd = hmp_info_stats, + }, + +SRST + ``stats`` + Show stats +ERST + + { + .name = "stats-schemas", + .args_type = "provider:s?", + .params = "[provider]", + .help = "show statistics schema for each provider", + .cmd = hmp_info_stats_schemas, + }, + +SRST + ``stats-schemas`` + Show stats per schema +ERST +
include/monitor/hmp.h +2 -0
@@ -133,5 +133,7 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *qdict);void hmp_calc_dirty_rate (Monitor *mon,const QDict *qdict);void hmp_human_readable_text_helper (Monitor *mon,HumanReadableText *(*qmp_handler)(Error **)); +void hmp_info_stats (Monitor *mon,const QDict *qdict); +void hmp_info_stats_schemas (Monitor *mon,const QDict *qdict);#endif
monitor/hmp-cmds.c +328 -0
337 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 3/3 kvm: Support for querying fd-based stats
In reply to Mark KandaAdd support for querying fd-based KVM stats - as introduced by Linux kernel commit:
cb082bfab59a ("KVM: stats: Add fd-based API to read binary stats data")
--- accel/kvm/kvm-all.c | 393 ++++++++++++++++++++++++++++++++++++++++++++ qapi/stats.json | 2 +- 2 files changed, 394 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +393 -0
@@ -47,6 +47,7 @@#include "kvm-cpus.h" #include "hw/boards.h" +#include "monitor/stats.h" /* This check must be after config-host.h is included */ #ifdef CONFIG_EVENTFD
@@ -2309,6 +2310,9 @@ bool kvm_dirty_ring_enabled(void)return kvm_state->kvm_dirty_ring_size ? true : false; } +static void query_stats_cb (StatsResults *,StatsFilter *,Error **); +static void query_stats_schemas_cb (StatsSchemaResults *,Error **); +static int kvm_init (MachineState *ms) {MachineClass *mc =MACHINE_GET_CLASS (ms);
@@ -2637,6 +2641,11 @@ static int kvm_init(MachineState *ms) } } +if (kvm_check_extension (kvm_state,KVM_CAP_BINARY_STATS_FD )) { +add_stats_callbacks (STATS_PROVIDER_KVM , &query_stats_cb, + &query_stats_schemas_cb); + } +return 0 ; err:
@@ -3696,3 +3705,387 @@ static void kvm_type_init(void) }type_init (kvm_type_init); + +typedef struct StatsArgs { +StatsFilter *filter; +bool is_schema; +union StatsResultsType { +StatsResults *stats; +StatsSchemaResults *schema; + } result; +Error **errp; +}StatsArgs ; + +static StatsList *add_kvmstat_entry (struct kvm_stats_desc *pdesc, +uint64_t *stats_data, +StatsList *stats_list, +Error **errp) +{ + +StatsList *stats_entry; +Stats *stats; +uint64List *val_list =NULL ; + +switch (pdesc->flags &KVM_STATS_TYPE_MASK ) { +case KVM_STATS_TYPE_CUMULATIVE : +case KVM_STATS_TYPE_INSTANT : +case KVM_STATS_TYPE_PEAK : +case KVM_STATS_TYPE_LINEAR_HIST : +case KVM_STATS_TYPE_LOG_HIST : +break ; +default : +return stats_list; + } + +switch (pdesc->flags &KVM_STATS_UNIT_MASK ) { +case KVM_STATS_UNIT_NONE : +case KVM_STATS_UNIT_BYTES : +case KVM_STATS_UNIT_CYCLES : +case KVM_STATS_UNIT_SECONDS : +break ; +default : +return stats_list; + } + +switch (pdesc->flags &KVM_STATS_BASE_MASK ) { +case KVM_STATS_BASE_POW10 : +case KVM_STATS_BASE_POW2 : +break ; +default : +return stats_list; + } + +/* Alloc and populate data list */ + stats_entry =g_malloc0 (sizeof (*stats_entry)); + stats =g_malloc0 (sizeof (*stats)); + stats->name =g_strdup (pdesc->name); + stats->value =g_malloc0 (sizeof (*stats->value)); + +if (pdesc->size ==1 ) { + stats->value->u.scalar = *stats_data; + stats->value->type =QTYPE_QNUM ; + }else { +int i; +for (i =0 ; i < pdesc->size; i++) { +uint64List *val_entry =g_malloc0 (sizeof (*val_entry)); + val_entry->value = stats_data[i]; + val_entry->next = val_list; + val_list = val_entry; + } + stats->value->u.list.values = val_list; + stats->value->type =QTYPE_QDICT ; + } + + stats_entry->value = stats; + stats_entry->next = stats_list; + +return stats_entry; +} + +static StatsSchemaValueList *add_kvmschema_entry (struct kvm_stats_desc *pdesc, +StatsSchemaValueList *list, +Error **errp) +{ +StatsSchemaValueList *schema_entry =g_malloc0 (sizeof (*schema_entry)); + schema_entry->value =g_malloc0 (sizeof (*schema_entry->value)); + +switch (pdesc->flags &KVM_STATS_TYPE_MASK ) { +case KVM_STATS_TYPE_CUMULATIVE : + schema_entry->value->type =STATS_TYPE_CUMULATIVE ; +break ; +case KVM_STATS_TYPE_INSTANT : + schema_entry->value->type =STATS_TYPE_INSTANT ; +break ; +case KVM_STATS_TYPE_PEAK : + schema_entry->value->type =STATS_TYPE_PEAK ; +break ; +case KVM_STATS_TYPE_LINEAR_HIST : + schema_entry->value->type =STATS_TYPE_LINEAR_HIST ; + schema_entry->value->bucket_size = pdesc->bucket_size; + schema_entry->value->has_bucket_size = true; +break ; +case KVM_STATS_TYPE_LOG_HIST : + schema_entry->value->type =STATS_TYPE_LOG_HIST ; +break ; +default : + goto exit; + } + +switch (pdesc->flags &KVM_STATS_UNIT_MASK ) { +case KVM_STATS_UNIT_NONE : + schema_entry->value->unit =STATS_UNIT_NONE ; +break ; +case KVM_STATS_UNIT_BYTES : + schema_entry->value->unit =STATS_UNIT_BYTES ; +break ; +case KVM_STATS_UNIT_CYCLES : + schema_entry->value->unit =STATS_UNIT_CYCLES ; +break ; +case KVM_STATS_UNIT_SECONDS : + schema_entry->value->unit =STATS_UNIT_SECONDS ; +break ; +default : + goto exit; + } + +switch (pdesc->flags &KVM_STATS_BASE_MASK ) { +case KVM_STATS_BASE_POW10 : + schema_entry->value->base =STATS_BASE_POW10 ; +break ; +case KVM_STATS_BASE_POW2 : + schema_entry->value->base =STATS_BASE_POW2 ; +break ; +default : + goto exit; + } + + schema_entry->value->name =g_strdup (pdesc->name); + schema_entry->value->exponent = pdesc->exponent; + schema_entry->next = list; +return schema_entry; +exit: +g_free (schema_entry->value); +g_free (schema_entry); +return list; +} + +/* Cached stats descriptors */ +typedef struct StatsDescriptors { +char *ident;/* 'vm' or vCPU qom path */ +struct kvm_stats_desc *kvm_stats_desc; +struct kvm_stats_header *kvm_stats_header; +QTAILQ_ENTRY (StatsDescriptors) next; +}StatsDescriptors ; + +static QTAILQ_HEAD(, StatsDescriptors) stats_descriptors = +QTAILQ_HEAD_INITIALIZER (stats_descriptors); + +static StatsDescriptors *find_stats_descriptors (StatsFilter *filter) +{ +StatsDescriptors *entry; + QTAILQ_FOREACH(entry, &stats_descriptors, next) { +switch (filter->target) { +case STATS_TARGET_VM : +if (g_str_equal (entry->ident,StatsTarget_str (STATS_TARGET_VM ))) { +return entry; + } +break ; +case STATS_TARGET_VCPU : +if (g_str_equal (entry->ident, + current_cpu->parent_obj.canonical_path)) { +return entry; + } +break ; +default : +break ; + } + } +return NULL ; +} + +static void query_stats (union StatsResultsType result,StatsFilter *filter, +int stats_fd,bool is_schema,Error **errp) +{ +struct kvm_stats_desc *kvm_stats_desc; +struct kvm_stats_header *kvm_stats_header; +StatsDescriptors *descriptors; + g_autofree uint64_t *stats_data = NULL; +struct kvm_stats_desc *pdesc; +void *stats_list =NULL ; +size_t size_desc, size_data =0 ; +ssize_t ret; +int i; + + descriptors =find_stats_descriptors (filter); +if (!descriptors) { + descriptors =g_malloc0 (sizeof (*descriptors)); + +/* Read stats header */ + kvm_stats_header =g_malloc (sizeof (*kvm_stats_header)); + ret =read (stats_fd, kvm_stats_header,sizeof (*kvm_stats_header)); +if (ret !=sizeof (*kvm_stats_header)) { +error_setg (errp,"KVM stats: failed to read stats header: " +"expected %zu actual %zu" , +sizeof (*kvm_stats_header), ret); +return ; + } + size_desc =sizeof (*kvm_stats_desc) + kvm_stats_header->name_size; + +/* Read stats descriptors */ + kvm_stats_desc =g_malloc0 (kvm_stats_header->num_desc * size_desc); + ret =pread (stats_fd, kvm_stats_desc, + size_desc * kvm_stats_header->num_desc, + kvm_stats_header->desc_offset); + +if (ret != size_desc * kvm_stats_header->num_desc) { +error_setg (errp,"KVM stats: failed to read stats descriptors: " +"expected %zu actual %zu" , + size_desc * kvm_stats_header->num_desc, ret); +return ; + } + descriptors->kvm_stats_header = kvm_stats_header; + descriptors->kvm_stats_desc = kvm_stats_desc; + descriptors->ident =strdup (filter->target ==STATS_TARGET_VM ? +StatsTarget_str (STATS_TARGET_VM ) : + current_cpu->parent_obj.canonical_path); +QTAILQ_INSERT_TAIL (&stats_descriptors, descriptors, next); + }else { + kvm_stats_header = descriptors->kvm_stats_header; + kvm_stats_desc = descriptors->kvm_stats_desc; + size_desc =sizeof (*kvm_stats_desc) + kvm_stats_header->name_size; + } + +/* Tally the total data size; read schema data */ +for (i =0 ; i < kvm_stats_header->num_desc; ++i) { + pdesc = (void *)kvm_stats_desc + i * size_desc; + size_data += pdesc->size *sizeof (*stats_data); +if (is_schema) { + stats_list =add_kvmschema_entry (pdesc, (StatsSchemaValueList *) + stats_list, errp); + } + } + +/* If schema request, add the entries and return */ +if (is_schema) { +switch (filter->target) { +case STATS_TARGET_VM : +add_vm_stats_schema ((StatsSchemaValueList *)stats_list, + result.schema,STATS_PROVIDER_KVM ); +break ; +case STATS_TARGET_VCPU : +add_vcpu_stats_schema ((StatsSchemaValueList *)stats_list, + result.schema,STATS_PROVIDER_KVM ); +break ; +default : +break ; + } +return ; + } + + stats_data =g_malloc0 (size_data); + ret =pread (stats_fd, stats_data, size_data, kvm_stats_header->data_offset); + +if (ret != size_data) { +error_setg (errp,"KVM stats: failed to read data: " +"expected %zu actual %zu" , size_data, ret); +return ; + } + +for (i =0 ; i < kvm_stats_header->num_desc; ++i) { +uint64_t *stats; + pdesc = (void *)kvm_stats_desc + i * size_desc; + +/* Add entry to the list */ + stats = (void *)stats_data + pdesc->offset; +if (!stats_requested_name (pdesc->name,STATS_PROVIDER_KVM , filter)) { +continue ; + } + stats_list = +add_kvmstat_entry (pdesc, stats, (StatsList *) stats_list, errp); + } + +if (!stats_list) { +return ; + } + +switch (filter->target) { +case STATS_TARGET_VM : +add_vm_stats_entry ((StatsList *)stats_list, result.stats, +STATS_PROVIDER_KVM ); +break ; +case STATS_TARGET_VCPU : +add_vcpu_stats_entry ((StatsList *)stats_list, result.stats, +STATS_PROVIDER_KVM , + current_cpu->parent_obj.canonical_path); +break ; +default : +break ; + } +} + +static void query_stats_vcpu (CPUState *cpu,run_on_cpu_data data) +{ +StatsArgs *kvm_stats_args = (StatsArgs *) data.host_ptr; +int stats_fd =kvm_vcpu_ioctl (cpu,KVM_GET_STATS_FD ,NULL ); +Error *local_err =NULL ; + +if (stats_fd ==-1 ) { +error_setg (&local_err,"KVM stats: ioctl failed" ); +error_propagate (kvm_stats_args->errp, local_err); +return ; + } +query_stats (kvm_stats_args->result, kvm_stats_args->filter, stats_fd, + kvm_stats_args->is_schema, kvm_stats_args->errp); +close (stats_fd); +} + +static void query_stats_cb (StatsResults *stats_result,StatsFilter *filter, +Error **errp) +{ +KVMState *s = kvm_state; +CPUState *cpu; +int stats_fd; + +switch (filter->target) { +case STATS_TARGET_VM : + { +union StatsResultsType result; + result.stats = stats_result; + stats_fd =kvm_vm_ioctl (s,KVM_GET_STATS_FD ,NULL ); +if (stats_fd ==-1 ) { +error_setg (errp,"KVM stats: ioctl failed" ); +return ; + } +query_stats (result, filter, stats_fd, false, errp); +break ; + } +case STATS_TARGET_VCPU : + { + g_autofree StatsArgs *stats_args = g_malloc0(sizeof(*stats_args)); + stats_args->filter = filter; + stats_args->errp = errp; + stats_args->result.stats = stats_result; +CPU_FOREACH (cpu) { +if (!stats_requested_vcpu (cpu->parent_obj.canonical_path, +STATS_PROVIDER_KVM , filter)) { +continue ; + } +run_on_cpu (cpu, query_stats_vcpu,RUN_ON_CPU_HOST_PTR (stats_args)); + } +break ; + } +default : +break ; + } +} + +void query_stats_schemas_cb (StatsSchemaResults *stats_result,Error **errp) +{ + g_autofree StatsArgs *stats_args = g_malloc0(sizeof(*stats_args)); + g_autofree StatsFilter *filter = g_malloc0(sizeof(*filter)); +union StatsResultsType result; +KVMState *s = kvm_state; +int stats_fd; + + stats_args->filter = filter; + stats_args->errp = errp; + + result.schema = stats_result; + + stats_fd =kvm_vm_ioctl (s,KVM_GET_STATS_FD ,NULL ); +if (stats_fd ==-1 ) { +error_setg (errp,"KVM stats: ioctl failed" ); +return ; + } + + stats_args->result.schema = stats_result; + stats_args->is_schema = true; + +/* Query VM */ + stats_args->filter->target =STATS_TARGET_VM ; +query_stats (result, filter, stats_fd, true, errp); + +/* Query vCPU */ + stats_args->filter->target =STATS_TARGET_VCPU ; +run_on_cpu (first_cpu, query_stats_vcpu,RUN_ON_CPU_HOST_PTR (stats_args)); +}
qapi/stats.json +1 -1
@@ -61,7 +61,7 @@ # Since: 7.0 ## { 'enum': 'StatsProvider', - 'data': [ ] } + 'data': [ 'kvm' ] } ## # @StatsTarget:
Signature · 1 line
2.27.0