Skip to content

Commit 8ca2486

Browse files
committed
Add Coarse provider
Add Coarse provider - a memory provider that should be used as a "cache" for pre-allocated buffer or with an additional upstream provider (e.g. OS Memory Provider). Developed-by: Rafał Rudnicki <[email protected]> Co-developed-by: Lukasz Dorau <[email protected]> Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 6c2c767 commit 8ca2486

File tree

9 files changed

+1985
-1
lines changed

9 files changed

+1985
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2023-2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#ifndef UMF_COARSE_PROVIDER_H
9+
#define UMF_COARSE_PROVIDER_H
10+
11+
#include <stdbool.h>
12+
#include <umf/memory_provider.h>
13+
14+
#if defined(__cplusplus)
15+
extern "C" {
16+
#endif
17+
18+
/// @brief Coarse Memory Provider settings struct.
19+
typedef struct coarse_memory_provider_params_t {
20+
/// Handle to the upstream memory provider, could be NULL.
21+
umf_memory_provider_handle_t upstream_memory_provider;
22+
23+
/// When set, the init buffer would be pre-allocated (with
24+
/// `init_buffer_size` bytes) during creation time. The memory used to
25+
/// pre-allocate it would be taken either from the `init_buffer` or from
26+
/// the `upstream_memory_provider`, so either one of them has to be set.
27+
bool immediate_init;
28+
29+
/// Init buffer used to pre-allocate memory at the creation time, could be
30+
/// NULL.
31+
void *init_buffer;
32+
33+
/// Size of the pre-allocated buffer. If the `init_buffer` is set, the
34+
/// `init_buffer_size` should be the size of this buffer.
35+
size_t init_buffer_size;
36+
} coarse_memory_provider_params_t;
37+
38+
/// @brief Coarse Memory Provider stats (TODO move to CTL)
39+
typedef struct coarse_memory_provider_stats_t {
40+
/// Total allocation size.
41+
size_t alloc_size;
42+
43+
/// Size of used memory.
44+
size_t used_size;
45+
46+
/// Number of memory blocks allocated from the upstream provider.
47+
size_t upstream_blocks_num;
48+
49+
/// Total number of allocated memory blocks.
50+
size_t blocks_num;
51+
52+
/// Number of free memory blocks.
53+
size_t free_blocks_num;
54+
} coarse_memory_provider_stats_t;
55+
56+
umf_memory_provider_ops_t *umfCoarseMemoryProviderOps(void);
57+
58+
// TODO use CTL
59+
coarse_memory_provider_stats_t
60+
umfCoarseMemoryProviderGetStats(umf_memory_provider_handle_t provider);
61+
62+
#ifdef __cplusplus
63+
}
64+
#endif
65+
66+
#endif // UMF_coarse_PROVIDER_H

scripts/docs_config/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ and operate on the provider.
8080
.. doxygenfile:: memory_provider.h
8181
:sections: define enum typedef func var
8282

83+
Coarse Provider
84+
------------------------------------------
85+
86+
A memory provider that should be used as a "cache" for pre-allocated buffer
87+
or with additional upstream provider (e.g. OS Memory Provider).
88+
89+
.. doxygenfile:: provider_coarse.h
90+
:sections: define enum typedef func var
91+
8392
OS Memory Provider
8493
------------------------------------------
8594

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ set(UMF_SOURCES
8282
memtarget.c
8383
mempolicy.c
8484
memspace.c
85+
provider/provider_coarse.c
8586
provider/provider_tracking.c
8687
critnib/critnib.c
8788
ravl/ravl.c
@@ -230,6 +231,7 @@ target_include_directories(
230231
umf
231232
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
232233
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
234+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ravl>
233235
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
234236
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
235237
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memspaces>

src/libumf.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ EXPORTS
1414
umfTearDown
1515
umfGetCurrentVersion
1616
umfCloseIPCHandle
17+
umfCoarseMemoryProviderGetStats
18+
umfCoarseMemoryProviderOps
1719
umfFree
1820
umfGetIPCHandle
1921
umfGetLastFailedMemoryProvider

src/libumf.map.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ UMF_1.0 {
88
umfTearDown;
99
umfGetCurrentVersion;
1010
umfCloseIPCHandle;
11+
umfCoarseMemoryProviderGetStats;
12+
umfCoarseMemoryProviderOps;
1113
umfFree;
1214
umfGetIPCHandle;
1315
umfGetLastFailedMemoryProvider;

0 commit comments

Comments
 (0)