Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp272294img; Mon, 18 Mar 2019 02:48:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpK7409nX9ufcgeO7/L4DSFVV8V4OFaiN342vuhVN4/xXfFJ5WgqLWCqjSrLcEzG47o2LA X-Received: by 2002:a65:6651:: with SMTP id z17mr16023947pgv.95.1552902516185; Mon, 18 Mar 2019 02:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902516; cv=none; d=google.com; s=arc-20160816; b=p1oh/ya0drCAgLb/osqFsOKFSAwYs0NIgLNKcHBd4kgohDrCs1lDXjnj0ui2x/1hbV 695ShE+lV4FZvObhNaC2nBJ43h4kurZFnWl0efvIYT6L4mzujMKVxlxP5ecPG24OIb9/ cyLerG3I7V5eoAL1dc7F+Zy6CWcgwDZ600jVMBXB/wQf7h3IanmMZfX4ljXHxZslkgoP GvJcw1ZCdGOu+x9SF0oFBnKArG6p6oiUf9gHgfvra1EM1XcS6Zu6q4r15C+nKu0wuQsr on3dgdvS6lybd8r/N5oIGDIC/mmMxYraqLWYl648/iB7bhyK2lyniPSwWIOad7aPUOxc PQGg== 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=HEGuI18hqh5frPWqUe6FxZWpHjMFVsQ6h+RIMt/o4ls=; b=oH1o9VQHVvZC2FIasXJvGihm7sgZ+X9IZKHSIGY5pwYQ/4suOFE0Bf8/1HPYVebIvI nDa7anmClXMJqjz/V2h3sVvYNKYgvNP6gXrmXr+AQL3ddNpIxg6uI1M7u7wilkuV1o8P 07bbza8eh9eCbkF3T/AbHKIyqwFsEqKLgrcQ8me/D00Sz4F1V2YZt+Q5oz9/18RzGuxa g5xYjDB5lOEAUZYI9wUDB4Xf6lsVGNi2r0Mk9fqf5pAHSF2h1mJ1YqsDM9FYqgUv0sCi NFC6odZUSJhMYxBlfxoKiwfUznUBXNbU0P57tPAab38Pj6izAk+5/ZdxVSFW5If8r0GO 2C8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Dvq0o8MZ; 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 b39si9407589pla.381.2019.03.18.02.48.21; Mon, 18 Mar 2019 02:48:36 -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=bombadil.20170209 header.b=Dvq0o8MZ; 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 S1728394AbfCRJrb (ORCPT + 99 others); Mon, 18 Mar 2019 05:47:31 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:56890 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbfCRJr2 (ORCPT ); Mon, 18 Mar 2019 05:47:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=HEGuI18hqh5frPWqUe6FxZWpHjMFVsQ6h+RIMt/o4ls=; b=Dvq0o8MZQ+YLi/ccMuFsGs4dL gUTqN/YuXqND7ULu8fuY026cbG+mwStnBCFv2nEUjg2B+3L5+1Zttc4ckd48tJRX+2olYW0K1Z34K 3JLJopKo2njoqX3AQwbqFmROaCTjHRhJaobim7FFAyl++NrlXcYICsVqr4h/loDCtkDiP81+Qa0By GV4z9Ky2ELMRrudCg7hBeGVLUXopDUe0s/Ryfwwy74Qw+7HhLy4+sdX/MjUIfM5pHCm5X1fx8TKt1 tJhuaJ8DqJmqszpyggPwceE/YL7v1aD2zbIWyj4lAhkuWOCr14JjG/QdjNOvTt2fdFdUmw6JMK9HZ k+IfPCSsw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h5ora-0006cP-Ge; Mon, 18 Mar 2019 09:47:22 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C9FC520A0FF88; Mon, 18 Mar 2019 10:47:19 +0100 (CET) Date: Mon, 18 Mar 2019 10:47:19 +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: <20190318094719.GD6521@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: <20190315120311.GX5996@hirez.programming.kicks-ass.net> 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 01:03:11PM +0100, Peter Zijlstra wrote: > 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? And I think I've spotted a bug there; consider the case where only PMC3 has an active event left, then the interrupt would consume the running state for PMC0-2, not leaving it for the spurious interrupt that might come after it. Similarly, if there's nothing running anymore, a single spurious interrupt will clear the entire state. It effectively is a single state, not a per-pmc one. Something like the below would cure that... would that help with something? Or were we going to get get rid of this entirely with your patches... diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index e2b1447192a8..a8b5535f7888 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1432,6 +1432,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) struct cpu_hw_events *cpuc; struct perf_event *event; int idx, handled = 0; + int ridx = -1; u64 val; cpuc = this_cpu_ptr(&cpu_hw_events); @@ -1453,8 +1454,8 @@ int x86_pmu_handle_irq(struct pt_regs *regs) * might still deliver spurious interrupts still * in flight. Catch them: */ - if (__test_and_clear_bit(idx, cpuc->running)) - handled++; + if (test_bit(idx, cpuc->running)) + ridx = idx; continue; } @@ -1477,6 +1478,11 @@ int x86_pmu_handle_irq(struct pt_regs *regs) x86_pmu_stop(event, 0); } + if (!handled && ridx >= 0) { + __clear_bit(ridx, cpuc->running); + handled++; + } + if (handled) inc_irq_stat(apic_perf_irqs);