All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org
Subject: [PULL for-7.1 10/36] tcg: Pass the locked filepointer to tcg_dump_ops
Date: Sun, 20 Mar 2022 10:11:09 -0700	[thread overview]
Message-ID: <20220320171135.2704502-11-richard.henderson@linaro.org> (raw)
In-Reply-To: <20220320171135.2704502-1-richard.henderson@linaro.org>

We have already looked up and locked the filepointer.
Use fprintf instead of qemu_log directly for output
in and around tcg_dump_ops.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/tcg.c | 109 ++++++++++++++++++++++++++----------------------------
 1 file changed, 52 insertions(+), 57 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 42c1620ec6..1e27367af6 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1808,7 +1808,11 @@ static inline TCGReg tcg_regset_first(TCGRegSet d)
     }
 }
 
-static void tcg_dump_ops(TCGContext *s, bool have_prefs)
+/* Return only the number of characters output -- no error return. */
+#define ne_fprintf(...) \
+    ({ int ret_ = fprintf(__VA_ARGS__); ret_ >= 0 ? ret_ : 0; })
+
+static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs)
 {
     char buf[128];
     TCGOp *op;
@@ -1824,7 +1828,7 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
 
         if (c == INDEX_op_insn_start) {
             nb_oargs = 0;
-            col += qemu_log("\n ----");
+            col += ne_fprintf(f, "\n ----");
 
             for (i = 0; i < TARGET_INSN_START_WORDS; ++i) {
                 target_ulong a;
@@ -1833,7 +1837,7 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
 #else
                 a = op->args[i];
 #endif
-                col += qemu_log(" " TARGET_FMT_lx, a);
+                col += ne_fprintf(f, " " TARGET_FMT_lx, a);
             }
         } else if (c == INDEX_op_call) {
             const TCGHelperInfo *info = tcg_call_info(op);
@@ -1844,7 +1848,7 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
             nb_iargs = TCGOP_CALLI(op);
             nb_cargs = def->nb_cargs;
 
-            col += qemu_log(" %s ", def->name);
+            col += ne_fprintf(f, " %s ", def->name);
 
             /*
              * Print the function name from TCGHelperInfo, if available.
@@ -1852,15 +1856,15 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
              * but the actual function pointer comes from the plugin.
              */
             if (func == info->func) {
-                col += qemu_log("%s", info->name);
+                col += ne_fprintf(f, "%s", info->name);
             } else {
-                col += qemu_log("plugin(%p)", func);
+                col += ne_fprintf(f, "plugin(%p)", func);
             }
 
-            col += qemu_log(",$0x%x,$%d", info->flags, nb_oargs);
+            col += ne_fprintf(f, ",$0x%x,$%d", info->flags, nb_oargs);
             for (i = 0; i < nb_oargs; i++) {
-                col += qemu_log(",%s", tcg_get_arg_str(s, buf, sizeof(buf),
-                                                       op->args[i]));
+                col += ne_fprintf(f, ",%s", tcg_get_arg_str(s, buf, sizeof(buf),
+                                                            op->args[i]));
             }
             for (i = 0; i < nb_iargs; i++) {
                 TCGArg arg = op->args[nb_oargs + i];
@@ -1868,34 +1872,32 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
                 if (arg != TCG_CALL_DUMMY_ARG) {
                     t = tcg_get_arg_str(s, buf, sizeof(buf), arg);
                 }
-                col += qemu_log(",%s", t);
+                col += ne_fprintf(f, ",%s", t);
             }
         } else {
-            col += qemu_log(" %s ", def->name);
+            col += ne_fprintf(f, " %s ", def->name);
 
             nb_oargs = def->nb_oargs;
             nb_iargs = def->nb_iargs;
             nb_cargs = def->nb_cargs;
 
             if (def->flags & TCG_OPF_VECTOR) {
-                col += qemu_log("v%d,e%d,", 64 << TCGOP_VECL(op),
-                                8 << TCGOP_VECE(op));
+                col += ne_fprintf(f, "v%d,e%d,", 64 << TCGOP_VECL(op),
+                                  8 << TCGOP_VECE(op));
             }
 
             k = 0;
             for (i = 0; i < nb_oargs; i++) {
-                if (k != 0) {
-                    col += qemu_log(",");
-                }
-                col += qemu_log("%s", tcg_get_arg_str(s, buf, sizeof(buf),
-                                                      op->args[k++]));
+                const char *sep =  k ? "," : "";
+                col += ne_fprintf(f, "%s%s", sep,
+                                  tcg_get_arg_str(s, buf, sizeof(buf),
+                                                  op->args[k++]));
             }
             for (i = 0; i < nb_iargs; i++) {
-                if (k != 0) {
-                    col += qemu_log(",");
-                }
-                col += qemu_log("%s", tcg_get_arg_str(s, buf, sizeof(buf),
-                                                      op->args[k++]));
+                const char *sep =  k ? "," : "";
+                col += ne_fprintf(f, "%s%s", sep,
+                                  tcg_get_arg_str(s, buf, sizeof(buf),
+                                                  op->args[k++]));
             }
             switch (c) {
             case INDEX_op_brcond_i32:
@@ -1910,9 +1912,9 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
             case INDEX_op_cmpsel_vec:
                 if (op->args[k] < ARRAY_SIZE(cond_name)
                     && cond_name[op->args[k]]) {
-                    col += qemu_log(",%s", cond_name[op->args[k++]]);
+                    col += ne_fprintf(f, ",%s", cond_name[op->args[k++]]);
                 } else {
-                    col += qemu_log(",$0x%" TCG_PRIlx, op->args[k++]);
+                    col += ne_fprintf(f, ",$0x%" TCG_PRIlx, op->args[k++]);
                 }
                 i = 1;
                 break;
@@ -1927,12 +1929,12 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
                     unsigned ix = get_mmuidx(oi);
 
                     if (op & ~(MO_AMASK | MO_BSWAP | MO_SSIZE)) {
-                        col += qemu_log(",$0x%x,%u", op, ix);
+                        col += ne_fprintf(f, ",$0x%x,%u", op, ix);
                     } else {
                         const char *s_al, *s_op;
                         s_al = alignment_name[(op & MO_AMASK) >> MO_ASHIFT];
                         s_op = ldst_name[op & (MO_BSWAP | MO_SSIZE)];
-                        col += qemu_log(",%s%s,%u", s_al, s_op, ix);
+                        col += ne_fprintf(f, ",%s%s,%u", s_al, s_op, ix);
                     }
                     i = 1;
                 }
@@ -1950,9 +1952,9 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
                         name = bswap_flag_name[flags];
                     }
                     if (name) {
-                        col += qemu_log(",%s", name);
+                        col += ne_fprintf(f, ",%s", name);
                     } else {
-                        col += qemu_log(",$0x%" TCG_PRIlx, flags);
+                        col += ne_fprintf(f, ",$0x%" TCG_PRIlx, flags);
                     }
                     i = k = 1;
                 }
