From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4C5AC43217 for ; Wed, 8 Dec 2021 20:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4oCH8EaRGne66HHe+6IVxvl3iXaCTr9nV2uBLqpHTIM=; b=dDAUcxQgqzc5Bt cX+lAUZOEH9yfcaJ+/F0ix/zp/i6HqxoRU0uaJFNbinfRcGX2MTyKuDFDP39CvqNUZtYbhui4D72D ALUyp9+Bb2lN9nmtScZo0Ci4HpvtiO46o5HJt7VB688BZVQ+3GXMeAJosmZTQR/BRdTBNypOnqiFE xVroQAs2VLxmd9gHv+TuPGJNpKIA/OBvR+E5i8I1Ax2Na7wFOCua6nTSxJUMZm/+Wjxwhfqp7Kts0 1+RMF80V0hEaZNnDeGqGZHY7LUOW34V5NHEEkhZklsYjdKyhH2d1eIbnnvpshcTnKFPnd10Ju362N zxp/hMMKN1JVQ+E2h9hA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mv3IB-00E9q7-C4; Wed, 08 Dec 2021 20:11:55 +0000 Received: from mail-oi1-f176.google.com ([209.85.167.176]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mv3Hn-00E9gv-Mx for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 20:11:33 +0000 Received: by mail-oi1-f176.google.com with SMTP id t19so5660994oij.1 for ; Wed, 08 Dec 2021 12:11:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rWW1E/t9pfEdNssngznEsk6lzbpnH9Rra30gS4jQWgM=; b=dnK3NBzuJqI10oKWabNyKz64CSbSsQCSv/1gW5kZ9e3faESLsPHQcCW/ZIef64rIQU 2IAI1zPHJf/PbjYAG+jMz9UiLTXqdBEQ3Mt61uUQY+FVeP17aKYj9FNBFS9bSUZWDCU1 rcvlZJGsLp6DhgmDTTLvpZ7J7XltR8Ovn+odNgyOHcxRV8hNlAhKCLOki464cv70+D/8 oW93Za2GILF3HM9pPuTGmR7sAeqFyNdSorEbUfEq1C8z48DzEhSQlUebx/dSv78htdng qoYOTjEGMaI9hlf/XsAypkm3kjC9uBuFOU6sCvzD53M7lzs4fV/AnyBH96achL4NWMQX l6lA== X-Gm-Message-State: AOAM532UZEgrXdte/+EmQNcTn8xvLnXmKtYJsNDXUjYmmI1Rpnpm7K+G ziUCeGX2CHO6HHF2fSrczA== X-Google-Smtp-Source: ABdhPJwvDqYUsSc+36IQZd5Gn0F8osm4042Wgki0XAJgGZwzCUQcjRxjtBdhmrl7gI1ZGPZhAtQ9tw== X-Received: by 2002:a05:6808:1396:: with SMTP id c22mr1725581oiw.59.1638994289957; Wed, 08 Dec 2021 12:11:29 -0800 (PST) Received: from xps15.herring.priv (66-90-148-213.dyn.grandenetworks.net. [66.90.148.213]) by smtp.googlemail.com with ESMTPSA id o2sm927926oik.11.2021.12.08.12.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 12:11:29 -0800 (PST) From: Rob Herring To: Will Deacon , Mark Rutland , Peter Zijlstra Cc: Vince Weaver , Jonathan Corbet , Catalin Marinas , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: [PATCH v13 2/5] perf: Add a counter for number of user access events in context Date: Wed, 8 Dec 2021 14:11:21 -0600 Message-Id: <20211208201124.310740-3-robh@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211208201124.310740-1-robh@kernel.org> References: <20211208201124.310740-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211208_121131_784921_D24F0CE0 X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On arm64, user space counter access will be controlled differently compared to x86. On x86, access in the strictest mode is enabled for all tasks in an MM when any event is mmap'ed. For arm64, access is explicitly requested for an event and only enabled when the event's context is active. This avoids hooks into the arch context switch code and gives better control of when access is enabled. In order to configure user space access when the PMU is enabled, it is necessary to know if any event (currently active or not) in the current context has user space accessed enabled. Add a counter similar to other counters in the context to avoid walking the event list every time. Reviewed-by: Mark Rutland Reviewed-by: Thomas Gleixner Signed-off-by: Rob Herring --- v13: - Rewrote commit message to give more background/reasoning v10: - Re-added. - Maintain the count in the perf core v9: - Dropped v8: - new patch --- include/linux/perf_event.h | 1 + kernel/events/core.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index ba9467972c09..411e34210fbf 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -831,6 +831,7 @@ struct perf_event_context { int nr_events; int nr_active; + int nr_user; int is_active; int nr_stat; int nr_freq; diff --git a/kernel/events/core.c b/kernel/events/core.c index 523106a506ee..68952c134968 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1808,6 +1808,8 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx) list_add_rcu(&event->event_entry, &ctx->event_list); ctx->nr_events++; + if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT) + ctx->nr_user++; if (event->attr.inherit_stat) ctx->nr_stat++; @@ -1999,6 +2001,8 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx) event->attach_state &= ~PERF_ATTACH_CONTEXT; ctx->nr_events--; + if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT) + ctx->nr_user--; if (event->attr.inherit_stat) ctx->nr_stat--; -- 2.32.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel