-
Notifications
You must be signed in to change notification settings - Fork 42
add ctl to fixed provider #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright (C) 2025 Intel Corporation | ||
| * | ||
| * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| */ | ||
|
|
||
| #ifdef UMF_PROVIDER_CTL_STATS_IMPL_H | ||
| #error This file should not be included more than once | ||
| #else | ||
| #define UMF_PROVIDER_CTL_STATS_IMPL_H 1 | ||
|
|
||
| #ifndef CTL_PROVIDER_TYPE | ||
| #error "CTL_PROVIDER_TYPE must be defined" | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #include "ctl/ctl.h" | ||
| #include "utils/utils_assert.h" | ||
|
|
||
| static int CTL_READ_HANDLER(peak_memory)(void *ctx, | ||
| umf_ctl_query_source_t source, | ||
| void *arg, | ||
| umf_ctl_index_utlist_t *indexes, | ||
| const char *extra_name, | ||
| umf_ctl_query_type_t query_type) { | ||
| /* suppress unused-parameter errors */ | ||
| (void)source, (void)indexes, (void)extra_name, (void)query_type; | ||
|
|
||
| size_t *arg_out = arg; | ||
| CTL_PROVIDER_TYPE *provider = (CTL_PROVIDER_TYPE *)ctx; | ||
| utils_atomic_load_acquire_size_t(&provider->stats.peak_memory, arg_out); | ||
| return 0; | ||
| } | ||
|
|
||
| static int CTL_READ_HANDLER(allocated_memory)(void *ctx, | ||
bratpiorka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| umf_ctl_query_source_t source, | ||
| void *arg, | ||
| umf_ctl_index_utlist_t *indexes, | ||
| const char *extra_name, | ||
| umf_ctl_query_type_t query_type) { | ||
| /* suppress unused-parameter errors */ | ||
| (void)source, (void)indexes, (void)extra_name, (void)query_type; | ||
|
|
||
| size_t *arg_out = arg; | ||
| CTL_PROVIDER_TYPE *provider = (CTL_PROVIDER_TYPE *)ctx; | ||
| utils_atomic_load_acquire_size_t(&provider->stats.allocated_memory, | ||
| arg_out); | ||
| return 0; | ||
| } | ||
|
|
||
| static int CTL_RUNNABLE_HANDLER(reset)(void *ctx, umf_ctl_query_source_t source, | ||
bratpiorka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void *arg, | ||
| umf_ctl_index_utlist_t *indexes, | ||
| const char *extra_name, | ||
| umf_ctl_query_type_t query_type) { | ||
| /* suppress unused-parameter errors */ | ||
| (void)source, (void)indexes, (void)arg, (void)extra_name, (void)query_type; | ||
|
|
||
| CTL_PROVIDER_TYPE *provider = (CTL_PROVIDER_TYPE *)ctx; | ||
| size_t allocated; | ||
| size_t current_peak; | ||
|
|
||
| utils_atomic_load_acquire_size_t(&provider->stats.peak_memory, | ||
| ¤t_peak); | ||
| do { | ||
| utils_atomic_load_acquire_size_t(&provider->stats.allocated_memory, | ||
| &allocated); | ||
| } while (!utils_compare_exchange_size_t(&provider->stats.peak_memory, | ||
| ¤t_peak, &allocated)); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static const umf_ctl_node_t CTL_NODE(peak_memory)[] = {CTL_LEAF_RUNNABLE(reset), | ||
| CTL_NODE_END}; | ||
|
|
||
| static const umf_ctl_node_t CTL_NODE(stats)[] = { | ||
bratpiorka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CTL_LEAF_RO(allocated_memory), CTL_LEAF_RO(peak_memory), | ||
| CTL_CHILD(peak_memory), CTL_LEAF_RUNNABLE(reset), CTL_NODE_END}; | ||
|
|
||
| static inline void provider_ctl_stats_alloc(CTL_PROVIDER_TYPE *provider, | ||
| size_t size) { | ||
| size_t allocated = | ||
| utils_fetch_and_add_size_t(&provider->stats.allocated_memory, size) + | ||
| size; | ||
|
|
||
| size_t peak; | ||
lplewa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| utils_atomic_load_acquire_size_t(&provider->stats.peak_memory, &peak); | ||
|
|
||
| // If the compare-exchange fails, 'peak' is updated to the current value | ||
| // of peak_memory. We then re-check whether allocated is still greater than | ||
| // the updated peak value. | ||
| while (allocated > peak && | ||
| !utils_compare_exchange_size_t(&provider->stats.peak_memory, &peak, | ||
| &allocated)) { | ||
| ; | ||
KFilipek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| static inline void provider_ctl_stats_free(CTL_PROVIDER_TYPE *provider, | ||
| size_t size) { | ||
| utils_fetch_and_sub_size_t(&provider->stats.allocated_memory, size); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright (C) 2025 Intel Corporation | ||
| * | ||
| * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| */ | ||
|
|
||
| #ifndef UMF_PROVIDER_CTL_STATS_TYPE_H | ||
| #define UMF_PROVIDER_CTL_STATS_TYPE_H 1 | ||
|
|
||
| #include <stddef.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef struct ctl_stats_t { | ||
| size_t allocated_memory; | ||
bratpiorka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| size_t peak_memory; | ||
| } ctl_stats_t; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.