@@ -1967,49 +1969,42 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
             case INDEX_op_brcond_i32:
             case INDEX_op_brcond_i64:
             case INDEX_op_brcond2_i32:
-                col += qemu_log("%s$L%d", k ? "," : "",
-                                arg_label(op->args[k])->id);
+                col += ne_fprintf(f, "%s$L%d", k ? "," : "",
+                                  arg_label(op->args[k])->id);
                 i++, k++;
                 break;
             default:
                 break;
             }
             for (; i < nb_cargs; i++, k++) {
-                col += qemu_log("%s$0x%" TCG_PRIlx, k ? "," : "", op->args[k]);
+                col += ne_fprintf(f, "%s$0x%" TCG_PRIlx, k ? "," : "",
+                                  op->args[k]);
             }
         }
 
         if (have_prefs || op->life) {
-
-            QemuLogFile *logfile;
-
-            rcu_read_lock();
-            logfile = qatomic_rcu_read(&qemu_logfile);
-            if (logfile) {
-                for (; col < 40; ++col) {
-                    putc(' ', logfile->fd);
-                }
+            for (; col < 40; ++col) {
+                putc(' ', f);
             }
-            rcu_read_unlock();
         }
 
         if (op->life) {
             unsigned life = op->life;
 
             if (life & (SYNC_ARG * 3)) {
-                qemu_log("  sync:");
+                ne_fprintf(f, "  sync:");
                 for (i = 0; i < 2; ++i) {
                     if (life & (SYNC_ARG << i)) {
-                        qemu_log(" %d", i);
+                        ne_fprintf(f, " %d", i);
                     }
                 }
             }
             life /= DEAD_ARG;
             if (life) {
-                qemu_log("  dead:");
+                ne_fprintf(f, "  dead:");
                 for (i = 0; life; ++i, life >>= 1) {
                     if (life & 1) {
-                        qemu_log(" %d", i);
+                        ne_fprintf(f, " %d", i);
                     }
                 }
             }
@@ -2020,28 +2015,28 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs)
                 TCGRegSet set = op->output_pref[i];
 
                 if (i == 0) {
-                    qemu_log("  pref=");
+                    ne_fprintf(f, "  pref=");
                 } else {
-                    qemu_log(",");
+                    ne_fprintf(f, ",");
                 }
                 if (set == 0) {
-                    qemu_log("none");
+                    ne_fprintf(f, "none");
                 } else if (set == MAKE_64BIT_MASK(0, TCG_TARGET_NB_REGS)) {
-                    qemu_log("all");
+                    ne_fprintf(f, "all");
 #ifdef CONFIG_DEBUG_TCG
                 } else if (tcg_regset_single(set)) {
                     TCGReg reg = tcg_regset_first(set);
-                    qemu_log("%s", tcg_target_reg_names[reg]);
+                    ne_fprintf(f, "%s", tcg_target_reg_names[reg]);
 #endif
                 } else if (TCG_TARGET_NB_REGS <= 32) {
-                    qemu_log("%#x", (uint32_t)set);
+                    ne_fprintf(f, "%#x", (uint32_t)set);
                 } else {
-                    qemu_log("%#" PRIx64, (uint64_t)set);
+                    ne_fprintf(f, "%#" PRIx64, (uint64_t)set);
                 }
             }
         }
 
