Skip to content

Commit a8a7fe8

Browse files
committed
TEST
1 parent 2d69eb6 commit a8a7fe8

File tree

7 files changed

+67
-31
lines changed

7 files changed

+67
-31
lines changed

include/umf/base.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef enum umf_ctl_query_type {
6666
/// @param name name of an attribute to be retrieved
6767
/// @param ctx pointer to the pool or the provider
6868
/// @param arg [out] pointer to the variable where the value will be stored
69-
/// @param size [in/out] size of the value
69+
/// @param size size of the value, depends on the context
7070
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
7171
///
7272
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg, size_t size);
@@ -76,7 +76,7 @@ umf_result_t umfCtlGet(const char *name, void *ctx, void *arg, size_t size);
7676
/// @param name name of an attribute to be set
7777
/// @param ctx pointer to the pool or the provider, NULL for the 'default' path
7878
/// @param arg [in] pointer to the value that will be set
79-
/// @param size [in] size of the value
79+
/// @param size [in] size of the value, depends on the context
8080
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
8181
///
8282
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size);
@@ -86,9 +86,10 @@ umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size);
8686
/// @param name name of an attribute to be executed
8787
/// @param ctx pointer to the pool or the provider
8888
/// @param arg [in/out] pointer to the value, can be used as an input or output
89+
/// @param size [in] size of the value, depends on the context
8990
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
9091
///
91-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg);
92+
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size);
9293

9394
#ifdef __cplusplus
9495
}

src/ctl/ctl.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size) {
9393
: UMF_RESULT_SUCCESS;
9494
}
9595

96-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
96+
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) {
9797
if (name == NULL || arg == NULL || ctx == NULL) {
9898
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
9999
}
100100
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
101-
CTL_QUERY_RUNNABLE, arg, 0)
101+
CTL_QUERY_RUNNABLE, arg, size)
102102
? UMF_RESULT_ERROR_UNKNOWN
103103
: UMF_RESULT_SUCCESS;
104104
}
@@ -410,14 +410,10 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
410410
errno = EINVAL;
411411
goto out;
412412
}
413-
const char *extra_name = &name[0];
414-
if (strstr(extra_name, "by_handle") != NULL) {
415-
extra_name = &name[0] + name_offset;
416-
}
417413

418414
ret =
419415
ctl_exec_query[n->type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type](
420-
ctx, n, source, arg, size, indexes, extra_name, type);
416+
ctx, n, source, arg, size, indexes, name + name_offset, type);
421417
out:
422418
ctl_delete_indexes(indexes);
423419

src/memory_pool.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77
*
88
*/
99

10-
#include "ctl/ctl.h"
11-
#include "libumf.h"
12-
#include "memory_pool_internal.h"
13-
#include "utils_assert.h"
14-
1510
#include <umf/base.h>
1611
#include <umf/memory_pool.h>
1712
#include <umf/memory_pool_ops.h>
1813

1914
#include <assert.h>
20-
#include <stdlib.h>
2115
#include <string.h>
2216

2317
#include "base_alloc_global.h"
18+
#include "ctl/ctl.h"
19+
#include "libumf.h"
2420
#include "memory_pool_internal.h"
2521
#include "memory_provider_internal.h"
22+
#include "utils_assert.h"
2623
#include "provider_tracking.h"
24+
#include "utils_log.h"
2725

2826
#define UMF_DEFAULT_SIZE 100
2927
#define UMF_DEFAULT_LEN 100
@@ -50,7 +48,7 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,
5048
const char *extra_name,
5149
umf_ctl_query_type_t queryType) {
5250
(void)indexes, (void)source, (void)size, (void)ctx;
53-
// assert(queryType == CTL_QUERY_WRITE && "not supported query type");
51+
5452
if (queryType == CTL_QUERY_WRITE) {
5553
int i = 0;
5654
for (; i < UMF_DEFAULT_SIZE; i++) {
@@ -73,8 +71,8 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,
7371
}
7472
}
7573
if (UMF_DEFAULT_SIZE == i) {
76-
LOG_ERR("Default entries array is full");
77-
return -1;
74+
LOG_WARN("Wrong path name: %s", extra_name);
75+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
7876
}
7977
}
8078
return 0;

src/pool/pool_disjoint.c

+45-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <umf/memory_provider.h>
1818

1919
#include "base_alloc_global.h"
20-
#include "pool_disjoint_ctl.h"
20+
#include <ctl/ctl.h>
2121
#include "pool_disjoint_internal.h"
2222
#include "provider/provider_tracking.h"
2323
#include "uthash/utlist.h"
@@ -26,6 +26,50 @@
2626
#include "utils_log.h"
2727
#include "utils_math.h"
2828

