From patchwork Wed Apr 20 18:05:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 563971 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp4401153map; Wed, 20 Apr 2022 11:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMsqZUYnngDlB/3iLUHciAkFa2FCYYolVsm8C5QoBh8s7y4jRLmWy1g+Z8l4eC/KM3qpSg X-Received: by 2002:a5b:f0b:0:b0:63c:bd4e:2b60 with SMTP id x11-20020a5b0f0b000000b0063cbd4e2b60mr21233408ybr.473.1650478254125; Wed, 20 Apr 2022 11:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650478254; cv=none; d=google.com; s=arc-20160816; b=LCoy9wSlIQVcwi01Y74O0GsQ6wc6VntM1ZuIBNJLU/N/jd6GGI4tRw3LDRuX0kA3jZ 4edySlrpXsTmNC/nmk3Yit58wbmDti0M7iIsXrJoc6PeMWPtLf2EgEaL1Kwii2Mnp34E j5y6gKcIdl4Js6MYrdjsiW837ebFzQAvSgiV6rFp9Qx7ZuFGhnqg5vftG2xQXbmGE2U1 /sOj6vjU/sRhiw0KyhXKWMIZN6V8B2yH3Qge0aOvqfWSFtT4KNlOJWjxjbTrSsOMuPYX gya+4H36ZXwpFW+yw92SOk7/psBIpbzqv8pJk616hnmI/Cpm6r8pTGvsUrt3kyj5kHMl bdZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=D1crAV8qM3lUOm/60yk2vLKxM13f73TQkwkg3i3emao=; b=EQcPrWBfTctmaAPAnlmWB4UX68KWC3xO1MJG8L8a9zLTs57zcSIWdVeeg+M7CTl77p 0YZHAYqpO/RbfK/IMaoRPHMnwYDxPZXVXNgdpWGfe/Y77H+sk91fClNyFIdsodnvbO6R 9rxtEPx9Hp+AScv1ANvLHFelTSxV7n5/Ggr88ys1ixXp29fyk3zPDlU976QWKUURmg5H 0JtF9qibmFWDmrb11Y+d+P9HdvFgd3dtO95PBxcdj91xkl4QqkdyhboFgFwit5eZ5Nav nrOWmNU0486QVGZsh7CKXtBTLTMfrxPobGwEWtRIjxrowH9bSZ/eTVDyr3OrcvtB/3Cl 9pOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iuDHN92O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j6-20020a0de006000000b002ec31af0156si582903ywe.189.2022.04.20.11.10.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Apr 2022 11:10:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iuDHN92O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhEmz-0003pz-JK for patch@linaro.org; Wed, 20 Apr 2022 14:10:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhEik-0005Ko-Am for qemu-devel@nongnu.org; Wed, 20 Apr 2022 14:06:30 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:35564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhEii-0001BZ-6o for qemu-devel@nongnu.org; Wed, 20 Apr 2022 14:06:29 -0400 Received: by mail-pg1-x531.google.com with SMTP id r83so2340661pgr.2 for ; Wed, 20 Apr 2022 11:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D1crAV8qM3lUOm/60yk2vLKxM13f73TQkwkg3i3emao=; b=iuDHN92OkRmc8Dl3VHjD67nffHtpdQwDu8XnupGugZND+IeQFrEKgsRonfJp5vMNdn tKTb0SWFbxthpZ9pAWPPK5K+cVtDkpazkVJva9EF7fdcWPCbj/bAQj34UzXhA9nEkEg3 SDNe0mAXDMC6ghynfofrDRXd9UNpI/FqYNLZal8G1wxnEMcNryooISzpQtCEgLcEA1nt ktVp7Sac2MFItqY0M/yEG4EP9IY7lWNLNAkUVAdi8tlDPk5a2J6hWDZrze21Ht9kN2oN XRMbIccWRrmW3qxQ+sUyaLWdLRBDCsT1hYWCbWYR+1cLzkCBOCiRCLVGTpO0o62dsG5L 2aKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D1crAV8qM3lUOm/60yk2vLKxM13f73TQkwkg3i3emao=; b=cBGtmImnp3QoI/ic1RUrnhDKzXjBzAypastulssfwr1sA2t2tnbk8eWm5fKBMdFBd3 8u7CDYfG75U3892ev6WNy8PYOODWF+Iromydu22FS/roxYDVJRTfhYDjW8vNhEq154fK X7EINr+sAlQKx6JAMUXvoIxCcVyfIT6foz82kMiuJLIDKnHJAzzzG+eAIdL4RAFf3BZD WAgSKMZRyieKhsNx27rornOmN4SphcVw+wgJofDdg1RswFgWFr1umQui3Qq8Fk/TuBfA 1AHeYgsCuQvyQJZm6fS+/VO2aFXqkqSF4qm9urqW7v5MhRxK3uM3XxOY5eJcJ98RB4UY Jddw== X-Gm-Message-State: AOAM532pcugov9Z5JYpxc6ViVE1SZDH67AddbXAISWZt+evz8PW46jKI 8Epwz3OseUQTjHV2weYQ97hny173CHCmpQ== X-Received: by 2002:a05:6a02:18b:b0:399:365e:f09c with SMTP id bj11-20020a056a02018b00b00399365ef09cmr20716002pgb.238.1650477986730; Wed, 20 Apr 2022 11:06:26 -0700 (PDT) Received: from stoup.. (174-21-142-130.tukw.qwest.net. [174.21.142.130]) by smtp.gmail.com with ESMTPSA id i2-20020a17090a058200b001d2fc489b8asm56681pji.25.2022.04.20.11.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 11:06:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/39] util/log: Rename qemu_log_lock to qemu_log_trylock Date: Wed, 20 Apr 2022 11:05:46 -0700 Message-Id: <20220420180618.1183855-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220420180618.1183855-1-richard.henderson@linaro.org> References: <20220420180618.1183855-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This function can fail, which makes it more like ftrylockfile or pthread_mutex_trylock than flockfile or pthread_mutex_lock, so rename it. To closer match the other trylock functions, release rcu_read_lock along the failure path, so that qemu_log_unlock need not be called on failure. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-Id: <20220417183019.755276-8-richard.henderson@linaro.org> --- include/exec/log.h | 2 +- include/qemu/log.h | 2 +- accel/tcg/cpu-exec.c | 2 +- accel/tcg/translate-all.c | 2 +- accel/tcg/translator.c | 2 +- cpu.c | 2 +- hw/net/can/can_sja1000.c | 2 +- net/can/can_socketcan.c | 2 +- target/i386/tcg/translate.c | 2 +- tcg/tcg.c | 8 ++++---- tests/unit/test-logging.c | 2 +- util/log.c | 6 ++++-- 12 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/exec/log.h b/include/exec/log.h index 3c7fa65ead..fb595d1eb7 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -71,7 +71,7 @@ static inline void log_disas(const void *code, unsigned long size) /* page_dump() output to the log file: */ static inline void log_page_dump(const char *operation) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); if (logfile) { qemu_log("page layout changed following %s\n", operation); page_dump(logfile); diff --git a/include/qemu/log.h b/include/qemu/log.h index 6a6b1efce5..d090faf22a 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -67,7 +67,7 @@ static inline bool qemu_log_separate(void) /* Lock/unlock output. */ -FILE *qemu_log_lock(void); +FILE *qemu_log_trylock(void); void qemu_log_unlock(FILE *fd); /* Logging functions: */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 083ada76b1..f61b056571 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -214,7 +214,7 @@ static inline void log_cpu_exec(target_ulong pc, CPUState *cpu, #if defined(DEBUG_DISAS) if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); int flags = 0; if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) { diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index a6e03c1e50..5937d6b7b2 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1527,7 +1527,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && qemu_log_in_addr_range(tb->pc)) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); int code_size, data_size; const tcg_target_ulong *rx_data_gen_ptr; size_t chunk_start; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index f06c314266..1506755f3c 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -139,7 +139,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(db->pc_first)) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("----------------\n"); ops->disas_log(db, cpu); qemu_log("\n"); diff --git a/cpu.c b/cpu.c index 0fef70e18e..9db144761d 100644 --- a/cpu.c +++ b/cpu.c @@ -399,7 +399,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...) fprintf(stderr, "\n"); cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP); if (qemu_log_separate()) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("qemu: fatal: "); qemu_log_vprintf(fmt, ap2); qemu_log("\n"); diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c index 3ba803e947..300313dfb8 100644 --- a/hw/net/can/can_sja1000.c +++ b/hw/net/can/can_sja1000.c @@ -247,7 +247,7 @@ int can_sja_accept_filter(CanSJA1000State *s, static void can_display_msg(const char *prefix, const qemu_can_frame *msg) { int i; - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("%s%03X [%01d] %s %s", prefix, diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c index 4b68f60c6b..4a505643e9 100644 --- a/net/can/can_socketcan.c +++ b/net/can/can_socketcan.c @@ -76,7 +76,7 @@ QEMU_BUILD_BUG_ON(offsetof(qemu_can_frame, data) static void can_host_socketcan_display_msg(struct qemu_can_frame *msg) { int i; - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("[cansocketcan]: %03X [%01d] %s %s", msg->can_id & QEMU_CAN_EFF_MASK, msg->can_dlc, diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 3ba1c99fff..f3cffee520 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2580,7 +2580,7 @@ static void gen_unknown_opcode(CPUX86State *env, DisasContext *s) gen_illegal_opcode(s); if (qemu_loglevel_mask(LOG_UNIMP)) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); target_ulong pc = s->pc_start, end = s->pc; qemu_log("ILLOPC: " TARGET_FMT_lx ":", pc); diff --git a/tcg/tcg.c b/tcg/tcg.c index f8542529d0..abe4ef7799 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -756,7 +756,7 @@ void tcg_prologue_init(TCGContext *s) #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("PROLOGUE: [size=%zu]\n", prologue_size); if (s->data_gen_ptr) { size_t code_size = s->data_gen_ptr - s->code_gen_ptr; @@ -4200,7 +4200,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) && qemu_log_in_addr_range(tb->pc))) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("OP:\n"); tcg_dump_ops(s, false); qemu_log("\n"); @@ -4245,7 +4245,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_IND) && qemu_log_in_addr_range(tb->pc))) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("OP before indirect lowering:\n"); tcg_dump_ops(s, false); qemu_log("\n"); @@ -4266,7 +4266,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT) && qemu_log_in_addr_range(tb->pc))) { - FILE *logfile = qemu_log_lock(); + FILE *logfile = qemu_log_trylock(); qemu_log("OP after optimization and liveness analysis:\n"); tcg_dump_ops(s, true); qemu_log("\n"); diff --git a/tests/unit/test-logging.c b/tests/unit/test-logging.c index d071400ebc..4c595356ae 100644 --- a/tests/unit/test-logging.c +++ b/tests/unit/test-logging.c @@ -162,7 +162,7 @@ static void test_logfile_lock(gconstpointer data) * our handle remains valid for use due to RCU. */ qemu_set_log_filename(file_path, &error_abort); - logfile = qemu_log_lock(); + logfile = qemu_log_trylock(); g_assert(logfile); fprintf(logfile, "%s 1st write to file\n", __func__); fflush(logfile); diff --git a/util/log.c b/util/log.c index 1a3121610a..6b7b358573 100644 --- a/util/log.c +++ b/util/log.c @@ -36,15 +36,17 @@ static GArray *debug_regions; /* Lock/unlock output. */ -FILE *qemu_log_lock(void) +FILE *qemu_log_trylock(void) { QemuLogFile *logfile; + rcu_read_lock(); logfile = qatomic_rcu_read(&qemu_logfile); if (logfile) { qemu_flockfile(logfile->fd); return logfile->fd; } else { + rcu_read_unlock(); return NULL; } } @@ -53,8 +55,8 @@ void qemu_log_unlock(FILE *fd) { if (fd) { qemu_funlockfile(fd); + rcu_read_unlock(); } - rcu_read_unlock(); } /* Return the number of characters emitted. */