Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3522760pxf; Mon, 15 Mar 2021 11:26:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhemZSe7wCM0BqtEQQrJjY9KC1as7175yUZlxZ9dK0LvDhUkr/BNRcNtA1vTq3hXJs33uI X-Received: by 2002:a17:906:3849:: with SMTP id w9mr25533534ejc.7.1615832795304; Mon, 15 Mar 2021 11:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832795; cv=none; d=google.com; s=arc-20160816; b=Vos2trV0tpy9DcNF0Hd1/XPhWAukSNKuzAQdyjSWnEIZQfvfqNdS1eUhVg5a+Mts7L gnYlHdw0lUb8oqYfRa0pNdTrGp18rwKiJ35L3Zlqx8KT1QtKZpfPK2ym7pmwFszMnGwI A6FfEnZb3vWjAoml2B+r/GL6BTtpgKcmoKNglXGxbgE71QyOaCYUafRoNyHV2ahSFSp4 yAPRABq/y9AUioTE+CXU9YzENcslQSFC5ik7nXy4p2R0Wej/tX6hp8r/r/GUXOdM7ZNK m42sfML/BabEUd8UkxjGOoyP8+hVqanCKlFtMWoMUltg5RdKfnc57q/9FYKN046VIBzV 0dGA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WuOxmwyUwUYeMikBOUOKmIlf8TX4Gmpq9FtoYI3fbEw=; b=EksccgFMsXm9Zi3dVpXZHVmPigNDCVcERoRV9W7ye0N49lR6OnfBD3X/tEkAvLDBzc v8r7FDPEk0dsssU433r4K3oAPicasBfJYJ0uZBJ8YwZy5+FWnPx6FIUF+tAbQ2NRhIik oknQO8G/FEuq5S3ODo3u5cYUjRsnCKPPKzh+DapnzAw7rvVcByw8mvQmVqBSdpeWaPju 8Phy7UHiXqt04lMMsciEadEUSOqAD3Y2CoK1EQa2eYpQllpbDgvZbjyiIjDoEz0fLKFG TyOeOL7ANputReQ/85yg+GN/vmREEIt1cjoeFKekD3BTWK7shIfhmt1F1vE+BoBSLBD9 tGRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dk3AgUZi; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si11416415ejy.135.2021.03.15.11.26.09; Mon, 15 Mar 2021 11:26:35 -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=@linuxfoundation.org header.s=korg header.b=dk3AgUZi; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232629AbhCOO0l (ORCPT + 99 others); Mon, 15 Mar 2021 10:26:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:36594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbhCOOAd (ORCPT ); Mon, 15 Mar 2021 10:00:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC3D264F17; Mon, 15 Mar 2021 14:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816812; bh=hQdHPMwGgGk4WGhFQSNaeVxXu8ip59ymBMc5lU7ocLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dk3AgUZi8isdSbYG1XW5mIN3xkwDYPBv19tQ9LGIQzb+rzRJJtV0Q31v+Voe7J+7j Dpss9+obErDnqmfL+AU1wP+hcbpgZdrkFXpO/ojAPE9oHkKLDBjFrcgWS4zSq5ftEi 1vD6Fcr/lsq79D/ASObHpBGXVdHtYXncmt96MAuc= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Athira Rajeev , Sasha Levin Subject: [PATCH 5.11 139/306] powerpc/perf: Record counter overflow always if SAMPLE_IP is unset Date: Mon, 15 Mar 2021 14:53:22 +0100 Message-Id: <20210315135512.340539325@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman 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 a4908652242e..51f413521fde 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2149,7 +2149,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) @@ -2167,9 +2177,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