From nobody Fri Dec 19 00:03:21 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A87321C19B for ; Fri, 2 Aug 2024 15:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722611765; cv=none; b=daGRzqtjOqDhks0pE8JO34+oVLUlCoCQe68TYVUnVl3ZvuQMPvuHlEbJ/BQdaQx14Fc8fC/k8WdlhWwbXgG/4NwIa698GWA0IZH1kcIeZ9Irx6kXAgaNj2EPY9GavEwWheB2H3tnudEaTtnISFtsTiuIcvtDIxMYzJ1QcK+Gvlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722611765; c=relaxed/simple; bh=+q6If9D2thIVk8mfxeitCcSfQbMYqV+Hm+rfEgc6qVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZQPC7pwFt30+ay00RdoxrWRMOhhDVnhKqWvgSaRyXis0AHLM2t4UdOGtPCc3X1j8VB0mmLlNXUDJSxcOTYELZ1dHqfSFmduIvsEevzpOtPXAzMNcl4NFNiZ1UEZVJzboG5Vofbm5PXq+Uvtk762wakA14R3okLlPmpilbav3BjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XHjqZIjO; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XHjqZIjO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1722611765; x=1754147765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+q6If9D2thIVk8mfxeitCcSfQbMYqV+Hm+rfEgc6qVY=; b=XHjqZIjOnZHEGALT25zFzby1673kf/zAJA8u/7/cweW+i0Pwa6kHOPsx qIWpllQ+pwxC0bAGGbaI8GdIUEtFvu75go8nmxHkKTm4OBM5MinJsMIzL P8ui5jzEAn2DZNmc1mB8mX1K7eBnx5hCTxaJD1LUgYRa2MYfRHSrRbD1x puRN21xjUU4/EU895tcj19Ipk5Y5yMZJx+xW1oCM0zcSkOkRlHt1PImVz EVlVJpoji3v24Q7B05pW7SCf+hoAkm+FyT2dwG8n3Id4jhbaXyWUGmF9c 2KRqIMmg1Yw9Daeuc8ln8VAwZz6WLtO3TqTDjc5M8DWxyfnTJ2EOt2s6m g==; X-CSE-ConnectionGUID: UPSow0eoReikZ55wkBuC3A== X-CSE-MsgGUID: mt9aBvO4QgWcFlx3XMG0DQ== X-IronPort-AV: E=McAfee;i="6700,10204,11152"; a="20473793" X-IronPort-AV: E=Sophos;i="6.09,258,1716274800"; d="scan'208";a="20473793" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2024 08:16:00 -0700 X-CSE-ConnectionGUID: lWCROytnRfa3mMPq4w0L0Q== X-CSE-MsgGUID: M/DABoEiRaWbfFYB4F/U5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,258,1716274800"; d="scan'208";a="55516942" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmviesa010.fm.intel.com with ESMTP; 02 Aug 2024 08:15:59 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, linux-kernel@vger.kernel.org Cc: Kan Liang , Dhananjay Ugwekar Subject: [PATCH 7/7] perf/x86/rapl: Clean up cpumask and hotplug Date: Fri, 2 Aug 2024 08:16:43 -0700 Message-Id: <20240802151643.1691631-8-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240802151643.1691631-1-kan.liang@linux.intel.com> References: <20240802151643.1691631-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kan Liang The rapl pmu is die scope, which is supported by the generic perf_event subsystem now. Set the scope for the rapl PMU and remove all the cpumask and hotplug codes. Signed-off-by: Kan Liang Cc: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 80 +------------------------------------- include/linux/cpuhotplug.h | 1 - 2 files changed, 2 insertions(+), 79 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index f8b6d504d03f..b70ad880c5bc 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -135,7 +135,6 @@ struct rapl_model { /* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly; static struct rapl_pmus *rapl_pmus; -static cpumask_t rapl_cpu_mask; static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; @@ -340,8 +339,6 @@ static int rapl_pmu_event_init(struct perf_event *event) if (event->cpu < 0) return -EINVAL; =20 - event->event_caps |=3D PERF_EV_CAP_READ_ACTIVE_PKG; - if (!cfg || cfg >=3D NR_RAPL_DOMAINS + 1) return -EINVAL; =20 @@ -360,7 +357,6 @@ static int rapl_pmu_event_init(struct perf_event *event) pmu =3D cpu_to_rapl_pmu(event->cpu); if (!pmu) return -EINVAL; - event->cpu =3D pmu->cpu; event->pmu_private =3D pmu; event->hw.event_base =3D rapl_msrs[bit].msr; event->hw.config =3D cfg; @@ -374,23 +370,6 @@ static void rapl_pmu_event_read(struct perf_event *eve= nt) rapl_event_update(event); } =20 -static ssize_t rapl_get_attr_cpumask(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return cpumap_print_to_pagebuf(true, buf, &rapl_cpu_mask); -} - -static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL); - -static struct attribute *rapl_pmu_attrs[] =3D { - &dev_attr_cpumask.attr, - NULL, -}; - -static struct attribute_group rapl_pmu_attr_group =3D { - .attrs =3D rapl_pmu_attrs, -}; - RAPL_EVENT_ATTR_STR(energy-cores, rapl_cores, "event=3D0x01"); RAPL_EVENT_ATTR_STR(energy-pkg , rapl_pkg, "event=3D0x02"); RAPL_EVENT_ATTR_STR(energy-ram , rapl_ram, "event=3D0x03"); @@ -438,7 +417,6 @@ static struct attribute_group rapl_pmu_format_group =3D= { }; =20 static const struct attribute_group *rapl_attr_groups[] =3D { - &rapl_pmu_attr_group, &rapl_pmu_format_group, &rapl_pmu_events_group, NULL, @@ -541,49 +519,6 @@ static struct perf_msr amd_rapl_msrs[] =3D { [PERF_RAPL_PSYS] =3D { 0, &rapl_events_psys_group, NULL, false, 0 }, }; =20 -static int rapl_cpu_offline(unsigned int cpu) -{ - struct rapl_pmu *pmu =3D cpu_to_rapl_pmu(cpu); - int target; - - /* Check if exiting cpu is used for collecting rapl events */ - if (!cpumask_test_and_clear_cpu(cpu, &rapl_cpu_mask)) - return 0; - - pmu->cpu =3D -1; - /* Find a new cpu to collect rapl events */ - target =3D cpumask_any_but(topology_die_cpumask(cpu), cpu); - - /* Migrate rapl events to the new target */ - if (target < nr_cpu_ids) { - cpumask_set_cpu(target, &rapl_cpu_mask); - pmu->cpu =3D target; - perf_pmu_migrate_context(pmu->pmu, cpu, target); - } - return 0; -} - -static int rapl_cpu_online(unsigned int cpu) -{ - struct rapl_pmu *pmu =3D cpu_to_rapl_pmu(cpu); - int target; - - if (!pmu) - return -ENOMEM; - - /* - * Check if there is an online cpu in the package which collects rapl - * events already. - */ - target =3D cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu)); - if (target < nr_cpu_ids) - return 0; - - cpumask_set_cpu(cpu, &rapl_cpu_mask); - pmu->cpu =3D cpu; - return 0; -} - static int rapl_check_hw_unit(struct rapl_model *rm) { u64 msr_rapl_power_unit_bits; @@ -709,6 +644,7 @@ static int __init init_rapl_pmus(void) rapl_pmus->pmu.stop =3D rapl_pmu_event_stop; rapl_pmus->pmu.read =3D rapl_pmu_event_read; rapl_pmus->pmu.module =3D THIS_MODULE; + rapl_pmus->pmu.scope =3D PERF_PMU_SCOPE_DIE; rapl_pmus->pmu.capabilities =3D PERF_PMU_CAP_NO_EXCLUDE; return 0; } @@ -856,24 +792,13 @@ static int __init rapl_pmu_init(void) if (ret) return ret; =20 - /* - * Install callbacks. Core will call them for each online cpu. - */ - ret =3D cpuhp_setup_state(CPUHP_AP_PERF_X86_RAPL_ONLINE, - "perf/x86/rapl:online", - rapl_cpu_online, rapl_cpu_offline); - if (ret) - goto out; - ret =3D perf_pmu_register(&rapl_pmus->pmu, "power", -1); if (ret) - goto out1; + goto out; =20 rapl_advertise(); return 0; =20 -out1: - cpuhp_remove_state(CPUHP_AP_PERF_X86_RAPL_ONLINE); out: pr_warn("Initialization failed (%d), disabled\n", ret); cleanup_rapl_pmus(); @@ -883,7 +808,6 @@ module_init(rapl_pmu_init); =20 static void __exit intel_rapl_exit(void) { - cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE); perf_pmu_unregister(&rapl_pmus->pmu); cleanup_rapl_pmus(); } diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 9ea6290ade56..f408521be568 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -207,7 +207,6 @@ enum cpuhp_state { CPUHP_AP_PERF_X86_UNCORE_ONLINE, CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE, CPUHP_AP_PERF_X86_AMD_POWER_ONLINE, - CPUHP_AP_PERF_X86_RAPL_ONLINE, CPUHP_AP_PERF_S390_CF_ONLINE, CPUHP_AP_PERF_S390_SF_ONLINE, CPUHP_AP_PERF_ARM_CCI_ONLINE, --=20 2.38.1