-        qemu_log("\n");
+        putc('\n', f);
     }
 }
 
@@ -4207,7 +4202,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
         FILE *logfile = qemu_log_lock();
         if (logfile) {
             fprintf(logfile, "OP:\n");
-            tcg_dump_ops(s, false);
+            tcg_dump_ops(s, logfile, false);
             fprintf(logfile, "\n");
             qemu_log_unlock(logfile);
         }
@@ -4254,7 +4249,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
             FILE *logfile = qemu_log_lock();
             if (logfile) {
                 fprintf(logfile, "OP before indirect lowering:\n");
-                tcg_dump_ops(s, false);
+                tcg_dump_ops(s, logfile, false);
                 fprintf(logfile, "\n");
                 qemu_log_unlock(logfile);
             }
@@ -4277,7 +4272,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
         FILE *logfile = qemu_log_lock();
         if (logfile) {
             fprintf(logfile, "OP after optimization and liveness analysis:\n");
-            tcg_dump_ops(s, true);
+            tcg_dump_ops(s, logfile, true);
             fprintf(logfile, "\n");
             qemu_log_unlock(logfile);
         }
-- 
2.25.1



  parent reply	other threads:[~2022-03-20 17:26 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-20 17:10 [PULL for-7.1 00/36] Logging cleanup and per-thread logfiles Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 01/36] util/log: Drop manual log buffering Richard Henderson
