From patchwork Thu Dec 28 10:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13505900 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 C78916FBF for ; Thu, 28 Dec 2023 10:49:29 +0000 (UTC) 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="iI0B8S3A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703760570; x=1735296570; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=R5TMjyXxMAVvHfktZcOqUrrKY5qVT+aFxOwGz5GOYow=; b=iI0B8S3AJVYfUcYh489rsq/VHkgmXn/Zt6/nq9/n1yj7hVZdJUztHrqx +kg9URBjparY56m3MGSZi02gZzcOyoLH1eQ2fCToFsqBzqwIqv+8vpzxK 3KH1eBOae8YUaxjL2QS4y5m1tZ/+ZnG7M3pCozDtzkSDp/QCdIx3CQbUb +edtfycctnWmSrwuweoTDEq7XbmJZg6OvaHSAzZ5HyB8+po8yocGpfJlg XEnoGKM02fpbKOtdLyhWEQbghFfsgzfqoFWedCkDRzNudkQYwjUZPcrmU 0OP0T1uYgIOlY2kpofFT58OSwLeqNy6yBnN6AO+2RI4IyHG6DBIxHfvV7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10936"; a="3832080" X-IronPort-AV: E=Sophos;i="6.04,311,1695711600"; d="scan'208";a="3832080" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 02:49:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10936"; a="897170668" X-IronPort-AV: E=Sophos;i="6.04,311,1695711600"; d="scan'208";a="897170668" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.50.175]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 02:49:27 -0800 From: Stanislaw Gruszka To: "Rafael J. Wysocki" Cc: Srinivas Pandruvada , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org Subject: [PATCH v2 1/2] thermal: netlink: Add enum for mutlicast groups indexes Date: Thu, 28 Dec 2023 11:02:47 +0100 Message-Id: <20231228100248.180721-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use enum instead of hard-coded numbers for indexing multicast groups. Signed-off-by: Stanislaw Gruszka --- v2: No change drivers/thermal/thermal_netlink.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c index 21f00d73acb7..aca36c4ddbf3 100644 --- a/drivers/thermal/thermal_netlink.c +++ b/drivers/thermal/thermal_netlink.c @@ -13,9 +13,14 @@ #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[] = { - { .name = THERMAL_GENL_SAMPLING_GROUP_NAME, }, - { .name = THERMAL_GENL_EVENT_GROUP_NAME, }, + [THERMAL_GENL_SAMPLING_GROUP] = { .name = THERMAL_GENL_SAMPLING_GROUP_NAME, }, + [THERMAL_GENL_EVENT_GROUP] = { .name = THERMAL_GENL_EVENT_GROUP_NAME, }, }; static const struct nla_policy thermal_genl_policy[THERMAL_GENL_ATTR_MAX + 1] = { @@ -95,7 +100,7 @@ int thermal_genl_sampling_temp(int id, int temp) genlmsg_end(skb, hdr); - genlmsg_multicast(&thermal_gnl_family, skb, 0, 0, GFP_KERNEL); + genlmsg_multicast(&thermal_gnl_family, skb, 0, THERMAL_GENL_SAMPLING_GROUP, GFP_KERNEL); return 0; out_cancel: @@ -290,7 +295,7 @@ static int thermal_genl_send_event(enum thermal_genl_event event, genlmsg_end(msg, hdr); - genlmsg_multicast(&thermal_gnl_family, msg, 0, 1, GFP_KERNEL); + genlmsg_multicast(&thermal_gnl_family, msg, 0, THERMAL_GENL_EVENT_GROUP, GFP_KERNEL); return 0; From patchwork Thu Dec 28 10:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13505901 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 C285A6ABA for ; Thu, 28 Dec 2023 10:49:33 +0000 (UTC) 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="iusbon4r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703760574; x=1735296574; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0sAvdIn2E0Oqh1TcFf0EvH/Qeo84THG6gytYAs8xgS8=; b=iusbon4rR+7HSsJ5hGcgjjq2TWWXyDKcpr/q5kt3aGZ0aviRDUgvUIyM jY4+7aNp3IQm9hF8DJEDwktJpBplPmPBcl5PtimoJ5SGKGMy3kRExOtU8 im6LOKvHxGLk1YFuxlMVxpkb9u9hjluwphysYWGTF7TyifiBTo0kX138P 1U6Q5AZ1Qx1FpwuH43PwXy3sNepQZEB3FxxnhGP9IpPMld8hn7jxBGmXe LfFVtRd9y/FnVY5MmpWYfJhW0ovouPAPI+xQChhqZela3LarJD3/7Qitu EKIQe9qnZf+G31IvWZSPIDEkacqFZxAsH2wze3QO61ZtmZYBnLYgtYnjd g==; X-IronPort-AV: E=McAfee;i="6600,9927,10936"; a="3372084" X-IronPort-AV: E=Sophos;i="6.04,311,1695711600"; d="scan'208";a="3372084" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 02:49:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,311,1695711600"; d="scan'208";a="12974781" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.50.175]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 02:49:31 -0800 From: Stanislaw Gruszka To: "Rafael J. Wysocki" Cc: Srinivas Pandruvada , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org Subject: [PATCH v2 2/2] thermal: netlink: Add thermal_group_has_listeners() helper Date: Thu, 28 Dec 2023 11:02:48 +0100 Message-Id: <20231228100248.180721-2-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231228100248.180721-1-stanislaw.gruszka@linux.intel.com> References: <20231228100248.180721-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 a helper function to check if there are listeners for thermal_gnl_family multicast groups. For now use it to avoid unnecessary allocations and sending thermal genl messages when there are no recipients. In the future, in conjunction with (not yet implemented) notification of change in the netlink socket group membership, this helper can be used to open/close hardware interfaces based on the presence of user space subscribers. Signed-off-by: Stanislaw Gruszka Acked-by: Daniel Lezcano --- v2: Do not return -ESRCH error when there are no listeners drivers/thermal/thermal_netlink.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c index aca36c4ddbf3..332052e24a86 100644 --- a/drivers/thermal/thermal_netlink.c +++ b/drivers/thermal/thermal_netlink.c @@ -76,6 +76,11 @@ 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) +{ + return genl_has_listeners(&thermal_gnl_family, &init_net, group); +} + /************************** Sampling encoding *******************************/ int thermal_genl_sampling_temp(int id, int temp) @@ -83,6 +88,9 @@ int thermal_genl_sampling_temp(int id, int temp) struct sk_buff *skb; void *hdr; + if (!thermal_group_has_listeners(THERMAL_GENL_SAMPLING_GROUP)) + return 0; + skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOMEM; @@ -280,6 +288,9 @@ static int thermal_genl_send_event(enum thermal_genl_event event, int ret = -EMSGSIZE; void *hdr; + if (!thermal_group_has_listeners(THERMAL_GENL_EVENT_GROUP)) + return 0; + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); if (!msg) return -ENOMEM;