Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp91294lqe; Tue, 26 Mar 2024 22:37:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbyVMdWmNE7RMbp4TVZzSlnusS1B/uFgPlQskszmqxUTme9H6boE1TgVYNNQyQhRX6RT3lkkDI3IFSkTEBJFfqSneC6ux5ALzT/n0pRw== X-Google-Smtp-Source: AGHT+IED7XZ2XKnb98rWSbR1i1+koiGPeAK3u5VXz24firyMtqwohpzXb0OfEfde7ukFE0dNVU/3 X-Received: by 2002:a17:90a:ce:b0:29b:a8a6:c6a7 with SMTP id v14-20020a17090a00ce00b0029ba8a6c6a7mr190628pjd.13.1711517837309; Tue, 26 Mar 2024 22:37:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711517837; cv=pass; d=google.com; s=arc-20160816; b=WWwaYJEWDXekJGOiqKfLf/E/74OIHly7brITLXagfkREllsl4uWQU+oWc0Dggi+HrH ccfZP8q/V0O75poVaHqSD9Cp5C0uinOrs0ORjhlFtt2ue9J+J/Ipt3ZstnVwVhX7fBhq pNEDSWtWZDoJHmz1LAxgA+cKxKRo/veVTUv0MAanc/acO2htImzYWuu+2zIysxgbGHk5 CO6M7xamsl111ML7tpV8nC3+zGeMVLJTqq7o1N1aIZXuWR1nRjovPClTDLyllYYczmfy wfaftutA4kPgiKK5ZTit06k6bi3SAWCrMrfWm31/BbcdtkmaYToOEmgQVq4w9gxSKjVW 8iIQ== 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=xDotf3qLJ0XcUAR4+tlCSoc4OzTuiL/EZY6fMJlWYbc=; fh=sonT1uLQRL1Mdm70DRR2RBNpwkQvRLVJkhlU7ejyFV4=; b=fk/a0xAl98I0mp/2oJVj52A1NOgRaBUfHdeK+iuYFAQKcgZErjTxmDTce09HpmnjbL CmnSYdGpGKru13UqdlkMpPHe432eC9t5GslMJMZPtVYuvPLC7L+5EUFQhVlyU8QvyhS5 t9qAB3mlPCeND4i2BRHL30T0PvbhLrPSh/saHvvex6Utr8cK4+c+Hh48/IT22KlRVDn/ gOFAZ7awoKqh1LMTc3Sp7sce7zchL6ilH2OjDkjLAkbYptHHrlZHlU3BVigSgRxq+FsG fXbTY/a5dnHgtGL8M/wCLqgcvV3R2XK9LoJKTHvVikFqjlSHHuNAi+qw26C7YjXb9DBM LNGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WJXv6naU; 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-120331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id v5-20020a17090a778500b002a09c423a11si599131pjk.151.2024.03.26.22.37.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 22:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WJXv6naU; 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-120331-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120331-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A27F4B22408 for ; Wed, 27 Mar 2024 05:36:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56EE91429E; Wed, 27 Mar 2024 05:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WJXv6naU" Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 D1058FC1D for ; Wed, 27 Mar 2024 05:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711517788; cv=none; b=kxW/IXkPl0+adXynsAhensHRbjq8ogXzZyjOC51iKCffaO8CICZi1zrLYPDHdy8PPVVvJYdfcMWLAL05SzYTdEnEz8OaH8WA8BHAFfrtWaME4FrKEAtH2cGfWuirXR4ng9Wd+CFP402hLk81izUquWgCASh/q/IfpXJNWvcyehs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711517788; c=relaxed/simple; bh=BLcCxiJXQZXgvVd25qKk9yY3fM3yD7KnkVdkHfMgu30=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jhHRlmuti4Hc5WhEOkTfTlbnIai4lP7tslKhDPBquJ7F9JWpZqQVu+AzCjnlI8u19TFKi8TKWfPXydmRL0OS+lywJwDNhjJBhc1SQitPvoetZCN8mIPN4UoCLZ+VuLKr/mY/t3/YsPgVSCReMr7MGPbXSnhHb7jAkUQ/YXmMVuY= 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=WJXv6naU; arc=none smtp.client-ip=209.85.210.44 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-ot1-f44.google.com with SMTP id 46e09a7af769-6e69ae0ff44so3307143a34.1 for ; Tue, 26 Mar 2024 22:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711517786; x=1712122586; 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=xDotf3qLJ0XcUAR4+tlCSoc4OzTuiL/EZY6fMJlWYbc=; b=WJXv6naUH9ZDONeFxPO27M9H6OCF3oW0tO9BDHTfe1jCxKENoNpl7X7iVkiQsBaQQ7 DSPy4oIZkabs+hHHMCjmjO5c1qvVY63SpRcyOP9Bmf+UZdAPdO5OZSl5or4qbjxNqelC /2gQjeY/dA/wc8HakqUCcSAcnvw95k67Quuav8h/VLiluRNkheWr7U3hbeRv6ceCOvKz Oud+MTNRetldVzmn7mTzuLnkHoWjUetKBcE4+5ipdiegpn558Wp0GQa262ISMgSrvP6F HxjM6IjxMoe6vMz7zMYqLXQUaop5/O6YjWuEm/TVogkqDiAJIR0Utcysb1nd1stUpP7Y ZenQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711517786; x=1712122586; 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=xDotf3qLJ0XcUAR4+tlCSoc4OzTuiL/EZY6fMJlWYbc=; b=O8I192xjN2HwUMu262JeTSbWosUCRx/KHpLug2Cpw2jf4roOqPfIjWvgHs+BqP7nCE eXpA2i50qN2XOiFeCBJQvCuKB8cPXuDMZNPK1m9zSJV2/WU5jsXwqiurFO8ddk9CTM35 gZzbALpbDlSSgtylQFZddt/+XqrMkO8spnwSbWC6uiEDlcxbV5rBaQSSgPuORgKtKgUL E0poOLrXcysrC2Pl4l3Y1OLi8UXOgwElIm4b/0eOscHM3SUqG1DdvgOnBA5jK44OPJwR 5NHd7DxI2KM5JBuLxCFgK2MkpvcPU+rSf9bBZA3Z3Mt3YGTI/Pk5ESjTLNbTp06RNdHZ cyUg== X-Forwarded-Encrypted: i=1; AJvYcCWUYvRHCkzJotQFT74rWV7E6fQYZbh1FWMBE6FTDebXYvdNffeupyFio78BzavFJCYQCEGODV8scliWvlOjMacE9VJ14/0+Fl7duLO2 X-Gm-Message-State: AOJu0Yz0EGGCmS9mtnS0CQCJAFMNqXD2KpRxDdUC15v9Mm259AZde1bB GXMa4rlot/P18MuM3bm9NhkF5bxxo0WrhuPu3fqyREJlq6HDbEo62MMQ7x5feA== X-Received: by 2002:a9d:77ce:0:b0:6e6:d509:bf8a with SMTP id w14-20020a9d77ce000000b006e6d509bf8amr243606otl.38.1711517785719; Tue, 26 Mar 2024 22:36:25 -0700 (PDT) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id m24-20020a635818000000b005dc4f9cecdcsm8515531pgb.86.2024.03.26.22.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 22:36:25 -0700 (PDT) Date: Wed, 27 Mar 2024 05:36: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 04/11] x86: pmu: Switch instructions and core cycles events sequence Message-ID: References: <20240103031409.2504051-1-dapeng1.mi@linux.intel.com> <20240103031409.2504051-5-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-5-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. > > 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. > > The event "instructions" instead of "core cycles" is a good choice as > the warm-up event since it would always return a fixed count. Thus > switch instructions and core cycles events sequence in the > xxx_gp_events[] array. The observation is great. However, it is hard to agree that we fix the problem by switching the order. Maybe directly tweaking the N from 50 to a larger value makes more sense. Thanks. -Mingwei > > Signed-off-by: Dapeng Mi > --- > x86/pmu.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/x86/pmu.c b/x86/pmu.c > index a42fff8d8b36..67ebfbe55b49 100644 > --- a/x86/pmu.c > +++ b/x86/pmu.c > @@ -31,16 +31,16 @@ struct pmu_event { > int min; > int max; > } intel_gp_events[] = { > - {"core cycles", 0x003c, 1*N, 50*N}, > {"instructions", 0x00c0, 10*N, 10.2*N}, > + {"core cycles", 0x003c, 1*N, 50*N}, > {"ref cycles", 0x013c, 1*N, 30*N}, > {"llc references", 0x4f2e, 1, 2*N}, > {"llc misses", 0x412e, 1, 1*N}, > {"branches", 0x00c4, 1*N, 1.1*N}, > {"branch misses", 0x00c5, 0, 0.1*N}, > }, amd_gp_events[] = { > - {"core cycles", 0x0076, 1*N, 50*N}, > {"instructions", 0x00c0, 10*N, 10.2*N}, > + {"core cycles", 0x0076, 1*N, 50*N}, > {"branches", 0x00c2, 1*N, 1.1*N}, > {"branch misses", 0x00c3, 0, 0.1*N}, > }, fixed_events[] = { > @@ -307,7 +307,7 @@ static void check_counter_overflow(void) > int i; > pmu_counter_t cnt = { > .ctr = MSR_GP_COUNTERx(0), > - .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[1].unit_sel /* instructions */, > + .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[0].unit_sel /* instructions */, > }; > overflow_preset = measure_for_overflow(&cnt); > > @@ -365,11 +365,11 @@ static void check_gp_counter_cmask(void) > { > pmu_counter_t cnt = { > .ctr = MSR_GP_COUNTERx(0), > - .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[1].unit_sel /* instructions */, > + .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[0].unit_sel /* instructions */, > }; > cnt.config |= (0x2 << EVNTSEL_CMASK_SHIFT); > measure_one(&cnt); > - report(cnt.count < gp_events[1].min, "cmask"); > + report(cnt.count < gp_events[0].min, "cmask"); > } > > static void do_rdpmc_fast(void *ptr) > @@ -446,7 +446,7 @@ static void check_running_counter_wrmsr(void) > uint64_t count; > pmu_counter_t evt = { > .ctr = MSR_GP_COUNTERx(0), > - .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[1].unit_sel, > + .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[0].unit_sel, > }; > > report_prefix_push("running counter wrmsr"); > @@ -455,7 +455,7 @@ static void check_running_counter_wrmsr(void) > loop(); > wrmsr(MSR_GP_COUNTERx(0), 0); > stop_event(&evt); > - report(evt.count < gp_events[1].min, "cntr"); > + report(evt.count < gp_events[0].min, "cntr"); > > /* clear status before overflow test */ > if (this_cpu_has_perf_global_status()) > @@ -493,7 +493,7 @@ static void check_emulated_instr(void) > pmu_counter_t instr_cnt = { > .ctr = MSR_GP_COUNTERx(1), > /* instructions */ > - .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[1].unit_sel, > + .config = EVNTSEL_OS | EVNTSEL_USR | gp_events[0].unit_sel, > }; > report_prefix_push("emulated instruction"); > > -- > 2.34.1 >