Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp109983lqe; Tue, 26 Mar 2024 23:33:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBBwuiqOnn+UOBC7bGUaxiEUhYXZCzmIzdWQr7p++gBO1y4cG6IT+KbbfkvXGT5ua0BA1//eb1dlusM7vTfGhK88MFIomq08a4R7DdDA== X-Google-Smtp-Source: AGHT+IFeRWT1Czi5VDyuMTm/0dhzqAajIx0uKHoMGF9kr91So+9E8SQzDuOHAEUcbNY3XHFoPs59 X-Received: by 2002:a05:6a20:7345:b0:1a1:67c0:c751 with SMTP id v5-20020a056a20734500b001a167c0c751mr5421581pzc.17.1711521205830; Tue, 26 Mar 2024 23:33:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711521205; cv=pass; d=google.com; s=arc-20160816; b=q2nE5Z+t42gXUWUE0k5zh5FewaRETRBX0JP6HRsCwW8/7r4J2zJrYCR1uO2cNNIoFd CjR1WTyeqSFUnXhx4EtqOeXHLbXguvvEHssFaKQ5TzoBqBIUmfDFNmJwLN+UcaVf/FO8 WWrE3or83zM4UPu2NOWzHkdIjidHSir/arLviDj6R7k5HA0dRO9ui491NU+MdRNmFePk U43FAChFRAvTR4cOzwS8D51R+1cVPcG7C9vMCzNZTx3b3HQyPBnP9IJhtLUWZmdwUBrm oJW/DW9DIjmTpvhj7S0ESsZAHtw/I4d4jhums9J5WXpm0NnrfI7ElQGd5Sleo1ySfkUY ieeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=O66PNVnF+NAj9JzaNCaQDZNthEAigIUk1c4UjwhWiQI=; fh=3YYEiMOSFB2yuvCDnUFAPHnHUIdeRauBSmb5FtNaQeo=; b=pceCF9RyGgi2dcDs5annVo1bfeVpk1lrmWQDFqSUC1GFLCeiBqd6Te26iNQ8PjaBqM MFnrXwKOnOD7cseDxKZ6Kb+h1ULw2DOzuyEZqWQWpw81/CCDTwMpPMBpUyEIQT53NHCl odzA2pn1hJ/zrj4KffKE9tsGt+BXyJVuaoeBvyZQPShQLDOGzsdfxstik00DvDknhPQ6 o8h0//C1UiApqxFyLoJvrO41J8b2rcg5NQOseRkjc6+rwLpUsDbDEaoYdoYHqYRcLCmk hNodAGveiU1XHTXA4KGL0vPYGDQGn6gRvl8sBSQoLB9CYsSY6x7EjmXy1G7c80V2xxTm 2+Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I4nJrXK2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-120366-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120366-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 s127-20020a632c85000000b005e4ceab6dbesi11114342pgs.880.2024.03.26.23.33.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:33:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120366-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=@google.com header.s=20230601 header.b=I4nJrXK2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-120366-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120366-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 9F01829B5A0 for ; Wed, 27 Mar 2024 06:23:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32E9A1EB3E; Wed, 27 Mar 2024 06:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I4nJrXK2" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D351C171C4 for ; Wed, 27 Mar 2024 06:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711520609; cv=none; b=hWfRO2Uig1N+Bq647PiKGnSbgmSfLYhEMOmtoFt8PopuCp9PNg1ZjWAQrplPKwGI3dvf8Ug9ni967II6t2da5G2m68CgFiGQGwaB7NFKoct3+8mB5EGElwWSiuFq4yGB2/ylRP9N5nC9kDEpQ2Kw1AFoolLsCdH2PLcyDX2WurY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711520609; c=relaxed/simple; bh=0i2kC23zVuArs9RpNNp6dBE7+7F68jiyLEw1IczmYjQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dvRzDiGlDctmwwRhQNHNQZxiLmVLAxawWLLyMZbhQG9VI82Py3nKeUPWmoSMZorHp0N6roXw5q2Qdhyko0XcDo+rB/3pWS2N+lyGdfW/FjViHqLN7DHIsfyIMVOSE4z4gV04EzlmiyXvqQQ6EbDVjtbL/AAtSpLRZYwV+ZjU09Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I4nJrXK2; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ea9a605ca7so420959b3a.0 for ; Tue, 26 Mar 2024 23:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711520607; x=1712125407; darn=vger.kernel.org; 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=O66PNVnF+NAj9JzaNCaQDZNthEAigIUk1c4UjwhWiQI=; b=I4nJrXK2cI/PKcoqNc59u2DLbmEKQiRxVutvO8xrLDPGKtu+MejaQ2YLJDJeP3P4FD QCYMURO8FQ+mjctHHWsYBDoWb4oE4ze48jf2vAg3h0oOxYD0XIM2N1CaMfIjNnCqmo9L 1RbFfJc9VIGrTsth+opIkMSu4rVxtsSfgLewtZFW6fGWcT79CiRHcqCJucNftY54NX7X 2bqP9HXwxvELrPXBKHxC8dLCsB3hE3XDGcZ1MB2evyVx1ia1Uhn7Gqz60ztFGGBzbRAm W8Xo9Muu3YCGdriO0yiB/Ckgh2T5dGiiRHe/8trusn2VLbT/h+74Nkgh8CSkW17eA4vv GINg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711520607; x=1712125407; 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=O66PNVnF+NAj9JzaNCaQDZNthEAigIUk1c4UjwhWiQI=; b=sWfkrmfNbJfdA5T+SAkyq3NVAm7x/KvCwdVQIu+T5SvkurdKxpZvf6PtStkD1lkEnd L3CwfC4sh1g1J+HiiLPU+8V1UT12KpETt1P7247JQW7UcYEExrd08Tr+su97MyGqRs2U VFjtCg/6dtsqwuXdsHczYg6ad+NsaLm+hOsZ+QjlRIS+ymgbQKcuKEeC3cI/AITSfQ82 NFYHeGmsSzRDGpoPpoZiNRfw4xVsB3sgy0O8XzlRYwh5qUOPN4J5YEDGo8BML/QnXIxB lfyQc39UrRjbhA5iDTswri7fFA+TxVeTclkWd3jprTnOir5aMg8MQQ3qXSD4YvPh/1WF IQjg== X-Forwarded-Encrypted: i=1; AJvYcCX/lAVaepyeEHqvubbS2OKoRr7qNFJJVDTr/EVPtz6k7anuHZ74L6N7ZesHvimp0iRxQL7xxbNvcP8c+Ggf9Ib8hQireeP9PEJDr2rx X-Gm-Message-State: AOJu0Yy2VEwIrmJsNkk4+sSD07dhewme0rhPnDUVmSRO77cTpDyG6rQP pMekMPfTTsS/CfA9k0ypg8zVboDybtqwcWgbDngi6XswiI0qgf3I6zVPywEVVQ== X-Received: by 2002:a05:6a00:8917:b0:6ea:c767:4699 with SMTP id hw23-20020a056a00891700b006eac7674699mr1677491pfb.13.1711520606896; Tue, 26 Mar 2024 23:23:26 -0700 (PDT) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id c17-20020aa781d1000000b006e6bfff6085sm7316210pfn.143.2024.03.26.23.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:23:26 -0700 (PDT) Date: Wed, 27 Mar 2024 06:23:22 +0000 From: Mingwei Zhang To: Dapeng Mi Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Like Xu , Jinrong Liang , Dapeng Mi Subject: Re: [kvm-unit-tests Patch v3 09/11] x86: pmu: Improve LLC misses event verification Message-ID: References: <20240103031409.2504051-1-dapeng1.mi@linux.intel.com> <20240103031409.2504051-10-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103031409.2504051-10-dapeng1.mi@linux.intel.com> On Wed, Jan 03, 2024, Dapeng Mi wrote: > When running pmu test on SPR, sometimes the following failure is > reported. > > 1 <= 0 <= 1000000 > FAIL: Intel: llc misses-4 > > Currently The LLC misses occurring only depends on probability. It's > possible that there is no LLC misses happened in the whole loop(), > especially along with processors have larger and larger cache size just > like what we observed on SPR. > > Thus, add clflush instruction into the loop() asm blob and ensure once > LLC miss is triggered at least. > > Suggested-by: Jim Mattson > Signed-off-by: Dapeng Mi I wonder if we can skip all LLC tests if CPU does not have clflush/clflushopt properties? > --- > x86/pmu.c | 43 ++++++++++++++++++++++++++++++------------- > 1 file changed, 30 insertions(+), 13 deletions(-) > > diff --git a/x86/pmu.c b/x86/pmu.c > index b764827c1c3d..8fd3db0fbf81 100644 > --- a/x86/pmu.c > +++ b/x86/pmu.c > @@ -20,19 +20,21 @@ > > // Instrustion number of LOOP_ASM code > #define LOOP_INSTRNS 10 > -#define LOOP_ASM \ > +#define LOOP_ASM(_clflush) \ > + _clflush "\n\t" \ > + "mfence;\n\t" \ > "1: mov (%1), %2; add $64, %1;\n\t" \ > "nop; nop; nop; nop; nop; nop; nop;\n\t" \ > "loop 1b;\n\t" > > -/*Enable GLOBAL_CTRL + disable GLOBAL_CTRL instructions */ > -#define PRECISE_EXTRA_INSTRNS (2 + 4) > +/*Enable GLOBAL_CTRL + disable GLOBAL_CTRL + clflush/mfence instructions */ > +#define PRECISE_EXTRA_INSTRNS (2 + 4 + 2) > #define PRECISE_LOOP_INSTRNS (N * LOOP_INSTRNS + PRECISE_EXTRA_INSTRNS) > #define PRECISE_LOOP_BRANCHES (N) > -#define PRECISE_LOOP_ASM \ > +#define PRECISE_LOOP_ASM(_clflush) \ > "wrmsr;\n\t" \ > "mov %%ecx, %%edi; mov %%ebx, %%ecx;\n\t" \ > - LOOP_ASM \ > + LOOP_ASM(_clflush) \ > "mov %%edi, %%ecx; xor %%eax, %%eax; xor %%edx, %%edx;\n\t" \ > "wrmsr;\n\t" > > @@ -72,14 +74,30 @@ char *buf; > static struct pmu_event *gp_events; > static unsigned int gp_events_size; > > +#define _loop_asm(_clflush) \ > +do { \ > + asm volatile(LOOP_ASM(_clflush) \ > + : "=c"(tmp), "=r"(tmp2), "=r"(tmp3) \ > + : "0"(N), "1"(buf)); \ > +} while (0) > + > +#define _precise_loop_asm(_clflush) \ > +do { \ > + asm volatile(PRECISE_LOOP_ASM(_clflush) \ > + : "=b"(tmp), "=r"(tmp2), "=r"(tmp3) \ > + : "a"(eax), "d"(edx), "c"(global_ctl), \ > + "0"(N), "1"(buf) \ > + : "edi"); \ > +} while (0) > > static inline void __loop(void) > { > unsigned long tmp, tmp2, tmp3; > > - asm volatile(LOOP_ASM > - : "=c"(tmp), "=r"(tmp2), "=r"(tmp3) > - : "0"(N), "1"(buf)); > + if (this_cpu_has(X86_FEATURE_CLFLUSH)) > + _loop_asm("clflush (%1)"); > + else > + _loop_asm("nop"); > } > > /* > @@ -96,11 +114,10 @@ static inline void __precise_count_loop(u64 cntrs) > u32 eax = cntrs & (BIT_ULL(32) - 1); > u32 edx = cntrs >> 32; > > - asm volatile(PRECISE_LOOP_ASM > - : "=b"(tmp), "=r"(tmp2), "=r"(tmp3) > - : "a"(eax), "d"(edx), "c"(global_ctl), > - "0"(N), "1"(buf) > - : "edi"); > + if (this_cpu_has(X86_FEATURE_CLFLUSH)) > + _precise_loop_asm("clflush (%1)"); > + else > + _precise_loop_asm("nop"); > } > > static inline void loop(u64 cntrs) > -- > 2.34.1 >