From nobody Tue May 21 07:38:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1601415226; cv=none; d=zohomail.com; s=zohoarc; b=WKoPG3negd+3JpWu9BkNBn1tAzGHdF10cIIHDKCpbvwlu1w9+a9WTUKsXJWtwCmfhYKrc3QJElEwYq4XFWeatL6Mi/ChoDLxJCQuuh6+C5+zuUbxtTjtbnTcNvXkdHFJstEANyy2eHTiCxfjoJTemVr40+swKnjYVLqcGnfIrCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601415226; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=XA+mrk18J1sNU6j9klyWCYlrjyCnZeUHkmu4Ub5BuP4=; b=nY3Tl0wDmimKinHK6CveMQ8pHVyhqNnGqXkwVUaunKAtz0NMZTaCmaa61tSRqsS6HBS8guh4G4or6p/fwJyf7IEam1pbgTedRIO5jWBMIYDdrOAxFSqPPzYpRG4HcphrcuUhsDfXDIfEnkk+25K+XMpUxgD4Wy0hPoP2alLqUDQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601415226877221.40081860085195; Tue, 29 Sep 2020 14:33:46 -0700 (PDT) Received: from localhost ([::1]:44148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNNFp-0006WY-HJ for importer@patchew.org; Tue, 29 Sep 2020 17:33:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNNEn-00064x-Ol for qemu-devel@nongnu.org; Tue, 29 Sep 2020 17:32:43 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:33261) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNNEl-0004Oo-LO for qemu-devel@nongnu.org; Tue, 29 Sep 2020 17:32:41 -0400 Received: by mail-ed1-x532.google.com with SMTP id g4so8288711edk.0 for ; Tue, 29 Sep 2020 14:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=XA+mrk18J1sNU6j9klyWCYlrjyCnZeUHkmu4Ub5BuP4=; b=ZREOQKvCecquZR3RdjzbuCyVtrRH7ttRBXvN9uMx/9HoM8nHWkncQ+mZQ3eFP6/HG6 Qv/sffZVVSwglGaCaXwqtQmRb6bv+XdedaXEVDqLqmZk+u1g/y6YiC+swrd6++ndRXRg FaTA1oKPB5GvZyhu3lVZQElpTLaqI1oS7L9BZmPcI1tlKxTwqJIXK8AeDmVycBK7wVmL Is/hGZm07x9C1dRqHOxj4LxzLTrXgdBKHV2f6mqzmbpeeagSHDp1Up81unB5AJncXYaN 4dIOBiGctfDE6y4LkvfB3iCn+FrmfrwcCm3xtfcmoFrfSD1tGZ8hPFlEEIFOeehrii2m ZNFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=XA+mrk18J1sNU6j9klyWCYlrjyCnZeUHkmu4Ub5BuP4=; b=ksZAG4HxaHdqZukvPHwf5BQl7Ma1FX65Jevzuj3+xon1JPALWZ43/qf+h3xyDqgpgI 1iseB7C88U574IeiP4mPF2cCD3ETSPyfJ2APutej7n/LjcJGVMBgZbdKJ2ljXAXq2mrt 9gdzoB6zJOJCLJqeZFbZPx2BtGxVgD5WNrLH6nt850m9NfgUBaOQOVUq4NOPzoY+ES6b 8LtfJuHTdDdi+9XYpESRprEemeLp3Y07/v0c+U9HZkSKmjrfpfQOkHNtBlfi8LX9Ng8P skkbpNqOIoBXwFZVkzZtfj8eWmYaGl7u1HaUr0TQ7/SjpDj3TCQNjJSiSHdTcaZ8+SVn Mrhg== X-Gm-Message-State: AOAM531pnJ7YBrwGRVDbrGUYFQd81ukezBiv0QItQlXvPMAkj6F2IsMK 3h5PjuA/a7Ld9TSE4CaiH65SVqLu3Y8WOZwNqHr7eEOT/1WzxA== X-Google-Smtp-Source: ABdhPJx2GAYo6MxlRvouHtQp8zRyaGoXpW9NrCJ/FRVDKECLMXXjcLS8iIX5bWXYGg+fH2VQ/Hrd99aLKNWMtUbQpWc= X-Received: by 2002:a05:6402:1656:: with SMTP id s22mr5718478edx.160.1601415156277; Tue, 29 Sep 2020 14:32:36 -0700 (PDT) MIME-Version: 1.0 From: Owen Anderson Date: Tue, 29 Sep 2020 14:32:25 -0700 Message-ID: Subject: [RFC] Don't lookup full CPU state in the indirect branch fast path on AArch64 when running in user mode. To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=oanderso@google.com; helo=mail-ed1-x532.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: -180 X-Spam_score: -18.1 X-Spam_bar: ------------------ X-Spam_report: (-18.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.468, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hello, I would like to request feedback on the following patch, which I do not believe should be applied to master as-is. The idea here is to avoid gathering the full CPU state in the fast path of an indirect branch lookup when running in user mode on a platform where the flags can only be changed in privileged mode. I believe this is true on the AArch64 scenario that I care about, but clearly not true in general. I'm particularly seeking feedback on how to clean this up into a version that checks the correct necessary and sufficient conditions to allow all users that can benefit from it to do so. On the workload that I am targeting (aarch64 on x86), this patch reduces execution wall time by approximately 20%, and eliminates indirect branch lookups from the hot stack traces entirely. Thank you, --Owen From 3d96db17d3baacb92ef1bc5e70ef06b97d06a0ae Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 29 Sep 2020 13:47:00 -0700 Subject: [RFC] Don't lookup full CPU state in the indirect branch fast path= on AArch64 when running in user mode. Most of the CPU state can't be changed in user mode, so this is useless wor= k. Signed-off-by: Owen Anderson --- include/exec/tb-lookup.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/exec/tb-lookup.h b/include/exec/tb-lookup.h index 9cf475bb03..f4ea0eb4c0 100644 --- a/include/exec/tb-lookup.h +++ b/include/exec/tb-lookup.h @@ -25,7 +25,15 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base, TranslationBlock *tb; uint32_t hash; +#if !defined(TARGET_ARM) || !defined(CONFIG_USER_ONLY) cpu_get_tb_cpu_state(env, pc, cs_base, flags); +#else + if (is_a64(env)) { + *pc =3D env->pc; + } else { + *pc =3D env->regs[15]; + } +#endif hash =3D tb_jmp_cache_hash_func(*pc); tb =3D qatomic_rcu_read(&cpu->tb_jmp_cache[hash]); @@ -34,12 +42,19 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base, if (likely(tb && tb->pc =3D=3D *pc && +#if !defined(TARGET_ARM) || !defined(CONFIG_USER_ONLY) tb->cs_base =3D=3D *cs_base && tb->flags =3D=3D *flags && +#endif tb->trace_vcpu_dstate =3D=3D *cpu->trace_dstate && (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) =3D=3D cf_mas= k)) { return tb; } + +#ifdef CONFIG_USER_ONLY + cpu_get_tb_cpu_state(env, pc, cs_base, flags); +#endif + tb =3D tb_htable_lookup(cpu, *pc, *cs_base, *flags, cf_mask); if (tb =3D=3D NULL) { return NULL; --=20 2.28.0.709.gb0816b6eb0-goog