From patchwork Fri Oct 19 06:06:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 149224 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2907829lji; Thu, 18 Oct 2018 23:13:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Dd1NbooRn2UyiYetbPb1SoAKvmcSgA1fIHGMt02W7laluMX7KjcEFsCE8OsaPpG5+3ysc X-Received: by 2002:a0c:d606:: with SMTP id c6mr10615892qvj.230.1539929584177; Thu, 18 Oct 2018 23:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539929584; cv=none; d=google.com; s=arc-20160816; b=YX2z9k9Dwh2Vuit3N2MwXBEYvyyHHbc85d+qjFEepSm23nyIsZqrmBGrAv+9N510nX OJYoOLIf+hgJUjM2YXataQQZcWcMjYGb3Lh+14wHXHp71C/qlsCEl3s2cgUxHI+P08hR j0F75eg2oRPwuYsCmTfuoZvNY7N3qvSzReRgE+frIgq5xT7obWTgBW7/cLSKH0BA0nlQ XbEIzwDZWBf+PHsN0rZtXLN778diAdhQqsQPEaqX2kpJWNpgflp6QPLNf6MPFqJG9g1R wfTI67yB5tPWGqWb1hnSPkwPPMT9ZlA+GVR8Ivx1+hzJWimAoFaGr0Pyag7gpYAFC36p KAww== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=TgDCiAlCqNyacH51QEaK7ppBxrOCvC2iTKIGNr6fsnY=; b=iW1FjpA4lmAF0GmH+vsCEDZXOpbrGebvf/PIBVri9yAjFAcM/BHUDT71ZVa6dR8uyM vhZpsPKSG4S2Qiql3FoBXUn1priWGZgEP2TULyvb4hQCa3BD2MxVO2gwBmk8OQq3qaub GuHrd7y53wA063cDWuFOIiVcOeCG516SoSkhBi7ESMeOIvSVto9x35TFMEQpaBRT2jYi Bgf4KuSHPx7CjD9WEqeW8XpKH9rorlGaTMQY7ilChwlAe5tmn9Rb3V3slVAPT/EtFJcg DGIgHOdxS3hVxXOVu1LjHR37zODbndApyKO0cqtswF040qU7LygPryRKEVZM/DQvaX6W /JPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=haQ8xveq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b44-v6si7879946qte.363.2018.10.18.23.13.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 18 Oct 2018 23:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=haQ8xveq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDO1v-0001OA-GG for patch@linaro.org; Fri, 19 Oct 2018 02:13:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDNwD-00040e-Gc for qemu-devel@nongnu.org; Fri, 19 Oct 2018 02:07:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDNwB-00020K-Iz for qemu-devel@nongnu.org; Fri, 19 Oct 2018 02:07:09 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:46866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDNwB-0001yl-3S for qemu-devel@nongnu.org; Fri, 19 Oct 2018 02:07:07 -0400 Received: by mail-pf1-x441.google.com with SMTP id r64-v6so15987817pfb.13 for ; Thu, 18 Oct 2018 23:07:06 -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; bh=TgDCiAlCqNyacH51QEaK7ppBxrOCvC2iTKIGNr6fsnY=; b=haQ8xveqFl3z22Q7dFPyS0127ruPQ25+sTF+GHRzWc/YC2iNhVrw6B/AfIVRqBzbEh Jm9+kSijWVKCqj8HgYQ7w9VZUOeERl9f2e/4++MGzyDLNDzV/QgryaBmMvqrXZcVm7FU UQxkGPApZ9Sut2iv953kuCKZ24a54jwhGv8YU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TgDCiAlCqNyacH51QEaK7ppBxrOCvC2iTKIGNr6fsnY=; b=Evq8EIow8XetGg2lY1ce8w6JfHDNbIQg/cjfvnEYzT6XFSuLQhm2veGKB6xyBSyCQd r5QXZziiLMvLA4mzMHXK9EmFtBz2V+lIp3dnl+KHXSlwWarUTMBRCwhK0+DJB/OmWWDf u/f2GTuD8MNBKuQjhkTA+obgshy5zeRdoJA/+wGE0M+CjaG98SLsM7Y9cmSpHl/ErwBT tyyJFx8XijQrX0zopdi1Q8bP5OYyI59dKa8t9w43pFbjeIG80P1JtJgUtIO0qET8tSDC JJjQidBu4n42Ohvai6O3a5wBbdui4+kkUsAyo8YJBbdaSG5lmvCJfC4Qg5D8623U3J1Z svFw== X-Gm-Message-State: ABuFfoguXAmvtV6WofcPhObY8HjPX6i7KbjCdjOxS+W0EfDG5sGQe4EC h2bZs96OpB96KJoOrLCswb8wGe98/7E= X-Received: by 2002:a62:42d4:: with SMTP id h81-v6mr34220583pfd.0.1539929225613; Thu, 18 Oct 2018 23:07:05 -0700 (PDT) Received: from cloudburst.twiddle.net (174-21-9-133.tukw.qwest.net. [174.21.9.133]) by smtp.gmail.com with ESMTPSA id q24-v6sm25609327pff.83.2018.10.18.23.07.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Oct 2018 23:07:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 23:06:40 -0700 Message-Id: <20181019060656.7968-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181019060656.7968-1-richard.henderson@linaro.org> References: <20181019060656.7968-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PULL v2 05/21] tcg: distribute tcg_time into TCG contexts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" When we implemented per-vCPU TCG contexts, we forgot to also distribute the tcg_time counter, which has remained as a global accessed without any serialization, leading to potentially missed counts. Fix it by distributing the field over the TCG contexts, embedding it into TCGProfile with a field called "cpu_exec_time", which is more descriptive than "tcg_time". Add a function to query this value directly, and for completeness, fill in the field in tcg_profile_snapshot, even though its callers do not use it. Signed-off-by: Emilio G. Cota Message-Id: <20181010144853.13005-5-cota@braap.org> Signed-off-by: Richard Henderson --- include/qemu/timer.h | 1 - tcg/tcg.h | 2 ++ cpus.c | 3 ++- monitor.c | 13 ++++++++++--- tcg/tcg.c | 23 +++++++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) -- 2.17.2 diff --git a/include/qemu/timer.h b/include/qemu/timer.h index a005ed2692..dfecd03e28 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -1046,7 +1046,6 @@ static inline int64_t profile_getclock(void) return get_clock(); } -extern int64_t tcg_time; extern int64_t dev_time; #endif diff --git a/tcg/tcg.h b/tcg/tcg.h index d80ef2a883..c59f254e27 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -629,6 +629,7 @@ typedef struct TCGOp { QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); typedef struct TCGProfile { + int64_t cpu_exec_time; int64_t tb_count1; int64_t tb_count; int64_t op_count; /* total insn count */ @@ -1002,6 +1003,7 @@ int tcg_check_temp_count(void); #define tcg_check_temp_count() 0 #endif +int64_t tcg_cpu_exec_time(void); void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf); void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf); diff --git a/cpus.c b/cpus.c index 361678e459..cce64874e6 100644 --- a/cpus.c +++ b/cpus.c @@ -1425,7 +1425,8 @@ static int tcg_cpu_exec(CPUState *cpu) ret = cpu_exec(cpu); cpu_exec_end(cpu); #ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; + atomic_set(&tcg_ctx->prof.cpu_exec_time, + tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti); #endif return ret; } diff --git a/monitor.c b/monitor.c index b9258a7438..823b5a1099 100644 --- a/monitor.c +++ b/monitor.c @@ -83,6 +83,7 @@ #include "sysemu/cpus.h" #include "sysemu/iothread.h" #include "qemu/cutils.h" +#include "tcg/tcg.h" #if defined(TARGET_S390X) #include "hw/s390x/storage-keys.h" @@ -1966,16 +1967,22 @@ static void hmp_info_numa(Monitor *mon, const QDict *qdict) #ifdef CONFIG_PROFILER -int64_t tcg_time; int64_t dev_time; static void hmp_info_profile(Monitor *mon, const QDict *qdict) { + static int64_t last_cpu_exec_time; + int64_t cpu_exec_time; + int64_t delta; + + cpu_exec_time = tcg_cpu_exec_time(); + delta = cpu_exec_time - last_cpu_exec_time; + monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", dev_time, dev_time / (double)NANOSECONDS_PER_SECOND); monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", - tcg_time, tcg_time / (double)NANOSECONDS_PER_SECOND); - tcg_time = 0; + delta, delta / (double)NANOSECONDS_PER_SECOND); + last_cpu_exec_time = cpu_exec_time; dev_time = 0; } #else diff --git a/tcg/tcg.c b/tcg/tcg.c index 8f26916b99..e85133ef05 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -30,6 +30,7 @@ /* Define to jump the ELF file used to communicate with GDB. */ #undef DEBUG_JIT +#include "qemu/error-report.h" #include "qemu/cutils.h" #include "qemu/host-utils.h" #include "qemu/timer.h" @@ -3361,6 +3362,7 @@ void tcg_profile_snapshot(TCGProfile *prof, bool counters, bool table) const TCGProfile *orig = &s->prof; if (counters) { + PROF_ADD(prof, orig, cpu_exec_time); PROF_ADD(prof, orig, tb_count1); PROF_ADD(prof, orig, tb_count); PROF_ADD(prof, orig, op_count); @@ -3412,11 +3414,32 @@ void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf) prof.table_op_count[i]); } } + +int64_t tcg_cpu_exec_time(void) +{ + unsigned int n_ctxs = atomic_read(&n_tcg_ctxs); + unsigned int i; + int64_t ret = 0; + + for (i = 0; i < n_ctxs; i++) { + const TCGContext *s = atomic_read(&tcg_ctxs[i]); + const TCGProfile *prof = &s->prof; + + ret += atomic_read(&prof->cpu_exec_time); + } + return ret; +} #else void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf) { cpu_fprintf(f, "[TCG profiler not compiled]\n"); } + +int64_t tcg_cpu_exec_time(void) +{ + error_report("%s: TCG profiler not compiled", __func__); + exit(EXIT_FAILURE); +} #endif