Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6196512rwb; Mon, 5 Dec 2022 09:05:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Lkq5IZJ1erdvLLAvhr0tLQcW63qrIxL1a+ZIodxI2JxYXIk6W/ZX63Tn8RJSJ97kg7t+G X-Received: by 2002:a17:906:ae4c:b0:7c0:cc80:8eba with SMTP id lf12-20020a170906ae4c00b007c0cc808ebamr10563853ejb.576.1670259923771; Mon, 05 Dec 2022 09:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670259923; cv=none; d=google.com; s=arc-20160816; b=ZHWYPEsZX4o1ElPXGn2UDgo0DKbr6WrcLK/jqn/IOOSNzShFzg8twYG664VSZp1hu7 IC55fFf+QpXhv+UQqlka2YCPYjoX4TYi5wnWNlXXsmq9JKkrvUx/ocVJSuwynTnz2SdZ afPkjP4g2uAzfRst2vLhiw2bi6ZEdy0b4m51mt4JLmWEHnJNT5ZB/X0zJti1c7or3jok rI0RuCElULhuf9BGBP8pJIZ/XQ1oAeCNC4qh2IscQShg97Vrn15D526YFtSl5AtOAj2W n6kA+v/hArn5pgSE0WP/9FUHKWkH8JuA8xdLbhpELLNgdtlVAnvh2EMJOK9Iy++5wSBi do7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wBuKcoM+BgmLWxWnn53uMMW9saBlJ8h0l5lioV+cxtw=; b=s9eoBonjWoPk6Mo0ASbXtEnZ5YsCd65fJ60zOipNWcgAONMJqK+Jbc+RNtrqc3Xtsu 0QTtM+SuuEhg3hqY8o2S7y2hqnPFISGzwKtmPjkNd8AwW9DAaeV8m2lRYKRNUqmas089 rawHojy5LrbQkUuj24QSh5rHXi605kUb68vkW5JqTTdCgqQFsGIdMGsDx3pvXoBipD9w 79IboQNzyRnfIj2i/rRu7REY4DOTGoWwXY3eBNFhHv04aBti6B/0NtgM54U0BP4Xrbna xw1O7ROKWowWacoZbd2oCh3NfbsiRZNWYnnv6LCI+6hNojq6Fvi5pNfGAZDAh2OUdnDc LZPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Yp/LshZj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc44-20020a17090716ac00b007c0dcb2ee45si4982248ejc.721.2022.12.05.09.04.55; Mon, 05 Dec 2022 09:05:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Yp/LshZj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbiLEQsP (ORCPT + 82 others); Mon, 5 Dec 2022 11:48:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232160AbiLEQrs (ORCPT ); Mon, 5 Dec 2022 11:47:48 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6921C1ADB8 for ; Mon, 5 Dec 2022 08:46:43 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id a14so7897109pfa.1 for ; Mon, 05 Dec 2022 08:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wBuKcoM+BgmLWxWnn53uMMW9saBlJ8h0l5lioV+cxtw=; b=Yp/LshZjsu5TY0+uEvPakxJqPBNW2xM8WfoaH2AN1/LuHVAa08gwyLQZzwHQYU7pp9 xaDAYlbhc1LHIJUSvT8Ipf1HLNYMZ+AAWtss21LwMl5y2RZR/QhpYncpNEQiGWoL/JSt 1IDg90fFHi0yENcoH2Oa/BhGz98n16svoHFxifSrnZEHHYFmr7sAL87gD9maRFNG4wPN w1ZKk5fLVw2Bs/16xWl05TfqhVy00n0e1yEhEb87Qs+J5AMCDAra/Vrhq1n3RVj8T9On XG2kS6/njA1UQC1cB8vbcukLWgPRohnQO37Bf2UtQoFgNaVmLCghXjpoDHblaoVlPmY8 5Mww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wBuKcoM+BgmLWxWnn53uMMW9saBlJ8h0l5lioV+cxtw=; b=jPTQRQaWwR6G6HlKVOKoRRHHOK5Cmss8u/r48r788YksjPoXcjEQeBuAJe8pA5Mzmh 2vqGCVS3pnFNeh5uVncnCT0opoX5ADof+/mdMP5i3YGflnXk/nT+kxbsxk24CAFLaytu ktMXL8vXt9uOf0aq7nKJsQmZGlHqFzPX079nMYtvKFZQHRC9H84UXHUimwZVokHycmj2 HwuHeccPGZ838Ay97yb0e2nYqolq+JFGp8f97KOoF7sz6YK3qLi5INmkFr8V5yLbe+rU rCTGTilhU8qviJxYeu746ZXa+YQ2xps8YQ+Q12KwrsJKOAO62mligvPei/zfq9E/hqtP ljfQ== X-Gm-Message-State: ANoB5plU/hGsW3p4QCYVtKI2ra3rXp6PUB+C48utkN8xtWjxpyTkXZlc oG9mAG7uQZS+B9iYl3/nLs9EOA== X-Received: by 2002:a63:ec45:0:b0:470:4320:ef39 with SMTP id r5-20020a63ec45000000b004704320ef39mr56788543pgj.381.1670258802815; Mon, 05 Dec 2022 08:46:42 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id n3-20020a170902dc8300b00189a50d2a3esm10749267pld.241.2022.12.05.08.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 08:46:42 -0800 (PST) Date: Mon, 5 Dec 2022 16:46:38 +0000 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86/pmu: Avoid ternary operator by directly referring to counters->type Message-ID: References: <20221205113718.1487-1-likexu@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221205113718.1487-1-likexu@tencent.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 05, 2022, Like Xu wrote: > From: Like Xu > > In either case, the counters will point to fixed or gp pmc array, and > taking advantage of the C pointer, it's reasonable to use an almost known > mem load operation directly without disturbing the branch predictor. The compiler is extremely unlikely to generate a branch for this, e.g. gcc-12 uses setne and clang-14 shifts "fixed" by 30. FWIW, clang is also clever enough to use a cmov to load the address of counters, i.e. the happy path will have no taken branches for either type of counter. > Signed-off-by: Like Xu > --- > arch/x86/kvm/vmx/pmu_intel.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index e5cec07ca8d9..28b0a784f6e9 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -142,7 +142,7 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu, > } > if (idx >= num_counters) > return NULL; > - *mask &= pmu->counter_bitmask[fixed ? KVM_PMC_FIXED : KVM_PMC_GP]; > + *mask &= pmu->counter_bitmask[counters->type]; In terms of readability, I have a slight preference for the current code as I don't have to look at counters->type to understand its possible values.