@cryptotaxi247 / netdata-1 / commits / c1e032a9d

WAITQ: fixed mixed up ordering (#19305)

fixed mixed up ordering

Costa Tsaousis committed Dec 31, 2024 at 14:29 UTC c1e032a9dbfdaca5b2214bbcebb9a744fd6dee7d
2 files changed +7 -7
src/libnetdata/locks/waitq.c
+2 -2
@@ -30,7 +30,7 @@ static inline bool write_our_priority(WAITQ *waitq, uint64_t our_order) {
30
31 do {
32
33 - if(current > our_order)
33 + if(current != NO_PRIORITY && current < our_order)
34 return false;
35
36 } while(!__atomic_compare_exchange_n(
@@ -206,7 +206,7 @@ static int unittest_stress(void) {
206
207 // Initialize stats and create threads
208 size_t thread_idx = 0;
209 - for(int prio = WAITQ_PRIO_URGENT; prio >= WAITQ_PRIO_LOW; prio--) {
209 + for(int prio = WAITQ_PRIO_URGENT; prio <= WAITQ_PRIO_LOW; prio++) {
210 for(int t = 0; t < THREADS_PER_PRIORITY; t++) {
211 stats[thread_idx] = (THREAD_STATS){
212 .priority = prio,
src/libnetdata/locks/waitq.h
+5 -5
@@ -23,10 +23,10 @@
23 */
24
25 typedef enum __attribute__((packed)) {
26 - WAITQ_PRIO_LOW = 0, // will be last
27 - WAITQ_PRIO_NORMAL, // will be third
28 - WAITQ_PRIO_HIGH, // will be second
29 - WAITQ_PRIO_URGENT, // will be first
26 + WAITQ_PRIO_URGENT = 0, // will be first
27 + WAITQ_PRIO_HIGH, // will be second
28 + WAITQ_PRIO_NORMAL, // will be third
29 + WAITQ_PRIO_LOW, // will be last
30
31 // terminator
32 WAITQ_PRIO_MAX,
@@ -36,7 +36,7 @@ typedef struct waiting_queue {
36 SPINLOCK spinlock; // protects the actual resource
37 pid_t writer; // the pid the thread currently holding the lock
38 uint64_t current_priority; // current highest priority attempting to acquire
39 - uint64_t last_seqno; // for FIFO ordering within same priority
39 + uint32_t last_seqno; // for FIFO ordering within same priority
40 } WAITQ;
41
42 #define WAITQ_INITIALIZER (WAITQ){ .spinlock = SPINLOCK_INITIALIZER, .current_priority = 0, .last_seqno = 0, }