Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp186300lqo; Wed, 27 Mar 2024 10:07:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuCOcnZDABY5YtvGOVzXsHPC0NkqlBiCs0PNeyT9B7iSGW6H5sK55l74QZGRuUEtNi0J1EMlTVXE/7r8MKp90MMGTwryCmas8eJn7USQ== X-Google-Smtp-Source: AGHT+IEwTVC/GwKlW696y+XxyNDcgnNyTjwqmwQMJoiqZGyfJ3AvGW2kT3KCSteVwJf4UVDFrms4 X-Received: by 2002:ad4:4709:0:b0:696:98c6:bffc with SMTP id qb9-20020ad44709000000b0069698c6bffcmr150592qvb.36.1711559225641; Wed, 27 Mar 2024 10:07:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711559225; cv=pass; d=google.com; s=arc-20160816; b=BavtzXs1NGwD0zgdwGaJgRR7Qt9PKYAL647omCHCTcQ/vnq2HQ6dZi8F7bgyoDcw8m Rs0HJLsQid3r+TOPtaNPkCscb76yUT07E/a++JPZ/sORrUYKzgyVsqjqaV1LrbjU1kQT 7KNGW9TWeFL8A0JzxwdqMF0dvt7liuwJBxF6NaOv/7Lx8NEudvU1tdzcBj0Ij+CURG8l J1SrHQbuDpQr7uapyF//xU4Fy/IJ54RFPx/g8+OHHemHidoHJ/yMRq+pUfeCIy5X0AnF mQVHjdQ1rFiLCNiVd/RbB9/B0mcnRPLGhFGfpCXSalJjF9QkTo58eVirIZRjAeJWN4+1 9FVQ== 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=db/vsjswu3WccKaVuM1UJ18xAjQJ5GOJeNQDmiP8KtE=; fh=YTbV5sKKOZP0FtfW0asa8EIUztSjQmZr83JuxNM9y8A=; b=gQWGCcaBcQPgtzn76SZ0bxnlCHDMPbJHLxvHKbeleTEQddj6QdVf+Z6YAxKV2apKyh 8jy8A45sVqsOr5Fiz5AN0U+upqo8wuXKgUBohImb429PwJWkBVVzTIgBzigPBEOEP9es Vo+kt1d2TcCLLHQ/Kx0/eA9eNLJdmKXunN59XjNSM2LP0VNaVVDkJm4lNc0I1DXb2t9G qrjjcmowLYUsqBJiwkAJClZunPxnRI2Y/gjRL0rZNmFZZcK+JhVEjcdjq2qxYQyqbQqz PwO4yyEBDirN1VcP/mKc2nas1WGDRMH7N/NfJwfzoaL4oo5kt0sC+W6lPOa1ZHKTkQg/ G6KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bqr3Agyk; 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-121668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121668-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w3-20020a05620a444300b0078a594fad2bsi7523774qkp.609.2024.03.27.10.07.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 10:07:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Bqr3Agyk; 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-121668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121668-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0299D1C2DD68 for ; Wed, 27 Mar 2024 17:07:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0216F14E2EE; Wed, 27 Mar 2024 17:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bqr3Agyk" Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 4723314D6F7 for ; Wed, 27 Mar 2024 17:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711559178; cv=none; b=dDR/6UsJB7W5Z6Qfc2+JvGHwoEeywPjbv7p08y3nTKF7o3Pxv5SnCQ8gB1a5WSW7cLwAEtrvNID+fIJtN5/q1bj9I/QnJn5+JZQG0Af1GB6rTv8QyHwGCooAjvhqZQHzL59M0BKeqiMA8CtbKO1H9MYGXxtRI30lorMuP+jRKhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711559178; c=relaxed/simple; bh=bBSoVZNXnImm2xWp7WBBSOxsMP+tK9xNwxw0jIzelj0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZYp/M75WsiJS502bXM5tNYpV+hCjYsFcYCb3Tf3i1u3v4a5npF5T/T4T/sSCn8qWcrVgA3pjA93wMEWWsswMM7KdZoaAmhjBgXfd1TLngey75wT3/ytbK5hRNueqfm7HpHr2ClKZTWUt7VX45c/rtbm/73Ff/VFdjbySQRKUbKY= 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=Bqr3Agyk; arc=none smtp.client-ip=209.85.215.177 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-pg1-f177.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so3970134a12.0 for ; Wed, 27 Mar 2024 10:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711559177; x=1712163977; 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=db/vsjswu3WccKaVuM1UJ18xAjQJ5GOJeNQDmiP8KtE=; b=Bqr3AgykjESSxRZ6DviXDvNZDNapHRE9QWcXBlrasJQvn4y2w4qmeEScTX3lvnYto0 RmREqjNn/atkKZp1geA1hmuNdtcmBCB5oaOIygC3Hipph2O1T5A0lPKlQsSoEZMdL8A7 ATbaryViqn3FCEn4iakJp60j3J3bkJnUnOaXdB8J+rT8rmz2n/vj6/SCsm6roFDz9c71 9u6xR7ZPLJzo4uvREXfsZNzSYKziRCqwPkzi44VgHbQ8kWoXg8NaoAroGl3gmswjfhve ya69bJtXXHF8czQFxMOmlt4HgDo3AYWgsPWg6m/EGfatdi/A9rHgCYM7+FAecEUzaG8b b9tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711559177; x=1712163977; 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=db/vsjswu3WccKaVuM1UJ18xAjQJ5GOJeNQDmiP8KtE=; b=UIRuKAZBikXPYT38VyOxEveFzFffyqIwtbuojzYh1Ypb5FO7lcGROE3ozFXi025tD/ K8NkfjbTjwNNthh6N+DYZ4heyZVu5HmMw7Jzd9vt6cy4dQ6W2Q+VLkxZUDR16m3Hl7q3 HsMn77xxXhxyqmr7TGDraXMsMqqHaOOI1lt2umBh9kyVV/ieHbE2ubofssPC5E70EyX5 bjGvvEhgtVZDiIwpnAYhPb7TKQZYdPbrqb8kEN8+jnarTu3AJAE8qoJNtNi5ZfAbeHla 8yD32prOi8XoU+Lah8eyeq1m+e+HAMqD0asbihjnBlbU2L96sBaMRdOmpQiclNvBGfv1 qy0Q== X-Forwarded-Encrypted: i=1; AJvYcCUZ5gwSs7RPJMXH8PI03mUIoJdrfMu1uW92ugPvzKq01Edims5qjs4afP9OGvwNjELTRiFA9Agidozsj4bT5mNDjRCGaZY0kmYGe4bE X-Gm-Message-State: AOJu0Yz3Mztni+XwiZVhEz/hHQ2JgSZqfzm8pTsqJjVaNGmZ3N14aSxg VabQUX769cVeKbyuOjQaIekBwspGAzvp0ceO8MSAwN7dGXrGJFOYiIRc6oh3EA== X-Received: by 2002:a17:90a:c78f:b0:29b:33eb:1070 with SMTP id gn15-20020a17090ac78f00b0029b33eb1070mr236752pjb.14.1711559176238; Wed, 27 Mar 2024 10:06:16 -0700 (PDT) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id pw13-20020a17090b278d00b002a055d4d2fesm1970561pjb.56.2024.03.27.10.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 10:06:15 -0700 (PDT) Date: Wed, 27 Mar 2024 17:06:12 +0000 From: Mingwei Zhang To: "Mi, Dapeng" 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: On Wed, Mar 27, 2024, Mi, Dapeng wrote: > > On 3/27/2024 1:36 PM, Mingwei Zhang wrote: > > 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 > > yeah, a larger upper boundary can fix the fault as well, but the question is > how large it would be enough. For different CPU model, the needed cycles > could be different for warming up. So we may have to set a quite large upper > boundary but a large boundary would decrease credibility of this validation. > Not sure which one is better. Any inputs from other ones? > Just checked with an expert from our side, so "core cycles" (0x003c) is affected the current CPU state/frequency, ie., its counting value could vary largely. In that sense, "warming" up seems reasonable. However, switching the order would be a terrible idea for maintanence since people will forget it and the problem will come back. From another perspective, "warming" up seems just a best effort. Nobody knows how warm is really warm. Besides, some systems might turn off some C-State and may set a cap on max turbo frequency. All of these will directly affect the warm-up process and the counting result of 0x003c. So, while adding a warm-up blob is reasonable, tweaking the heuristics seems to be same for me. Regarding the value, I think I will rely on your experiments and observation. 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 > > >