Skip to content

Commit f33f86d

Browse files
committed
To append
1 parent 475229e commit f33f86d

File tree

12 files changed

+99
-64
lines changed

12 files changed

+99
-64
lines changed

include/umf/base.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,27 @@ typedef enum umf_result_t {
4949
} umf_result_t;
5050

5151
/// @brief Type for determine the type of the CTL query
52-
enum ctl_query_type {
52+
typedef enum umf_ctl_query_type {
5353
CTL_QUERY_READ,
5454
CTL_QUERY_WRITE,
5555
CTL_QUERY_RUNNABLE,
5656
CTL_QUERY_SUBTREE,
5757

5858
MAX_CTL_QUERY_TYPE
59-
};
59+
} umf_ctl_query_type;
60+
61+
// struct ctl;
62+
63+
// enum ctl_query_source;
64+
65+
// int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
66+
// const char *name, typedef enum umf_ctl_query_type type, void *arg);
67+
68+
int umfCtlGet(const char *name, void *ctx, void *arg);
69+
70+
// void umfCtlSet(const char *name, ...) { (void)name; }
71+
72+
// void umfCtlExec(const char *name, ...) { (void)name; }
6073

6174
#ifdef __cplusplus
6275
}

include/umf/memory_provider_ops.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ typedef struct umf_memory_provider_ext_ops_t {
9292
/// @return umf_result_t result of the control operation.
9393
///
9494
umf_result_t (*ctl)(void *hProvider, int operationType, const char *name,
95-
void *arg, char *extra_name,
96-
enum ctl_query_type query_type);
95+
void *arg, umf_ctl_query_type query_type);
9796

9897
} umf_memory_provider_ext_ops_t;
9998

src/ctl/ctl.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ char *Strdup(const char *s) {
7979
return p;
8080
}
8181

