mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-24 12:20:59 +01:00
MINOR: thread: implement ha_thread_relax()
At some places we're using a painful ifdef to decide whether to use sched_yield() or pl_cpu_relax() to relax in loops, this is hardly exportable. Let's move this to ha_thread_relax() instead and une this one only.
This commit is contained in:
parent
20db9115dc
commit
38171daf21
@ -22,6 +22,11 @@
|
|||||||
#ifndef _COMMON_HATHREADS_H
|
#ifndef _COMMON_HATHREADS_H
|
||||||
#define _COMMON_HATHREADS_H
|
#define _COMMON_HATHREADS_H
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#ifdef _POSIX_PRIORITY_SCHEDULING
|
||||||
|
#include <sched.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/initcall.h>
|
#include <common/initcall.h>
|
||||||
|
|
||||||
@ -130,6 +135,13 @@ static inline void ha_set_tid(unsigned int tid)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void ha_thread_relax(void)
|
||||||
|
{
|
||||||
|
#if _POSIX_PRIORITY_SCHEDULING
|
||||||
|
sched_yield();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline void __ha_barrier_atomic_load(void)
|
static inline void __ha_barrier_atomic_load(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -391,6 +403,15 @@ static inline void ha_set_tid(unsigned int data)
|
|||||||
tid_bit = (1UL << tid);
|
tid_bit = (1UL << tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void ha_thread_relax(void)
|
||||||
|
{
|
||||||
|
#if _POSIX_PRIORITY_SCHEDULING
|
||||||
|
sched_yield();
|
||||||
|
#else
|
||||||
|
pl_cpu_relax();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Marks the thread as harmless. Note: this must be true, i.e. the thread must
|
/* Marks the thread as harmless. Note: this must be true, i.e. the thread must
|
||||||
* not be touching any unprotected shared resource during this period. Usually
|
* not be touching any unprotected shared resource during this period. Usually
|
||||||
* this is called before poll(), but it may also be placed around very slow
|
* this is called before poll(), but it may also be placed around very slow
|
||||||
|
|||||||
@ -52,11 +52,7 @@ void thread_harmless_till_end()
|
|||||||
{
|
{
|
||||||
_HA_ATOMIC_OR(&threads_harmless_mask, tid_bit);
|
_HA_ATOMIC_OR(&threads_harmless_mask, tid_bit);
|
||||||
while (threads_want_rdv_mask & all_threads_mask) {
|
while (threads_want_rdv_mask & all_threads_mask) {
|
||||||
#if _POSIX_PRIORITY_SCHEDULING
|
ha_thread_relax();
|
||||||
sched_yield();
|
|
||||||
#else
|
|
||||||
pl_cpu_relax();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +77,7 @@ void thread_isolate()
|
|||||||
else if (_HA_ATOMIC_CAS(&threads_harmless_mask, &old, old & ~tid_bit))
|
else if (_HA_ATOMIC_CAS(&threads_harmless_mask, &old, old & ~tid_bit))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if _POSIX_PRIORITY_SCHEDULING
|
ha_thread_relax();
|
||||||
sched_yield();
|
|
||||||
#else
|
|
||||||
pl_cpu_relax();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/* one thread gets released at a time here, with its harmess bit off.
|
/* one thread gets released at a time here, with its harmess bit off.
|
||||||
* The loss of this bit makes the other one continue to spin while the
|
* The loss of this bit makes the other one continue to spin while the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user