29+
/* Disjoint pool CTL implementation */
30+
struct ctl disjoint_ctl_root;
31+
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT;
32+
33+
static int CTL_READ_HANDLER(name)(void *ctx, umf_ctl_query_source_t source,
34+
void *arg, size_t size,
35+
umf_ctl_index_utlist_t *indexes,
36+
const char *extra_name,
37+
umf_ctl_query_type_t queryType) {
38+
(void)source, (void)indexes, (void)queryType, (void)size, (void)extra_name;
39+
disjoint_pool_t *pool = (disjoint_pool_t *)ctx;
40+
41+
if (arg == NULL) {
42+
return -1;
43+
}
44+
45+
strncpy(pool->params.name, (char *)arg, sizeof(pool->params.name) - 1);
46+
return 0;
47+
}
48+
49+
static const umf_ctl_node_t CTL_NODE(disjoint)[] = {CTL_LEAF_RO(name),
50+
CTL_NODE_END};
51+
52+
static void initialize_disjoint_ctl(void) {
53+
CTL_REGISTER_MODULE(&disjoint_ctl_root, disjoint);
54+
}
55+
56+
umf_result_t disjoint_pool_ctl(void *hPool, int operationType, const char *name,
57+
void *arg, size_t size,
58+
umf_ctl_query_type_t queryType) {
59+
(void)operationType, (void)queryType;
60+
utils_init_once(&ctl_initialized, initialize_disjoint_ctl);
61+
62+
const char *prefix = "disjoint.";
63+
const char *name_wo_prefix = strstr(name, "disjoint.");
64+
65+
// Check if the name has the prefix
66+
if ((name_wo_prefix = strstr(name, prefix)) == NULL) {
67+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
68+
}
69+
return ctl_query(&disjoint_ctl_root, hPool, CTL_QUERY_PROGRAMMATIC,
70+
name_wo_prefix, CTL_QUERY_READ, arg, size);
71+
}
72+
2973
// Temporary solution for disabling memory poisoning. This is needed because
3074
// AddressSanitizer does not support memory poisoning for GPU allocations.
3175
// More info: https://github.com/oneapi-src/unified-memory-framework/issues/634

src/pool/pool_disjoint_ctl.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
*/
77

8-
#include "pool/pool_disjoint_internal.h"
9-
#include <stdio.h>
108
#include <string.h>
119

1210
#include <ctl/ctl.h>
@@ -15,6 +13,8 @@
1513
#include <umf/memory_pool_ops.h>
1614
#include <umf/memory_provider.h>
1715

16+
#include "pool/pool_disjoint_internal.h"
17+
1818
struct ctl disjoint_ctl_root;
1919
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT;
2020

@@ -23,16 +23,14 @@ static int CTL_READ_HANDLER(name)(void *ctx, umf_ctl_query_source_t source,
2323
umf_ctl_index_utlist_t *indexes,
2424
const char *extra_name,
2525
umf_ctl_query_type_t queryType) {
26-
(void)source, (void)indexes, (void)queryType, (void)size;
26+
(void)source, (void)indexes, (void)queryType, (void)size, (void)extra_name;
2727
disjoint_pool_t *pool = (disjoint_pool_t *)ctx;
2828

2929
if (arg == NULL) {
3030
return -1;
3131
}
3232

33-
if (strstr(extra_name, pool->params.name) != NULL) {
34-
strncpy(pool->params.name, (char *)arg, sizeof(pool->params.name) - 1);
35-
}
33+
strncpy(pool->params.name, (char *)arg, sizeof(pool->params.name) - 1);
3634
return 0;
3735
}
3836

test/ctl/ctl_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ TEST_F(CtlTest, ctlDefault) {
169169
sizeof(output));
170170
ASSERT_EQ(res, UMF_RESULT_SUCCESS);
171171
ASSERT_STREQ(output, arg);
172-
}
172+
}

test/pools/disjoint_pool_ctl.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exceptiongi
44

55
#include <gtest/gtest.h>
6-
7-
#include "base.hpp"
8-
#include "utils_log.h"
9-
106
#include <umf/memory_pool.h>
117
#include <umf/memory_provider.h>
128
#include <umf/memory_provider_ops.h>
139
#include <umf/pools/pool_disjoint.h>
1410
#include <umf/providers/provider_os_memory.h>
1511

12+
#include "base.hpp"
13+
#include "utils_log.h"
14+
1615
using umf_test::test;
1716
using namespace umf_test;
1817

0 commit comments

Comments
 (0)