tcg: add "-accel tcg,tb-size" and deprecate "-tb-size"

-tb-size fits nicely in the new framework for accelerator-specific options.  It
is a very niche option, so insta-deprecate it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2019-11-13 15:16:44 +01:00
parent 12ceaef6ae
commit fe17413247
5 changed files with 53 additions and 11 deletions

View File

@ -34,11 +34,13 @@
#include "include/qapi/error.h" #include "include/qapi/error.h"
#include "include/qemu/error-report.h" #include "include/qemu/error-report.h"
#include "include/hw/boards.h" #include "include/hw/boards.h"
#include "qapi/qapi-builtin-visit.h"
typedef struct TCGState { typedef struct TCGState {
AccelState parent_obj; AccelState parent_obj;
bool mttcg_enabled; bool mttcg_enabled;
unsigned long tb_size;
} TCGState; } TCGState;
#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") #define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
@ -46,8 +48,6 @@ typedef struct TCGState {
#define TCG_STATE(obj) \ #define TCG_STATE(obj) \
OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
unsigned long tcg_tb_size;
/* mask must never be zero, except for A20 change call */ /* mask must never be zero, except for A20 change call */
static void tcg_handle_interrupt(CPUState *cpu, int mask) static void tcg_handle_interrupt(CPUState *cpu, int mask)
{ {
@ -126,7 +126,7 @@ static int tcg_init(MachineState *ms)
{ {
TCGState *s = TCG_STATE(current_machine->accelerator); TCGState *s = TCG_STATE(current_machine->accelerator);
tcg_exec_init(tcg_tb_size * 1024 * 1024); tcg_exec_init(s->tb_size * 1024 * 1024);
cpu_interrupt_handler = tcg_handle_interrupt; cpu_interrupt_handler = tcg_handle_interrupt;
mttcg_enabled = s->mttcg_enabled; mttcg_enabled = s->mttcg_enabled;
return 0; return 0;
@ -167,6 +167,33 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp)
} }
} }
static void tcg_get_tb_size(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
TCGState *s = TCG_STATE(obj);
uint32_t value = s->tb_size;
visit_type_uint32(v, name, &value, errp);
}
static void tcg_set_tb_size(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
TCGState *s = TCG_STATE(obj);
Error *error = NULL;
uint32_t value;
visit_type_uint32(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
return;
}
s->tb_size = value;
}
static void tcg_accel_class_init(ObjectClass *oc, void *data) static void tcg_accel_class_init(ObjectClass *oc, void *data)
{ {
AccelClass *ac = ACCEL_CLASS(oc); AccelClass *ac = ACCEL_CLASS(oc);
@ -178,6 +205,13 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
tcg_get_thread, tcg_get_thread,
tcg_set_thread, tcg_set_thread,
NULL); NULL);
object_class_property_add(oc, "tb-size", "int",
tcg_get_tb_size, tcg_set_tb_size,
NULL, NULL, &error_abort);
object_class_property_set_description(oc, "tb-size",
"TCG translation block cache size", &error_abort);
} }
static const TypeInfo tcg_accel_type = { static const TypeInfo tcg_accel_type = {

View File

@ -64,8 +64,6 @@ typedef struct AccelClass {
#define ACCEL_GET_CLASS(obj) \ #define ACCEL_GET_CLASS(obj) \
OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
extern unsigned long tcg_tb_size;
AccelClass *accel_find(const char *opt_name); AccelClass *accel_find(const char *opt_name);
int accel_init_machine(AccelState *accel, MachineState *ms); int accel_init_machine(AccelState *accel, MachineState *ms);

View File

@ -142,6 +142,12 @@ QEMU 4.1 has three options, please migrate to one of these three:
to do is specify the kernel they want to boot with the -kernel option to do is specify the kernel they want to boot with the -kernel option
3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae. 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae.
@subsection -tb-size option (since 5.0)
QEMU 5.0 introduced an alternative syntax to specify the size of the translation
block cache, @option{-accel tcg,tb-size=}. The new syntax deprecates the
previously available @option{-tb-size} option.
@section QEMU Machine Protocol (QMP) commands @section QEMU Machine Protocol (QMP) commands
@subsection change (since 2.5.0) @subsection change (since 2.5.0)

View File

@ -118,8 +118,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection)
ETEXI ETEXI
DEF("accel", HAS_ARG, QEMU_OPTION_accel, DEF("accel", HAS_ARG, QEMU_OPTION_accel,
"-accel [accel=]accelerator[,thread=single|multi]\n" "-accel [accel=]accelerator[,prop[=value][,...]]\n"
" select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n"
" tb-size=n (TCG translation block cache size)\n"
" thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL)
STEXI STEXI
@item -accel @var{name}[,prop=@var{value}[,...]] @item -accel @var{name}[,prop=@var{value}[,...]]
@ -129,6 +130,8 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th
more than one accelerator specified, the next one is used if the previous one more than one accelerator specified, the next one is used if the previous one
fails to initialize. fails to initialize.
@table @option @table @option
@item tb-size=@var{n}
Controls the size (in MiB) of the TCG translation block cache.
@item thread=single|multi @item thread=single|multi
Controls number of TCG threads. When the TCG is multi-threaded there will be one Controls number of TCG threads. When the TCG is multi-threaded there will be one
thread per vCPU therefor taking advantage of additional host cores. The default thread per vCPU therefor taking advantage of additional host cores. The default
@ -3923,7 +3926,8 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \
STEXI STEXI
@item -tb-size @var{n} @item -tb-size @var{n}
@findex -tb-size @findex -tb-size
Set TB size. Set TCG translation block cache size. Deprecated, use @samp{-accel tcg,tb-size=@var{n}}
instead.
ETEXI ETEXI
DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \

8
vl.c
View File

@ -2727,6 +2727,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
return 0; return 0;
} }
accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
object_apply_compat_props(OBJECT(accel));
qemu_opt_foreach(opts, accelerator_set_property, qemu_opt_foreach(opts, accelerator_set_property,
accel, accel,
&error_fatal); &error_fatal);
@ -2738,6 +2739,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
acc, strerror(-ret)); acc, strerror(-ret));
return 0; return 0;
} }
return 1; return 1;
} }
@ -3590,10 +3592,8 @@ int main(int argc, char **argv, char **envp)
error_report("TCG is disabled"); error_report("TCG is disabled");
exit(1); exit(1);
#endif #endif
if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) { warn_report("The -tb-size option is deprecated, use -accel tcg,tb-size instead");
error_report("Invalid argument to -tb-size"); object_register_sugar_prop(ACCEL_CLASS_NAME("tcg"), "tb-size", optarg);
exit(1);
}
break; break;
case QEMU_OPTION_icount: case QEMU_OPTION_icount:
icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),