@@ -148,13 +148,11 @@ static umf_result_t numa_get_capacity(void *memTarget, size_t *capacity) {
148
148
return UMF_RESULT_SUCCESS ;
149
149
}
150
150
151
- static umf_result_t numa_get_bandwidth (void * srcMemoryTarget ,
152
- void * dstMemoryTarget ,
153
- size_t * bandwidth ) {
154
- if (!srcMemoryTarget || !dstMemoryTarget || !bandwidth ) {
155
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
156
- }
151
+ enum memattr_type { MEMATTR_TYPE_BANDWIDTH , MEMATTR_TYPE_LATENCY };
157
152
153
+ static umf_result_t query_attribute_value (void * srcMemoryTarget ,
154
+ void * dstMemoryTarget , size_t * value ,
155
+ enum memattr_type type ) {
158
156
hwloc_topology_t topology = umfGetTopology ();
159
157
if (!topology ) {
160
158
return UMF_RESULT_ERROR_NOT_SUPPORTED ;
@@ -176,23 +174,72 @@ static umf_result_t numa_get_bandwidth(void *srcMemoryTarget,
176
174
177
175
// Given NUMA nodes aren't local, HWLOC returns an error in such case.
178
176
if (!hwloc_bitmap_intersects (srcNumaNode -> cpuset , dstNumaNode -> cpuset )) {
179
- * bandwidth = 0 ;
177
+ * value = 0 ;
180
178
return UMF_RESULT_SUCCESS ;
181
179
}
182
180
181
+ enum hwloc_memattr_id_e hwlocMemAttrType = INT_MAX ;
182
+ switch (type ) {
183
+ case MEMATTR_TYPE_BANDWIDTH :
184
+ hwlocMemAttrType = HWLOC_MEMATTR_ID_BANDWIDTH ;
185
+ break ;
186
+ case MEMATTR_TYPE_LATENCY :
187
+ hwlocMemAttrType = HWLOC_MEMATTR_ID_LATENCY ;
188
+ break ;
189
+ default :
190
+ assert (0 ); // Shouldn't be reachable.
191
+ }
192
+
183
193
struct hwloc_location initiator = {.location .cpuset = srcNumaNode -> cpuset ,
184
194
.type = HWLOC_LOCATION_TYPE_CPUSET };
185
- hwloc_uint64_t value = 0 ;
186
- int ret = hwloc_memattr_get_value (topology , HWLOC_MEMATTR_ID_BANDWIDTH ,
187
- dstNumaNode , & initiator , 0 , & value );
195
+
196
+ hwloc_uint64_t memAttrValue = 0 ;
197
+ int ret = hwloc_memattr_get_value (topology , hwlocMemAttrType , dstNumaNode ,
198
+ & initiator , 0 , & memAttrValue );
188
199
if (ret ) {
189
- LOG_ERR ("Retrieving bandwidth for initiator node %u to node %u failed." ,
190
- srcNumaNode -> os_index , dstNumaNode -> os_index );
191
200
return (errno == EINVAL ) ? UMF_RESULT_ERROR_NOT_SUPPORTED
192
201
: UMF_RESULT_ERROR_UNKNOWN ;
193
202
}
194
203
195
- * bandwidth = value ;
204
+ * value = memAttrValue ;
205
+
206
+ return UMF_RESULT_SUCCESS ;
207
+ }
208
+
209
+ static umf_result_t numa_get_bandwidth (void * srcMemoryTarget ,
210
+ void * dstMemoryTarget ,
211
+ size_t * bandwidth ) {
212
+ if (!srcMemoryTarget || !dstMemoryTarget || !bandwidth ) {
213
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
214
+ }
215
+
216
+ umf_result_t ret = query_attribute_value (srcMemoryTarget , dstMemoryTarget ,
217
+ bandwidth , MEMATTR_TYPE_BANDWIDTH );
218
+ if (ret ) {
219
+ LOG_ERR ("Retrieving bandwidth for initiator node %u to node %u failed." ,
220
+ ((struct numa_memory_target_t * )srcMemoryTarget )-> physical_id ,
221
+ ((struct numa_memory_target_t * )dstMemoryTarget )-> physical_id );
222
+ return ret ;
223
+ }
224
+
225
+ return UMF_RESULT_SUCCESS ;
226
+ }
227
+
228
+ static umf_result_t numa_get_latency (void * srcMemoryTarget ,
229
+ void * dstMemoryTarget , size_t * latency ) {
230
+ if (!srcMemoryTarget || !dstMemoryTarget || !latency ) {
231
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
232
+ }
233
+
234
+ umf_result_t ret = query_attribute_value (srcMemoryTarget , dstMemoryTarget ,
235
+ latency , MEMATTR_TYPE_LATENCY );
236
+ if (ret ) {
237
+ LOG_ERR ("Retrieving latency for initiator node %u to node %u failed." ,
238
+ ((struct numa_memory_target_t * )srcMemoryTarget )-> physical_id ,
239
+ ((struct numa_memory_target_t * )dstMemoryTarget )-> physical_id );
240
+ return ret ;
241
+ }
242
+
196
243
return UMF_RESULT_SUCCESS ;
197
244
}
198
245
@@ -204,5 +251,6 @@ struct umf_memory_target_ops_t UMF_MEMORY_TARGET_NUMA_OPS = {
204
251
.clone = numa_clone ,
205
252
.get_capacity = numa_get_capacity ,
206
253
.get_bandwidth = numa_get_bandwidth ,
254
+ .get_latency = numa_get_latency ,
207
255
.memory_provider_create_from_memspace =
208
256
numa_memory_provider_create_from_memspace };
0 commit comments