@@ -102,6 +102,9 @@ umf_result_t umfOsMemoryProviderParamsSetPartitions(
102
102
#include "utils_concurrency.h"
103
103
#include "utils_log.h"
104
104
105
+ #define CTL_PROVIDER_TYPE os_memory_provider_t
106
+ #include "provider_ctl_stats_impl.h"
107
+
105
108
#define NODESET_STR_BUF_LEN 1024
106
109
107
110
#define TLS_MSG_BUF_LEN 1024
@@ -189,70 +192,6 @@ static int CTL_READ_HANDLER(ipc_enabled)(void *ctx,
189
192
return 0 ;
190
193
}
191
194
192
- static int CTL_READ_HANDLER (peak_memory )(void * ctx ,
193
- umf_ctl_query_source_t source ,
194
- void * arg ,
195
- umf_ctl_index_utlist_t * indexes ,
196
- const char * extra_name ,
197
- umf_ctl_query_type_t query_type ) {
198
- /* suppress unused-parameter errors */
199
- (void )source , (void )indexes , (void )ctx , (void )extra_name , (void )query_type ;
200
-
201
- size_t * arg_out = arg ;
202
- os_memory_provider_t * os_provider = (os_memory_provider_t * )ctx ;
203
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .peak_memory ) !=
204
- sizeof (uint64_t ));
205
- utils_atomic_load_acquire_u64 ((uint64_t * )& os_provider -> stats .peak_memory ,
206
- (uint64_t * )arg_out );
207
- return 0 ;
208
- }
209
-
210
- static int CTL_READ_HANDLER (allocated_memory )(void * ctx ,
211
- umf_ctl_query_source_t source ,
212
- void * arg ,
213
- umf_ctl_index_utlist_t * indexes ,
214
- const char * extra_name ,
215
- umf_ctl_query_type_t query_type ) {
216
- /* suppress unused-parameter errors */
217
- (void )source , (void )indexes , (void )ctx , (void )extra_name , (void )query_type ;
218
-
219
- size_t * arg_out = arg ;
220
- os_memory_provider_t * os_provider = (os_memory_provider_t * )ctx ;
221
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .allocated_memory ) !=
222
- sizeof (uint64_t ));
223
- COMPILE_ERROR_ON (sizeof (* arg_out ) != sizeof (uint64_t ));
224
- utils_atomic_load_acquire_u64 (
225
- (uint64_t * )& os_provider -> stats .allocated_memory , (uint64_t * )arg_out );
226
- return 0 ;
227
- }
228
-
229
- static int CTL_RUNNABLE_HANDLER (reset )(void * ctx , umf_ctl_query_source_t source ,
230
- void * arg ,
231
- umf_ctl_index_utlist_t * indexes ,
232
- const char * extra_name ,
233
- umf_ctl_query_type_t query_type ) {
234
- /* suppress unused-parameter errors */
235
- (void )source , (void )indexes , (void )arg , (void )extra_name , (void )query_type ;
236
-
237
- os_memory_provider_t * os_provider = (os_memory_provider_t * )ctx ;
238
- size_t allocated ;
239
-
240
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .allocated_memory ) !=
241
- sizeof (uint64_t ));
242
- COMPILE_ERROR_ON (sizeof (allocated ) != sizeof (uint64_t ));
243
-
244
- utils_atomic_load_acquire_u64 (
245
- (uint64_t * )& os_provider -> stats .allocated_memory ,
246
- (uint64_t * )& allocated );
247
- utils_atomic_store_release_u64 ((uint64_t * )& os_provider -> stats .peak_memory ,
248
- (uint64_t )allocated );
249
-
250
- return 0 ;
251
- }
252
- static const umf_ctl_node_t CTL_NODE (stats )[] = {
253
- CTL_LEAF_RO (allocated_memory ), CTL_LEAF_RO (peak_memory ),
254
- CTL_LEAF_RUNNABLE (reset ), CTL_NODE_END };
255
-
256
195
static const umf_ctl_node_t CTL_NODE (params )[] = {CTL_LEAF_RO (ipc_enabled ),
257
196
CTL_NODE_END };
258
197
@@ -1176,29 +1115,7 @@ static umf_result_t os_alloc(void *provider, size_t size, size_t alignment,
1176
1115
1177
1116
* resultPtr = addr ;
1178
1117
1179
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .allocated_memory ) !=
1180
- sizeof (uint64_t ));
1181
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .peak_memory ) !=
1182
- sizeof (uint64_t ));
1183
- COMPILE_ERROR_ON (sizeof (size ) != sizeof (uint64_t ));
1184
- // TODO: Change to memory_order_relaxed when we will have a proper wrapper
1185
- size_t allocated =
1186
- utils_fetch_and_add_u64 (
1187
- (uint64_t * )& os_provider -> stats .allocated_memory , (uint64_t )size ) +
1188
- size ;
1189
-
1190
- uint64_t peak ;
1191
- utils_atomic_load_acquire_u64 ((uint64_t * )& os_provider -> stats .peak_memory ,
1192
- & peak );
1193
-
1194
- while (allocated > peak && !utils_compare_exchange_u64 (
1195
- (uint64_t * )& os_provider -> stats .peak_memory ,
1196
- & peak , (uint64_t * )& allocated )) {
1197
- /* If the compare-exchange fails, 'peak' is updated to the current value of peak_memory.
1198
- We then re-check whether allocated is still greater than the updated peak value. */
1199
- ;
1200
- }
1201
-
1118
+ provider_ctl_stats_alloc (os_provider , size );
1202
1119
return UMF_RESULT_SUCCESS ;
1203
1120
1204
1121
err_unmap :
@@ -1226,13 +1143,7 @@ static umf_result_t os_free(void *provider, void *ptr, size_t size) {
1226
1143
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
1227
1144
}
1228
1145
1229
- COMPILE_ERROR_ON (sizeof (size ) != sizeof (uint64_t ));
1230
- COMPILE_ERROR_ON (sizeof (os_provider -> stats .allocated_memory ) !=
1231
- sizeof (uint64_t ));
1232
-
1233
- // TODO: Change it to memory_order_relaxed when we will have a proper wrapper
1234
- utils_fetch_and_sub_u64 ((uint64_t * )& os_provider -> stats .allocated_memory ,
1235
- size );
1146
+ provider_ctl_stats_free (os_provider , size );
1236
1147
1237
1148
return UMF_RESULT_SUCCESS ;
1238
1149
}
@@ -1530,11 +1441,9 @@ static umf_result_t os_close_ipc_handle(void *provider, void *ptr,
1530
1441
1531
1442
static umf_result_t os_ctl (void * hProvider , int operationType , const char * name ,
1532
1443
void * arg , umf_ctl_query_type_t query_type ) {
1533
- (void )operationType ; // unused
1534
- os_memory_provider_t * os_provider = (os_memory_provider_t * )hProvider ;
1535
1444
utils_init_once (& ctl_initialized , initialize_os_ctl );
1536
- return ctl_query (os_memory_ctl_root , os_provider , CTL_QUERY_PROGRAMMATIC ,
1537
- name , query_type , arg );
1445
+ return ctl_query (os_memory_ctl_root , hProvider , operationType , name ,
1446
+ query_type , arg );
1538
1447
}
1539
1448
1540
1449
static umf_memory_provider_ops_t UMF_OS_MEMORY_PROVIDER_OPS = {
0 commit comments