[PATCH 2/4] drivers/base/node: Add a helper function node_update_perf_attrs()

Dave Jiang posted 4 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 2/4] drivers/base/node: Add a helper function node_update_perf_attrs()
Posted by Dave Jiang 1 month, 2 weeks ago
Add helper function node_update_perf_attrs() to allow update of node access
coordinates computed by an external agent such as CXL. The helper allows
updating of coordinates after the attribute being created by HMAT.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/base/node.c  | 39 +++++++++++++++++++++++++++++++++++++++
 include/linux/node.h |  8 ++++++++
 2 files changed, 47 insertions(+)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index 3399594136b2..cf395da18c9b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -248,6 +248,45 @@ void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
 }
 EXPORT_SYMBOL_GPL(node_set_perf_attrs);
 
+/**
+ * node_update_perf_attrs - Update the performance values for given access class
+ * @nid: Node identifier to be updated
+ * @coord: Heterogeneous memory performance coordinates
+ * @access: The access class the for the given attributes
+ */
+void node_update_perf_attrs(unsigned int nid, struct access_coordinate *coord,
+			    enum access_coordinate_class access)
+{
+	struct node_access_nodes *access_node;
+	struct node *node;
+	int i;
+
+	if (WARN_ON_ONCE(!node_online(nid)))
+		return;
+
+	node = node_devices[nid];
+	list_for_each_entry(access_node, &node->access_list, list_node) {
+		if (access_node->access != access)
+			continue;
+
+		access_node->coord = *coord;
+		for (i = 0; access_attrs[i]; i++) {
+			sysfs_notify(&access_node->dev.kobj,
+				     NULL, access_attrs[i]->name);
+		}
+		break;
+	}
+
+	/* When setting CPU access coordinates, update mempolicy */
+	if (access == ACCESS_COORDINATE_CPU) {
+		if (mempolicy_set_node_perf(nid, coord)) {
+			pr_info("failed to set mempolicy attrs for node %d\n",
+				nid);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(node_update_perf_attrs);
+
 /**
  * struct node_cache_info - Internal tracking for memory node caches
  * @dev:	Device represeting the cache level
diff --git a/include/linux/node.h b/include/linux/node.h
index 2c7529335b21..866e3323f1fd 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -85,6 +85,8 @@ struct node_cache_attrs {
 void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
 void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
 			 enum access_coordinate_class access);
+void node_update_perf_attrs(unsigned int nid, struct access_coordinate *coord,
+			    enum access_coordinate_class access);
 #else
 static inline void node_add_cache(unsigned int nid,
 				  struct node_cache_attrs *cache_attrs)
@@ -96,6 +98,12 @@ static inline void node_set_perf_attrs(unsigned int nid,
 				       enum access_coordinate_class access)
 {
 }
+
+static inline void node_update_perf_attrs(unsigned int nid,
+					  struct access_coordinate *coord,
+					  enum access_coordinate_class access)
+{
+}
 #endif
 
 struct node {
-- 
2.50.1
Re: [PATCH 2/4] drivers/base/node: Add a helper function node_update_perf_attrs()
Posted by David Hildenbrand 1 month, 2 weeks ago
On 14.08.25 19:16, Dave Jiang wrote:
> Add helper function node_update_perf_attrs() to allow update of node access
> coordinates computed by an external agent such as CXL. The helper allows
> updating of coordinates after the attribute being created by HMAT.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>   drivers/base/node.c  | 39 +++++++++++++++++++++++++++++++++++++++
>   include/linux/node.h |  8 ++++++++
>   2 files changed, 47 insertions(+)
> 
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index 3399594136b2..cf395da18c9b 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -248,6 +248,45 @@ void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
>   }
>   EXPORT_SYMBOL_GPL(node_set_perf_attrs);
>   
> +/**
> + * node_update_perf_attrs - Update the performance values for given access class
> + * @nid: Node identifier to be updated
> + * @coord: Heterogeneous memory performance coordinates
> + * @access: The access class the for the given attributes

"the for": there is probably something missing

> + */
> +void node_update_perf_attrs(unsigned int nid, struct access_coordinate *coord,
> +			    enum access_coordinate_class access)
> +{
> +	struct node_access_nodes *access_node;
> +	struct node *node;
> +	int i;
> +
> +	if (WARN_ON_ONCE(!node_online(nid)))
> +		return;
> +
> +	node = node_devices[nid];
> +	list_for_each_entry(access_node, &node->access_list, list_node) {
> +		if (access_node->access != access)
> +			continue;
> +
> +		access_node->coord = *coord;
> +		for (i = 0; access_attrs[i]; i++) {
> +			sysfs_notify(&access_node->dev.kobj,
> +				     NULL, access_attrs[i]->name);
> +		}
> +		break;
> +	}
> +
> +	/* When setting CPU access coordinates, update mempolicy */
> +	if (access == ACCESS_COORDINATE_CPU) {
> +		if (mempolicy_set_node_perf(nid, coord)) {
> +			pr_info("failed to set mempolicy attrs for node %d\n",
> +				nid);
> +		}
if (access == ACCESS_COORDINATE_CPU &&
     mempolicy_set_node_perf(nid, coord))
	pr_info("failed to set mempolicy attrs for node %d\n", nid);

or

if (access != ACCESS_COORDINATE_CPU)
	return
if (mempolicy_set_node_perf(nid, coord))
	pr_info("failed to set mempolicy attrs for node %d\n", nid);


With both things sorted

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers

David / dhildenb
Re: [PATCH 2/4] drivers/base/node: Add a helper function node_update_perf_attrs()
Posted by Dave Jiang 1 month, 2 weeks ago

On 8/18/25 2:49 AM, David Hildenbrand wrote:
> On 14.08.25 19:16, Dave Jiang wrote:
>> Add helper function node_update_perf_attrs() to allow update of node access
>> coordinates computed by an external agent such as CXL. The helper allows
>> updating of coordinates after the attribute being created by HMAT.
>>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>>   drivers/base/node.c  | 39 +++++++++++++++++++++++++++++++++++++++
>>   include/linux/node.h |  8 ++++++++
>>   2 files changed, 47 insertions(+)
>>
>> diff --git a/drivers/base/node.c b/drivers/base/node.c
>> index 3399594136b2..cf395da18c9b 100644
>> --- a/drivers/base/node.c
>> +++ b/drivers/base/node.c
>> @@ -248,6 +248,45 @@ void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
>>   }
>>   EXPORT_SYMBOL_GPL(node_set_perf_attrs);
>>   +/**
>> + * node_update_perf_attrs - Update the performance values for given access class
>> + * @nid: Node identifier to be updated
>> + * @coord: Heterogeneous memory performance coordinates
>> + * @access: The access class the for the given attributes
> 
> "the for": there is probably something missing

looks like extra 'the'

> 
>> + */
>> +void node_update_perf_attrs(unsigned int nid, struct access_coordinate *coord,
>> +                enum access_coordinate_class access)
>> +{
>> +    struct node_access_nodes *access_node;
>> +    struct node *node;
>> +    int i;
>> +
>> +    if (WARN_ON_ONCE(!node_online(nid)))
>> +        return;
>> +
>> +    node = node_devices[nid];
>> +    list_for_each_entry(access_node, &node->access_list, list_node) {
>> +        if (access_node->access != access)
>> +            continue;
>> +
>> +        access_node->coord = *coord;
>> +        for (i = 0; access_attrs[i]; i++) {
>> +            sysfs_notify(&access_node->dev.kobj,
>> +                     NULL, access_attrs[i]->name);
>> +        }
>> +        break;
>> +    }
>> +
>> +    /* When setting CPU access coordinates, update mempolicy */
>> +    if (access == ACCESS_COORDINATE_CPU) {
>> +        if (mempolicy_set_node_perf(nid, coord)) {
>> +            pr_info("failed to set mempolicy attrs for node %d\n",
>> +                nid);
>> +        }
> if (access == ACCESS_COORDINATE_CPU &&
>     mempolicy_set_node_perf(nid, coord))
>     pr_info("failed to set mempolicy attrs for node %d\n", nid);
> 
> or
> 
> if (access != ACCESS_COORDINATE_CPU)
>     return
> if (mempolicy_set_node_perf(nid, coord))
>     pr_info("failed to set mempolicy attrs for node %d\n", nid);
> 
ok


> 
> With both things sorted
> 
> Acked-by: David Hildenbrand <david@redhat.com>
> 
Thanks for the ack
Re: [PATCH 2/4] drivers/base/node: Add a helper function node_update_perf_attrs()
Posted by Jonathan Cameron 1 month, 2 weeks ago
On Thu, 14 Aug 2025 10:16:48 -0700
Dave Jiang <dave.jiang@intel.com> wrote:

> Add helper function node_update_perf_attrs() to allow update of node access
> coordinates computed by an external agent such as CXL. The helper allows
> updating of coordinates after the attribute being created by HMAT.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>