Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp390703lqt; Thu, 18 Apr 2024 20:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXceN35NA4gw2xfWOgc2VWksIaOmMP8qne2Zo/EVPOglQ4/TAa13P9jnSEBbTIYRjRSN/t9/Kyhb4vSm6rzpYBgnRt7sEmHX3qHVjJd2w== X-Google-Smtp-Source: AGHT+IG1Xz7yfa7CbZUfsS81qaeNmhki4eapPGfBDyWQUbAPRKIMmREbEnrLmvoDsEAHCdGucPyj X-Received: by 2002:a17:907:d9e:b0:a51:d522:13c8 with SMTP id go30-20020a1709070d9e00b00a51d52213c8mr635793ejc.60.1713498470624; Thu, 18 Apr 2024 20:47:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713498470; cv=pass; d=google.com; s=arc-20160816; b=QFs29lyAa0CLzd9Eq8pDMiv//03//IFEsKxYSI4o82CACYrG6k/ginvs7fctrgtY83 Xo7LNKXwep1ow2b1Qs4oZEgOm9CTJOTH9r2cV06PYCN1JYtWEXwVXBWO4N2GYcQqwr++ 2yx0WWvw7C83kDOx3Ajwh+b63MCGshN5rbOUZapGa1WlVhBsavbKNJHpgqkIIlOk1noo EMVM6hdSwq+WkngBFE3qsYeiz8/pDwrJiXmgVqXyY8ULhO+w1Vllo6kWg3hKh6ZHWRcf ewb1fsDj5RmZOxTegt4HMDDYjZLqoA/cjVG6K9Z/5a80bL7Ta6X2FnleeyfnijgktVSP revw== 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=LrcTN4RHtxqNDyU71SHT4ik9q3FP5oC8Y5FawEI2E/s=; fh=3qX1+dlN8PYECDPP2iJ6RyaKnRhI0MQxvVbehX3gfaw=; b=Nrbfh6Jc5VPi+jB05fFzBYjkvys9+TJ+XJnxIdFRXhW+4TtWpx4R8HSYIczTu+KR0i u82GLrRBDB8xib7QXq0cblhUWd75eTAUbklt9mxzCjtXlgZQ2jxzJlGZkfmTq2cb+2yZ q1FF0m+iM5bV+yioro33MCWB2jXfNKb6JkRJDVcOQalfvFwNoJ8WDcFtlUlyE5mxsx44 kkCYKfnPOf+zCuV1WhfhOAFYdg+pS403KmX5OSJqDaECYZNm9y+coJnqykZaly8tE5j/ dyhAPlAsH3YuvhizTtsRzhW3KmsaoqxZ2HFyrqj/yDajMZ30hZ7lEfbM5pTylYMXd1UQ 95rQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ikeXhYwS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150983-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s7-20020a1709067b8700b00a5245767d95si1601327ejo.131.2024.04.18.20.47.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 20:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ikeXhYwS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150983-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5C1CC1F21507 for ; Fri, 19 Apr 2024 03:47:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E10362BAFE; Fri, 19 Apr 2024 03:45:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ikeXhYwS" 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 BA29E2AF17; Fri, 19 Apr 2024 03:45:54 +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=1713498356; cv=none; b=QnJG9oS8fRiVDMbTOErJbkpOcs6zVbD6CRnePKHjc8T7sbgUUV0jdZn7BxuKgG/otz3HHl9FT/x0okNzv7bfuc60y/PpO/U7F0e51bHkPKq1mzmNfeJY3HrnhcaHSN3039zg1gWB+B1VnfZUwzhjWrpSMC6LZgJddgsAt7Wq0SY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713498356; c=relaxed/simple; bh=Qsmg2ffUGXqjYUoa6KnIqYzBA5c7umCrK37g6zMvxy8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GFFZK8/dqTdMWuYMyhagb4cr5yI9ehQQ6AJqwFgOitrUBVm0wkb+3ITa6Lk2/cQm+Fjuih42doP2QUIJJdac/B+gw80fTMstHkJUPwN80mXUZiq7tr1hQyJwYjhcKk0ThLrAByKihTorzP6vNt0L5r7nkHgJV+XlPgZYYlrYgLs= 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=ikeXhYwS; 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=1713498355; x=1745034355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qsmg2ffUGXqjYUoa6KnIqYzBA5c7umCrK37g6zMvxy8=; b=ikeXhYwSMJwKP+dmHi/JT9S0OtDHbuy++AdzSxeGr3zLJ93NfWBb97vb 4DO2pjVPFB/YzTQGbz9zStxFImeMmxA7tdFGRYvZFclzp43EO3kKQm/EX EkPdCOiJaum+a6nYLyjvNirOE1m70xgC7XyFcY3kap9HIBPT+GCWfDtb/ TtXpXP7+rb9mDVL1zDLEUiVZN2fUJTcdMnmCyl6J49GQ4TzjdwsbnaZ8/ Wuv+ZRuoY03hLzjEKFCs+q7crFavS3+dYKK2xoqwqUz8VHMLHrazJd1Yl mvPLKqY+DDYJzczsXbMh1UXNltx+YblCrSt4gkABVOMuvA4vDMUnZp5Jf g==; X-CSE-ConnectionGUID: qAc2q0AHQpq9B8Ifo+vSxA== X-CSE-MsgGUID: Myia6YNlSXusML20p7DLpA== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="31565450" X-IronPort-AV: E=Sophos;i="6.07,213,1708416000"; d="scan'208";a="31565450" 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:45:54 -0700 X-CSE-ConnectionGUID: W1VyNyMfRJe7HdPoKvzNzw== X-CSE-MsgGUID: 5O11IwgkTKuehBxMZyagnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,213,1708416000"; d="scan'208";a="54410163" 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:51 -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 07/17] x86: pmu: Fix cycles event validation failure Date: Fri, 19 Apr 2024 11:52:23 +0800 Message-Id: <20240419035233.3837621-8-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 When running pmu test on SPR, sometimes the following failure is reported. PMU version: 2 GP counters: 8 GP counter width: 48 Mask length: 8 Fixed counters: 3 Fixed counter width: 48 1000000 <= 55109398 <= 50000000 FAIL: Intel: core cycles-0 1000000 <= 18279571 <= 50000000 PASS: Intel: core cycles-1 1000000 <= 12238092 <= 50000000 PASS: Intel: core cycles-2 1000000 <= 7981727 <= 50000000 PASS: Intel: core cycles-3 1000000 <= 6984711 <= 50000000 PASS: Intel: core cycles-4 1000000 <= 6773673 <= 50000000 PASS: Intel: core cycles-5 1000000 <= 6697842 <= 50000000 PASS: Intel: core cycles-6 1000000 <= 6747947 <= 50000000 PASS: Intel: core cycles-7 The count of the "core cycles" on first counter would exceed the upper boundary and leads to a failure, and then the "core cycles" count would drop gradually and reach a stable state. That looks reasonable. The "core cycles" event is defined as the 1st event in xxx_gp_events[] array and it is always verified at first. when the program loop() is executed at the first time it needs to warm up the pipeline and cache, such as it has to wait for cache is filled. All these warm-up work leads to a quite large core cycles count which may exceeds the verification range. To avoid the false positive of cycles event caused by warm-up, explicitly introduce a warm-up state before really starting verification. Signed-off-by: Dapeng Mi --- x86/pmu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/x86/pmu.c b/x86/pmu.c index 461a4090d475..43ef7ecbcaea 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -591,11 +591,27 @@ static void check_tsx_cycles(void) report_prefix_pop(); } +static void warm_up(void) +{ + int i = 8; + + /* + * Since cycles event is always run as the first event, there would be + * a warm-up state to warm up the cache, it leads to the measured cycles + * value may exceed the pre-defined cycles upper boundary and cause + * false positive. To avoid this, introduce an warm-up state before + * the real verification. + */ + while (i--) + loop(); +} + static void check_counters(void) { if (is_fep_available()) check_emulated_instr(); + warm_up(); check_gp_counters(); check_fixed_counters(); check_rdpmc(); -- 2.34.1