Received: by 10.223.185.116 with SMTP id b49csp1321937wrg; Fri, 23 Feb 2018 16:20:45 -0800 (PST) X-Google-Smtp-Source: AH8x226ay6QMeR0yqjNFMMmjiRsS2urKZDhCiszSgtIvH+OBMmvkZxeISaVAH0TMpIqY3rvB9HDq X-Received: by 2002:a17:902:be02:: with SMTP id r2-v6mr3347999pls.234.1519431645667; Fri, 23 Feb 2018 16:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519431645; cv=none; d=google.com; s=arc-20160816; b=iay9oRFhe5PHRLqrdi6geADkGX4rNrtM6ihv/5fYZnY/ATlFMYMbDX610++Ufqa2vB pYotlx0F1NqrKPR8ehLrbrYuk7BU7eLIM9lZFRJWeXLc4Moqc3O3RItUyeD6V/zsqMuB o+q9aMiJMtebkJhjQ9Gz90SBW4yHNYQB/QgjNnGU3Ip5hW3/9y2LcIE/3bk90uhhoOfd lmxvquzd15Mwh6VMDQijo1lDgoXFXhUtZiHb/oXlFqAvZemm8VvM19lW40OBk3CQQOES 0218/rilZrdOqVNrC5UvA05gYS8lH0g5zDsEG/fRAy6J6U2810mhYxMBuOIDZ1j6yBO4 Ge+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=wMRH+sgaxJD6azxA2rpXib4yLqBxK4fjMOXLaBZMcRs=; b=EXtOTIkANZ1rSzg51/vb6IToR8WXqfaq9wByo1JTV6zIQ3nLyY++pI6AfuGTjJMUnr nsKI6cnBRKkx5c5rFG8SYICtpJzYLZxVoncBxNx9Kc0BtpzjuRS+lhk+blPQaZ41J50h EJZOgLUx53RlSarRyOI9ImUXI2xce8NzFK+2x2kd7reI4zncsa/GIk5L3g/mlBV9gvnD q6Euma5rxoDpEid0gxznpEGzT+AHpSDiG9tN8u8HhsOyT0IRjVpt3TXHKv2RqmRuEcDr WnzIqhmi0zrM49aNQelYh7sRBvQljYCPHBLZ7D8VJmYs98WRhLy1KfjAOwXhD5O2Ahww wNtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=eKGVnPUc; dkim=pass header.i=@codeaurora.org header.s=default header.b=JiVutdrJ; 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 n5si2155176pgc.459.2018.02.23.16.20.31; Fri, 23 Feb 2018 16:20:45 -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=pass header.i=@codeaurora.org header.s=default header.b=eKGVnPUc; dkim=pass header.i=@codeaurora.org header.s=default header.b=JiVutdrJ; 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 S1752504AbeBXATu (ORCPT + 99 others); Fri, 23 Feb 2018 19:19:50 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:40728 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbeBXATr (ORCPT ); Fri, 23 Feb 2018 19:19:47 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A983560F6C; Sat, 24 Feb 2018 00:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519431586; bh=W09lFgjXsnIveq368KsE8chNpG6OoYswKCD+Qie9kbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKGVnPUc5+dERBN/UfhbWPqHGwCHJ4UNA0Q9RPY7gq6YUB6sXaD4RVlsNFGZMDbST fPhwWaOtCekzj77wnQBNkgxjaghgMxhV3UGWPqbIzuHw1vIh5X8INFvmZYeRZlrSsR EzocTe3W27ckgcuhb0M54v3SDfHof6p1qDHldUsg= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 4F70A60F6C; Sat, 24 Feb 2018 00:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519431585; bh=W09lFgjXsnIveq368KsE8chNpG6OoYswKCD+Qie9kbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiVutdrJ1bCdyoveZgx+fMCn4RpM+yPQ48N34dLYfTDtKFIi9jdCz8EhOEKDg9AOH oBmGwcqddaU4VtKY3a5HztLrqp3AIYg3hnP5bCF+YGcg6YVrj+EOqfV2UCQd9r72Xi dg7v4koYVFV2REndSDaYXmcwnX/ywwAk55uKbdaM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4F70A60F6C 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, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim Cc: skannan@codeaurora.org, avilaj@codeaurora.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] perf/core: Add support for PMUs that can be read from any CPU Date: Fri, 23 Feb 2018 16:19:38 -0800 Message-Id: <1519431578-11995-2-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1519431578-11995-1-git-send-email-skannan@codeaurora.org> References: <1519431578-11995-1-git-send-email-skannan@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some PMUs events can be read from any CPU. So allow the PMU 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 wake ups. Good examples of such events would be events from caches shared across all CPUs. Signed-off-by: Saravana Kannan --- include/linux/perf_event.h | 3 +++ kernel/events/core.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 7546822..ee8978f 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -510,9 +510,12 @@ typedef void (*perf_overflow_handler_t)(struct perf_event *, * PERF_EV_CAP_SOFTWARE: Is a software event. * PERF_EV_CAP_READ_ACTIVE_PKG: A CPU event (or cgroup event) that can be read * from any CPU in the package where it is active. + * PERF_EV_CAP_READ_ANY_CPU: A CPU event (or cgroup event) that can be read + * from any CPU. */ #define PERF_EV_CAP_SOFTWARE BIT(0) #define PERF_EV_CAP_READ_ACTIVE_PKG BIT(1) +#define PERF_EV_CAP_READ_ANY_CPU BIT(2) #define SWEVENT_HLIST_BITS 8 #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS) diff --git a/kernel/events/core.c b/kernel/events/core.c index 5d3df58..570187b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3484,6 +3484,10 @@ static int __perf_event_read_cpu(struct perf_event *event, int event_cpu) { u16 local_pkg, event_pkg; + if (event->group_caps & PERF_EV_CAP_READ_ANY_CPU) { + return smp_processor_id(); + } + if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) { int local_cpu = smp_processor_id(); @@ -3575,6 +3579,7 @@ int perf_event_read_local(struct perf_event *event, u64 *value, { unsigned long flags; int ret = 0; + bool is_any_cpu = !!(event->group_caps & PERF_EV_CAP_READ_ANY_CPU); /* * Disabling interrupts avoids all counter scheduling (context @@ -3600,7 +3605,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 != smp_processor_id() && + !is_any_cpu) { ret = -EINVAL; goto out; } @@ -3610,7 +3616,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() || is_any_cpu) event->pmu->read(event); *value = local64_read(&event->count); -- Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project