1 /***** public prototypes *****/
2 #include "../inc/liblfds710.h"
10 #define LFDS710_VERSION_STRING "7.1.0"
11 #define LFDS710_VERSION_INTEGER 710
13 #if( defined KERNEL_MODE )
14 #define MODE_TYPE_STRING "kernel-mode"
17 #if( !defined KERNEL_MODE )
18 #define MODE_TYPE_STRING "user-mode"
21 #if( defined NDEBUG && !defined COVERAGE && !defined TSAN && !defined PROF )
22 #define BUILD_TYPE_STRING "release"
25 #if( !defined NDEBUG && !defined COVERAGE && !defined TSAN && !defined PROF )
26 #define BUILD_TYPE_STRING "debug"
29 #if( !defined NDEBUG && defined COVERAGE && !defined TSAN && !defined PROF )
30 #define BUILD_TYPE_STRING "coverage"
33 #if( !defined NDEBUG && !defined COVERAGE && defined TSAN && !defined PROF )
34 #define BUILD_TYPE_STRING "threadsanitizer"
37 #if( !defined NDEBUG && !defined COVERAGE && !defined TSAN && defined PROF )
38 #define BUILD_TYPE_STRING "profiling"
41 #define LFDS710_BACKOFF_INITIAL_VALUE 0
42 #define LFDS710_BACKOFF_LIMIT 10
44 #define LFDS710_BACKOFF_EXPONENTIAL_BACKOFF( backoff_state, backoff_iteration ) \
46 lfds710_pal_uint_t volatile \
52 if( (backoff_iteration) == LFDS710_BACKOFF_LIMIT ) \
53 (backoff_iteration) = LFDS710_BACKOFF_INITIAL_VALUE; \
56 endloop = ( ((lfds710_pal_uint_t) 0x1) << (backoff_iteration) ) * (backoff_state).metric; \
57 for( loop = 0 ; loop < endloop ; loop++ ); \
60 (backoff_iteration)++; \
63 #define LFDS710_BACKOFF_AUTOTUNE( bs, backoff_iteration ) \
65 if( (backoff_iteration) < 2 ) \
66 (bs).backoff_iteration_frequency_counters[(backoff_iteration)]++; \
68 if( ++(bs).total_operations >= 10000 and (bs).lock == LFDS710_MISC_FLAG_LOWERED ) \
73 lfds710_pal_uint_t LFDS710_PAL_ALIGN(LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES) \
74 compare = LFDS710_MISC_FLAG_LOWERED; \
76 LFDS710_PAL_ATOMIC_CAS( &(bs).lock, &compare, LFDS710_MISC_FLAG_RAISED, LFDS710_MISC_CAS_STRENGTH_WEAK, result ); \
80 /* TRD : if E[1] is less than 1/100th of E[0], decrease the metric, to increase E[1] */ \
81 if( (bs).backoff_iteration_frequency_counters[1] < (bs).backoff_iteration_frequency_counters[0] / 100 ) \
83 if( (bs).metric >= 11 ) \
89 (bs).backoff_iteration_frequency_counters[0] = 0; \
90 (bs).backoff_iteration_frequency_counters[1] = 0; \
91 (bs).total_operations = 0; \
93 LFDS710_MISC_BARRIER_STORE; \
95 LFDS710_PAL_ATOMIC_SET( &(bs).lock, LFDS710_MISC_FLAG_LOWERED ); \
100 /***** library-wide prototypes *****/
101 void lfds710_misc_internal_backoff_init( struct lfds710_misc_backoff_state *bs );