82+
int umfCtlGet(const char *name, void *ctx, void *arg) {
83+
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ,
84+
arg);
85+
}
86+
8287
/*
8388
* ctl_find_node -- (internal) searches for a matching entry point in the
8489
* provided nodes
@@ -251,7 +256,7 @@ static int ctl_exec_query_read(void *ctx, const struct ctl_node *n,
251256
enum ctl_query_source source, void *arg,
252257
struct ctl_index_utlist *indexes,
253258
char *extra_name,
254-
enum ctl_query_type query_type) {
259+
umf_ctl_query_type query_type) {
255260
(void)extra_name, (void)query_type;
256261
if (arg == NULL) {
257262
errno = EINVAL;
@@ -270,7 +275,7 @@ static int ctl_exec_query_write(void *ctx, const struct ctl_node *n,
270275
enum ctl_query_source source, void *arg,
271276
struct ctl_index_utlist *indexes,
272277
char *extra_name,
273-
enum ctl_query_type query_type) {
278+
umf_ctl_query_type query_type) {
274279
(void)extra_name, (void)query_type;
275280
if (arg == NULL) {
276281
errno = EINVAL;
@@ -297,7 +302,7 @@ static int ctl_exec_query_runnable(void *ctx, const struct ctl_node *n,
297302
enum ctl_query_source source, void *arg,
298303
struct ctl_index_utlist *indexes,
299304
char *extra_name,
300-
enum ctl_query_type query_type) {
305+
umf_ctl_query_type query_type) {
301306
(void)extra_name, (void)query_type;
302307
assert(MAX_CTL_QUERY_TYPE != query_type);
303308
return n->cb[CTL_QUERY_RUNNABLE](ctx, source, arg, indexes, NULL,
@@ -308,15 +313,15 @@ static int ctl_exec_query_subtree(void *ctx, const struct ctl_node *n,
308313
enum ctl_query_source source, void *arg,
309314
struct ctl_index_utlist *indexes,
310315
char *extra_name,
311-
enum ctl_query_type query_type) {
316+
umf_ctl_query_type query_type) {
312317
return n->cb[CTL_QUERY_SUBTREE](ctx, source, arg, indexes, extra_name,
313318
query_type);
314319
}
315320

316321
static int (*ctl_exec_query[MAX_CTL_QUERY_TYPE])(
317322
void *ctx, const struct ctl_node *n, enum ctl_query_source source,
318323
void *arg, struct ctl_index_utlist *indexes, char *extra_name,
319-
enum ctl_query_type query_type) = {
324+
umf_ctl_query_type query_type) = {
320325
ctl_exec_query_read,
321326
ctl_exec_query_write,
322327
ctl_exec_query_runnable,
@@ -328,7 +333,7 @@ static int (*ctl_exec_query[MAX_CTL_QUERY_TYPE])(
328333
* from the ctl tree
329334
*/
330335
int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
331-
const char *name, enum ctl_query_type type, void *arg) {
336+
const char *name, umf_ctl_query_type type, void *arg) {
332337
if (name == NULL) {
333338
errno = EINVAL;
334339
return -1;
@@ -629,9 +634,3 @@ int ctl_arg_string(const void *arg, void *dest, size_t dest_size) {
629634

630635
return 0;
631636
}
632-
633-
void umfCtlGet(const char *name, ...) { (void)name; }
634-
635-
void umfCtlSet(const char *name, ...) { (void)name; }
636-
637-
void umfCtlExec(const char *name, ...) { (void)name; }

src/ctl/ctl.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,9 @@ enum ctl_query_source {
4545
MAX_CTL_QUERY_SOURCE
4646
};
4747

48-
// enum ctl_query_type {
49-
// CTL_QUERY_READ,
50-
// CTL_QUERY_WRITE,
51-
// CTL_QUERY_RUNNABLE,
52-
// CTL_QUERY_SUBTREE,
53-
54-
// MAX_CTL_QUERY_TYPE
55-
// };
56-
5748
typedef int (*node_callback)(void *ctx, enum ctl_query_source type, void *arg,
5849
struct ctl_index_utlist *indexes, char *extra_name,
59-
enum ctl_query_type query_type);
50+
umf_ctl_query_type query_type);
6051

6152
enum ctl_node_type {
6253
CTL_NODE_UNKNOWN,
@@ -146,7 +137,7 @@ int ctl_arg_string(const void *arg, void *dest, size_t dest_size);
146137
#define CTL_NODE(name, ...) ctl_node_##__VA_ARGS__##_##name
147138

148139
int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
149-
const char *name, enum ctl_query_type type, void *arg);
140+
const char *name, umf_ctl_query_type type, void *arg);
150141

151142
/* Declaration of a new child node */
152143
#define CTL_CHILD(name, ...) \

src/libumf.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ EXPORTS
1414
umfTearDown
1515
umfGetCurrentVersion
1616
umfCloseIPCHandle
17+
;umfCtlExec
18+
umfCtlGet
19+
;umfCtlSet
1720
umfCUDAMemoryProviderOps
1821
umfCUDAMemoryProviderParamsCreate
1922
umfCUDAMemoryProviderParamsDestroy

