From patchwork Tue Sep 12 12:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 138472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp723722vqx; Tue, 12 Sep 2023 15:47:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4BwJ0MdBYU61/pluUxC1511F3rSLIvJoBCsceUwxwsIbONvix2C4XSnJs/uGEKf9Ye4aB X-Received: by 2002:a05:6358:2611:b0:135:3f5c:9675 with SMTP id l17-20020a056358261100b001353f5c9675mr1246492rwc.19.1694558833650; Tue, 12 Sep 2023 15:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694558833; cv=none; d=google.com; s=arc-20160816; b=lo0f03tYIDipKTJfAC10mr+ieIxFrA919HEkUZMymx9DpPegCu/G3D8mEpu+xKXk8q U1EwhabLuw7UuPt7hqRzXnKv3T2e6OegS7cS/qcZ5m1MXJmMIN3qs9AjdJzY9x2KjRK9 QqPBdR8FSylsiDJ/8cXivK7tlCeTNaVAmaacH7hHd/6/1PgB3AON4tdevEmp1McQdMr8 4brObmLtgNw/gwyx1V4OwMchum+SXbaO4GE4WTsYO71BAUfqRwJdHRl1IFr0x8TypqJx bHmMoXH8IGqa6nJHCSaTtqtlw+ZFpEmLd/nfLU16XSFVO5xUdxi55ii91pWqrNHvJuKL 6jZg== 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=HzPZ0toviYOXEMs+VvGzv0GJIbHeVR9AUYQ1mRH9vHY=; fh=JnhsZniFxBeHyTNUjxdwY/q15bBEio1YLd/oxHi0Yes=; b=j4Ag93QsdyYoifcpVwIj/4lsmGrx2tgcgCAAP68KGhxXdambChisG1m/W61kTnCvDv xTfyvqFukwZghBcntk4Ajn6uZJIGEGINFkRcNhyo54fwxkQvtjwLnw2ssuQ8rWTJOunC T1lB/hdZ4hk1h34wNgm1lDUw2lBiZ95xulYPTKgA3ieJUoxgQjCIg2YbLX2D+g3Divau gXs/s4MSOM3bV/KsDc1maBFo9AFtMerl/gYEppfQxOdWmaKnf29xJDmz/8+tsLQehDDf ginzww2E+YsJhML9fNhaPn1f1KfrB4jpFKtlYWiAc/7ft7sP6gFZgEr4cxNcASb3aGPT KMTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mSVLddfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id k25-20020a6568d9000000b00569466198c3si8592928pgt.751.2023.09.12.15.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:47:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mSVLddfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 15CD9826EC90; Tue, 12 Sep 2023 05:45:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235205AbjILMpc (ORCPT + 37 others); Tue, 12 Sep 2023 08:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235255AbjILMp1 (ORCPT ); Tue, 12 Sep 2023 08:45:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9CC110D8; Tue, 12 Sep 2023 05:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694522724; x=1726058724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fP06kTzAN8WOEYJEVv+7hMOrn0c51DQEva6ses5OiO4=; b=mSVLddfoR1X5CRBONCywrFJBzIJQRd7/H2DPJsCOKWUqQOd0bBc4SxXu 46kGfZVjLsk4GDfPdO4aLrLlYrgY6oj5wrRPhiTGjKW6wRwV8jKrhSW+X MDnTO1RRz06fpH4HYiUdrfsato2PxUvBbf0JPysI5bIoxtTsS1/MOpGGV +BWx2LSpMS6BimRPmrkHnRt4bnOx6Q/YjKwOFvXeXNkbAHW1pgcLx6ozt Vlf6I4Wi8NR1/eybfyGq3VunQ1FPghiZtsvbe17AHdOxf1SCUdSRRjSXM hjJA8K/hAFufqauJKjHvQ4OODXJXq96b5tM0BWSGsTFlIuRDBZFpOefGs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="358638834" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="358638834" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:45:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="867352818" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="867352818" Received: from srosalim-mobl1.ger.corp.intel.com (HELO tkristo-desk.intel.com) ([10.251.217.51]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:45:18 -0700 From: Tero Kristo To: x86@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com Cc: irogers@google.com, mark.rutland@arm.com, linux-perf-users@vger.kernel.org, hpa@zytor.com, mingo@redhat.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, peterz@infradead.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, namhyung@kernel.org, jolsa@kernel.org, Kan Liang Subject: [RESEND PATCH 1/2] perf/x86/cstate: Allow reading the package statistics from local CPU Date: Tue, 12 Sep 2023 15:44:31 +0300 Message-Id: <20230912124432.3616761-2-tero.kristo@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230912124432.3616761-1-tero.kristo@linux.intel.com> References: <20230912124432.3616761-1-tero.kristo@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 05:45:42 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776873723479716461 X-GMAIL-MSGID: 1776873723479716461 The MSR registers for reading the package residency counters are available on every CPU of the package. To avoid doing unnecessary SMP calls to read the values for these from the various CPUs inside a package, allow reading them from any CPU of the package. Signed-off-by: Tero Kristo Suggested-by: Kan Liang --- arch/x86/events/intel/cstate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c index 96fffb2d521d..cbeb6d2bf5b4 100644 --- a/arch/x86/events/intel/cstate.c +++ b/arch/x86/events/intel/cstate.c @@ -336,6 +336,9 @@ static int cstate_pmu_event_init(struct perf_event *event) cfg = array_index_nospec((unsigned long)cfg, PERF_CSTATE_PKG_EVENT_MAX); if (!(pkg_msr_mask & (1 << cfg))) return -EINVAL; + + event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG; + event->hw.event_base = pkg_msr[cfg].msr; cpu = cpumask_any_and(&cstate_pkg_cpu_mask, topology_die_cpumask(event->cpu)); From patchwork Tue Sep 12 12:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 138563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp815472vqx; Tue, 12 Sep 2023 19:47:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIDIN6ojwxGV916WGs6V58/DGZAYTukAEShp9PHd8jcaGqcLTXIHWbyV5SuLdvbZoW0YX/ X-Received: by 2002:a05:6a20:1614:b0:13f:d171:fd6d with SMTP id l20-20020a056a20161400b0013fd171fd6dmr1358261pzj.51.1694573255064; Tue, 12 Sep 2023 19:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694573255; cv=none; d=google.com; s=arc-20160816; b=RIY/E1ShsE6+K9aqVHdqJKSWzitX5ZnQaNtkqJU3C1fhVuDf8FmnvHxLFF//0YrvrH wmfDkDTxGbztfWvevm9XzLeiBwqSq8lcSG/JgF2Ta1gyKsQRaxUgsZepEpTdOSRWTAxD PFtjDiODMG6DG6ZDOpfswoH78VFgi1LHbKX1S5O0a6qY5cbawZ8Juj4WlLs4qvaW00jf DM15liZeu1js2pK6kyNYrma+pWj3ly+juBmiKpeffsHPXqdt6jxQZIG5TTsemh1zB4dd NrMSOzsaXRI/ETYegvcGCBgkR3JQMhYeEersTj1Wp7OlCJZyMP4PU4joYoy+70+pi5sP m+zw== 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=onIxlG/GOwVaH/dyIQEJs+gOWKwHYnltB//efuRLiMs=; fh=1BjoLzis1YUocfaOuycg809dRmcroAGhQwcn1xfg9PY=; b=DjNREXnuAQ10F5wb1YB7sToIfYGTfK5an8UUJxsdMk5vgEuU2EPttZAf0DOxIG7PTy e7g8+Ah2xg0gy22MXyhbFq/mP72u6QwG7OJ/ZKc4WHG9IxzZSlhYYSyiMOmtXb5UG8EH ic8NV2ueK5lFU9607h7tqVYOYzDnW+XAu2DxUlHUIkCgHvU9pmWGsxxHmm+oL6DaR9VG A4kFKvMX2sxP5qf72ldjcTXvjEOT8jijrpx41ln23xLP3pty0uxjqedcgysxgBKDcGto QUfnb6da7ErXtdehehH/IvMDL3B2ClNk1q1PK6uc9IM5812Gzj34+rHxmclF/OjvAN2W q/VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FaPqQdqF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i14-20020a17090a4b8e00b00263a5cf8e64si600561pjh.67.2023.09.12.19.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 19:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FaPqQdqF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2F4FC80E5BA8; Tue, 12 Sep 2023 05:45:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235313AbjILMph (ORCPT + 37 others); Tue, 12 Sep 2023 08:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235274AbjILMpc (ORCPT ); Tue, 12 Sep 2023 08:45:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDEE610DC; Tue, 12 Sep 2023 05:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694522728; x=1726058728; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QbKO5F53E+2iDJzfFlggemhEhBQc5+LlHD2g0rs4x5M=; b=FaPqQdqFuXkabTgD+bZEGM0fF3xI7ybQMmrPUtVzM34hR/GStlKQf2Ps rL2AxkGwppHczctvRUO/xbJMY2eIOCiEnCM6Xv5RqhDiKlwzcAxXSmLdo 48uomb561rOMsSDZ890aYxrGgHKzgBbwUFFR5erkEBYyn34wY205NMhUA aRoj2d7IDRgPbsC6BdhJNSiHow3jI1bz+0Q39NXYFiovwmJ98SblStHGp 8E1ICtAoOJ2MT1NCNCmW1t5uoSsRcTDn5xzga4VSzyIniarMJUdheiYTc Cuk/Arr29TpNvhdsTc5Be//O36Ca1VpyAq7/ZAZ+Z4BQvy2FoYPXtoohj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="358638856" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="358638856" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:45:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="867352848" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="867352848" Received: from srosalim-mobl1.ger.corp.intel.com (HELO tkristo-desk.intel.com) ([10.251.217.51]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:45:23 -0700 From: Tero Kristo To: x86@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com Cc: irogers@google.com, mark.rutland@arm.com, linux-perf-users@vger.kernel.org, hpa@zytor.com, mingo@redhat.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, peterz@infradead.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, namhyung@kernel.org, jolsa@kernel.org Subject: [RESEND PATCH 2/2] perf/core: Allow reading package events from perf_event_read_local Date: Tue, 12 Sep 2023 15:44:32 +0300 Message-Id: <20230912124432.3616761-3-tero.kristo@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230912124432.3616761-1-tero.kristo@linux.intel.com> References: <20230912124432.3616761-1-tero.kristo@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 12 Sep 2023 05:45:55 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776850397188331394 X-GMAIL-MSGID: 1776888845335746378 Per-package perf events are typically registered with a single CPU only, however they can be read across all the CPUs within the package. Currently perf_event_read maps the event CPU according to the topology information to avoid an unnecessary SMP call, however perf_event_read_local deals with hard values and rejects a read with a failure if the CPU is not the one exactly registered. Allow similar mapping within the perf_event_read_local if the perf event in question can support this. This allows users like BPF code to read the package perf events properly across different CPUs within a package. Signed-off-by: Tero Kristo --- kernel/events/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 4c72a41f11af..780dde646e8a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4528,6 +4528,7 @@ int perf_event_read_local(struct perf_event *event, u64 *value, { unsigned long flags; int ret = 0; + int event_cpu; /* * Disabling interrupts avoids all counter scheduling (context @@ -4551,15 +4552,18 @@ int perf_event_read_local(struct perf_event *event, u64 *value, goto out; } + event_cpu = READ_ONCE(event->oncpu); + event_cpu = __perf_event_read_cpu(event, event_cpu); + /* 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()) { ret = -EINVAL; goto out; } /* If this is a pinned event it must be running on this CPU */ - if (event->attr.pinned && event->oncpu != smp_processor_id()) { + if (event->attr.pinned && event_cpu != smp_processor_id()) { ret = -EBUSY; goto out; } @@ -4569,7 +4573,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_cpu == smp_processor_id()) event->pmu->read(event); *value = local64_read(&event->count);