Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1445615rwl; Wed, 29 Mar 2023 18:31:07 -0700 (PDT) X-Google-Smtp-Source: AKy350YDKoDcKflA3bTco2hJV3R38230vdLwuCzJJtm+DTH5McJLsbl1QnmtG+KZ8aUXgSH4clCK X-Received: by 2002:a62:cfc1:0:b0:625:ebc3:b26c with SMTP id b184-20020a62cfc1000000b00625ebc3b26cmr17576792pfg.22.1680139867665; Wed, 29 Mar 2023 18:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680139867; cv=none; d=google.com; s=arc-20160816; b=LzZXZRgK5hLLXlSKRodGlHNOWs1IwGlNoJGyS748ar9SC8JmFjV0yZhl+6OB+VfGYW DHpoTMS3eUD0EW/4j3TUJgTV0kcsBMbH83iMjS5XYk6Hzej5g9wc9k/5BF5kAzcFS+4p VesY8oJMRKpesCoGTr9lZsa1g/eVfmz8m71SIqqAptZF/HfQS4Y8om+HVUfl/OqXUKd3 VgwJOSRsjjagw3AUAntKsFOq0wUsgkv3Mc28rqkI612y6Z6TlTqeTr6Jcslc0Ur72YsJ bc+qeMh2lVjpD+hQYjQA5akqclwklw79WGtoaGccCafk1R2021pVf6jAp2MDMaevxe3N 8EOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=16d1f/7TqKXYTgMoy7mhbsTKwY95jm0MzpMeZPNbPTI=; b=mcxXQF8iEJ2m7P5XQzTqzLJvfI6jMKMQcUHdkL3Wq+GkUE/Ve98ZGI9dgMMUyOLDoo SNpMq9Tsodhs0aL+ODXizgawsyPFoHmGQlLfUX4otaYEUANBiwhm/vd0XgRUae06W5C2 8UAdcKaktUSNxcu7A+JlSVRSbRQ3e77RXR6Pu44r0ll6MoVNRDRL2kO70jra2trbmghJ e5w+w9YLVvZzytjJMWEZrxJuaB3211ObZ7FX3NiOUAMByufpopgZPknV7jcmQNM6xmo0 LhxCA+2i4Lu/ETNX2HRd8hqrwNGqkPcTfZr8ZrYeGVRBPfH2xi7ScwgbwK3+Z5fIZcs4 ymSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fjFCTQ51; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa794b0000000b0062dc2495ea6si858061pfl.61.2023.03.29.18.30.52; Wed, 29 Mar 2023 18:31:07 -0700 (PDT) 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=@intel.com header.s=Intel header.b=fjFCTQ51; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbjC3BXn (ORCPT + 99 others); Wed, 29 Mar 2023 21:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjC3BXm (ORCPT ); Wed, 29 Mar 2023 21:23:42 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B5C4EDB; Wed, 29 Mar 2023 18:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680139420; x=1711675420; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VTxGweIAXTyub8ayicN0Qd452cPhoT+4Iswx+Pz3KLY=; b=fjFCTQ51VMf+tMx7+zhOUwyaBhHTb84CQx3SGwJHiw6kRKnFg8LlchCS COotoHsYZW3YouRBl7mbvDqUjrJVCVuJebqzxgQpy5h/H1neXGzNh46AT oI8BEr2fHqrPR1p7QSE2mnapDg6u8rAJkpFd+DQ1XgNCj7016GywHd4kv QCe5FoV4ZnzGowQnj4iG6tuTPR2C61k4KOUKDu6DPrunO12HnDZVgqb61 IEVqdhURMSo3n1GNpVXaCzi3OMAVeO7MUjXz8QYbnYxyKUkNi5i0nVElp evdX0nE4W1di8of4bW2B3dI2MXzfEGQs2vyyJ6qfLPpPkkQ88C515goTB w==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="343489873" X-IronPort-AV: E=Sophos;i="5.98,301,1673942400"; d="scan'208";a="343489873" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 18:23:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="678001234" X-IronPort-AV: E=Sophos;i="5.98,301,1673942400"; d="scan'208";a="678001234" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by orsmga007.jf.intel.com with ESMTP; 29 Mar 2023 18:23:35 -0700 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , Thomas Gleixner , Dave Hansen , x86@kernel.org, Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Zhenyu Wang , Zhang Tinghao , Zhuocheng Ding , Dapeng Mi Subject: [PATCH] perf/x86/intel: Define bit macros for FixCntrCtl MSR Date: Thu, 30 Mar 2023 09:28:46 +0800 Message-Id: <20230330012846.2927220-1-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Define bit macros for FixCntrCtl MSR and replace the bit hardcoding with these bit macros. This would make code be more human-readable. Perf commands 'perf stat -e "instructions,cycles,ref-cycles"' and 'perf record -e "instructions,cycles,ref-cycles"' pass. Signed-off-by: Dapeng Mi --- arch/x86/events/intel/core.c | 18 +++++++++--------- arch/x86/include/asm/perf_event.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 070cc4ef2672..b7c0bb78ed59 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2451,7 +2451,7 @@ static void intel_pmu_disable_fixed(struct perf_event *event) intel_clear_masks(event, idx); - mask = 0xfULL << ((idx - INTEL_PMC_IDX_FIXED) * 4); + mask = intel_fixed_bits(idx - INTEL_PMC_IDX_FIXED, INTEL_FIXED_BITS_MASK); cpuc->fixed_ctrl_val &= ~mask; } @@ -2750,25 +2750,25 @@ static void intel_pmu_enable_fixed(struct perf_event *event) * if requested: */ if (!event->attr.precise_ip) - bits |= 0x8; + bits |= INTEL_FIXED_0_ENABLE_PMI; if (hwc->config & ARCH_PERFMON_EVENTSEL_USR) - bits |= 0x2; + bits |= INTEL_FIXED_0_USER; if (hwc->config & ARCH_PERFMON_EVENTSEL_OS) - bits |= 0x1; + bits |= INTEL_FIXED_0_KERNEL; /* * ANY bit is supported in v3 and up */ if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY) - bits |= 0x4; + bits |= INTEL_FIXED_0_ANYTHREAD; idx -= INTEL_PMC_IDX_FIXED; - bits <<= (idx * 4); - mask = 0xfULL << (idx * 4); + bits = intel_fixed_bits(idx, bits); + mask = intel_fixed_bits(idx, INTEL_FIXED_BITS_MASK); if (x86_pmu.intel_cap.pebs_baseline && event->attr.precise_ip) { - bits |= ICL_FIXED_0_ADAPTIVE << (idx * 4); - mask |= ICL_FIXED_0_ADAPTIVE << (idx * 4); + bits |= intel_fixed_bits(idx, ICL_FIXED_0_ADAPTIVE); + mask |= intel_fixed_bits(idx, ICL_FIXED_0_ADAPTIVE); } cpuc->fixed_ctrl_val &= ~mask; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 8fc15ed5e60b..bdaf015a620e 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -32,11 +32,21 @@ #define ARCH_PERFMON_EVENTSEL_INV (1ULL << 23) #define ARCH_PERFMON_EVENTSEL_CMASK 0xFF000000ULL +#define INTEL_FIXED_BITS_MASK 0xFULL +#define INTEL_FIXED_BITS_STRIDE 4 +#define INTEL_FIXED_0_KERNEL (1ULL << 0) +#define INTEL_FIXED_0_USER (1ULL << 1) +#define INTEL_FIXED_0_ANYTHREAD (1ULL << 2) +#define INTEL_FIXED_0_ENABLE_PMI (1ULL << 3) + #define HSW_IN_TX (1ULL << 32) #define HSW_IN_TX_CHECKPOINTED (1ULL << 33) #define ICL_EVENTSEL_ADAPTIVE (1ULL << 34) #define ICL_FIXED_0_ADAPTIVE (1ULL << 32) +#define intel_fixed_bits(_idx, _bits) \ + ((_bits) << ((_idx) * INTEL_FIXED_BITS_STRIDE)) + #define AMD64_EVENTSEL_INT_CORE_ENABLE (1ULL << 36) #define AMD64_EVENTSEL_GUESTONLY (1ULL << 40) #define AMD64_EVENTSEL_HOSTONLY (1ULL << 41) -- 2.34.1