Message ID | 20201116131011.26607-6-r.bolshakov@yadro.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add HMP/QMP commands to query accelerator | expand |
* Roman Bolshakov (r.bolshakov@yadro.com) wrote: > The command is made after 'info kvm' and aims to replace it as more > generic one. > > If used without parameters, the command can used to get current > accelerator. Otherwise, it may be used to determine if an accelerator is > available. Here's an example if a VM with hvf accel is started: > > (qemu) info accel > hvf support: enabled > (qemu) info accel kvm > kvm support: not compiled > (qemu) info accel tcg > tcg support: disabled > > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> > --- > hmp-commands-info.hx | 13 +++++++++++++ > include/monitor/hmp.h | 1 + > monitor/hmp-cmds.c | 32 ++++++++++++++++++++++++++++++++ > 3 files changed, 46 insertions(+) > > diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx > index 117ba25f91..e9da6b52e4 100644 > --- a/hmp-commands-info.hx > +++ b/hmp-commands-info.hx > @@ -337,6 +337,19 @@ SRST > Show KVM information. > ERST > > + { > + .name = "accel", > + .args_type = "name:s?", > + .params = "[name]", > + .help = "show accelerator information", > + .cmd = hmp_info_accel, > + }, > + > +SRST > + ``info accel``` [*name*] > + Show accelerator information. > +ERST > + > { > .name = "numa", > .args_type = "", > diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h > index ed2913fd18..03f22957d9 100644 > --- a/include/monitor/hmp.h > +++ b/include/monitor/hmp.h > @@ -21,6 +21,7 @@ void hmp_handle_error(Monitor *mon, Error *err); > void hmp_info_name(Monitor *mon, const QDict *qdict); > void hmp_info_version(Monitor *mon, const QDict *qdict); > void hmp_info_kvm(Monitor *mon, const QDict *qdict); > +void hmp_info_accel(Monitor *mon, const QDict *qdict); > void hmp_info_status(Monitor *mon, const QDict *qdict); > void hmp_info_uuid(Monitor *mon, const QDict *qdict); > void hmp_info_chardev(Monitor *mon, const QDict *qdict); > diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c > index ea86289fe8..00db791aa3 100644 > --- a/monitor/hmp-cmds.c > +++ b/monitor/hmp-cmds.c > @@ -20,6 +20,7 @@ > #include "chardev/char.h" > #include "sysemu/block-backend.h" > #include "sysemu/runstate.h" > +#include "sysemu/accel.h" > #include "qemu/config-file.h" > #include "qemu/option.h" > #include "qemu/timer.h" > @@ -133,6 +134,37 @@ void hmp_info_kvm(Monitor *mon, const QDict *qdict) > qapi_free_AccelInfo(info); > } > > +void hmp_info_accel(Monitor *mon, const QDict *qdict) > +{ > + AccelInfo *info; > + AccelClass *acc; > + const char *name, *typename; > + char *current_name; > + int len; > + > + /* Figure out current accelerator */ > + acc = ACCEL_GET_CLASS(current_accel()); Is that always guaranteed non-null? > + typename = object_class_get_name(OBJECT_CLASS(acc)); > + len = strlen(typename) - strlen(ACCEL_CLASS_SUFFIX); > + current_name = g_strndup(typename, len); > + > + name = qdict_get_try_str(qdict, "name"); > + if (!name) { > + name = current_name; > + } > + > + info = qmp_query_accel(name, NULL); > + monitor_printf(mon, "%s support: ", name); > + if (info->present) { > + monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); > + } else { > + monitor_printf(mon, "not compiled\n"); > + } > + > + qapi_free_AccelInfo(info); > + g_free(current_name); > +} I think that's fine, since HMP is not guaranteed stable, I'd say it's fine to kill off 'info kvm' and replace it with this. Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Dave > + > void hmp_info_status(Monitor *mon, const QDict *qdict) > { > StatusInfo *info; > -- > 2.29.2 >
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 117ba25f91..e9da6b52e4 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -337,6 +337,19 @@ SRST Show KVM information. ERST + { + .name = "accel", + .args_type = "name:s?", + .params = "[name]", + .help = "show accelerator information", + .cmd = hmp_info_accel, + }, + +SRST + ``info accel``` [*name*] + Show accelerator information. +ERST + { .name = "numa", .args_type = "", diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index ed2913fd18..03f22957d9 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -21,6 +21,7 @@ void hmp_handle_error(Monitor *mon, Error *err); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); +void hmp_info_accel(Monitor *mon, const QDict *qdict); void hmp_info_status(Monitor *mon, const QDict *qdict); void hmp_info_uuid(Monitor *mon, const QDict *qdict); void hmp_info_chardev(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index ea86289fe8..00db791aa3 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -20,6 +20,7 @@ #include "chardev/char.h" #include "sysemu/block-backend.h" #include "sysemu/runstate.h" +#include "sysemu/accel.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/timer.h" @@ -133,6 +134,37 @@ void hmp_info_kvm(Monitor *mon, const QDict *qdict) qapi_free_AccelInfo(info); } +void hmp_info_accel(Monitor *mon, const QDict *qdict) +{ + AccelInfo *info; + AccelClass *acc; + const char *name, *typename; + char *current_name; + int len; + + /* Figure out current accelerator */ + acc = ACCEL_GET_CLASS(current_accel()); + typename = object_class_get_name(OBJECT_CLASS(acc)); + len = strlen(typename) - strlen(ACCEL_CLASS_SUFFIX); + current_name = g_strndup(typename, len); + + name = qdict_get_try_str(qdict, "name"); + if (!name) { + name = current_name; + } + + info = qmp_query_accel(name, NULL); + monitor_printf(mon, "%s support: ", name); + if (info->present) { + monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); + } else { + monitor_printf(mon, "not compiled\n"); + } + + qapi_free_AccelInfo(info); + g_free(current_name); +} + void hmp_info_status(Monitor *mon, const QDict *qdict) { StatusInfo *info;
The command is made after 'info kvm' and aims to replace it as more generic one. If used without parameters, the command can used to get current accelerator. Otherwise, it may be used to determine if an accelerator is available. Here's an example if a VM with hvf accel is started: (qemu) info accel hvf support: enabled (qemu) info accel kvm kvm support: not compiled (qemu) info accel tcg tcg support: disabled Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- hmp-commands-info.hx | 13 +++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+)