Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp444062lqt; Thu, 18 Apr 2024 23:47:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUj4i6hKL5R6nV0nbDsZRY7xvUpF3SInFLzH8Z0gpUcRpTg5x+5w4zXxk1Dy4aoD2cxhKJZyv4CegsizCt8TcOftrytTVXHL1puIISOOQ== X-Google-Smtp-Source: AGHT+IF8Y1SxxNW+hX/imjKlTXWlGUMHLYgHpa1zDcTkHgwiR1fpOceKcKyK6g6P5aBKsvKUUHKZ X-Received: by 2002:a05:6871:d189:b0:22a:4b4c:23dc with SMTP id pj9-20020a056871d18900b0022a4b4c23dcmr934888oac.33.1713509249266; Thu, 18 Apr 2024 23:47:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713509249; cv=pass; d=google.com; s=arc-20160816; b=w77ieKaOxpICIfSKa/TE+cimxbFcUvXOuhixfDjYNro9r4z4+datDTojifCAtVeWzw C9+b1SBe474uyWyBgtpR4Vp7R0UJ8z4G/YZmnmzvNx1Jtk7WFo19YBvAaSsPyxF0GChs CoDqb9JJ3qRBPlF/S4ESbv8w4xfJKEMZ/ZC6mu5R9YIU9KWp1QgJkRlc2MWacd0Nm/WL u9ZbVMe3o/DOcdILIhRbDPuFr5v5vjpboNBMsZy9mimcEO/MRnBsFOQX8ZQ/NhacUFQr p9KfnsfvJj6ZwXLESdRV/PVsSo4W6uPW7CN8NCWw9v/vdAR4SPiMYh7Il+CXGK4QUXOd ghAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CUvj6Yo9FhyYBWGuA+U8b6T+n12QjEKKBCNnJXB5mLQ=; fh=3qX1+dlN8PYECDPP2iJ6RyaKnRhI0MQxvVbehX3gfaw=; b=eN1q36kiTc4x3V9cfOLFCPvPhAeBsAlns1jgpyRkCWbAYiOLXKLW476if/Q2eZabX9 UBQwe96HUJwugQkx9eGBreuNaqIlTL+eUS/o3f457RIIZYpVQapY6JFq1cz+EZpJdxMM 1jAE5oS+1xpwztxu/Do7St9/yd5rOmrC6W8w164FzrzID7ehzL+rJTNpIIqY0QA852CR ilLNEa+VVZQN3DzyCGyH20M7JMBMb7u7KY1gknS8wR1dj4ymcVZG00ZsYx09lcggy6j5 RwWBDLOEq3+pWlXeCtM4i8VMel20KYaG2zQsI2RF7JemaPUbQ0sRdJejkHVDtbqk0fDt FpTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OJcrAJl/"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u32-20020a631420000000b005f41486adcfsi2660451pgl.592.2024.04.18.23.47.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 23:47:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OJcrAJl/"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F06382852EF for ; Fri, 19 Apr 2024 03:48:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE1DE42AB5; Fri, 19 Apr 2024 03:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OJcrAJl/" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BAAC3E485; Fri, 19 Apr 2024 03:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713498361; cv=none; b=pSUvwHLeNooNqihy7B0g+xkpBDh+DATl7hyJkfPd5Xp1aAX0qU77i+fPIx+tN0SwRQkwS3IZK/livNNo4li5TArPdpoNrNtGL8nxfHfgzheTyJjB9jHpSGSkwQAxUlkZWr9iFoCO+PpPdrq1qGtkfO7nyqPdcSvWlU49Iep3LhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713498361; c=relaxed/simple; bh=5/QEb1aKZvreLoUXtF0uNhYLsiRGyvEfapJ7il+jZgM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=INtOocGN7P+Q5gJbGg9tADbXCBXfnUGQaErdIhFYjEMBDT4dEmzDpOx5F+IH3oG788Cvi+VFZtAP2w175Ec7zdYKW0B+xtDs3t3tjj1pXFqWMSx159uNUWxOJrbxdM28zCvbV4IUApsSitTBu/Mn9tNBjlJhEoCj674exVosNIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OJcrAJl/; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713498360; x=1745034360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5/QEb1aKZvreLoUXtF0uNhYLsiRGyvEfapJ7il+jZgM=; b=OJcrAJl/n9RN5vX+2KhRr6pe09D6MWR2oJqmgACAEFksvcfZoiBdZtMa wfx4X4j3NYZSLXwXr+osbtYNYA8gD03+zIip5qIbqtm9XKYMwlpA8Uk5o twJ3Lvfniju74P95bvDK/k3Bbrs9UxODYGYKALny/A9R8v3ijmX2guiZ/ Otu8+oIj55ZoJy7mFJYjtKO9t+LKv2JqCuHyYujOVjmdH5kO4hTa9V6kr 3Z7UdQCYajFdUDLODt99AEMzXzNtF1MZppsae3SZAm3qrKTB2AOtixft+ Jc6V2Mvrfb5xwV2jyEY1vF5ZIn79i9TcnrejJH6QJH31G8U3JtF9yB33y Q==; X-CSE-ConnectionGUID: 7SByHVvVQr2GgV0z14Yhzg== X-CSE-MsgGUID: fdvePZ+nRHqBS+EA2jsSjQ== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="31565463" X-IronPort-AV: E=Sophos;i="6.07,213,1708416000"; d="scan'208";a="31565463" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2024 20:46:00 -0700 X-CSE-ConnectionGUID: wtrIdJe7TvmMzrRFSpU+JQ== X-CSE-MsgGUID: xj6HBejRTIKIRZ4yRuSWcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,213,1708416000"; d="scan'208";a="54410183" Received: from unknown (HELO dmi-pnp-i7.sh.intel.com) ([10.239.159.155]) by fmviesa001.fm.intel.com with ESMTP; 18 Apr 2024 20:45:57 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini , Jim Mattson , Mingwei Zhang Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiong Zhang , Zhenyu Wang , Like Xu , Jinrong Liang , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v4 09/17] x86: pmu: Use macro to replace hard-coded ref-cycles event index Date: Fri, 19 Apr 2024 11:52:25 +0800 Message-Id: <20240419035233.3837621-10-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035233.3837621-1-dapeng1.mi@linux.intel.com> References: <20240419035233.3837621-1-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace hard-coded ref-cycles event index with macro to avoid possible mismatch issue if new event is added in the future and cause ref-cycles event index changed, but forget to update the hard-coded ref-cycles event index. Signed-off-by: Dapeng Mi --- x86/pmu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index fd1b22104fc4..6ae46398d84b 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -54,6 +54,7 @@ struct pmu_event { * intel_gp_events[]. */ enum { + INTEL_REF_CYCLES_IDX = 2, INTEL_BRANCHES_IDX = 5, }; @@ -697,7 +698,8 @@ static void set_ref_cycle_expectations(void) { pmu_counter_t cnt = { .ctr = MSR_IA32_PERFCTR0, - .config = EVNTSEL_OS | EVNTSEL_USR | intel_gp_events[2].unit_sel, + .config = EVNTSEL_OS | EVNTSEL_USR | + intel_gp_events[INTEL_REF_CYCLES_IDX].unit_sel, }; uint64_t tsc_delta; uint64_t t0, t1, t2, t3; @@ -733,8 +735,10 @@ static void set_ref_cycle_expectations(void) if (!tsc_delta) return; - intel_gp_events[2].min = (intel_gp_events[2].min * cnt.count) / tsc_delta; - intel_gp_events[2].max = (intel_gp_events[2].max * cnt.count) / tsc_delta; + intel_gp_events[INTEL_REF_CYCLES_IDX].min = + (intel_gp_events[INTEL_REF_CYCLES_IDX].min * cnt.count) / tsc_delta; + intel_gp_events[INTEL_REF_CYCLES_IDX].max = + (intel_gp_events[INTEL_REF_CYCLES_IDX].max * cnt.count) / tsc_delta; } static void check_invalid_rdpmc_gp(void) -- 2.34.1