Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp444487pxy; Wed, 5 May 2021 06:09:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRjj+sGrDxpVT8k17TAnSbtuX6svvMy6cyehV5HAbIV8KdIP+zOzl4+uG0QuEK8gWQEy7m X-Received: by 2002:a17:90a:588f:: with SMTP id j15mr3740037pji.30.1620220157146; Wed, 05 May 2021 06:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620220157; cv=none; d=google.com; s=arc-20160816; b=hAXCKmQqCR4dg672488jg6N0PDmVAVhayfvX6m9WPsWHHx0sEqD6wrH/77ZqIoyVvH U/zGH/DSYZrC2mskwfC0aTn8GumsL6WGWUqzOACk2wqte1cHk4P1KbrBSc4q3IRC1VMx 0NZQHWnpGrBkHj4A9kBJ8Y4P5ZopcBdWYk0iPkff149llq/MvxGfKU9EyNVULOteIwpw K03Rc0GvXrDieB9yx7SSUCNNxSOtuST2BHYHO2JptH+pevRAMlHhCQ70pGsLn8QRlGAF uCXf72RqcCF+TEr7LUrtwbDZjtBXXrlHG5IqvsBdlUdOi9OXEba2uQR9O2kzvCGeS33p cNQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kj3lk+MzppwZnR4pyZdWYqNDn2L5VLUwXkqm3e6rR9s=; b=W2j/EwWyc8e63HxQAtVTuVp/olCSn+xZ4f7JYaUTMlIXft15C6I8FnvDf+lLcqI7OA 7yX6eiq5JXwIg1FGd50ub5Q2Ui/SqQ/SQxe/RxyHhXubmYbJPQsqiJFTZ/86qBOHd4+X u5m4vHx06JHEpX2FuLjr5AB8E8iT+K/ALPELHtr2kMxVN43mp/PqDOG2eYxU1OcAXLzS h/jBABmhxb65ZhJw5xEklcz9Oqd57lm3tA8W3+7uv5IceL1Q+F8jE/Pe7RuuKvMn7oRF LgMMKVuqX5HcjImo23ipNnBJk0GJqT8u4UOdGVM1rj1sY6Db44UZ7rOw1vqj6ZDbUOWD Ryew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IcRzhmy3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r125si20175056pfc.210.2021.05.05.06.08.57; Wed, 05 May 2021 06:09:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IcRzhmy3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233305AbhEENHi (ORCPT + 99 others); Wed, 5 May 2021 09:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbhEENHi (ORCPT ); Wed, 5 May 2021 09:07:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDBEDC061574; Wed, 5 May 2021 06:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=kj3lk+MzppwZnR4pyZdWYqNDn2L5VLUwXkqm3e6rR9s=; b=IcRzhmy3e3QVV24Wb/38lgZKdv sToVrmEzizW7NxLWDO+fD+mh0CDfrQSBuQ13qVXeOpcizNeTdVuacmPo3XrSw81+31tkcQFXH1Al0 i/ueRj/Poi8z1POz6VbBtkD7hdQsg47KGMcDS8quFo4FwvjYLwnjA6Up2Ve8w1c12jrkrCmTj6AMs snNqpQIQ1qgDkc6OQV24oyvU6eqsD0ySV0fKp5X/ZtjDRRCcnzqJS5J4j1sHotocr8EhU8CmIBHrM dVGzUkcR6HxsPMjxN092z6w3Nthn4EOizVNcET3qjdH4FgEsTizIhA3X0ZG1cEZvozuAMqNzGnsCi TDpZTrdw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1leHDA-000LSn-UF; Wed, 05 May 2021 13:05:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2CD993001CD; Wed, 5 May 2021 15:05:06 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2E32A203E67C5; Wed, 5 May 2021 15:05:06 +0200 (CEST) Date: Wed, 5 May 2021 15:05:06 +0200 From: Peter Zijlstra To: "Suthikulpanit, Suravee" Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, iommu@lists.linux-foundation.org, mingo@redhat.com, joro@8bytes.org, Jon.Grimm@amd.com, amonakov@ispras.ru, David Coe Subject: Re: [PATCH] x86/events/amd/iommu: Fix invalid Perf result due to IOMMU PMC power-gating Message-ID: References: <20210504065236.4415-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 05, 2021 at 07:39:14PM +0700, Suthikulpanit, Suravee wrote: > Peter, > > On 5/4/2021 7:13 PM, Peter Zijlstra wrote: > > On Tue, May 04, 2021 at 06:58:29PM +0700, Suthikulpanit, Suravee wrote: > > > Peter, > > > > > > On 5/4/2021 4:39 PM, Peter Zijlstra wrote: > > > > On Tue, May 04, 2021 at 01:52:36AM -0500, Suravee Suthikulpanit wrote: > > > > > > > > > 2. Since AMD IOMMU PMU does not support interrupt mode, the logic > > > > > can be simplified to always start counting with value zero, > > > > > and accumulate the counter value when stopping without the need > > > > > to keep track and reprogram the counter with the previously read > > > > > counter value. > > > > > > > > This relies on the hardware counter being the full 64bit wide, is it? > > > > > > > > > > The HW counter value is 48-bit. Not sure why it needs to be 64-bit? > > > I might be missing some points here? Could you please describe? > > > > How do you deal with the 48bit overflow if you don't use the interrupt? > > The IOMMU Perf driver does not currently handle counter overflow since the overflow > notification mechanism (i.e. IOMMU creates an EVENT_COUNTER_ZERO event in the IOMMU event log, > and generate an IOMMU MSI interrupt to signal IOMMU driver to process the event.) is not > currently supported. When counter overflows, the counter becomes zero, and Perf > reports value zero for the event. > > Alternatively, to detect overflow, we might start counting with value 1 so that > we can detect overflow when the value becomes zero in which case the Perf driver > could generate error message. Urgh.. the intel uncore driver programs an hrtimer to periodically fold deltas. That way the counter will never be short.