src/libumf.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ UMF_0.10 {
88
umfTearDown;
99
umfGetCurrentVersion;
1010
umfCloseIPCHandle;
11+
umfCtlExec;
12+
umfCtlGet;
13+
umfCtlSet;
1114
umfCUDAMemoryProviderOps;
1215
umfCUDAMemoryProviderParamsCreate;
1316
umfCUDAMemoryProviderParamsDestroy;

src/memory_provider.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ typedef struct umf_memory_provider_t {
2828
static int CTL_SUBTREE_HANDLER(by_handle_provider)(
2929
void *ctx, enum ctl_query_source source, void *arg,
3030
struct ctl_index_utlist *indexes, char *extra_name,
31-
enum ctl_query_type query_type) {
31+
umf_ctl_query_type query_type) {
3232
(void)indexes, (void)source;
3333
umf_memory_provider_handle_t hProvider = (umf_memory_provider_handle_t)ctx;
3434
hProvider->ops.ext.ctl(hProvider->provider_priv, /*unused*/ 0,
35-
/*unused*/ NULL, arg, extra_name, query_type);
35+
extra_name, arg, query_type);
3636
return 0;
3737
}
3838

src/provider/provider_os_memory.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int CTL_READ_HANDLER(ipc_enabled)(void *ctx,
177177
void *arg,
178178
struct ctl_index_utlist *indexes,
179179
char *extra_name,
180-
enum ctl_query_type query_type) {
180+
umf_ctl_query_type query_type) {
181181
/* suppress unused-parameter errors */
182182
(void)source, (void)indexes, (void)ctx, (void)extra_name, (void)query_type;
183183

@@ -1431,13 +1431,12 @@ static umf_result_t os_close_ipc_handle(void *provider, void *ptr,
14311431
}
14321432

14331433
static umf_result_t os_ctl(void *hProvider, int operationType, const char *name,
1434-
void *arg, char *extra_name,
1435-
enum ctl_query_type query_type) {
1436-
(void)operationType, (void)name; // unused
1434+
void *arg, umf_ctl_query_type query_type) {
1435+
(void)operationType; // unused
14371436
os_memory_provider_t *os_provider = (os_memory_provider_t *)hProvider;
14381437
utils_init_once(&ctl_initialized, initialize_os_ctl);
14391438
return ctl_query(os_memory_ctl_root, os_provider, CTL_QUERY_PROGRAMMATIC,
1440-
extra_name, query_type, arg);
1439+
name, query_type, arg);
14411440
}
14421441

14431442
static umf_memory_provider_ops_t UMF_OS_MEMORY_PROVIDER_OPS = {

test/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,14 @@ add_umf_test(
197197
LIBS ${UMF_LOGGER_LIBS})
198198

199199
add_umf_test(
200-
NAME ctl
201-
SRCS ctl/test.cpp ctl/ctl_debug.c ../src/ctl/ctl.c ${BA_SOURCES_FOR_TEST}
200+
NAME ctl_unittest
201+
SRCS ctl/ctl_unittest.cpp ctl/ctl_debug.c ../src/ctl/ctl.c
202+
${BA_SOURCES_FOR_TEST}
203+
LIBS ${UMF_UTILS_FOR_TEST})
204+
205+
add_umf_test(
206+
NAME ctl_api
207+
SRCS ctl/ctl_api.cpp ${BA_SOURCES_FOR_TEST}
202208
LIBS ${UMF_UTILS_FOR_TEST})
203209

204210
add_umf_test(

test/ctl/ctl_api.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
#include <umf.h>
11+
#include <umf/memory_provider.h>
12+
#include <umf/providers/provider_os_memory.h>
13+
14+
#include "../common/base.hpp"
15+
#include "gtest/gtest.h"
16+
17+
using namespace umf_test;
18+
19+
TEST_F(test, ctl_by_handle_os_provider) {
20+
umf_memory_provider_handle_t hProvider = NULL;
21+
umf_memory_provider_ops_t *os_provider_ops = umfOsMemoryProviderOps();
22+
umf_os_memory_provider_params_handle_t os_memory_provider_params = NULL;
23+
24+
int ret = umfOsMemoryProviderParamsCreate(&os_memory_provider_params);
25+
printf("ret: %d\n", ret);
26+
if (ret == UMF_RESULT_ERROR_NOT_SUPPORTED) {
27+
GTEST_SKIP();
28+
}
29+
ret = umfMemoryProviderCreate(os_provider_ops, os_memory_provider_params,
30+
&hProvider);
31+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
32+
33+
int ipc_enabled = 0xBAD;
34+
ret = umfCtlGet("umf.provider.by_handle.ipc_enabled", hProvider,
35+
&ipc_enabled);
36+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
37+
ASSERT_EQ(ipc_enabled, 0);
38+
39+
umfOsMemoryProviderParamsDestroy(os_memory_provider_params);
40+
umfMemoryProviderDestroy(hProvider);
41+
}
42+
43+
TEST_F(test, ctl_by_handle_pool) {}

0 commit comments

Comments
 (0)