RT-Thread / RT-Thread/rt-thread
Whether to consider adding "rt_hw_spin_trylock" function before spinlock to avoid CPU busy waiting?【是否考虑在spinlock之前先尝试获取锁trylock,避免CPU忙等】
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
The Linux kernel spinlock will try to lock before each spinlock. This attempt to lock can bring performance gains under fierce lock competition. Refer to the following kernel code:
static inline int arch_spin_trylock(arch_spinlock_t *lock)
{
unsigned long contended, res;
u32 slock;
prefetchw(&lock->slock);
do {
__asm__ __volatile__(
" ldrex %0, [%3]\n"
" mov %2, #0\n"
" subs %1, %0, %0, ror #16\n"
" addeq %0, %0, %4\n"
" strexeq %2, %0, [%3]"
: "=&r" (slock), "=&r" (contended), "=&r" (res)
: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
: "cc");
} while (res);
if (!contended) {
smp_mb();
return 1;
} else {
return 0;
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating RT-Thread's spinlock implementation and architecture-specific lock entry points, then compare their contention behavior with the cited Linux trylock. Confirm the supported targets and expected API before deciding whether a trylock path belongs before blocking acquisition; completion would require an agreed scope and regression or performance evidence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux
- Domain
- embedded-iot, operating-systems, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100