Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp530002ima; Fri, 15 Mar 2019 08:13:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX7/25CzYMKoWXcXvx8WJ8N8pDLazxCZXCtpPf9ta0e4SA5BtZVJqdkZTYZLX/LGdaGmKQ X-Received: by 2002:a63:ce07:: with SMTP id y7mr3887620pgf.44.1552662784232; Fri, 15 Mar 2019 08:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552662784; cv=none; d=google.com; s=arc-20160816; b=BKAshM6TwOAeYuyW0pzQZpFslYgw7N8dUE2jjtLNQQYLtWCr/EaRNMw6gWCjJM/J+s deM6qx+az3om5gWWF+i66Z2vMr8kzfDHu40yp/MEpv8e6Uqg79zsXauy1aN7Vh+RRH6t do6G1/xiHDaVVB9QfPLh/NS7oneEfZ/FNFNUOSkurQw2OBmbwGgMtX3Mcts5Z0XBc+Dh G4nqP0kZ+01SBBSzIFHrzmpVOMU1VkStNDPX71f9YOv1vqEp1yQRKq5tn4sXDR9GC9GB TFbu00mDQmYdYVzG+iWgFyVCMi2GdQ3ra8p8TFWHx23ck1an+xhuStSrQHj83+pnxifV 4Uow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WH+mhh1U03ZhBYk41Hu8JvupxkfHg7aEqGBgx4656B4=; b=rm/gDK5hT2XlRPBIyRyu5Jk0Ns8NshQ9TjS+HJEnTyJcL8P6dXnhYqb5vIyc+rg11F YYt5PiVvioDTcBq2pr75eCASc6esnmLB3zGejKvHWB7WsFxjyPsenI955BVkt1VKlqAM 2WxQW5A0cuyXrvqoLpOnlnMBpRw0/mPqy4WOyr7D6EqUal5AIcNTbfe1iQKmuFXwEGLE LjGR6Dg2/fCOd7bos7folZgTqZsR/Y4nxS6rKPVjSmTFBjfAS+z/2mwnshZX3F3DgCe4 eHdlyr8F59E5ERoD+W4LyBCoCzUB/TofyzZLa9FyvoQUxTWGQAAdB7KlalZkWrnWVJV7 rf6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="u8/mt62+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si2132723pfh.127.2019.03.15.08.12.33; Fri, 15 Mar 2019 08:13:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="u8/mt62+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbfCOPLY (ORCPT + 99 others); Fri, 15 Mar 2019 11:11:24 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40520 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726097AbfCOPLY (ORCPT ); Fri, 15 Mar 2019 11:11:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WH+mhh1U03ZhBYk41Hu8JvupxkfHg7aEqGBgx4656B4=; b=u8/mt62+oDr/gv8PeRPA3/ZWV i7utCi1XFwQbgj1ooowqmijDxAn69VoHt3Y0P5YaALED88s3NpU/qleskECUhkkRJvOJ1ijeyTioA yfSYshfsDzn4+7BdQEp4ZMYE0mF9eSLLqA/QajYUDlfwQYR7X1oIJrYN1SdWLxXztkTmiNJXp8l4K 7mQw53BXUi47JWtHSa6fTOnU2Y8up44aEVmOwVuJFJKEhYitGLOAal6OJleNBdopeHefkd/myAvV0 8DBbg74n7cRnyvAwxLZ8Kxx9fNlVcfJlnqVeeElEgwzcmRaTiV8gGSUlu1BG/2b76Ft83n25h7cMr tnO2rsfvA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4oUG-0006Uj-Ji; Fri, 15 Mar 2019 15:11:08 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 42A7F236812A9; Fri, 15 Mar 2019 16:11:07 +0100 (CET) Date: Fri, 15 Mar 2019 16:11:07 +0100 From: Peter Zijlstra To: "Lendacky, Thomas" Cc: "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Arnaldo Carvalho de Melo , Alexander Shishkin , Ingo Molnar , Borislav Petkov , Namhyung Kim , Thomas Gleixner , Jiri Olsa Subject: Re: [RFC PATCH 2/2] x86/perf/amd: Resolve NMI latency issues when multiple PMCs are active Message-ID: <20190315151107.GG6058@hirez.programming.kicks-ass.net> References: <155232291547.21417.2499429555505085131.stgit@tlendack-t1.amdoffice.net> <155232292961.21417.3665243457569518550.stgit@tlendack-t1.amdoffice.net> <20190315120311.GX5996@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 15, 2019 at 02:44:32PM +0000, Lendacky, Thomas wrote: > >> @@ -689,6 +731,7 @@ static __initconst const struct x86_pmu amd_pmu = { > >> > >> .amd_nb_constraints = 1, > >> .wait_on_overflow = amd_pmu_wait_on_overflow, > >> + .mitigate_nmi_latency = amd_pmu_mitigate_nmi_latency, > >> }; > > > > Again, you could just do amd_pmu_handle_irq() and avoid an extra > > callback. > > This is where there would be a bunch of code duplication where I thought > adding the callback at the end would be better. But if it's best to add > an AMD handle_irq callback I can do that. I'm easy, let me know if you'd > prefer that. Hmm, the thing that avoids you directly using x86_pmu_handle_irq() is that added active count, but is that not the same as the POPCNT of cpuc->active_mask? Is the latency of POPCNT so bad that we need avoid it? That is, I was thinking of something like: int amd_pmu_handle_irq(struct pt_regs *regs) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); int active = hweight_long(cpuc->active_mask); int handled = x86_pmu_handle_irq(regs); + if (active <= 1) { this_cpu_write(perf_nmi_counter, 0); + return handled; } + + /* + * If a counter was handled, record the number of possible remaining + * NMIs that can occur. + */ + if (handled) { + this_cpu_write(perf_nmi_counter, + min_t(unsigned int, 2, active - 1)); + + return handled; + } + + if (!this_cpu_read(perf_nmi_counter)) + return NMI_DONE; + + this_cpu_dec(perf_nmi_counter); + + return NMI_HANDLED; } > > Anyway, we already had code to deal with spurious NMIs from AMD; see > > commit: > > > > 63e6be6d98e1 ("perf, x86: Catch spurious interrupts after disabling counters") > > > > And that looks to be doing something very much the same. Why then do you > > still need this on top? > > This can happen while perf is handling normal counter overflow as opposed > to covering the disabling of the counter case. When multiple counters > overflow at roughly the same time, but the NMI doesn't arrive in time to > get collapsed into a pending NMI, the back-to-back support in > do_default_nmi() doesn't kick in. > > Hmmm... I wonder if the wait on overflow in the disable_all() function > would eliminate the need for 63e6be6d98e1. That would take a more testing > on some older hardware to verify. That's something I can look into > separate from this series. Yes please, or at least better document the reason for their separate existence. It's all turning into a bit of magic it seems.