From patchwork Wed Jan 31 12:05:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13539440 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 6AF7F7BB06; Wed, 31 Jan 2024 13:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706592; cv=none; b=koAXf8qaci4j1qnOZTpo9kw6r5W3Kdqo32D670zMYO9iBSo7CYRx5OsOxMCKqbBSNc96SUG0Fs/U+ixVZTnlceGRkN6zSJffEk810woObph1EDa1cGHFISwoBXBkWQLi5OmRWDZbztZV9wmkAQTpU+B1zClXq+wZzYmdEP71HI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706592; c=relaxed/simple; bh=JX0N/7ypdkFlnA58ZmbSsHLuhJ9NA5OC0DOrMAeMuvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y+GwX8IzCPgy2yMm4PQsN/ZA273kE0Q+ym8+Qdu2B6iE2s+/jkUKaNLaARxMaz9CuIVZw0DFcZxyvDgM0qg+950U7ZFyo2bszwq/W4xwJWHZpv1TAC9AnK03D61VGg7w7LsmZs1EC+rNDLobfMbanaJlPXUYWNswhZqj7bjA/xI= 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=iCGrseRB; arc=none smtp.client-ip=192.198.163.8 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="iCGrseRB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706706590; x=1738242590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JX0N/7ypdkFlnA58ZmbSsHLuhJ9NA5OC0DOrMAeMuvk=; b=iCGrseRBmbWSt/CD92xmR8reF2SlgdwmoqQrqa/KP9eUvxpBIwQinpR9 nVvQPem3LD2b6GwjPKpAiEqCqw2CVWZfK6shHEdVv0sbmsiyPmIToHx2X Xkwjv8lW0eqm6mNASIfi3S4zWMA2mBo7jtb3KlwBuofsnPlFJnKh08BeT BYzvJMh28rAeFxma2LSSni3iuWgJX2wMuFi4NJ+xOuSX/KrAcjQCXJivT V3S+WxXFiemZuM0539IoQRcBhK2nPdWPJI1Ws4SxwI1frCFtAVd42uswb f6u9nwtjczIHb4SSyUb3aG/b1zXXVZGtDqjqgDtCWJHdRn+dftwhk+/8i g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="17126949" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="17126949" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="858816182" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="858816182" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.43.19]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:41 -0800 From: Stanislaw Gruszka To: linux-pm@vger.kernel.org Cc: "Rafael J. Wysocki" , Srinivas Pandruvada , Ricardo Neri , Daniel Lezcano , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH 1/3] netlink: Add notifier when changing netlink socket membership Date: Wed, 31 Jan 2024 13:05:33 +0100 Message-Id: <20240131120535.933424-2-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> References: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add notification when adding/removing multicast group to/from client socket via setsockopt() syscall. It can be used with conjunction with netlink_has_listeners() to check if consumers of netlink multicast messages emerge or disappear. A client can call netlink_register_notifier() to register a callback. In the callback check for state NETLINK_CHANGE and NETLINK_URELEASE to get notification for change in the netlink socket membership. Thus, a client can now send events only when there are active consumers, preventing unnecessary work when none exist. Signed-off-by: Stanislaw Gruszka --- include/linux/notifier.h | 1 + net/netlink/af_netlink.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/linux/notifier.h b/include/linux/notifier.h index 45702bdcbceb..8f5a5eed1e0e 100644 --- a/include/linux/notifier.h +++ b/include/linux/notifier.h @@ -227,6 +227,7 @@ static inline int notifier_to_errno(int ret) /* Virtual Terminal events are defined in include/linux/vt.h. */ #define NETLINK_URELEASE 0x0001 /* Unicast netlink socket released */ +#define NETLINK_CHANGE 0x0002 /* Changed membership of netlink socket */ /* Console keyboard events. * Note: KBD_KEYCODE is always sent before KBD_UNBOUND_KEYCODE, KBD_UNICODE and diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index eb086b06d60d..674af2cb0f12 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1680,6 +1680,11 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, case NETLINK_ADD_MEMBERSHIP: case NETLINK_DROP_MEMBERSHIP: { int err; + struct netlink_notify n = { + .net = sock_net(sk), + .protocol = sk->sk_protocol, + .portid = nlk->portid, + }; if (!netlink_allowed(sock, NL_CFG_F_NONROOT_RECV)) return -EPERM; @@ -1700,6 +1705,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, if (optname == NETLINK_DROP_MEMBERSHIP && nlk->netlink_unbind) nlk->netlink_unbind(sock_net(sk), val); + blocking_notifier_call_chain(&netlink_chain, NETLINK_CHANGE, &n); break; } case NETLINK_BROADCAST_ERROR: From patchwork Wed Jan 31 12:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13539441 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 1F29A7BB0D; Wed, 31 Jan 2024 13:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706593; cv=none; b=qF914E5jgWwuLRQbuh2Enep6IXR2BkFoURxY2o8Bu33o37+lKVc8W2/RTNiHL8LAyHnNIwFJtzQfJkaEqlGGv/2bMY+qn2BgFY6e50oKDGzuhS05++btUFqwhOUOZHbtxBucHtgPduZXv2dXQb3i3hzSQ3SJzQ0DVm57YUiRTaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706593; c=relaxed/simple; bh=RCT/pm4jNBaLXvngRoHheyS4c+M6ptTcHkicWfz+8qM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M4zgDtscQ3hwrXYNWy7CLJ78jpMBBAd8xDgXQDbcqUiLOlmsebtxXzOj3zn7gi+3etxkWsNWpayA2oKUh19mbJ0vGKESs68CzvPJaSfrVifOBZG9GFjd8K5J3E72H2twLrD3f9MXjbycXtN/xzzl4Q4mIkJc0a1p/lfjbN2HNkc= 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=iakkdDkD; arc=none smtp.client-ip=192.198.163.8 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="iakkdDkD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706706592; x=1738242592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RCT/pm4jNBaLXvngRoHheyS4c+M6ptTcHkicWfz+8qM=; b=iakkdDkDzaii6RpggdOMoQDECMkJrKC9xbrAWqlsfY5gqSVYXbCTN7Qt AUEwt6svXrRN9pnjYYZe/3wQVqsuA4W4iExdUcTA0VH4ss06GXwo1ep7z s+avRwpGo4ArjBfDvQBnGcqPGZgxcEVdk9hI1SOj4/L1FJiehHMBLYTwD FguLrljlMTM5/5zqSa/mUgJLAZu725dorlgc69+vpNZl9ltSiuktHL483 yvyP71AYoth2T60ss/XCh/eXnXqR4SZRf/n2L3Z7OSuZ3ee38pHDCK7iq YvCWdJjiGP9Eh3t/DEEAx1vniA2/NR8Vk8a+N+SdgpoueGtoRDiWREw/M Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="17127000" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="17127000" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="858816208" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="858816208" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.43.19]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:46 -0800 From: Stanislaw Gruszka To: linux-pm@vger.kernel.org Cc: "Rafael J. Wysocki" , Srinivas Pandruvada , Ricardo Neri , Daniel Lezcano , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH 2/3] thermal: netlink: Export thermal_group_has_listeners() Date: Wed, 31 Jan 2024 13:05:34 +0100 Message-Id: <20240131120535.933424-3-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> References: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Let drivers use thermal_group_has_listners(). The intel_hfi driver needs it to enable HFI only when user-space consumers are present. Signed-off-by: Stanislaw Gruszka --- drivers/thermal/thermal_netlink.c | 7 +------ drivers/thermal/thermal_netlink.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c index 569e4fa62f73..44e8df2751ba 100644 --- a/drivers/thermal/thermal_netlink.c +++ b/drivers/thermal/thermal_netlink.c @@ -13,11 +13,6 @@ #include "thermal_core.h" -enum thermal_genl_multicast_groups { - THERMAL_GENL_SAMPLING_GROUP = 0, - THERMAL_GENL_EVENT_GROUP = 1, -}; - static const struct genl_multicast_group thermal_genl_mcgrps[] = { [THERMAL_GENL_SAMPLING_GROUP] = { .name = THERMAL_GENL_SAMPLING_GROUP_NAME, }, [THERMAL_GENL_EVENT_GROUP] = { .name = THERMAL_GENL_EVENT_GROUP_NAME, }, @@ -76,7 +71,7 @@ typedef int (*cb_t)(struct param *); static struct genl_family thermal_gnl_family; -static int thermal_group_has_listeners(enum thermal_genl_multicast_groups group) +int thermal_group_has_listeners(enum thermal_genl_multicast_groups group) { return genl_has_listeners(&thermal_gnl_family, &init_net, group); } diff --git a/drivers/thermal/thermal_netlink.h b/drivers/thermal/thermal_netlink.h index 0a9987c3bc57..3272a966f404 100644 --- a/drivers/thermal/thermal_netlink.h +++ b/drivers/thermal/thermal_netlink.h @@ -10,10 +10,16 @@ struct thermal_genl_cpu_caps { int efficiency; }; +enum thermal_genl_multicast_groups { + THERMAL_GENL_SAMPLING_GROUP = 0, + THERMAL_GENL_EVENT_GROUP = 1, +}; + /* Netlink notification function */ #ifdef CONFIG_THERMAL_NETLINK int __init thermal_netlink_init(void); void __init thermal_netlink_exit(void); +int thermal_group_has_listeners(enum thermal_genl_multicast_groups group); int thermal_notify_tz_create(int tz_id, const char *name); int thermal_notify_tz_delete(int tz_id); int thermal_notify_tz_enable(int tz_id); @@ -38,6 +44,11 @@ static inline int thermal_netlink_init(void) return 0; } +static inline int thermal_group_has_listeners(enum thermal_genl_multicast_groups group) +{ + return 0; +} + static inline int thermal_notify_tz_create(int tz_id, const char *name) { return 0; From patchwork Wed Jan 31 12:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13539442 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 CDC237D416; Wed, 31 Jan 2024 13:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706596; cv=none; b=eZEWIFMrZAoffcIxfMAgIFeaYOK90E9CW1gP3gxjMZGXqX4WEpWcgKstKmv3fac5XaqUy/JwnsrAzYYDkKuSNdt7Ce1knxyX0VabhoY5MRGPcn129sc0rJ8Pss1HodUg9LTRv6XoYHpVvIj27bMKnctv25oxcY/CX0MfRBIvI7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706596; c=relaxed/simple; bh=rcpiNeB7CiWeBJw4zwN20vL/n4yivIooXRYMSS2oiw4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=morBDBP1w6uNkGpkFXISG2O44MmcGTm775ohGVDVbBuzntaOKAb16QexHwvi1gbFPFJg+WvsNJKups4ujOY2mq2vr61u2OzFhM62BrhunS71veplxPyz9h31Wt+GYdUIfZua+3ggN3n1dpehvoIX55Wua1HGm1YTM7cUtaSh8X8= 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=FRCKs/WT; arc=none smtp.client-ip=192.198.163.8 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="FRCKs/WT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706706594; x=1738242594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rcpiNeB7CiWeBJw4zwN20vL/n4yivIooXRYMSS2oiw4=; b=FRCKs/WTqV4XJCdhCxtHyjehc27jpnacKHlLamFpc5NKS/2OdIDj/O4b WLd8yGcEQerwWUt8xj5at54EbTlCPH02G4E54fSURQuAE3IXea3KVJtYi Lxmwk6wwgjPzsmn3O5I1veV7Esje10f9EGQTiJld2FI8meZl2Bw5JdokU mkUDQKlw1P/IJJ9sVsVnhMoJi0dGSuoE+V6isyQ6JAWcmR6lkVaiK+YEo +BECU0IkMzAEMpWPUo+hS8zIJcWfLeTQSwfqeuQjY/OhYBw/1ifNwqgiB 3946PGg7u5W05C7278ujC4q3Gznl2mOVFAR+w5WMtI07eZNaVAYWikFwr Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="17127027" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="17127027" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="858816218" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="858816218" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.43.19]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:52 -0800 From: Stanislaw Gruszka To: linux-pm@vger.kernel.org Cc: "Rafael J. Wysocki" , Srinivas Pandruvada , Ricardo Neri , Daniel Lezcano , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH 3/3] thermal: intel: hfi: Enable interface only when required Date: Wed, 31 Jan 2024 13:05:35 +0100 Message-Id: <20240131120535.933424-4-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> References: <20240131120535.933424-1-stanislaw.gruszka@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enable and disable hardware feedback interface (HFI) when user space handler is present. For example, enable HFI, when intel-speed-select or Intel Low Power daemon is running and subscribing to thermal netlink events,. When user space handlers exit or remove subscription for thermal netlink events, disable HFI. Summary of changes: - When CPU is online, instead of blindly enabling HFI by calling hfi_enable(), check if the thermal netlink group has any listener. This will make sure that HFI is not enabled by default during boot time. - Register a netlink notifier. - In the notifier process reason code NETLINK_CHANGE and NETLINK_URELEASE. If thermal netlink group has any listener enable HFI on all packages. If there are no listener disable HFI on all packages. - Actual processing to enable/disable matches what is done in suspend/resume callbacks. So, create two functions hfi_do_enable() and hfi_do_disable(), which can be called fromĀ  the netlink notifier callback and suspend/resume callbacks. Signed-off-by: Stanislaw Gruszka --- drivers/thermal/intel/intel_hfi.c | 82 +++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index 3b04c6ec4fca..50601f75f6dc 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -480,7 +481,8 @@ void intel_hfi_online(unsigned int cpu) /* Enable this HFI instance if this is its first online CPU. */ if (cpumask_weight(hfi_instance->cpus) == 1) { hfi_set_hw_table(hfi_instance); - hfi_enable(); + if (thermal_group_has_listeners(THERMAL_GENL_EVENT_GROUP)) + hfi_enable(); } unlock: @@ -573,28 +575,84 @@ static __init int hfi_parse_features(void) return 0; } -static void hfi_do_enable(void) +/* + * HFI enable/disable run in non-concurrent manner on boot CPU in syscore + * callbacks or under protection of hfi_instance_lock. + */ +static void hfi_do_enable(void *ptr) +{ + struct hfi_instance *hfi_instance = ptr; + + hfi_set_hw_table(hfi_instance); + hfi_enable(); +} + +static void hfi_do_disable(void *ptr) +{ + hfi_disable(); +} + +static void hfi_syscore_resume(void) { /* This code runs only on the boot CPU. */ struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0); struct hfi_instance *hfi_instance = info->hfi_instance; - /* No locking needed. There is no concurrency with CPU online. */ - hfi_set_hw_table(hfi_instance); - hfi_enable(); + hfi_do_enable(hfi_instance); } -static int hfi_do_disable(void) +static int hfi_syscore_suspend(void) { - /* No locking needed. There is no concurrency with CPU offline. */ hfi_disable(); return 0; } static struct syscore_ops hfi_pm_ops = { - .resume = hfi_do_enable, - .suspend = hfi_do_disable, + .resume = hfi_syscore_resume, + .suspend = hfi_syscore_suspend, +}; + +static int hfi_netlink_notify(struct notifier_block *nb, unsigned long state, + void *_notify) +{ + struct netlink_notify *notify = _notify; + struct hfi_instance *hfi_instance; + smp_call_func_t func; + unsigned int cpu; + int i; + + if (notify->protocol != NETLINK_GENERIC) + return NOTIFY_DONE; + + switch (state) { + case NETLINK_CHANGE: + case NETLINK_URELEASE: + mutex_lock(&hfi_instance_lock); + + if (thermal_group_has_listeners(THERMAL_GENL_EVENT_GROUP)) + func = hfi_do_enable; + else + func = hfi_do_disable; + + for (i = 0; i < max_hfi_instances; i++) { + hfi_instance = &hfi_instances[i]; + if (cpumask_empty(hfi_instance->cpus)) + continue; + + cpu = cpumask_any(hfi_instance->cpus); + smp_call_function_single(cpu, func, hfi_instance, true); + } + + mutex_unlock(&hfi_instance_lock); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + +static struct notifier_block hfi_netlink_nb = { + .notifier_call = hfi_netlink_notify, }; void __init intel_hfi_init(void) @@ -628,10 +686,16 @@ void __init intel_hfi_init(void) if (!hfi_updates_wq) goto err_nomem; + if (netlink_register_notifier(&hfi_netlink_nb)) + goto err_nl_notif; + register_syscore_ops(&hfi_pm_ops); return; +err_nl_notif: + destroy_workqueue(hfi_updates_wq); + err_nomem: for (j = 0; j < i; ++j) { hfi_instance = &hfi_instances[j];