From patchwork Fri Jun 5 17:34:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187567 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp2588326ilo; Fri, 5 Jun 2020 10:42:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy99jQoPC3L8yFId+dtQ7oZHrmt2FpiviAHk2MgM5v2RlgnMfRCk+RCk3PvXU96iot7s3g2 X-Received: by 2002:a25:2e48:: with SMTP id b8mr16281872ybn.56.1591378973179; Fri, 05 Jun 2020 10:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591378973; cv=none; d=google.com; s=arc-20160816; b=dCwn2e4dSc6kBLXlyWxefdvADrrrsMPPplmWjD632qAWz4X/4zBz+eLkDxy6oe2lJ6 2y4jJRju+5m5zlxo/0/j0YVB3tIZCPgZzcZmbZfZDYZU1nLVDj2ellId5TTM9GPxCMF5 n29JQtTQ+K8PjohIHrgj+djsowUd8m6+kavVC1JQiDowVV+lVtK5yjFg09EcMgwntvSH iNEa1SLw+ZhizTUakKjGvzAl66xgYxBJc38xHbHnTRhYgrOku8qMSMEKNbfYL0+/eEW4 oapdyMuU0BqDBvUQY/WaPsIk9URYZSqmhpzH3IgnfYkX47EBSkcKZ9fbAzsu7Ciy4iyD a4LA== 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:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=RacwspMU1aiCw26khXDltgXnqBmBxJ7+lFvKXbJihlsEStHex0GrlsX6iJPu7i7GYo E83HUdl6k6aIK1DUlBsMsln4qnMs7wltSMndWYUkAePHuZL1b4h7nFMQAVeyXwLGCIhJ 507so2ZdOhPDnQsKA5fzanatPhpMMDZrEC4G8SoqXqkYeTOec5bJyLXs0f2NdHvjy9SP CblIPgXSK3vKYfxzFtMVE3liseSuYBJo6ZpdAirf7zMvZyjkeI+xsebEW3Wi3Vb99GLJ 8u9NJFeDUPuwJUZLg//ORyoZ3Z9mtQJkEDI1ZOJJDEka40d1K7hR+/Wbm0LgiO8euJaz Aumg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fAjq30UD; 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=fail (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 z8si7271611ybm.9.2020.06.05.10.42.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jun 2020 10:42:53 -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=fail header.i=@linaro.org header.s=google header.b=fAjq30UD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGMm-0003eA-MC for patch@linaro.org; Fri, 05 Jun 2020 13:42:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHq-0003iZ-Vx for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:47 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:33988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHq-0003rm-1Z for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:46 -0400 Received: by mail-pg1-x543.google.com with SMTP id m1so5553648pgk.1 for ; Fri, 05 Jun 2020 10:37:45 -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=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=fAjq30UDfRMczkw9kAgAOc6e/2WHU9tQNAZohYKObI8yjhCUJDNKtU0JxMztVwR0OB /HSFNlmaBLgOvl8dy4+/Mos9gNtcdMFNkL1rAFRxP8jdxhMFYovTwmY1sIrgd1NdXPNA IijlFVKNqHfATy/OT9vnu4XWp17zi+A4Adbz2+9JragalNkcTO+qjnCY4Vh8Cl/e2IV8 p19Vr1MGmAZzfxQBVSutZYxf4JSiTAYL6AK3oRJivuHleKBFO6hFm7+OhbZn8U8v3MLq 1tgxRkRG1tqAPPbkSMbbubvNPRC5IkXt2ce+aHU3kRLUcIJHosCPnuh2Qw4lCSL/Ay8P B3BQ== 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=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=GPZCma/BSLqO0lhLcUqyN1ZhafvN/52WzZxERXboLQYJQiE/mKPQ9tZHO2AU9XlyAE HkLyOiVXulpoqLssfZS4CK61/EoaKYNqSFYRN9d8koYXvQdrNxwh6E9t7sKzwqPOCozn xSW/HL6q0VWvsl6FE4k1D4yP1iFjnsmmnSx6daBbmQFZB/aq87bYJJ+3MElBvMUnoWXC 8SMskFOG0j8FMgRYALoWxstbhSD4ytGQ5iWYzOpJO1RjGT55+iPm/beohkI4koBtJ9dV ESoPs8SoNjIHxQuLGj8oHDXign8qlBrH7Vcw6wU5ob1LNzZFEnVZEmhpdT13ISXi1rO4 a0uQ== X-Gm-Message-State: AOAM530l/Hv/tz/auD2gm0nhEhFr7GQm883wTH9V0l0PZpA5QmicSvW5 2Dc9XKl8AdXs/ZzVwHtPjeSEBSJ7beQOBg== X-Received: by 2002:a63:f91b:: with SMTP id h27mr10442676pgi.276.1591378664440; Fri, 05 Jun 2020 10:37:44 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:43 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 06/13] tcg: call qemu_spin_destroy for tb->jmp_lock Date: Fri, 5 Jun 2020 13:34:15 -0400 Message-Id: <20200605173422.1490-7-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley [RF: Minor changes to fix some checkpatch errors] --- accel/tcg/translate-all.c | 10 +++++++++- include/tcg/tcg.h | 3 ++- tcg/tcg.c | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..3708aab36b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -384,6 +384,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, return 0; } +static void tb_destroy(TranslationBlock *tb) +{ + qemu_spin_destroy(&tb->jmp_lock); +} + bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) { TranslationBlock *tb; @@ -413,6 +418,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) /* one-shot translation, invalidate it immediately */ tb_phys_invalidate(tb, -1); tcg_tb_remove(tb); + tb_destroy(tb); } r = true; } @@ -1230,7 +1236,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); - tcg_region_reset_all(); + tcg_region_reset_all(tb_destroy); /* XXX: flush processor icache at this point if cache flush is expensive */ atomic_mb_set(&tb_ctx.tb_flush_count, tb_ctx.tb_flush_count + 1); @@ -1886,6 +1892,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize); atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); + tb_destroy(tb); return existing_tb; } tcg_tb_insert(tb); @@ -2235,6 +2242,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) tb_phys_invalidate(tb->orig_tb, -1); } tcg_tb_remove(tb); + tb_destroy(tb); } /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 380014ed80..c8313fdcf0 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -818,8 +818,9 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); +typedef void (*tb_destroy_func)(TranslationBlock *tb); void tcg_region_init(void); -void tcg_region_reset_all(void); +void tcg_region_reset_all(tb_destroy_func tb_destroy); size_t tcg_code_size(void); size_t tcg_code_capacity(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index 1aa6cb47f2..7ae9dd7cf8 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -502,7 +502,16 @@ size_t tcg_nb_tbs(void) return nb_tbs; } -static void tcg_region_tree_reset_all(void) +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) +{ + TranslationBlock *tb = v; + tb_destroy_func tb_destroy = data; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(tb_destroy_func tb_destroy) { size_t i; @@ -510,6 +519,10 @@ static void tcg_region_tree_reset_all(void) for (i = 0; i < region.n; i++) { struct tcg_region_tree *rt = region_trees + i * tree_size; + if (tb_destroy != NULL) { + g_tree_foreach(rt->tree, tcg_region_tree_traverse, tb_destroy); + } + /* Increment the refcount first so that destroy acts as a reset */ g_tree_ref(rt->tree); g_tree_destroy(rt->tree); @@ -586,7 +599,7 @@ static inline bool tcg_region_initial_alloc__locked(TCGContext *s) } /* Call from a safe-work context */ -void tcg_region_reset_all(void) +void tcg_region_reset_all(tb_destroy_func tb_destroy) { unsigned int n_ctxs = atomic_read(&n_tcg_ctxs); unsigned int i; @@ -603,7 +616,7 @@ void tcg_region_reset_all(void) } qemu_mutex_unlock(®ion.lock); - tcg_region_tree_reset_all(); + tcg_region_tree_reset_all(tb_destroy); } #ifdef CONFIG_USER_ONLY