diff options
author | Yonggang Luo <luoyonggang@gmail.com> | 2022-07-30 12:40:55 +0800 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-08-29 18:06:07 +0000 |
commit | b660c0eff3132299ec50475dc77a3847c7bb3c5d (patch) | |
tree | 63085026d1024ee94d219cfd95b5c37ba17ac01e /src/util | |
parent | 0993361ea776c9d256a97a43587f9498723eca5c (diff) |
util: Move detect_done out of struct util_cpu_caps_t
Also util_cpu_caps are hided, not accessed directly now
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17803>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/u_cpu_detect.c | 28 | ||||
-rw-r--r-- | src/util/u_cpu_detect.h | 26 |
2 files changed, 28 insertions, 26 deletions
diff --git a/src/util/u_cpu_detect.c b/src/util/u_cpu_detect.c index 13405a6e358..564c5e4d001 100644 --- a/src/util/u_cpu_detect.c +++ b/src/util/u_cpu_detect.c @@ -92,9 +92,15 @@ DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", false) -/* Do not try to access util_cpu_caps directly, call to util_get_cpu_caps instead */ +static struct util_cpu_caps_t util_cpu_caps; +/* Do not try to access _util_cpu_caps_state directly, call to util_get_cpu_caps instead */ +struct _util_cpu_caps_state_t _util_cpu_caps_state = { + .once_flag = ONCE_FLAG_INIT, + .detect_done = 0, +}; + #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) static int has_cpuid(void); #endif @@ -584,8 +590,10 @@ get_cpu_topology(void) #endif } -static void -util_cpu_detect_once(void) +void _util_cpu_detect_once(void); + +void +_util_cpu_detect_once(void) { int available_cpus = 0; int total_cpus = 0; @@ -912,18 +920,8 @@ util_cpu_detect_once(void) printf("util_cpu_caps.num_L3_caches = %u\n", util_cpu_caps.num_L3_caches); printf("util_cpu_caps.num_cpu_mask_bits = %u\n", util_cpu_caps.num_cpu_mask_bits); } + _util_cpu_caps_state.caps = util_cpu_caps; /* This must happen at the end as it's used to guard everything else */ - p_atomic_set(&util_cpu_caps.detect_done, 1); -} - -static once_flag cpu_once_flag = ONCE_FLAG_INIT; - -void _util_cpu_detect_local(void); - -/* Do not call to this function directly, using util_get_cpu_caps instead */ -void -_util_cpu_detect_local(void) -{ - call_once(&cpu_once_flag, util_cpu_detect_once); + p_atomic_set(&_util_cpu_caps_state.detect_done, 1); } diff --git a/src/util/u_cpu_detect.h b/src/util/u_cpu_detect.h index 646b5d0c470..974e35dc806 100644 --- a/src/util/u_cpu_detect.h +++ b/src/util/u_cpu_detect.h @@ -62,12 +62,6 @@ typedef uint32_t util_affinity_mask[UTIL_MAX_CPUS / 32]; struct util_cpu_caps_t { /** - * Initialized to 0 and set to non-zero with an atomic after the entire - * struct has been initialized. - */ - uint32_t detect_done; - - /** * Number of CPUs available to the process. * * This will be less than or equal to \c max_cpus. This is the number of @@ -132,13 +126,23 @@ struct util_cpu_caps_t { util_affinity_mask *L3_affinity_mask; }; +struct _util_cpu_caps_state_t { + once_flag once_flag; + /** + * Initialized to 0 and set to non-zero with an atomic after the entire + * struct has been initialized. + */ + uint32_t detect_done; + struct util_cpu_caps_t caps; +}; + #define U_CPU_INVALID_L3 0xffff static inline ATTRIBUTE_CONST const struct util_cpu_caps_t * util_get_cpu_caps(void) { - extern void _util_cpu_detect_local(void); - extern struct util_cpu_caps_t util_cpu_caps; + extern void _util_cpu_detect_once(void); + extern struct _util_cpu_caps_state_t _util_cpu_caps_state; /* On most CPU architectures, an atomic read is simply a regular memory * load instruction with some extra compiler magic to prevent code @@ -163,10 +167,10 @@ util_get_cpu_caps(void) * sure, but that state is such that it appears to return exactly the same * value with the same internal data every time. */ - if (unlikely(!p_atomic_read(&util_cpu_caps.detect_done))) - _util_cpu_detect_local(); + if (unlikely(!p_atomic_read(&_util_cpu_caps_state.detect_done))) + call_once(&_util_cpu_caps_state.once_flag, _util_cpu_detect_once); - return &util_cpu_caps; + return &_util_cpu_caps_state.caps; } #ifdef __cplusplus |