From patchwork Sat Mar 3 01:14:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 10255923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3657D60211 for ; Sat, 3 Mar 2018 01:15:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2285A28617 for ; Sat, 3 Mar 2018 01:15:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1650F2860C; Sat, 3 Mar 2018 01:15:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 898DC2860C for ; Sat, 3 Mar 2018 01:15:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=g2WopOhLQNcDtIs8UIU8mpMwOxiPkuS5y/vIuwLGRoI=; b=f1d oZB1lJhGIeZr4wxWul+rkA1aXk2n6IZUZaa6YlGOUdMTrqFeHBAnlh4QW7G0nvTgBMKTIxwT9TIYe DML5QtvmOeMXM1rSlqQKFrspjifASaKAZb1D4EitSYD9MPhFWS/jAFAPyl8YhayueXJCctYu512Yl EI2LErqvXRngALpJET6FfJ+W2aOa2lfTrpv+rPrRXQicg7KDQwUELjvD+X0tI0nySBQUY6D3C91Z0 8h6ATbmZepfmfcZHy2qxt9oerYdh5jNylY2K18oulLNSkj4AWeSohAoNNwVEQhZylrI9fpRHBb0ZL 9t4GWYAl7JEA3fAug1B8vrVQb0SmNvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ervld-0002M8-3A; Sat, 03 Mar 2018 01:15:17 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ervlZ-00014v-HS for linux-arm-kernel@lists.infradead.org; Sat, 03 Mar 2018 01:15:15 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F1BC8607B9; Sat, 3 Mar 2018 01:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520039702; bh=ghI+X5RSNqZRFhjQU9t13Sas8+6NRLDMg8pau5Ce9qg=; h=From:To:Cc:Subject:Date:From; b=jvbhSm8B6Pmrqy2gBdcoH9lxmDn7GWk4lSsh3beZZ1PxcOPgGPLRwNXhWOtNU/6qR T80VQZa0AqkVYwPKrDQ+gTbtdKx6FS9ilZOQE+MbS7DxsAMOB6YacT6ucbkjUpg8IJ rVx02jm/y5csnZPvcM7KEAzibSuh06iJTd5mnyBk= Received: from skannan1-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skannan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id B10E6601A1; Sat, 3 Mar 2018 01:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520039701; bh=ghI+X5RSNqZRFhjQU9t13Sas8+6NRLDMg8pau5Ce9qg=; h=From:To:Cc:Subject:Date:From; b=cIUhC8N+2mxZsfUbDOTW82pLV+pwj+gwXSTR9X9fNLY+QC23ctKFt/3uoCqWFIQZz WHSYmxlYJaoM0NPlHQJ+NuBEn+Mil/+6QwJXzxJyDQ89q/03tpwbBZI7K8yVi8Qg+h 5A242M8L1fclxi56WKPCu6YyRUtfB3OXc8ApJVIQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B10E6601A1 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=skannan@codeaurora.org From: Saravana Kannan To: mark.rutland@arm.com, suzuki.poulose@arm.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: [PATCH v2] perf/core: Add support for PMUs that can be read from more than 1 CPU Date: Fri, 2 Mar 2018 17:14:53 -0800 Message-Id: <1520039693-30914-1-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180302_171513_641813_6E913509 X-CRM114-Status: GOOD ( 16.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rananta@codeaurora.org, skannan@codeaurora.org, avilaj@codeaurora.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some PMUs events can be read from more than the one CPU. So allow the PMU driver to mark events as such. For these events, we don't need to reject reads or make smp calls to the event's CPU (and cause unnecessary overhead and wake ups). When a PMU driver marks an event as such, care must be taken by the driver to make sure they can handle the event being read/updated from more than 1 CPU at the same time (Eg: due to an IRQ indicating event counter overflow and another thread trying to read the latest values). Good examples of such events would be events from caches shared across CPUs. Signed-off-by: Saravana Kannan --- Changes since v1: - Use cpumasks instead of capability flag as that's more flexible. include/linux/perf_event.h | 1 + kernel/events/core.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 7546822..4cec431 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -629,6 +629,7 @@ struct perf_event { int oncpu; int cpu; + cpumask_t readable_on_cpus; struct list_head owner_entry; struct task_struct *owner; diff --git a/kernel/events/core.c b/kernel/events/core.c index 5d3df58..1a8fbfa 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3483,10 +3483,12 @@ struct perf_read_data { static int __perf_event_read_cpu(struct perf_event *event, int event_cpu) { u16 local_pkg, event_pkg; + int local_cpu = smp_processor_id(); - if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) { - int local_cpu = smp_processor_id(); + if (cpumask_test_cpu(local_cpu, &event->readable_on_cpus)) + return local_cpu; + if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) { event_pkg = topology_physical_package_id(event_cpu); local_pkg = topology_physical_package_id(local_cpu); @@ -3575,7 +3577,8 @@ int perf_event_read_local(struct perf_event *event, u64 *value, { unsigned long flags; int ret = 0; - + int local_cpu = smp_processor_id(); + bool readable = cpumask_test_cpu(local_cpu, &event->readable_on_cpus); /* * Disabling interrupts avoids all counter scheduling (context * switches, timer based rotation and IPIs). @@ -3600,7 +3603,8 @@ int perf_event_read_local(struct perf_event *event, u64 *value, /* If this is a per-CPU event, it must be for this CPU */ if (!(event->attach_state & PERF_ATTACH_TASK) && - event->cpu != smp_processor_id()) { + event->cpu != local_cpu && + !readable) { ret = -EINVAL; goto out; } @@ -3610,7 +3614,7 @@ int perf_event_read_local(struct perf_event *event, u64 *value, * or local to this CPU. Furthermore it means its ACTIVE (otherwise * oncpu == -1). */ - if (event->oncpu == smp_processor_id()) + if (event->oncpu == smp_processor_id() || readable) event->pmu->read(event); *value = local64_read(&event->count);