diff options
| author | xqyjlj <[email protected]> | 2023-10-25 20:31:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-25 20:31:25 +0800 |
| commit | 3283f54c7a0444b2e51ec79a4da57e7871528f05 (patch) | |
| tree | e4bcd748ad2362f16d0dea5c5da62922de466999 /components/libc | |
| parent | 91fc52df3635d5dda8285616420f08efa79cea04 (diff) | |
🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)
Signed-off-by: Shell <[email protected]>
Co-authored-by: Shell <[email protected]>
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/compilers/common/ctime.c | 34 | ||||
| -rw-r--r-- | components/libc/posix/io/poll/poll.c | 10 | ||||
| -rw-r--r-- | components/libc/posix/pthreads/pthread.c | 7 |
3 files changed, 27 insertions, 24 deletions
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index 8a6ca0dc67..15cc3743f2 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -23,6 +23,7 @@ * 2023-07-16 Shell update signal generation routine for lwp * adapt to new api and do the signal handling in thread context * 2023-08-12 Meco Man re-implement RT-Thread lightweight timezone API + * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable */ #include "sys/time.h" @@ -136,21 +137,12 @@ static volatile int32_t _current_tz_offset_sec = \ /* return current timezone offset in seconds */ void rt_tz_set(int32_t offset_sec) { - rt_base_t level; - level = rt_hw_interrupt_disable(); _current_tz_offset_sec = offset_sec; - rt_hw_interrupt_enable(level); } int32_t rt_tz_get(void) { - int32_t offset_sec; - rt_base_t level; - - level = rt_hw_interrupt_disable(); - offset_sec = _current_tz_offset_sec; - rt_hw_interrupt_enable(level); - return offset_sec; + return _current_tz_offset_sec; } int8_t rt_tz_is_dst(void) @@ -796,11 +788,15 @@ static void _lwp_timer_event_from_tid(struct rt_work *work, void *param) RT_ASSERT(data->tid); - thread = lwp_tid_get_thread(data->tid); + /* stop others from delete thread */ + thread = lwp_tid_get_thread_and_inc_ref(data->tid); + /** The tid of thread is a READ ONLY value, but here still facing the risk of thread already been delete error */ ret = lwp_thread_signal_kill(thread, data->signo, SI_TIMER, 0); + lwp_tid_dec_ref(thread); + if (ret) { - LOG_W("%s: Do kill failed(tid %d) returned %d", __func__, data->tid, ret); + LOG_D("%s: Do kill failed(tid %d) returned %d", __func__, data->tid, ret); } } @@ -808,11 +804,21 @@ static void _lwp_timer_event_from_pid(struct rt_work *work, void *param) { rt_err_t ret; struct lwp_timer_event_param *data = rt_container_of(work, struct lwp_timer_event_param, work); + struct rt_lwp *lwp; + + lwp_pid_lock_take(); + lwp = lwp_from_pid_locked(data->pid); + if (lwp) + lwp_ref_inc(lwp); + lwp_pid_lock_release(); + + ret = lwp_signal_kill(lwp, data->signo, SI_TIMER, 0); + if (lwp) + lwp_ref_dec(lwp); - ret = lwp_signal_kill(lwp_from_pid(data->pid), data->signo, SI_TIMER, 0); if (ret) { - LOG_W("%s: Do kill failed(pid %d) returned %d", __func__, data->pid, ret); + LOG_D("%s: Do kill failed(pid %d) returned %d", __func__, data->pid, ret); } } diff --git a/components/libc/posix/io/poll/poll.c b/components/libc/posix/io/poll/poll.c index 3a94ee9abd..105727e4b3 100644 --- a/components/libc/posix/io/poll/poll.c +++ b/components/libc/posix/io/poll/poll.c @@ -32,6 +32,8 @@ struct rt_poll_node struct rt_poll_node *next; }; +static RT_DEFINE_SPINLOCK(_spinlock); + static int __wqueue_pollwake(struct rt_wqueue_node *wait, void *key) { struct rt_poll_node *pn; @@ -85,7 +87,7 @@ static int poll_wait_timeout(struct rt_poll_table *pt, int msec) timeout = rt_tick_from_millisecond(msec); - level = rt_hw_interrupt_disable(); + level = rt_spin_lock_irqsave(&_spinlock); if (timeout != 0 && !pt->triggered) { @@ -99,16 +101,16 @@ static int poll_wait_timeout(struct rt_poll_table *pt, int msec) rt_timer_start(&(thread->thread_timer)); } - rt_hw_interrupt_enable(level); + rt_spin_unlock_irqrestore(&_spinlock, level); rt_schedule(); - level = rt_hw_interrupt_disable(); + level = rt_spin_lock_irqsave(&_spinlock); } } ret = !pt->triggered; - rt_hw_interrupt_enable(level); + rt_spin_unlock_irqrestore(&_spinlock, level); return ret; } diff --git a/components/libc/posix/pthreads/pthread.c b/components/libc/posix/pthreads/pthread.c index f193763548..d035515be4 100644 --- a/components/libc/posix/pthreads/pthread.c +++ b/components/libc/posix/pthreads/pthread.c @@ -17,13 +17,12 @@ #include <sys/time.h> #include "pthread_internal.h" -RT_DEFINE_SPINLOCK(pth_lock); +RT_DEFINE_HW_SPINLOCK(pth_lock); _pthread_data_t *pth_table[PTHREAD_NUM_MAX] = {NULL}; static int concurrency_level; _pthread_data_t *_pthread_get_data(pthread_t thread) { - RT_DECLARE_SPINLOCK(pth_lock); _pthread_data_t *ptd; if (thread >= PTHREAD_NUM_MAX) return NULL; @@ -40,7 +39,6 @@ _pthread_data_t *_pthread_get_data(pthread_t thread) pthread_t _pthread_data_get_pth(_pthread_data_t *ptd) { int index; - RT_DECLARE_SPINLOCK(pth_lock); rt_hw_spin_lock(&pth_lock); for (index = 0; index < PTHREAD_NUM_MAX; index ++) @@ -56,7 +54,6 @@ pthread_t _pthread_data_create(void) { int index; _pthread_data_t *ptd = NULL; - RT_DECLARE_SPINLOCK(pth_lock); ptd = (_pthread_data_t*)rt_malloc(sizeof(_pthread_data_t)); if (!ptd) return PTHREAD_NUM_MAX; @@ -90,8 +87,6 @@ pthread_t _pthread_data_create(void) void _pthread_data_destroy(_pthread_data_t *ptd) { - RT_DECLARE_SPINLOCK(pth_lock); - extern _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX]; pthread_t pth; |
