✨ feat: spinlock should lock sched (#8360)

This commit is contained in:
xqyjlj
2023-12-22 11:15:18 +08:00
committed by GitHub
parent a01b66d57b
commit e31fa93423
5 changed files with 100 additions and 60 deletions
+29 -5
View File
@@ -20,6 +20,7 @@
* 2023-05-20 Bernard add rtatomic.h header file to included files.
* 2023-06-30 ChuShicheng move debug check from the rtdebug.h
* 2023-10-16 Shell Support a new backtrace framework
* 2023-12-10 xqyjlj fix spinlock in up
*/
#ifndef __RT_THREAD_H__
@@ -553,11 +554,34 @@ void rt_spin_unlock(struct rt_spinlock *lock);
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock);
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level);
#else
#define rt_spin_lock_init(lock) do {RT_UNUSED(lock);} while (0)
#define rt_spin_lock(lock) do {RT_UNUSED(lock);} while (0)
#define rt_spin_unlock(lock) do {RT_UNUSED(lock);} while (0)
rt_inline rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock) {RT_UNUSED(lock);return rt_hw_interrupt_disable();}
#define rt_spin_unlock_irqrestore(lock, level) do {RT_UNUSED(lock); rt_hw_interrupt_enable(level);} while (0)
rt_inline void rt_spin_lock_init(struct rt_spinlock *lock)
{
RT_UNUSED(lock);
}
rt_inline void rt_spin_lock(struct rt_spinlock *lock)
{
RT_UNUSED(lock);
rt_enter_critical();
}
rt_inline void rt_spin_unlock(struct rt_spinlock *lock)
{
RT_UNUSED(lock);
rt_exit_critical();
}
rt_inline rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
{
rt_base_t level;
RT_UNUSED(lock);
level = rt_hw_interrupt_disable();
return level;
}
rt_inline void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
{
RT_UNUSED(lock);
rt_hw_interrupt_enable(level);
}
#endif /* RT_USING_SMP */
/**@}*/
+4
View File
@@ -169,6 +169,10 @@ RTM_EXPORT(rt_tick_from_millisecond);
*/
rt_weak rt_tick_t rt_tick_get_millisecond(void)
{
#if RT_TICK_PER_SECOND == 0 // make cppcheck happy
#error "RT_TICK_PER_SECOND must be greater than zero"
#endif
#if 1000 % RT_TICK_PER_SECOND == 0u
return rt_tick_get() * (1000u / RT_TICK_PER_SECOND);
#else
+10 -5
View File
@@ -7,6 +7,7 @@
* Date Author Notes
* 2018-10-30 Bernard The first version
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
* 2023-12-10 xqyjlj spinlock should lock sched
*/
#include <rthw.h>
#include <rtthread.h>
@@ -44,7 +45,7 @@ void rt_spin_lock_init(struct rt_spinlock *lock)
RTM_EXPORT(rt_spin_lock_init)
/**
* @brief This function will lock the spinlock.
* @brief This function will lock the spinlock, will lock the thread scheduler.
*
* @note If the spinlock is locked, the current CPU will keep polling the spinlock state
* until the spinlock is unlocked.
@@ -53,6 +54,7 @@ RTM_EXPORT(rt_spin_lock_init)
*/
void rt_spin_lock(struct rt_spinlock *lock)
{
rt_enter_critical();
rt_hw_spin_lock(&lock->lock);
#if defined(RT_DEBUGING_SPINLOCK)
if (rt_cpu_self() != RT_NULL)
@@ -65,7 +67,7 @@ void rt_spin_lock(struct rt_spinlock *lock)
RTM_EXPORT(rt_spin_lock)
/**
* @brief This function will unlock the spinlock.
* @brief This function will unlock the spinlock, will unlock the thread scheduler.
*
* @param lock is a pointer to the spinlock.
*/
@@ -76,11 +78,12 @@ void rt_spin_unlock(struct rt_spinlock *lock)
lock->owner = __OWNER_MAGIC;
lock->pc = RT_NULL;
#endif /* RT_DEBUGING_SPINLOCK */
rt_exit_critical();
}
RTM_EXPORT(rt_spin_unlock)
/**
* @brief This function will disable the local interrupt and then lock the spinlock.
* @brief This function will disable the local interrupt and then lock the spinlock, will lock the thread scheduler.
*
* @note If the spinlock is locked, the current CPU will keep polling the spinlock state
* until the spinlock is unlocked.
@@ -94,6 +97,7 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
unsigned long level;
level = rt_hw_local_irq_disable();
rt_enter_critical();
rt_hw_spin_lock(&lock->lock);
#if defined(RT_DEBUGING_SPINLOCK)
if (rt_cpu_self() != RT_NULL)
@@ -107,7 +111,7 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
RTM_EXPORT(rt_spin_lock_irqsave)
/**
* @brief This function will unlock the spinlock and then restore current cpu interrupt status.
* @brief This function will unlock the spinlock and then restore current cpu interrupt status, will unlock the thread scheduler.
*
* @param lock is a pointer to the spinlock.
*
@@ -121,6 +125,7 @@ void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
#endif /* RT_DEBUGING_SPINLOCK */
rt_hw_spin_unlock(&lock->lock);
rt_hw_local_irq_enable(level);
rt_exit_critical();
}
RTM_EXPORT(rt_spin_unlock_irqrestore)
@@ -221,7 +226,7 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread)
#endif
if (pcpu->current_thread != RT_NULL )
{
rt_spin_unlock(&(pcpu->current_thread->spinlock));
rt_hw_spin_unlock(&(pcpu->current_thread->spinlock.lock));
if ((pcpu->current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
rt_schedule_insert_thread(pcpu->current_thread);
+55 -48
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -17,13 +17,13 @@ import format_ignore
class CPPCheck:
def __init__(self, file_list):
self.file_list = file_list
def check(self):
file_list_filtered = [file for file in self.file_list if file.endswith(('.c', '.cpp', '.cc', '.cxx'))]
logging.info("Start to static code analysis.")
check_result = True
for file in file_list_filtered:
result = subprocess.run(['cppcheck', '--enable=warning', 'performance', 'portability', '--inline-suppr', '--error-exitcode=1', '--force', file], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
result = subprocess.run(['cppcheck', '-DRTM_EXPORT', '--enable=warning', 'performance', 'portability', '--inline-suppr', '--error-exitcode=1', '--force', file], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
logging.info(result.stdout.decode())
logging.info(result.stderr.decode())
if result.stderr: