Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp958301pxb; Wed, 3 Mar 2021 22:31:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSiJqPqf9xlPtNY3O2BE+tMx25j5QWo6MRuHneq3VsG8/9NcJwYUVEkIzRpsGAXMRVU3B2 X-Received: by 2002:a17:906:3603:: with SMTP id q3mr2415682ejb.201.1614839491185; Wed, 03 Mar 2021 22:31:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839491; cv=none; d=google.com; s=arc-20160816; b=xa2+nSiQicfQ9aBgQ2pNzEaMbqgoRXTXcCw/gPdY/gk0GUPAd+ocsXP97ps2XiCkS6 k4mmWs2/+VSHHOTsBYKPTH0GP9PBkpihZcqyoFAeVdMFqKHlWCbVQuM9ofqYC7lIjqcy nfgMdwoddHi29FrO6F3PNqxN9QyGrhKbxW67fzf6Qs+6xVNQ5o7b/omrXkjFyYRPbYIN o7J2+j1s3V2f3w2ie5hc06HA5V5qLlcrPq8n3Q7p5uMPEWxjWIqU4slcw1SlRo+o62Rl eENldyNrA2FUp6lrBbLENyO0wuJFrAyxV/vH/pQGfLte7iwk6vtgjTXI+RcHTDbnBB6g ufEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/474G1GjFg2kS+WKqBQoBK/Wxy40atWbGnrrB87YVsQ=; b=flkUTb13Rp37Zl5CbqLw505asAd1e4P9zGOMSK74KC1n068hOGQdNhjLvi6fzVF58Z Ag/bz+KRZ3VdnLJB/0wfLRCHxh0CJhFzjgvZLjnX3UCVwLgszkqvE23geZHbV9cUykV8 b5j8u0vnYbcGLIuKaGNaNrfJvT1rJxintxZFXaw001fzcSk9dwXTm2ilDDsDbb6eo34c tE1IFAYKOifySKJ8EJM50+3GBfuQy78DzsmVYeIV8EerBrWoFW+yYpqqmcxNp9cy9aqC pgJdJ5m+m/zMyONQoELTPnybPPYIjMBoZTiF3niGQMO378kjDsP9i5uoVcsXwOP/liM6 cMWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f4xsXUxr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si17441607ejj.318.2021.03.03.22.31.09; Wed, 03 Mar 2021 22:31:31 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=f4xsXUxr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579286AbhCBQqu (ORCPT + 99 others); Tue, 2 Mar 2021 11:46:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:46242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351381AbhCBOWV (ORCPT ); Tue, 2 Mar 2021 09:22:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2890C64FCF; Tue, 2 Mar 2021 11:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614686380; bh=glpC+gZtIoGE6mio5K8dAKMeg1fOZFQX0piH/UGVogQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f4xsXUxr7khE8NYgN05N2QjwgZSdUOs7nVj+OLp4B0v78wSt4yHyldv48YiB9H0Te qm/Ly+jiJyLWKrxm11U8S9SzXH8tI1tnNZiRr/PCAytSf+Ck5v6yEvQr+66ZyLuo9U /GLpfLXCRw0ocbNYmQ9RrDlu/dOv4fJmnDeoOFMHAUgY3C1mLBCeB18AfW4Dly1Dck 5MdZpp+Kvy1cUSapMxiGidiiOi70sBU+oJ6NhoCuYIQfyN07ezGbOPzyy9iGTSnLG2 rgEdlEy2+/yyucjhcnV4uPSMRX/758mDruM0SHDL55MKiAKpE8fac2FrRcX4xgmWPU pzlUxBvslHigA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Athira Rajeev , Michael Ellerman , Sasha Levin , linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 4.4 3/8] powerpc/perf: Record counter overflow always if SAMPLE_IP is unset Date: Tue, 2 Mar 2021 06:59:30 -0500 Message-Id: <20210302115935.63777-3-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210302115935.63777-1-sashal@kernel.org> References: <20210302115935.63777-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Athira Rajeev [ Upstream commit d137845c973147a22622cc76c7b0bc16f6206323 ] While sampling for marked events, currently we record the sample only if the SIAR valid bit of Sampled Instruction Event Register (SIER) is set. SIAR_VALID bit is used for fetching the instruction address from Sampled Instruction Address Register(SIAR). But there are some usecases, where the user is interested only in the PMU stats at each counter overflow and the exact IP of the overflow event is not required. Dropping SIAR invalid samples will fail to record some of the counter overflows in such cases. Example of such usecase is dumping the PMU stats (event counts) after some regular amount of instructions/events from the userspace (ex: via ptrace). Here counter overflow is indicated to userspace via signal handler, and captured by monitoring and enabling I/O signaling on the event file descriptor. In these cases, we expect to get sample/overflow indication after each specified sample_period. Perf event attribute will not have PERF_SAMPLE_IP set in the sample_type if exact IP of the overflow event is not requested. So while profiling if SAMPLE_IP is not set, just record the counter overflow irrespective of SIAR_VALID check. Suggested-by: Michael Ellerman Signed-off-by: Athira Rajeev [mpe: Reflow comment and if formatting] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/1612516492-1428-1-git-send-email-atrajeev@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/perf/core-book3s.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index e593e7f856ed..7a80e1cff6e2 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2008,7 +2008,17 @@ static void record_and_restart(struct perf_event *event, unsigned long val, left += period; if (left <= 0) left = period; - record = siar_valid(regs); + + /* + * If address is not requested in the sample via + * PERF_SAMPLE_IP, just record that sample irrespective + * of SIAR valid check. + */ + if (event->attr.sample_type & PERF_SAMPLE_IP) + record = siar_valid(regs); + else + record = 1; + event->hw.last_period = event->hw.sample_period; } if (left < 0x80000000LL) @@ -2026,9 +2036,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val, * MMCR2. Check attr.exclude_kernel and address to drop the sample in * these cases. */ - if (event->attr.exclude_kernel && record) - if (is_kernel_addr(mfspr(SPRN_SIAR))) - record = 0; + if (event->attr.exclude_kernel && + (event->attr.sample_type & PERF_SAMPLE_IP) && + is_kernel_addr(mfspr(SPRN_SIAR))) + record = 0; /* * Finally record data if requested. -- 2.30.1