[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 46/52] tcg: allocate optimizer temps with tcg_mal
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v7 46/52] tcg: allocate optimizer temps with tcg_malloc |
Date: |
Fri, 20 Oct 2017 16:20:17 -0700 |
From: "Emilio G. Cota" <address@hidden>
Groundwork for supporting multiple TCG contexts.
While at it, also allocate temps_used directly as a bitmap of the
required size, instead of using a bitmap of TCG_MAX_TEMPS via
TCGTempSet.
Performance-wise we lose about 1.12% in a translation-heavy workload
such as booting+shutting down debian-arm:
Performance counter stats for 'taskset -c 0 arm-softmmu/qemu-system-arm \
-machine type=virt -nographic -smp 1 -m 4096 \
-netdev user,id=unet,hostfwd=tcp::2222-:22 \
-device virtio-net-device,netdev=unet \
-drive file=die-on-boot.qcow2,id=myblock,index=0,if=none \
-device virtio-blk-device,drive=myblock \
-kernel kernel.img -append console=ttyAMA0 root=/dev/vda1 \
-name arm,debug-threads=on -smp 1' (10 runs):
exec time (s) Relative slowdown wrt original (%)
---------------------------------------------------------------
original 20.213321616 0.
tcg_malloc 20.441130078 1.1270214
TCGContext 20.477846517 1.3086662
g_malloc 20.780527895 2.8061013
The other two alternatives shown in the table are:
- TCGContext: embed temps[TCG_MAX_TEMPS] and TCGTempSet used_temps
in TCGContext. This is simple enough but it isn't faster than using
tcg_malloc; moreover, it wastes memory.
- g_malloc: allocate/deallocate both temps and used_temps every time
tcg_optimize is executed.
Suggested-by: Richard Henderson <address@hidden>
Signed-off-by: Emilio G. Cota <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
tcg/optimize.c | 42 +++++++++++++++++++-----------------------
1 file changed, 19 insertions(+), 23 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 66daced167..438321c6cc 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -40,9 +40,6 @@ struct tcg_temp_info {
tcg_target_ulong mask;
};
-static struct tcg_temp_info temps[TCG_MAX_TEMPS];
-static TCGTempSet temps_used;
-
static inline struct tcg_temp_info *ts_info(TCGTemp *ts)
{
return ts->state_ptr;
@@ -88,31 +85,27 @@ static void reset_temp(TCGArg arg)
reset_ts(arg_temp(arg));
}
-/* Reset all temporaries, given that there are NB_TEMPS of them. */
-static void reset_all_temps(int nb_temps)
-{
- bitmap_zero(temps_used.l, nb_temps);
-}
-
/* Initialize and activate a temporary. */
-static void init_ts_info(TCGTemp *ts)
+static void init_ts_info(struct tcg_temp_info *infos,
+ TCGTempSet *temps_used, TCGTemp *ts)
{
size_t idx = temp_idx(ts);
- if (!test_bit(idx, temps_used.l)) {
- struct tcg_temp_info *ti = &temps[idx];
+ if (!test_bit(idx, temps_used->l)) {
+ struct tcg_temp_info *ti = &infos[idx];
ts->state_ptr = ti;
ti->next_copy = ts;
ti->prev_copy = ts;
ti->is_const = false;
ti->mask = -1;
- set_bit(idx, temps_used.l);
+ set_bit(idx, temps_used->l);
}
}
-static void init_arg_info(TCGArg arg)
+static void init_arg_info(struct tcg_temp_info *infos,
+ TCGTempSet *temps_used, TCGArg arg)
{
- init_ts_info(arg_temp(arg));
+ init_ts_info(infos, temps_used, arg_temp(arg));
}
static int op_bits(TCGOpcode op)
@@ -611,6 +604,8 @@ void tcg_optimize(TCGContext *s)
{
int oi, oi_next, nb_temps, nb_globals;
TCGOp *prev_mb = NULL;
+ struct tcg_temp_info *infos;
+ TCGTempSet temps_used;
/* Array VALS has an element for each temp.
If this temp holds a constant then its value is kept in VALS' element.
@@ -619,7 +614,8 @@ void tcg_optimize(TCGContext *s)
nb_temps = s->nb_temps;
nb_globals = s->nb_globals;
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
+ infos = tcg_malloc(sizeof(struct tcg_temp_info) * nb_temps);
for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) {
tcg_target_ulong mask, partmask, affected;
@@ -640,14 +636,14 @@ void tcg_optimize(TCGContext *s)
for (i = 0; i < nb_oargs + nb_iargs; i++) {
TCGTemp *ts = arg_temp(op->args[i]);
if (ts) {
- init_ts_info(ts);
+ init_ts_info(infos, &temps_used, ts);
}
}
} else {
nb_oargs = def->nb_oargs;
nb_iargs = def->nb_iargs;
for (i = 0; i < nb_oargs + nb_iargs; i++) {
- init_arg_info(op->args[i]);
+ init_arg_info(infos, &temps_used, op->args[i]);
}
}
@@ -1208,7 +1204,7 @@ void tcg_optimize(TCGContext *s)
op->args[1], op->args[2]);
if (tmp != 2) {
if (tmp) {
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
op->opc = INDEX_op_br;
op->args[0] = op->args[3];
} else {
@@ -1297,7 +1293,7 @@ void tcg_optimize(TCGContext *s)
if (tmp != 2) {
if (tmp) {
do_brcond_true:
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
op->opc = INDEX_op_br;
op->args[0] = op->args[5];
} else {
@@ -1313,7 +1309,7 @@ void tcg_optimize(TCGContext *s)
/* Simplify LT/GE comparisons vs zero to a single compare
vs the high word of the input. */
do_brcond_high:
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
op->opc = INDEX_op_brcond_i32;
op->args[0] = op->args[1];
op->args[1] = op->args[3];
@@ -1339,7 +1335,7 @@ void tcg_optimize(TCGContext *s)
goto do_default;
}
do_brcond_low:
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
op->opc = INDEX_op_brcond_i32;
op->args[1] = op->args[2];
op->args[2] = op->args[4];
@@ -1459,7 +1455,7 @@ void tcg_optimize(TCGContext *s)
block, otherwise we only trash the output args. "mask" is
the non-zero bits mask for the first output arg. */
if (def->flags & TCG_OPF_BB_END) {
- reset_all_temps(nb_temps);
+ bitmap_zero(temps_used.l, nb_temps);
} else {
do_reset_output:
for (i = 0; i < nb_oargs; i++) {
--
2.13.6
- [Qemu-devel] [PATCH v7 35/52] cpu-exec: lookup/generate TB outside exclusive region during step_atomic, (continued)
- [Qemu-devel] [PATCH v7 35/52] cpu-exec: lookup/generate TB outside exclusive region during step_atomic, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 36/52] tcg: Add CF_LAST_IO + CF_USE_ICOUNT to CF_HASH_MASK, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 37/52] tcg: Remove CF_IGNORE_ICOUNT, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 39/52] exec-all: rename tb_free to tb_remove, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 38/52] translate-all: use a binary search tree to track TBs in TBContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 40/52] translate-all: report correct avg host TB size, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 41/52] tcg: take tb_ctx out of TCGContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 44/52] tcg: introduce **tcg_ctxs to keep track of all TCGContext's, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 45/52] tcg: distribute profiling counters across TCGContext's, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 42/52] tcg: define tcg_init_ctx and make tcg_ctx a pointer, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 46/52] tcg: allocate optimizer temps with tcg_malloc,
Richard Henderson <=
- [Qemu-devel] [PATCH v7 43/52] gen-icount: fold exitreq_label into TCGContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 47/52] osdep: introduce qemu_mprotect_rwx/none, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 49/52] tcg: introduce regions to split code_gen_buffer, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 50/52] tcg: enable multiple TCG contexts in softmmu, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 52/52] translate-all: exit from tb_phys_invalidate if qht_remove fails, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 48/52] translate-all: use qemu_protect_rwx/none helpers, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 51/52] tcg: Initialize cpu_env generically, Richard Henderson, 2017/10/20
- Re: [Qemu-devel] [PATCH v7 00/52] tcg queued patches, no-reply, 2017/10/20
- Re: [Qemu-devel] [PATCH v7 00/52] tcg queued patches, no-reply, 2017/10/22