Skip to content

Commit 5d80c48

Browse files
committed
Add: New metadata APIs for C
1 parent 7fbddb2 commit 5d80c48

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

c/lib.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ size_t fu_count_quality_levels(void) {
143143
return 1; // TODO: One day I'll get some of those weird CPUs to do this
144144
}
145145

146-
size_t fu_volume_huge_pages(size_t numa_node_index) {
146+
size_t fu_volume_any_pages(void) { return fu::get_ram_total_volume(); }
147+
148+
size_t fu_volume_huge_pages_in(size_t numa_node_index) {
147149
#if FU_ENABLE_NUMA
148150
size_t total_volume = 0;
149151
auto const &node = global_numa_topology.node(numa_node_index);
@@ -154,13 +156,13 @@ size_t fu_volume_huge_pages(size_t numa_node_index) {
154156
#endif
155157
}
156158

157-
size_t fu_volume_any_pages(size_t numa_node_index) {
159+
size_t fu_volume_any_pages_in(size_t numa_node_index) {
158160
#if FU_ENABLE_NUMA
159161
if (!globals_initialize()) return 0;
160162
if (numa_node_index >= global_numa_topology.nodes_count()) return 0;
161163

162164
auto const &node = global_numa_topology.node(numa_node_index);
163-
return node.total_memory_bytes();
165+
return node.memory_size;
164166
#else
165167
return fu::get_ram_total_volume();
166168
#endif
@@ -348,9 +350,8 @@ size_t fu_pool_count_threads_in(fu_pool_t *pool, size_t colocation_index) {
348350
size_t fu_pool_locate_thread_in(fu_pool_t *pool, size_t global_thread_index, size_t colocation_index) {
349351
assert(pool != nullptr);
350352
opaque_pool_t *opaque = reinterpret_cast<opaque_pool_t *>(pool);
351-
return std::visit([=](auto &variant) {
352-
return variant.thread_local_index(global_thread_index, colocation_index);
353-
}, opaque->variants);
353+
return std::visit([=](auto &variant) { return variant.thread_local_index(global_thread_index, colocation_index); },
354+
opaque->variants);
354355
}
355356

356357
#pragma endregion - Lifetime

include/fork_union.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ typedef enum fu_caller_exclusivity_t {
153153
* @retval "numa+x86_tpause" for the NUMA-aware pool with `tpause` instruction with "waitpkg" CPU feature.
154154
* @retval "numa+arm64_wfet" for the NUMA-aware pool with `wfet` instruction on AArch64.
155155
* @retval "numa+risc5_pause" for the NUMA-aware pool with `pause` instruction on RISC-V.
156-
* @note This API is @b not synchronized and should be called once during initialization.
157156
*
158157
* The string describes both the memory topology awareness and the CPU-specific optimizations
159158
* available for busy-waiting. These capabilities directly affect performance characteristics:
@@ -167,7 +166,6 @@ char const *fu_capabilities_string(void);
167166
* @brief Describes the number of logical CPU cores available on the system.
168167
* @retval 0 if the thread pool is not supported on the current platform or detection failed.
169168
* @retval 1-N where N is the number of logical cores detected by the OS.
170-
* @note This API is @b not synchronized and should be called once during initialization.
171169
*
172170
* On x86 systems with hyper-threading enabled, this will be 2x the number of physical cores.
173171
* On ARM big.LITTLE architectures, this includes both performance and efficiency cores.
@@ -186,7 +184,6 @@ size_t fu_count_logical_cores(void);
186184
* @retval 1 on most desktop, laptop, or IoT platforms with unified memory.
187185
* @retval 2-8 on typical dual-socket servers or heterogeneous mobile chips.
188186
* @retval 4-32 is a typical range on high-end cloud servers with multiple sockets.
189-
* @note This API is @b not synchronized and should be called once during initialization.
190187
*
191188
* A "colocation" represents a group of threads that share the same:
192189
* - NUMA memory domain (fast local memory access)
@@ -205,7 +202,6 @@ size_t fu_count_colocations(void);
205202
* @retval 1 on systems with uniform memory access (UMA).
206203
* @retval 2-8 on typical multi-socket servers.
207204
* @retval 8+ on high-end systems with complex topologies.
208-
* @note This API is @b not synchronized and should be called once during initialization.
209205
*
210206
* NUMA nodes represent distinct memory domains with different access latencies.
211207
* Memory allocated on the local NUMA node is typically 2-3x faster to access
@@ -220,19 +216,36 @@ size_t fu_count_numa_nodes(void);
220216
* @retval 0 if QoS detection is not supported.
221217
* @retval 1 on systems with homogeneous cores.
222218
* @retval 2-3 on systems with heterogeneous cores (e.g., ARM big.LITTLE, Intel P+E cores).
223-
* @note This API is @b not synchronized and should be called once during initialization.
224219
*
225220
* Different QoS levels may have vastly different performance characteristics.
226221
* Consider creating separate thread pools for different workload types.
227222
*/
228223
size_t fu_count_quality_levels(void);
229224

225+
/**
226+
* @brief Returns the total volume of any pages (huge or regular) available across all NUMA nodes.
227+
* @retval Number of bytes of memory pages available across all NUMA nodes.
228+
*/
229+
size_t fu_volume_any_pages(void);
230+
231+
/**
232+
* @brief Returns the volume of any pages (huge or regular) available on the specified NUMA node.
233+
* @param[in] numa_node_index The index of the NUMA node to query, in [0, numa_nodes_count).
234+
* @retval 0 if the NUMA node index is invalid or if no memory is available.
235+
* @retval Number of bytes of memory pages available on the specified NUMA node.
236+
*
237+
* This function queries the operating system for the total amount of memory pages
238+
* (both huge pages and regular pages) available for allocation on the specified NUMA node.
239+
* This is useful for determining how much memory can be allocated for vector storage
240+
* based on a percentage of available memory.
241+
*/
242+
size_t fu_volume_any_pages_in(size_t numa_node_index);
243+
230244
/**
231245
* @brief Describes the number of different huge page sizes supported.
232246
* @param[in] numa_node_index The index of the NUMA node to allocate memory on, in [0, numa_nodes_count).
233247
* @retval 0 if huge pages are not supported or not available.
234248
* @retval 1-4 on systems with huge page support (typically 2MB, 1GB sizes).
235-
* @note This API is @b not synchronized and should be called once during initialization.
236249
*
237250
* Huge pages reduce TLB (Translation Lookaside Buffer) pressure by using larger
238251
* page sizes than the standard 4KB. This can significantly improve performance
@@ -244,21 +257,7 @@ size_t fu_count_quality_levels(void);
244257
* - 16KB/64KB: Base page sizes on some ARM configurations
245258
* @sa `fu_allocate_at_least` for NUMA-aware allocation with huge page support.
246259
*/
247-
size_t fu_volume_huge_pages(size_t numa_node_index);
248-
249-
/**
250-
* @brief Returns the volume of any pages (huge or regular) available on the specified NUMA node.
251-
* @param[in] numa_node_index The index of the NUMA node to query, in [0, numa_nodes_count).
252-
* @retval 0 if the NUMA node index is invalid or if no memory is available.
253-
* @retval Number of bytes of memory pages available on the specified NUMA node.
254-
* @note This API is @b not synchronized and should be called once during initialization.
255-
*
256-
* This function queries the operating system for the total amount of memory pages
257-
* (both huge pages and regular pages) available for allocation on the specified NUMA node.
258-
* This is useful for determining how much memory can be allocated for vector storage
259-
* based on a percentage of available memory.
260-
*/
261-
size_t fu_volume_any_pages(size_t numa_node_index);
260+
size_t fu_volume_huge_pages_in(size_t numa_node_index);
262261

263262
#pragma endregion - Metadata
264263

0 commit comments

Comments
 (0)