2022-03-23 13:54   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 02/36] target/hexagon: Remove qemu_set_log in hexagon_translate_init Richard Henderson
2022-03-23 13:56   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 03/36] util/log: Pass Error pointer to qemu_set_log Richard Henderson
2022-03-20 21:50   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 04/36] os-posix: Use qemu_log_enabled Richard Henderson
2022-03-20 21:51   ` Philippe Mathieu-Daudé
2022-03-23 16:41   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 05/36] util/log: Move qemu_log_lock, qemu_log_unlock out of line Richard Henderson
2022-03-20 21:52   ` Philippe Mathieu-Daudé
2022-03-23 16:42   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 06/36] util/log: Treat qemu_log_lock like trylock Richard Henderson
2022-03-23 16:43   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 07/36] hw/xen: Split out xen_pv_output_msg Richard Henderson
2022-03-23 17:19   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 08/36] *: Use fprintf between qemu_log_lock/unlock Richard Henderson
2022-03-23 17:22   ` Alex Bennée
2022-03-23 20:46     ` Richard Henderson
2022-03-24 14:30       ` Alex Bennée
2022-03-25 15:00         ` Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 09/36] util/log: Remove qemu_log_vprintf Richard Henderson
2022-03-23 13:32   ` Alex Bennée
2022-03-23 16:36     ` Richard Henderson
2022-03-20 17:11 ` Richard Henderson [this message]
2022-03-20 17:11 ` [PULL for-7.1 11/36] exec/translator: Pass the locked filepointer to disas_log hook Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 12/36] exec/log: Remove log_disas and log_target_disas Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 13/36] accel/tcg: Use cpu_dump_state between qemu_log_lock/unlock Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 14/36] target/nios2: Remove log_cpu_state from reset Richard Henderson
2022-03-20 21:54   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 15/36] util/log: Use qemu_log_lock/unlock in qemu_log Richard Henderson
2022-03-23 17:28   ` Alex Bennée
2022-03-20 17:11 ` [PULL for-7.1 16/36] util/log: Remove qemu_log_flush Richard Henderson
2022-03-20 21:55   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 17/36] util/log: Drop call to setvbuf Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 18/36] bsd-user: Expand log_page_dump inline Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 19/36] linux-user: " Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 20/36] tests/unit: Do not reference QemuLogFile directly Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 21/36] include/exec/log: " Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 22/36] include/qemu/log: Move entire implementation out-of-line Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 23/36] sysemu/os-win32: Test for and use _lock_file/_unlock_file Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 24/36] util/log: Introduce qemu_set_log_filename_flags Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 25/36] bsd-user: Use qemu_set_log_filename_flags Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 26/36] linux-user: " Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 27/36] softmmu: " Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 28/36] util/log: Remove qemu_log_close Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 29/36] util/log: Rename logfilename to global_filename Richard Henderson
2022-03-20 21:59   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 30/36] util/log: Rename qemu_logfile to global_file Richard Henderson
2022-03-20 22:00   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 31/36] util/log: Rename qemu_logfile_mutex to global_mutex Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 32/36] util/log: Hoist the eval of is_daemonized in qemu_set_log_internal Richard Henderson
2022-03-20 21:58   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 33/36] util/log: Combine two logfile closes Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 34/36] util/log: Rename QemuLogFile to RCUCloseFILE Richard Henderson
2022-03-20 21:58   ` Philippe Mathieu-Daudé
2022-03-20 17:11 ` [PULL for-7.1 35/36] util/log: Limit RCUCloseFILE to file closing Richard Henderson
2022-03-20 17:11 ` [PULL for-7.1 36/36] util/log: Support per-thread log files Richard Henderson
2022-03-20 17:14 ` [PULL for-7.1 00/36] Logging cleanup and per-thread logfiles Richard Henderson

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=20220320171135.2704502-11-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --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.