Received: by 10.223.176.5 with SMTP id f5csp719868wra; Fri, 9 Feb 2018 06:11:46 -0800 (PST) X-Google-Smtp-Source: AH8x224VP6k0yV9iF/XqnEAj747jGv4LfyFWAzQCGNLRdCAVEuitxeAHCd0zPo8daOn6CPWZLZAe X-Received: by 10.99.128.195 with SMTP id j186mr235361pgd.37.1518185506725; Fri, 09 Feb 2018 06:11:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518185506; cv=none; d=google.com; s=arc-20160816; b=IkS7/NTiq/gLHx9WnvgGnTyD9kclf0L3lilFsZIEDg44otVta1IgCZdN2jY9jqvLMl CAQrG9gTJQ1FzCSfFWY7LbaeT6eQgLIRnyFC/cms7rhoX8ju3wJnz6i/lNkJn86TZzu7 cQtPUZBwOQPXbJFiAnK5xHdkxUyENVdooTIIDnNaNn3OywgHMjd17mP/GhIMKdwMG3IZ TH/aR3mgrv1blNKinH3BIS+SG/eyF5xqxy+OpMPmp0UgIFvf9C4ZJwN4qxlbyDJncfb9 rhjjTN73k1kuS/YkAR2ZtVn2+/cJrEXAPpkuoNLhsSqI8V5FNxGYcNIHHKDCCm7CdRyj Fp8w== 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:arc-authentication-results; bh=YiSpSyHqqFU/VTHX92s6nn515eX4pdI47q0mqstj3MA=; b=Z5aLjHKpPaW5nqo6sc7ECZTVjlAyXPcP0cCVWpmt9iHyAxn1ncmgMhWjArmt5Jf3Iw zcq9tvWwXP5RM3BROW/jfDpAwSmYMHGrN/qvvsRMI767HDJWdS09hPJI9tZa+l1CNYMS qiQNKkfyduwq6bOnmj6eMfTgp6pKjtSup3wSEQVAWk8bOxODPTcZIR1a4No2Rl8g1PUQ X7XTtGBD749pV9xQyuM4u8EnpBW2V1ZvAVYKSwm5L6Te9cRU/Dh3DEKoWhPLlNnJAhGJ N5L7zFOESqQVHyb9GEfOS3BoqJsSUpjmK3MCQrSySM/f3FtG0m/PRJLDjY97cjR2MQ64 YAwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=j2i5swO5; 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 x19si1416819pge.2.2018.02.09.06.11.32; Fri, 09 Feb 2018 06:11:46 -0800 (PST) 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=j2i5swO5; 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 S1753015AbeBIOJP (ORCPT + 99 others); Fri, 9 Feb 2018 09:09:15 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:52105 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752830AbeBIOJM (ORCPT ); Fri, 9 Feb 2018 09:09:12 -0500 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=YiSpSyHqqFU/VTHX92s6nn515eX4pdI47q0mqstj3MA=; b=j2i5swO5QEsgaYhGY/GkiYHiW IE69AR27Nwhu4yauTNDdBcN4kQplFSGTqEBIxH9H/hAtRRLAVD9nosPJdiBnwJKM8Aoj1SWObdtJJ UA8sTVtUyo+tA6n+C00bHvJn5mPdvINIMqb6w2WI9UNWYFfHr6nZCA2wCEyUkIETAxLpbsEx9iGzd jGeevQVrS+tWrfss8/u7KtcCx8jtVrQtGMol/9KF/qckHi7RmlTATyZtYsk/cppGbsrVzsxRh7TGl BglzUcC3JvcTnjjcVwcQOZb2zihLV+nRfibmupDwAJMzbeDb0H/nnNkdf3Ap19i/NpVFanK2PG+rO puRJzAnuA==; 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.89 #1 (Red Hat Linux)) id 1ek9MS-0000jO-4x; Fri, 09 Feb 2018 14:09:08 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1336520207C90; Fri, 9 Feb 2018 15:09:05 +0100 (CET) Date: Fri, 9 Feb 2018 15:09:05 +0100 From: Peter Zijlstra To: "Liang, Kan" Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, acme@kernel.org, tglx@linutronix.de, jolsa@redhat.com, eranian@google.com, ak@linux.intel.com Subject: Re: [PATCH V3 1/5] perf/x86/intel: fix event update for auto-reload Message-ID: <20180209140905.GG25181@hirez.programming.kicks-ass.net> References: <1517243373-355481-1-git-send-email-kan.liang@linux.intel.com> <1517243373-355481-2-git-send-email-kan.liang@linux.intel.com> <20180206150648.GK2249@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.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 06, 2018 at 12:58:23PM -0500, Liang, Kan wrote: > > > > With the exception of handling 'empty' buffers, I ended up with the > > below. Please try again. > > > > There are two small errors. After fixing them, the patch works well. Well, it still doesn't do A, two read()s without PEBS record in between. So that needs fixing. What 3/5 does, call x86_perf_event_update() after drain_pebs() is actively wrong after this patch. > > + > > + /* > > + * Careful, not all hw sign-extends above the physical width > > + * of the counter. > > + */ > > + delta = (new_raw_count << shift) - (prev_raw_count << shift); > > + delta >>= shift; > > new_raw_count could be smaller than prev_raw_count. > The sign bit will be set. The delta>> could be wrong. > > I think we can add a period here to prevent it. > + delta = (period << shift) + (new_raw_count << shift) - > + (prev_raw_count << shift); > + delta >>= shift; > ...... > + local64_add(delta + period * (count - 1), &event->count); > Right it does, but that wrecks case A again, because then we get here with !@count. Maybe something like: s64 new, old; new = ((s64)(new_raw_count << shift) >> shift); old = ((s64)(old_raw_count << shift) >> shift); local64_add(new - old + count * period, &event->count); And then make intel_pmu_drain_pebs_*(), call this function even when !n.