mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-26 01:07:21 +00:00
🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)
Signed-off-by: Shell <smokewood@qq.com> Co-authored-by: Shell <smokewood@qq.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user