🎈 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:
xqyjlj
2023-10-25 20:31:25 +08:00
committed by GitHub
co-authored by Shell
parent 91fc52df36
commit 3283f54c7a
80 changed files with 2478 additions and 1962 deletions
@@ -12,6 +12,7 @@
#include "gic.h"
#include "interrupt.h"
#include "mmu.h"
#include "gtimer.h"
#ifdef RT_USING_SMP
@@ -29,8 +30,9 @@ void rt_hw_secondary_cpu_bsp_start(void)
arm_gic_cpu_init(0, 0);
// local timer init
rt_hw_gtimer_init();
rt_system_scheduler_start();
}
#endif // SMP
#endif // SMP
+3 -1
View File
@@ -800,11 +800,13 @@ struct dfs_fdtable *dfs_fdtable_get_pid(int pid)
struct rt_lwp *lwp = RT_NULL;
struct dfs_fdtable *fdt = RT_NULL;
lwp = lwp_from_pid(pid);
lwp_pid_lock_take();
lwp = lwp_from_pid_locked(pid);
if (lwp)
{
fdt = &lwp->fdt;
}
lwp_pid_lock_release();
return fdt;
}
+3 -1
View File
@@ -401,11 +401,13 @@ struct dfs_fdtable *dfs_fdtable_get_pid(int pid)
struct rt_lwp *lwp = RT_NULL;
struct dfs_fdtable *fdt = RT_NULL;
lwp = lwp_from_pid(pid);
lwp_pid_lock_take();
lwp = lwp_from_pid_locked(pid);
if (lwp)
{
fdt = &lwp->fdt;
}
lwp_pid_lock_release();
return fdt;
}
@@ -152,6 +152,8 @@ struct rt_serial_device
void *serial_rx;
void *serial_tx;
struct rt_spinlock spinlock;
struct rt_device_notify rx_notify;
};
typedef struct rt_serial_device rt_serial_t;
@@ -22,6 +22,7 @@ struct rt_completion
/* suspended list */
rt_list_t suspended_list;
struct rt_spinlock spinlock;
};
void rt_completion_init(struct rt_completion *completion);
@@ -33,6 +33,7 @@ struct rt_data_queue
rt_uint16_t is_full : 1;
struct rt_data_item *queue;
struct rt_spinlock spinlock;
rt_list_t suspended_push_list;
rt_list_t suspended_pop_list;
@@ -78,6 +78,7 @@ struct rt_rbb
rt_slist_t *tail;
/* free node list */
rt_slist_t free_list;
struct rt_spinlock spinlock;
};
typedef struct rt_rbb *rt_rbb_t;
@@ -26,6 +26,7 @@ struct rt_wqueue_node
rt_thread_t polling_thread;
rt_list_t list;
rt_wqueue_t *wqueue;
rt_wqueue_func_t wakeup;
rt_uint32_t key;
};
@@ -39,6 +40,7 @@ rt_inline void rt_wqueue_init(rt_wqueue_t *queue)
queue->flag = RT_WQ_FLAG_CLEAN;
rt_list_init(&(queue->waiting_list));
rt_spin_lock_init(&(queue->spinlock));
}
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node);
@@ -41,6 +41,7 @@ struct rt_workqueue
struct rt_semaphore sem;
rt_thread_t work_thread;
struct rt_spinlock spinlock;
};
struct rt_work
+11 -9
View File
@@ -7,6 +7,7 @@
* Date Author Notes
* 2012-09-30 Bernard first version.
* 2021-08-18 chenyingchun add comments
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -25,10 +26,11 @@ void rt_completion_init(struct rt_completion *completion)
rt_base_t level;
RT_ASSERT(completion != RT_NULL);
level = rt_hw_interrupt_disable();
rt_spin_lock_init(&(completion->spinlock));
level = rt_spin_lock_irqsave(&(completion->spinlock));
completion->flag = RT_UNCOMPLETED;
rt_list_init(&completion->suspended_list);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
}
RTM_EXPORT(rt_completion_init);
@@ -62,7 +64,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
result = RT_EOK;
thread = rt_thread_self();
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(completion->spinlock));
if (completion->flag != RT_COMPLETED)
{
/* only one thread can suspend on complete */
@@ -97,7 +99,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_timer_start(&(thread->thread_timer));
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
/* do schedule */
rt_schedule();
@@ -105,14 +107,14 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
/* thread is waked up */
result = thread->error;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(completion->spinlock));
}
}
/* clean completed flag */
completion->flag = RT_UNCOMPLETED;
__exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
return result;
}
@@ -131,7 +133,7 @@ void rt_completion_done(struct rt_completion *completion)
if (completion->flag == RT_COMPLETED)
return;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(completion->spinlock));
completion->flag = RT_COMPLETED;
if (!rt_list_isempty(&(completion->suspended_list)))
@@ -146,14 +148,14 @@ void rt_completion_done(struct rt_completion *completion)
/* resume it */
rt_thread_resume(thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
/* perform a schedule */
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
}
}
RTM_EXPORT(rt_completion_done);
+26 -23
View File
@@ -7,6 +7,7 @@
* Date Author Notes
* 2012-09-30 Bernard first version.
* 2016-10-31 armink fix some resume push and pop thread bugs
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -57,6 +58,8 @@ rt_data_queue_init(struct rt_data_queue *queue,
queue->is_empty = 1;
queue->is_full = 0;
rt_spin_lock_init(&(queue->spinlock));
rt_list_init(&(queue->suspended_push_list));
rt_list_init(&(queue->suspended_pop_list));
@@ -103,7 +106,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
result = RT_EOK;
thread = rt_thread_self();
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
while (queue->is_full)
{
/* queue is full */
@@ -131,14 +134,14 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* do schedule */
rt_schedule();
/* thread is waked up */
result = thread->error;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
if (result != RT_EOK) goto __exit;
}
@@ -165,7 +168,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
/* resume it */
rt_thread_resume(thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* perform a schedule */
rt_schedule();
@@ -174,7 +177,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
}
__exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
if ((result == RT_EOK) && queue->evt_notify != RT_NULL)
{
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_PUSH);
@@ -222,7 +225,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
result = RT_EOK;
thread = rt_thread_self();
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
while (queue->is_empty)
{
/* queue is empty */
@@ -249,14 +252,14 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* do schedule */
rt_schedule();
/* thread is waked up */
result = thread->error;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
if (result != RT_EOK)
goto __exit;
}
@@ -286,14 +289,14 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
/* resume it */
rt_thread_resume(thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* perform a schedule */
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
if (queue->evt_notify != RT_NULL)
@@ -303,7 +306,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
}
__exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
if ((result == RT_EOK) && (queue->evt_notify != RT_NULL))
{
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_POP);
@@ -339,12 +342,12 @@ rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
return -RT_EEMPTY;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
*data_ptr = queue->queue[queue->get_index].data_ptr;
*size = queue->queue[queue->get_index].data_size;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
return RT_EOK;
}
@@ -366,14 +369,14 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
queue->get_index = 0;
queue->put_index = 0;
queue->is_empty = 1;
queue->is_full = 0;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_enter_critical();
/* wakeup all suspend threads */
@@ -382,7 +385,7 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
while (!rt_list_isempty(&(queue->suspended_pop_list)))
{
/* disable interrupt */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* get next suspend thread */
thread = rt_list_entry(queue->suspended_pop_list.next,
@@ -399,14 +402,14 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
rt_thread_resume(thread);
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
/* resume on push list */
while (!rt_list_isempty(&(queue->suspended_push_list)))
{
/* disable interrupt */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* get next suspend thread */
thread = rt_list_entry(queue->suspended_push_list.next,
@@ -423,7 +426,7 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
rt_thread_resume(thread);
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
rt_exit_critical();
@@ -448,9 +451,9 @@ rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
/* wakeup all suspend threads */
rt_data_queue_reset(queue);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
queue->magic = 0;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_free(queue->queue);
@@ -478,7 +481,7 @@ rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
return 0;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
if (queue->put_index > queue->get_index)
{
@@ -489,7 +492,7 @@ rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
len = queue->size + queue->put_index - queue->get_index;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
return len;
}
+12 -10
View File
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2018-08-25 armink the first version
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -44,6 +45,7 @@ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t
rt_slist_init(&block_set[i].list);
rt_slist_insert(&rbb->free_list, &block_set[i].list);
}
rt_spin_lock_init(&(rbb->spinlock));
}
RTM_EXPORT(rt_rbb_init);
@@ -173,7 +175,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
RT_ASSERT(rbb);
RT_ASSERT(blk_size < (1L << 24));
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(rbb->spinlock));
new_rbb = find_empty_blk_in_set(rbb);
@@ -255,7 +257,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
new_rbb = RT_NULL;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
return new_rbb;
}
@@ -294,7 +296,7 @@ rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb)
if (rt_slist_isempty(&rbb->blk_list))
return 0;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(rbb->spinlock));
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
{
@@ -310,7 +312,7 @@ rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb)
__exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
return block;
}
@@ -360,12 +362,12 @@ void rt_rbb_blk_free(rt_rbb_t rbb, rt_rbb_blk_t block)
RT_ASSERT(block);
RT_ASSERT(block->status != RT_RBB_BLK_UNUSED);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(rbb->spinlock));
/* remove it on rbb block list */
list_remove(rbb, &block->list);
block->status = RT_RBB_BLK_UNUSED;
rt_slist_insert(&rbb->free_list, &block->list);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
}
RTM_EXPORT(rt_rbb_blk_free);
@@ -405,7 +407,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
if (rt_slist_isempty(&rbb->blk_list))
return 0;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(rbb->spinlock));
node = rt_slist_first(&rbb->blk_list);
if (node != RT_NULL)
@@ -454,7 +456,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
blk_queue->blk_num++;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
return data_total_size;
}
@@ -541,7 +543,7 @@ rt_size_t rt_rbb_next_blk_queue_len(rt_rbb_t rbb)
if (rt_slist_isempty(&rbb->blk_list))
return 0;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(rbb->spinlock));
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
{
@@ -573,7 +575,7 @@ rt_size_t rt_rbb_next_blk_queue_len(rt_rbb_t rbb)
data_len += last_block->size;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
return data_len;
}
+19 -14
View File
@@ -8,6 +8,7 @@
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
* to blocked thread.
* 2022-01-24 THEWON let rt_wqueue_wait return thread->error when using signal
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <stdint.h>
@@ -25,9 +26,10 @@ void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
node->wqueue = queue;
rt_list_insert_before(&(queue->waiting_list), &(node->list));
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
/**
@@ -39,9 +41,11 @@ void rt_wqueue_remove(struct rt_wqueue_node *node)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
RT_ASSERT(node->wqueue != RT_NULL);
level = rt_spin_lock_irqsave(&(node->wqueue->spinlock));
rt_list_remove(&(node->list));
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(node->wqueue->spinlock), level);
}
/**
@@ -79,7 +83,7 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
queue_list = &(queue->waiting_list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* set wakeup flag in the queue */
queue->flag = RT_WQ_FLAG_WAKEUP;
@@ -93,13 +97,12 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
rt_thread_resume(entry->polling_thread);
need_schedule = 1;
rt_wqueue_remove(entry);
rt_list_remove(&(entry->list));
break;
}
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
if (need_schedule)
rt_schedule();
}
@@ -136,9 +139,10 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
__wait.polling_thread = rt_thread_self();
__wait.key = 0;
__wait.wakeup = __wqueue_default_wake;
__wait.wqueue = queue;
rt_list_init(&__wait.list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* reset thread error */
tid->error = RT_EOK;
@@ -152,11 +156,12 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
ret = rt_thread_suspend_with_flag(tid, suspend_flag);
if (ret != RT_EOK)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* suspend failed */
return -RT_EINTR;
}
rt_wqueue_add(queue, &__wait);
rt_list_insert_before(&(queue->waiting_list), &(__wait.list));
/* start timer */
if (tick != RT_WAITING_FOREVER)
@@ -167,15 +172,15 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
rt_timer_start(tmr);
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_schedule();
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
__exit_wakeup:
queue->flag = RT_WQ_FLAG_CLEAN;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_wqueue_remove(&__wait);
+18 -18
View File
@@ -9,6 +9,7 @@
* 2021-08-01 Meco Man remove rt_delayed_work_init()
* 2021-08-14 Jackistang add comments for function interface
* 2022-01-16 Meco Man add rt_work_urgent()
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -22,7 +23,6 @@ rt_inline rt_err_t _workqueue_work_completion(struct rt_workqueue *queue)
{
rt_err_t result;
rt_enter_critical();
while (1)
{
/* try to take condition semaphore */
@@ -44,7 +44,6 @@ rt_inline rt_err_t _workqueue_work_completion(struct rt_workqueue *queue)
break;
}
}
rt_exit_critical();
return result;
}
@@ -60,12 +59,12 @@ static void _workqueue_thread_entry(void *parameter)
while (1)
{
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
if (rt_list_isempty(&(queue->work_list)))
{
/* no software timer exist, suspend self. */
rt_thread_suspend_with_flag(rt_thread_self(), RT_UNINTERRUPTIBLE);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_schedule();
continue;
}
@@ -76,7 +75,7 @@ static void _workqueue_thread_entry(void *parameter)
queue->work_current = work;
work->flags &= ~RT_WORK_STATE_PENDING;
work->workqueue = RT_NULL;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
/* do work */
work->work_func(work, work->work_data);
@@ -93,7 +92,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
{
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* remove list */
rt_list_remove(&(work->list));
@@ -111,12 +110,12 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
return RT_EOK;
}
@@ -137,11 +136,11 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
work->workqueue = queue;
/* insert delay work list */
rt_list_insert_after(queue->delayed_list.prev, &(work->list));
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_timer_start(&(work->timer));
return RT_EOK;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
return -RT_ERROR;
}
@@ -150,7 +149,7 @@ static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_wor
rt_base_t level;
rt_err_t err;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
rt_list_remove(&(work->list));
work->flags &= ~RT_WORK_STATE_PENDING;
/* Timer started */
@@ -162,7 +161,7 @@ static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_wor
}
err = queue->work_current != work ? RT_EOK : -RT_EBUSY;
work->workqueue = RT_NULL;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
return err;
}
@@ -176,7 +175,7 @@ static void _delayed_work_timeout_handler(void *parameter)
queue = work->workqueue;
RT_ASSERT(queue != RT_NULL);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
rt_timer_detach(&(work->timer));
work->flags &= ~RT_WORK_STATE_SUBMITTING;
/* remove delay list */
@@ -193,12 +192,12 @@ static void _delayed_work_timeout_handler(void *parameter)
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
}
@@ -258,6 +257,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz
return RT_NULL;
}
rt_spin_lock_init(&(queue->spinlock));
rt_thread_startup(queue->work_thread);
}
@@ -341,7 +341,7 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(work != RT_NULL);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(queue->spinlock));
/* NOTE: the work MUST be initialized firstly */
rt_list_remove(&(work->list));
rt_list_insert_after(&queue->work_list, &(work->list));
@@ -351,12 +351,12 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
}
return RT_EOK;
+2 -9
View File
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2023-07-10 xqyjlj The first version.
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rtdevice.h>
@@ -22,7 +23,7 @@
static rt_list_t _timer_list = RT_LIST_OBJECT_INIT(_timer_list);
static rt_ktime_hrtimer_t _nowtimer = RT_NULL;
static struct rt_spinlock _spinlock;
static RT_DEFINE_SPINLOCK(_spinlock);
rt_weak unsigned long rt_ktime_hrtimer_getres(void)
{
@@ -389,11 +390,3 @@ rt_err_t rt_ktime_hrtimer_mdelay(unsigned long ms)
{
return rt_ktime_hrtimer_ndelay(ms * 1000000);
}
static int rt_ktime_hrtimer_lock_init(void)
{
RT_UNUSED(_spinlock);
rt_spin_lock_init(&_spinlock);
return 0;
}
INIT_BOARD_EXPORT(rt_ktime_hrtimer_lock_init);
+24 -21
View File
@@ -26,6 +26,7 @@
* when using interrupt tx
* 2020-12-14 Meco Man implement function of setting window's size(TIOCSWINSZ)
* 2021-08-22 Meco Man implement function of getting window's size(TIOCGWINSZ)
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -208,10 +209,10 @@ static int serial_fops_poll(struct dfs_file *fd, struct rt_pollreq *req)
rx_fifo = (struct rt_serial_rx_fifo*) serial->serial_rx;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
if ((rx_fifo->get_index != rx_fifo->put_index) || (rx_fifo->get_index == rx_fifo->put_index && rx_fifo->is_full == RT_TRUE))
mask |= POLLIN;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
}
return mask;
@@ -303,13 +304,13 @@ rt_inline int _serial_int_rx(struct rt_serial_device *serial, rt_uint8_t *data,
rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
/* there's no data: */
if ((rx_fifo->get_index == rx_fifo->put_index) && (rx_fifo->is_full == RT_FALSE))
{
/* no data, enable interrupt and break out */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
break;
}
@@ -324,7 +325,7 @@ rt_inline int _serial_int_rx(struct rt_serial_device *serial, rt_uint8_t *data,
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
*data = ch & 0xff;
data ++; length --;
@@ -501,7 +502,7 @@ rt_inline int _serial_dma_rx(struct rt_serial_device *serial, rt_uint8_t *data,
RT_ASSERT((serial != RT_NULL) && (data != RT_NULL));
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
if (serial->config.bufsz == 0)
{
@@ -518,7 +519,7 @@ rt_inline int _serial_dma_rx(struct rt_serial_device *serial, rt_uint8_t *data,
serial->ops->dma_transmit(serial, data, length, RT_SERIAL_DMA_RX);
}
else result = -RT_EBUSY;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
if (result == RT_EOK) return length;
@@ -547,7 +548,7 @@ rt_inline int _serial_dma_rx(struct rt_serial_device *serial, rt_uint8_t *data,
recv_len + rx_fifo->get_index - serial->config.bufsz);
}
rt_dma_recv_update_get_index(serial, recv_len);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
return recv_len;
}
}
@@ -563,18 +564,18 @@ rt_inline int _serial_dma_tx(struct rt_serial_device *serial, const rt_uint8_t *
result = rt_data_queue_push(&(tx_dma->data_queue), data, length, RT_WAITING_FOREVER);
if (result == RT_EOK)
{
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
if (tx_dma->activated != RT_TRUE)
{
tx_dma->activated = RT_TRUE;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
/* make a DMA transfer */
serial->ops->dma_transmit(serial, (rt_uint8_t *)data, length, RT_SERIAL_DMA_TX);
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
}
return length;
@@ -980,10 +981,10 @@ static void _tc_flush(struct rt_serial_device *serial, int queue)
if((device->open_flag & RT_DEVICE_FLAG_INT_RX) || (device->open_flag & RT_DEVICE_FLAG_DMA_RX))
{
RT_ASSERT(RT_NULL != rx_fifo);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
rx_fifo->get_index = rx_fifo->put_index;
rx_fifo->is_full = RT_FALSE;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
}
else
{
@@ -1245,9 +1246,9 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
rt_size_t recved = 0;
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
recved = _serial_fifo_calc_recved_len(serial);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
*(rt_size_t *)args = recved;
}
@@ -1286,6 +1287,8 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
struct rt_device *device;
RT_ASSERT(serial != RT_NULL);
rt_spin_lock_init(&(serial->spinlock));
device = &(serial->parent);
device->type = RT_Device_Class_Char;
@@ -1337,7 +1340,7 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
/* disable interrupt */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
rx_fifo->buffer[rx_fifo->put_index] = ch;
rx_fifo->put_index += 1;
@@ -1354,7 +1357,7 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
}
/* invoke callback */
@@ -1363,10 +1366,10 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
rt_size_t rx_length;
/* get rx length */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
rx_length = (rx_fifo->put_index >= rx_fifo->get_index)? (rx_fifo->put_index - rx_fifo->get_index):
(serial->config.bufsz - (rx_fifo->get_index - rx_fifo->put_index));
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
if (rx_length)
{
@@ -1438,13 +1441,13 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
else
{
/* disable interrupt */
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(serial->spinlock));
/* update fifo put index */
rt_dma_recv_update_put_index(serial, length);
/* calculate received total length */
length = rt_dma_calc_recved_len(serial);
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(serial->spinlock), level);
/* invoke callback */
if (serial->parent.rx_indicate != RT_NULL)
{
+5 -12
View File
@@ -149,14 +149,7 @@ static rt_err_t iodev_open(struct tty_struct *console)
struct rt_device *console_get_iodev(void)
{
rt_base_t level = 0;
struct rt_device *iodev = RT_NULL;
level = rt_hw_interrupt_disable();
iodev = console_dev.io_dev;
rt_hw_interrupt_enable(level);
return iodev;
return console_dev.io_dev;
}
struct rt_device *console_set_iodev(struct rt_device *iodev)
@@ -169,7 +162,7 @@ struct rt_device *console_set_iodev(struct rt_device *iodev)
console = &console_dev;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&console->spinlock);
RT_ASSERT(console->init_flag >= TTY_INIT_FLAG_REGED);
@@ -195,7 +188,7 @@ struct rt_device *console_set_iodev(struct rt_device *iodev)
}
exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&console->spinlock, level);
return io_before;
}
@@ -213,7 +206,7 @@ static rt_err_t rt_console_init(struct rt_device *dev)
console = (struct tty_struct *)dev;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&console->spinlock);
RT_ASSERT(console->init_flag == TTY_INIT_FLAG_REGED);
@@ -225,7 +218,7 @@ static rt_err_t rt_console_init(struct rt_device *dev)
console->init_flag = TTY_INIT_FLAG_INITED;
exit:
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&console->spinlock, level);
return result;
}
+1
View File
@@ -166,6 +166,7 @@ struct tty_struct
#define RT_TTY_BUF 1024
rt_list_t tty_drivers;
struct rt_spinlock spinlock;
};
enum
+24 -18
View File
@@ -50,6 +50,8 @@
#define ECHO_BLOCK 256
#define ECHO_DISCARD_WATERMARK RT_TTY_BUF - (ECHO_BLOCK + 32)
static struct rt_spinlock _spinlock = RT_SPINLOCK_INIT;
struct n_tty_data
{
/* producer-published */
@@ -87,27 +89,29 @@ struct n_tty_data
rt_inline int set_bit(int nr,int *addr)
{
int mask, retval, level;
int mask, retval;
rt_base_t level;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
retval = (mask & *addr) != 0;
*addr |= mask;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return retval;
}
rt_inline int clear_bit(int nr, int *addr)
{
int mask, retval, level;
int mask, retval;
rt_base_t level;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
retval = (mask & *addr) != 0;
*addr &= ~mask;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return retval;
}
@@ -122,15 +126,16 @@ rt_inline int test_bit(int nr, int *addr)
rt_inline int test_and_clear_bit(int nr, volatile void *addr)
{
int mask, retval, level;
int mask, retval;
rt_base_t level;
volatile unsigned int *a = addr;
a += nr >> 5;
mask = 1 << (nr & 0x1f);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
retval = (mask & *a) != 0;
*a &= ~mask;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return retval;
}
@@ -1358,7 +1363,7 @@ static int copy_from_read_buf(struct tty_struct *tty,char *b,size_t nr)
if (n)
{
const char *from = read_buf_addr(ldata, tail);
rt_memcpy(b, from, n);
memcpy(b, from, n);
is_eof = n == 1 && *from == EOF_CHAR(tty);
ldata->read_tail += n;
/* Turn single EOF into zero-length read */
@@ -1445,12 +1450,12 @@ static int canon_copy_from_read_buf(struct tty_struct *tty, char *b, size_t nr)
size_t temp_n = n;
if (n > buf_size)
{
rt_memcpy(b, from, buf_size);
memcpy(b, from, buf_size);
b += buf_size;
temp_n -= buf_size;
from = ldata->read_buf;
}
rt_memcpy(b, from, temp_n);
memcpy(b, from, temp_n);
if (found)
{
@@ -2021,7 +2026,7 @@ static struct rt_wqueue *_wait_queue_current_get(struct tty_struct *tty)
static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
{
int level = 0;
rt_base_t level = 0;
char *b = (char *)buf;
struct tty_struct *tty = RT_NULL;
struct rt_wqueue *wq = RT_NULL;
@@ -2029,13 +2034,11 @@ static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
int retval = 0;
int c = 0;
level = rt_hw_interrupt_disable();
tty = (struct tty_struct *)fd->vnode->data;
RT_ASSERT(tty != RT_NULL);
c = job_control(tty);
if (c < 0)
{
rt_hw_interrupt_enable(level);
return c;
}
@@ -2054,12 +2057,14 @@ static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
}
wait_ret = rt_wqueue_wait_interruptible(wq, 0, RT_WAITING_FOREVER);
if (wait_ret != 0)
{
break;
}
}
level = rt_spin_lock_irqsave(&tty->spinlock);
if (ldata->icanon && !L_EXTPROC(tty))
{
retval = canon_copy_from_read_buf(tty, b, count);
@@ -2068,13 +2073,14 @@ static int n_tty_read(struct dfs_file *fd, void *buf, size_t count)
{
retval = copy_from_read_buf(tty, b, count);
}
rt_spin_unlock_irqrestore(&tty->spinlock, level);
if (retval >= 1)
{
break;
}
}
rt_hw_interrupt_enable(level);
return retval;
}
@@ -2189,12 +2195,12 @@ static int n_tty_poll(struct dfs_file *fd, struct rt_pollreq *req)
wq = _wait_queue_current_get(tty);
rt_poll_add(wq, req);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&tty->spinlock);
if (input_available_p(tty, 1))
{
mask |= POLLIN;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&tty->spinlock, level);
return mask;
}
+2 -5
View File
@@ -73,17 +73,14 @@ static int pty_get_index(struct tty_struct *tty, int *arg)
*/
static rt_err_t pty_device_init(struct rt_device *dev)
{
rt_ubase_t level = 0;
rt_err_t result = RT_EOK;
struct tty_struct *tty = RT_NULL;
RT_ASSERT(dev != RT_NULL);
tty = (struct tty_struct *)dev;
level = rt_hw_interrupt_disable();
RT_ASSERT(tty->init_flag == TTY_INIT_FLAG_REGED);
tty->init_flag = TTY_INIT_FLAG_INITED;
rt_hw_interrupt_enable(level);
return result;
}
@@ -150,12 +147,12 @@ static rt_ssize_t pty_device_write(struct rt_device *dev,
RT_ASSERT(tty->init_flag == TTY_INIT_FLAG_INITED);
to = tty->other_struct;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&tty->spinlock);
if (to->ldisc->ops->receive_buf)
{
len = to->ldisc->ops->receive_buf(to, (char *)buffer, size);
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&tty->spinlock, level);
return len;
}
+8 -9
View File
@@ -142,29 +142,27 @@ int __tty_check_change(struct tty_struct *tty, int sig)
{
pid_t pgrp = 0, tty_pgrp = 0;
int ret = 0;
int level = 0;
struct rt_lwp *lwp;
level = rt_hw_interrupt_disable();
if (current == RT_NULL)
lwp = lwp_self();
if (lwp == RT_NULL)
{
rt_hw_interrupt_enable(level);
return 0;
}
if (current->tty != tty)
if (lwp->tty != tty)
{
rt_hw_interrupt_enable(level);
return 0;
}
pgrp = current->__pgrp;
pgrp = lwp->__pgrp;
tty_pgrp = tty->pgrp;
if (tty_pgrp && (pgrp != tty->pgrp))
{
lwp_signal_kill(current, sig, SI_USER, 0);
lwp_signal_kill(lwp, sig, SI_USER, 0);
}
rt_hw_interrupt_enable(level);
if (!tty_pgrp)
{
@@ -494,6 +492,7 @@ int tty_init(struct tty_struct *tty, int type, int subtype, struct rt_device *io
rt_mutex_init(&tty->lock, "ttyLock", RT_IPC_FLAG_PRIO);
rt_wqueue_init(&tty->wait_queue);
rt_spin_lock_init(&tty->spinlock);
tty_ldisc_init(tty);
tty->init_termios = tty_std_termios;
+5 -5
View File
@@ -39,7 +39,7 @@ static int set_termios(struct tty_struct *tty, void *arg, int opt)
struct termios old_termios;
struct tty_ldisc *ld = RT_NULL;
struct termios *new_termios = (struct termios *)arg;
int level = 0;
rt_base_t level = 0;
int retval = tty_check_change(tty);
if (retval)
@@ -47,10 +47,10 @@ static int set_termios(struct tty_struct *tty, void *arg, int opt)
return retval;
}
rt_memcpy(&old_termios, &(tty->init_termios), sizeof(struct termios));
level = rt_hw_interrupt_disable();
memcpy(&old_termios, &(tty->init_termios), sizeof(struct termios));
level = rt_spin_lock_irqsave(&tty->spinlock);
tty->init_termios = *new_termios;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&tty->spinlock, level);
ld = tty->ldisc;
if (ld != NULL)
{
@@ -88,7 +88,7 @@ int n_tty_ioctl_extend(struct tty_struct *tty, int cmd, void *args)
return -RT_EINVAL;
}
rt_memcpy(tio, &real_tty->init_termios, sizeof(real_tty->init_termios));
memcpy(tio, &real_tty->init_termios, sizeof(real_tty->init_termios));
return ret;
}
case TCSETSF:
+11 -12
View File
@@ -14,27 +14,29 @@ static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS] = {
&n_tty_ops, /* N_TTY = 0 */
};
static struct rt_spinlock _spinlock = RT_SPINLOCK_INIT;
static struct tty_ldisc_ops *get_ldops(int disc)
{
struct tty_ldisc_ops *ldops = RT_NULL;
int level = 0;
level = rt_hw_interrupt_disable();
rt_base_t level = 0;
level = rt_spin_lock_irqsave(&_spinlock);
ldops = tty_ldiscs[disc];
if (ldops)
{
ldops->refcount++;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return ldops;
}
static void put_ldops(struct tty_ldisc_ops *ldops)
{
int level = 0;
rt_base_t level = 0;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
ldops->refcount--;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
}
static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc)
@@ -120,18 +122,18 @@ void tty_ldisc_kill(struct tty_struct *tty)
int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
{
int ret = 0;
int level = 0;
rt_base_t level = 0;
if (disc < N_TTY || disc >= NR_LDISCS)
{
return -EINVAL;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
tty_ldiscs[disc] = new_ldisc;
new_ldisc->num = disc;
new_ldisc->refcount = 0;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return ret;
}
@@ -146,20 +148,17 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
void tty_ldisc_release(struct tty_struct *tty)
{
int level = 0;
struct tty_struct *o_tty = tty->other_struct;
/*
* Shutdown this line discipline. As this is the final close,
* it does not race with the set_ldisc code path.
*/
level = rt_hw_interrupt_disable();
tty_ldisc_kill(tty);
if (o_tty)
{
tty_ldisc_kill(o_tty);
}
rt_hw_interrupt_enable(level);
}
/**
+56 -33
View File
@@ -30,6 +30,7 @@
* Provide protection for the "first layer of objects" when list_*
* 2020-04-07 chenhui add clear
* 2022-07-02 Stanley Lwin add list command
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
@@ -94,6 +95,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
rt_base_t level;
rt_list_t *node, *list;
rt_list_t **array;
struct rt_object_information *info;
int nr;
arg->nr_out = 0;
@@ -104,6 +106,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
}
list = arg->list;
info = rt_list_entry(list, struct rt_object_information, object_list);
if (!current) /* find first */
{
@@ -115,7 +118,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
node = current;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if (!first_flag)
{
@@ -124,7 +127,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
obj = rt_list_entry(node, struct rt_object, list);
if ((obj->type & ~RT_Object_Class_Static) != arg->type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
return (rt_list_t *)RT_NULL;
}
}
@@ -148,7 +151,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
arg->nr_out = nr;
return node;
}
@@ -157,6 +160,7 @@ long list_thread(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
const char *item_title = "thread";
@@ -164,6 +168,7 @@ long list_thread(void)
int maxlen;
list_find_init(&find_arg, RT_Object_Class_Thread, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -194,16 +199,16 @@ long list_thread(void)
struct rt_thread thread_info, *thread;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
/* copy info */
rt_memcpy(&thread_info, obj, sizeof thread_info);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
thread = (struct rt_thread *)obj;
{
@@ -277,6 +282,7 @@ long list_sem(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -284,6 +290,7 @@ long list_sem(void)
const char *item_title = "semaphore";
list_find_init(&find_arg, RT_Object_Class_Semaphore, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -302,13 +309,13 @@ long list_sem(void)
struct rt_semaphore *sem;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
sem = (struct rt_semaphore *)obj;
if (!rt_list_isempty(&sem->parent.suspend_thread))
@@ -343,6 +350,7 @@ long list_event(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -350,6 +358,7 @@ long list_event(void)
const char *item_title = "event";
list_find_init(&find_arg, RT_Object_Class_Event, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -368,14 +377,14 @@ long list_event(void)
struct rt_event *e;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
e = (struct rt_event *)obj;
if (!rt_list_isempty(&e->parent.suspend_thread))
@@ -407,6 +416,7 @@ long list_mutex(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -414,6 +424,7 @@ long list_mutex(void)
const char *item_title = "mutex";
list_find_init(&find_arg, RT_Object_Class_Mutex, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -432,14 +443,14 @@ long list_mutex(void)
struct rt_mutex *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_mutex *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
@@ -480,6 +491,7 @@ long list_mailbox(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -487,6 +499,7 @@ long list_mailbox(void)
const char *item_title = "mailbox";
list_find_init(&find_arg, RT_Object_Class_MailBox, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -505,14 +518,14 @@ long list_mailbox(void)
struct rt_mailbox *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_mailbox *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
@@ -550,6 +563,7 @@ long list_msgqueue(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -557,6 +571,7 @@ long list_msgqueue(void)
const char *item_title = "msgqueue";
list_find_init(&find_arg, RT_Object_Class_MessageQueue, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -574,14 +589,14 @@ long list_msgqueue(void)
struct rt_messagequeue *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_messagequeue *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
@@ -616,6 +631,7 @@ long list_memheap(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -623,6 +639,7 @@ long list_memheap(void)
const char *item_title = "memheap";
list_find_init(&find_arg, RT_Object_Class_MemHeap, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -640,14 +657,14 @@ long list_memheap(void)
struct rt_memheap *mh;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
mh = (struct rt_memheap *)obj;
@@ -672,6 +689,7 @@ long list_mempool(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -679,6 +697,7 @@ long list_mempool(void)
const char *item_title = "mempool";
list_find_init(&find_arg, RT_Object_Class_MemPool, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -698,14 +717,14 @@ long list_mempool(void)
rt_list_t *node;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
mp = (struct rt_mempool *)obj;
@@ -750,6 +769,7 @@ long list_timer(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
@@ -757,6 +777,7 @@ long list_timer(void)
const char *item_title = "timer";
list_find_init(&find_arg, RT_Object_Class_Timer, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -774,14 +795,14 @@ long list_timer(void)
struct rt_timer *timer;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
timer = (struct rt_timer *)obj;
rt_kprintf("%-*.*s 0x%08x 0x%08x ",
@@ -848,6 +869,7 @@ long list_device(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
const char *device_type;
@@ -856,6 +878,7 @@ long list_device(void)
const char *item_title = "device";
list_find_init(&find_arg, RT_Object_Class_Device, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
@@ -873,14 +896,14 @@ long list_device(void)
struct rt_device *device;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&info->spinlock, level);
device = (struct rt_device *)obj;
device_type = "Unknown";
+20 -14
View File
@@ -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);
}
}
+6 -4
View File
@@ -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;
}
+1 -6
View File
@@ -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;
@@ -96,6 +96,31 @@ int arch_expand_user_stack(void *addr)
}
#endif
int arch_set_thread_context(void (*exit)(void), void *new_thread_stack,
void *user_stack, void **thread_sp)
{
struct rt_hw_exp_stack *syscall_frame;
struct rt_hw_exp_stack *thread_frame;
struct rt_hw_exp_stack *ori_syscall = rt_thread_self()->user_ctx.ctx;
RT_ASSERT(ori_syscall != RT_NULL);
thread_frame = (void *)((long)new_thread_stack - sizeof(struct rt_hw_exp_stack));
syscall_frame = (void *)((long)new_thread_stack - 2 * sizeof(struct rt_hw_exp_stack));
memcpy(syscall_frame, ori_syscall, sizeof(*syscall_frame));
syscall_frame->sp_el0 = (long)user_stack;
syscall_frame->x0 = 0;
thread_frame->cpsr = ((3 << 6) | 0x4 | 0x1);
thread_frame->pc = (long)exit;
thread_frame->x0 = 0;
*thread_sp = syscall_frame;
return 0;
}
#define ALGIN_BYTES (16)
struct signal_ucontext
+13 -20
View File
@@ -94,21 +94,6 @@ arch_crt_start_umode:
msr elr_el1, x1
eret
/*
void arch_set_thread_context(void *exit_addr, void *new_thread_stack, void *user_stack, void **thread_sp);
*/
.global arch_set_thread_context
arch_set_thread_context:
sub x1, x1, #CONTEXT_SIZE
str x2, [x1, #CONTEXT_OFFSET_SP_EL0]
sub x1, x1, #CONTEXT_SIZE
str xzr, [x1, #CONTEXT_OFFSET_X0] /* new thread return 0 */
mov x4, #((3 << 6) | 0x4 | 0x1) /* el1h, disable interrupt */
str x4, [x1, #CONTEXT_OFFSET_SPSR_EL1]
str x0, [x1, #CONTEXT_OFFSET_ELR_EL1]
str x1, [x3]
ret
.global arch_get_user_sp
arch_get_user_sp:
mrs x0, sp_el0
@@ -197,6 +182,7 @@ arch_syscall_exit:
/* the sp is reset to the outer most level, irq and fiq are disabled */
START_POINT(arch_ret_to_user)
msr daifset, #3
/* save exception frame */
SAVE_FPU sp
stp x0, x1, [sp, #-0x10]!
@@ -226,6 +212,7 @@ START_POINT(arch_ret_to_user)
bl lwp_check_exit_request
cbz w0, 1f
/* exit on event */
msr daifclr, #3
mov x0, xzr
b sys_exit
1:
@@ -247,7 +234,7 @@ START_POINT(arch_ret_to_user)
/**
* push 2 dummy words to simulate a exception frame of interrupt
* @note in kernel state, the context switch dont saved the context
* Note: in kernel state, the context switch dont saved the context
*/
mrs x0, spsr_el1
mrs x1, elr_el1
@@ -397,7 +384,6 @@ lwp_check_debug_quit:
ret
arch_signal_quit:
msr daifset, #3
/* drop current exception frame */
add sp, sp, #CONTEXT_SIZE
@@ -406,6 +392,12 @@ arch_signal_quit:
add x0, x0, #-CONTEXT_SIZE
msr sp_el0, x0
/**
* Note: Since we will reset spsr, but the reschedule will
* corrupt the spsr, we diable irq for a short period here
*/
msr daifset, #3
/* restore previous exception frame */
msr spsel, #0
@@ -471,14 +463,14 @@ arch_thread_signal_enter:
dsb sy
/**
* @brief Prepare the environment for signal handler
* Brief: Prepare the environment for signal handler
*/
/**
/**
* reset the cpsr
* and drop exp frame on kernel stack, reset kernel sp
*
* @note Since we will reset spsr, but the reschedule will
* Note: Since we will reset spsr, but the reschedule will
* corrupt the spsr, we diable irq for a short period here
*/
msr daifset, #3
@@ -501,6 +493,7 @@ arch_thread_signal_enter:
/**
* handler(signo, psi, ucontext);
*
*/
eret
+82 -35
View File
@@ -15,14 +15,14 @@
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
#define FUTEX_FD 2
#define FUTEX_REQUEUE 3
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_WAIT_BITSET 9
#define FUTEX_FD 2
#define FUTEX_REQUEUE 3
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_WAIT_BITSET 9
#define FUTEX_PRIVATE 128
@@ -35,30 +35,28 @@
#define PMUTEX_DESTROY 3
/* for sys/mman.h */
#define MAP_FAILED ((void *) -1)
#define MAP_FAILED ((void *)-1)
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_SHARED_VALIDATE 0x03
#define MAP_TYPE 0x0f
#define MAP_FIXED 0x10
#define MAP_ANON 0x20
#define MAP_ANONYMOUS MAP_ANON
#define MAP_NORESERVE 0x4000
#define MAP_GROWSDOWN 0x0100
#define MAP_DENYWRITE 0x0800
#define MAP_EXECUTABLE 0x1000
#define MAP_LOCKED 0x2000
#define MAP_POPULATE 0x8000
#define MAP_NONBLOCK 0x10000
#define MAP_STACK 0x20000
#define MAP_HUGETLB 0x40000
#define MAP_SYNC 0x80000
#define MAP_TYPE 0x0f
#define MAP_FIXED 0x10
#define MAP_ANON 0x20
#define MAP_ANONYMOUS MAP_ANON
#define MAP_NORESERVE 0x4000
#define MAP_GROWSDOWN 0x0100
#define MAP_DENYWRITE 0x0800
#define MAP_EXECUTABLE 0x1000
#define MAP_LOCKED 0x2000
#define MAP_POPULATE 0x8000
#define MAP_NONBLOCK 0x10000
#define MAP_STACK 0x20000
#define MAP_HUGETLB 0x40000
#define MAP_SYNC 0x80000
#define MAP_FIXED_NOREPLACE 0x100000
#define MAP_FILE 0
#define MAP_UNINITIALIZED 0x4000000 /** For anonymous mmap, memory could be
* uninitialized */
#define MAP_FILE 0
#define MAP_UNINITIALIZED 0x4000000
#define MAP_HUGE_SHIFT 26
#define MAP_HUGE_MASK 0x3f
@@ -83,13 +81,13 @@
#define PROT_GROWSDOWN 0x01000000
#define PROT_GROWSUP 0x02000000
#define MS_ASYNC 1
#define MS_INVALIDATE 2
#define MS_SYNC 4
#define MS_ASYNC 1
#define MS_INVALIDATE 2
#define MS_SYNC 4
#define MCL_CURRENT 1
#define MCL_FUTURE 2
#define MCL_ONFAULT 4
#define MCL_CURRENT 1
#define MCL_FUTURE 2
#define MCL_ONFAULT 4
#define POSIX_MADV_NORMAL 0
#define POSIX_MADV_RANDOM 1
@@ -97,4 +95,53 @@
#define POSIX_MADV_WILLNEED 3
#define POSIX_MADV_DONTNEED 4
#define CLONE_VM 0x00000100
#define CLONE_FS 0x00000200
#define CLONE_FILES 0x00000400
#define CLONE_SIGHAND 0x00000800
#define CLONE_PTRACE 0x00002000
#define CLONE_VFORK 0x00004000
#define CLONE_PARENT 0x00008000
#define CLONE_THREAD 0x00010000
#define CLONE_NEWNS 0x00020000
#define CLONE_SYSVSEM 0x00040000
#define CLONE_SETTLS 0x00080000
#define CLONE_PARENT_SETTID 0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED 0x00400000
#define CLONE_UNTRACED 0x00800000
#define CLONE_CHILD_SETTID 0x01000000
#define CLONE_NEWCGROUP 0x02000000
#define CLONE_NEWUTS 0x04000000
#define CLONE_NEWIPC 0x08000000
#define CLONE_NEWUSER 0x10000000
#define CLONE_NEWPID 0x20000000
#define CLONE_NEWNET 0x40000000
#define CLONE_IO 0x80000000
/* arg[] -> flags
* stack
* new_tid
* tls
* set_clear_tid_address
* quit_func
* start_args
* */
#define SYS_CLONE_ARGS_NR 7
/* wait.h */
/* options */
#define WNOHANG 1
#define WUNTRACED 2
#define WSTOPPED 2
#define WEXITED 4
#define WCONTINUED 8
#define WNOWAIT 0x1000000
#define __WNOTHREAD 0x20000000
#define __WALL 0x40000000
#define __WCLONE 0x80000000
#endif /* __LIBC_MUSL_H__ */
+61 -17
View File
@@ -14,7 +14,7 @@
* 2023-10-16 Shell Support a new backtrace framework
*/
#define DBG_TAG "LWP"
#define DBG_TAG "lwp"
#define DBG_LVL DBG_WARNING
#include <rtdbg.h>
@@ -34,7 +34,7 @@
#error "lwp need file system(RT_USING_DFS)"
#endif
#include "lwp.h"
#include "lwp_internal.h"
#include "lwp_arch.h"
#include "lwp_arch_comm.h"
#include "lwp_signal.h"
@@ -68,6 +68,21 @@ struct termios *get_old_termios(void)
return &old_stdin_termios;
}
int lwp_component_init(void)
{
int rc;
if ((rc = lwp_tid_init()) != RT_EOK)
{
LOG_E("%s: lwp_component_init() failed", __func__);
}
else if ((rc = lwp_pid_init()) != RT_EOK)
{
LOG_E("%s: lwp_pid_init() failed", __func__);
}
return rc;
}
INIT_COMPONENT_EXPORT(lwp_component_init);
void lwp_setcwd(char *buf)
{
struct rt_lwp *lwp = RT_NULL;
@@ -1030,10 +1045,9 @@ out:
return ret;
}
/* lwp thread clean up */
/* lwp-thread clean up routine */
void lwp_cleanup(struct rt_thread *tid)
{
rt_base_t level;
struct rt_lwp *lwp;
if (tid == NULL)
@@ -1044,16 +1058,16 @@ void lwp_cleanup(struct rt_thread *tid)
else
LOG_D("cleanup thread: %s, stack_addr: 0x%x", tid->parent.name, tid->stack_addr);
level = rt_hw_interrupt_disable();
/**
* Brief: lwp thread cleanup
*
* Note: Critical Section
* - thread control block (RW. It's ensured that no one else can access tcb
* other than itself)
*/
lwp = (struct rt_lwp *)tid->lwp;
/* lwp thread cleanup */
lwp_tid_put(tid->tid);
rt_list_remove(&tid->sibling);
lwp_thread_signal_detach(&tid->signal);
rt_hw_interrupt_enable(level);
/* tty will be release in lwp_ref_dec() if ref is cleared */
lwp_ref_dec(lwp);
return;
@@ -1133,10 +1147,44 @@ struct rt_lwp *lwp_self(void)
return RT_NULL;
}
rt_err_t lwp_children_register(struct rt_lwp *parent, struct rt_lwp *child)
{
/* lwp add to children link */
LWP_LOCK(parent);
child->sibling = parent->first_child;
parent->first_child = child;
child->parent = parent;
LWP_UNLOCK(parent);
LOG_D("%s(parent=%p, child=%p)", __func__, parent, child);
return 0;
}
rt_err_t lwp_children_unregister(struct rt_lwp *parent, struct rt_lwp *child)
{
struct rt_lwp **lwp_node;
LWP_LOCK(parent);
/* detach from children link */
lwp_node = &parent->first_child;
while (*lwp_node != child)
{
RT_ASSERT(*lwp_node != RT_NULL);
lwp_node = &(*lwp_node)->sibling;
}
(*lwp_node) = child->sibling;
child->parent = RT_NULL;
LWP_UNLOCK(parent);
LOG_D("%s(parent=%p, child=%p)", __func__, parent, child);
return 0;
}
pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
{
int result;
rt_base_t level;
struct rt_lwp *lwp;
char *thread_name;
char *argv_last = argv[argc - 1];
@@ -1231,7 +1279,6 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
lwp_tid_set_thread(tid, thread);
LOG_D("lwp kernel => (0x%08x, 0x%08x)\n", (rt_size_t)thread->stack_addr,
(rt_size_t)thread->stack_addr + thread->stack_size);
level = rt_hw_interrupt_disable();
self_lwp = lwp_self();
if (self_lwp)
{
@@ -1239,9 +1286,7 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
lwp->__pgrp = tid;
lwp->session = self_lwp->session;
/* lwp add to children link */
lwp->sibling = self_lwp->first_child;
self_lwp->first_child = lwp;
lwp->parent = self_lwp;
lwp_children_register(self_lwp, lwp);
}
else
{
@@ -1331,7 +1376,6 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
lwp->debug = debug;
rt_thread_control(thread, RT_THREAD_CTRL_BIND_CPU, (void*)0);
}
rt_hw_interrupt_enable(level);
rt_thread_startup(thread);
return lwp_to_pid(lwp);
+26 -2
View File
@@ -37,6 +37,7 @@
#ifdef ARCH_MM_MMU
#include "lwp_shm.h"
#include <locale.h>
#include "mmu.h"
#include "page.h"
#else
@@ -75,6 +76,12 @@ struct rt_lwp_notify
rt_slist_t list_node;
};
#ifdef RT_USING_MUSLLIBC
#define LWP_CREATE_STAT(exit_code) (((exit_code) & 0xff) << 8)
#else
#error "No compatible lwp set status provided for this libc"
#endif
struct rt_lwp
{
#ifdef ARCH_MM_MMU
@@ -98,7 +105,6 @@ struct rt_lwp
struct rt_lwp *sibling;
rt_list_t wait_list;
rt_bool_t finish;
rt_bool_t terminated;
rt_bool_t background;
int lwp_ret;
@@ -150,6 +156,8 @@ struct rt_lwp
typedef struct rt_lwp *rt_lwp_t;
struct rt_lwp *lwp_self(void);
rt_err_t lwp_children_register(struct rt_lwp *parent, struct rt_lwp *child);
rt_err_t lwp_children_unregister(struct rt_lwp *parent, struct rt_lwp *child);
enum lwp_exit_request_type
{
@@ -165,9 +173,25 @@ int lwp_check_exit_request(void);
void lwp_terminate(struct rt_lwp *lwp);
void lwp_wait_subthread_exit(void);
int lwp_tid_init(void);
int lwp_tid_get(void);
void lwp_tid_put(int tid);
rt_thread_t lwp_tid_get_thread(int tid);
/**
* @brief Automatically get a thread and increase a reference count
*
* @param tid queried thread ID
* @return rt_thread_t
*/
rt_thread_t lwp_tid_get_thread_and_inc_ref(int tid);
/**
* @brief Decrease a reference count
*
* @param thread target thread
*/
void lwp_tid_dec_ref(rt_thread_t thread);
void lwp_tid_set_thread(int tid, rt_thread_t thread);
int lwp_execve(char *filename, int debug, int argc, char **argv, char **envp);
-47
View File
@@ -1,47 +0,0 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-07-06 RT-Thread the first version
*/
#ifndef __LWP_CLONE_H__
#define __LWP_CLONE_H__
#define CLONE_VM 0x00000100
#define CLONE_FS 0x00000200
#define CLONE_FILES 0x00000400
#define CLONE_SIGHAND 0x00000800
#define CLONE_PTRACE 0x00002000
#define CLONE_VFORK 0x00004000
#define CLONE_PARENT 0x00008000
#define CLONE_THREAD 0x00010000
#define CLONE_NEWNS 0x00020000
#define CLONE_SYSVSEM 0x00040000
#define CLONE_SETTLS 0x00080000
#define CLONE_PARENT_SETTID 0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED 0x00400000
#define CLONE_UNTRACED 0x00800000
#define CLONE_CHILD_SETTID 0x01000000
#define CLONE_NEWCGROUP 0x02000000
#define CLONE_NEWUTS 0x04000000
#define CLONE_NEWIPC 0x08000000
#define CLONE_NEWUSER 0x10000000
#define CLONE_NEWPID 0x20000000
#define CLONE_NEWNET 0x40000000
#define CLONE_IO 0x80000000
/* arg[] -> flags
* stack
* new_tid
* tls
* set_clear_tid_address
* quit_func
* start_args
* */
#define SYS_CLONE_ARGS_NR 7
#endif /* __LWP_CLONE_H__ */
+4 -4
View File
@@ -82,7 +82,7 @@ rt_err_t lwp_critical_exit(struct rt_lwp *lwp);
#endif /* LWP_OVERRIDE_CPUS_LOCK */
/**
* @brief Return code with safety check
* Brief: Return code with safety check
* There tend to be chances where a return value is returned without correctly init
*/
#ifndef LWP_DEBUG
@@ -90,9 +90,9 @@ rt_err_t lwp_critical_exit(struct rt_lwp *lwp);
#define RETURN(name) return name
#else
#define UNINITIALIZED 0xbeefcafe
#define DEF_RETURN_CODE(name) rt_err_t name = UNINITIALIZED
#define RETURN(name) {RT_ASSERT(name != UNINITIALIZED);return name;}
#define _LWP_UNINITIALIZED_RC 0xbeefcafe
#define DEF_RETURN_CODE(name) rt_err_t name = _LWP_UNINITIALIZED_RC
#define RETURN(name) {RT_ASSERT(name != _LWP_UNINITIALIZED_RC);return name;}
#endif /* LWP_DEBUG */
#endif /* __LWP_INTERNAL_H__ */
+347 -303
View File
File diff suppressed because it is too large Load Diff
+239 -151
View File
File diff suppressed because it is too large Load Diff
+35 -2
View File
@@ -23,8 +23,22 @@ extern "C" {
struct rt_lwp;
struct lwp_avl_struct *lwp_get_pid_ary(void);
int lwp_pid_init(void);
void lwp_pid_put(struct rt_lwp *lwp);
void lwp_pid_lock_take(void);
void lwp_pid_lock_release(void);
/* create a lwp object */
/**
* @brief Create a new lwp object
* This will initialize the member in the object and register to system.
* Besides, a new pid is allocate with lwp
*
* @param flags control the property of the lwp object. Can be ORed with:
* LWP_CREATE_FLAG_NONE: raw lwp object
* LWP_CREATE_FLAG_ALLOC_PID: lwp object with specified pid
*
* @return struct rt_lwp* object
*/
struct rt_lwp* lwp_create(rt_base_t flags);
void lwp_free(struct rt_lwp* lwp);
@@ -32,7 +46,7 @@ void lwp_free(struct rt_lwp* lwp);
int lwp_ref_inc(struct rt_lwp *lwp);
int lwp_ref_dec(struct rt_lwp *lwp);
struct rt_lwp* lwp_from_pid(pid_t pid);
struct rt_lwp* lwp_from_pid_locked(pid_t pid);
pid_t lwp_to_pid(struct rt_lwp* lwp);
pid_t lwp_name2pid(const char* name);
@@ -40,6 +54,7 @@ char* lwp_pid2name(int32_t pid);
int lwp_getpid(void);
pid_t lwp_waitpid(const pid_t pid, int *status, int options);
pid_t waitpid(pid_t pid, int *status, int options);
long list_process(void);
@@ -52,6 +67,24 @@ rt_err_t lwp_user_object_delete(struct rt_lwp *lwp, rt_object_t object);
void lwp_user_object_clear(struct rt_lwp *lwp);
void lwp_user_object_dup(struct rt_lwp *dst_lwp, struct rt_lwp *src_lwp);
rt_inline struct rt_lwp *lwp_from_pid_and_lock(pid_t pid)
{
struct rt_lwp *lwp;
lwp_pid_lock_take();
lwp = lwp_from_pid_locked(pid);
if (lwp)
lwp_ref_inc(lwp);
lwp_pid_lock_release();
return lwp;
}
rt_inline void lwp_from_pid_release_lock(struct rt_lwp *lwp)
{
if (lwp)
lwp_ref_dec(lwp);
}
#ifdef __cplusplus
}
#endif
+11 -11
View File
@@ -65,15 +65,14 @@ INIT_PREV_EXPORT(pmutex_system_init);
static rt_err_t pmutex_destory(void *data)
{
rt_err_t ret = -1;
rt_base_t level = 0;
struct rt_pmutex *pmutex = (struct rt_pmutex *)data;
if (pmutex)
{
level = rt_hw_interrupt_disable();
lwp_mutex_take_safe(&_pmutex_lock, RT_WAITING_FOREVER, 0);
/* remove pmutex from pmutext avl */
lwp_avl_remove(&pmutex->node, (struct lwp_avl_struct **)pmutex->node.data);
rt_hw_interrupt_enable(level);
lwp_mutex_release_safe(&_pmutex_lock);
if (pmutex->type == PMUTEX_NORMAL)
{
@@ -214,8 +213,7 @@ static int _pthread_mutex_init(void *umutex)
}
else
{
rt_base_t level = rt_hw_interrupt_disable();
lwp_mutex_take_safe(&_pmutex_lock, RT_WAITING_FOREVER, 1);
if (pmutex->type == PMUTEX_NORMAL)
{
pmutex->lock.ksem->value = 1;
@@ -227,7 +225,7 @@ static int _pthread_mutex_init(void *umutex)
pmutex->lock.kmutex->hold = 0;
pmutex->lock.kmutex->ceiling_priority = 0xFF;
}
rt_hw_interrupt_enable(level);
lwp_mutex_release_safe(&_pmutex_lock);
}
rt_mutex_release(&_pmutex_lock);
@@ -242,7 +240,6 @@ static int _pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
struct rt_umutex *umutex_p = (struct rt_umutex*)umutex;
rt_err_t lock_ret = 0;
rt_int32_t time = RT_WAITING_FOREVER;
register rt_base_t temp;
if (!lwp_user_accessable((void *)umutex, sizeof(struct rt_umutex)))
{
@@ -291,11 +288,14 @@ static int _pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
}
break;
case PMUTEX_ERRORCHECK:
temp = rt_hw_interrupt_disable();
lock_ret = lwp_mutex_take_safe(&_pmutex_lock, RT_WAITING_FOREVER, 1);
if (lock_ret != RT_EOK)
{
return -EINTR;
}
if (pmutex->lock.kmutex->owner == rt_thread_self())
{
/* enable interrupt */
rt_hw_interrupt_enable(temp);
lwp_mutex_release_safe(&_pmutex_lock);
return -EDEADLK;
}
lock_ret = rt_mutex_take_interruptible(pmutex->lock.kmutex, time);
@@ -303,7 +303,7 @@ static int _pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
{
umutex_p->_m_lock = rt_thread_self()->tid;
}
rt_hw_interrupt_enable(temp);
lwp_mutex_release_safe(&_pmutex_lock);
break;
default: /* unknown type */
return -EINVAL;
+47 -60
View File
@@ -12,17 +12,15 @@
* update the generation, pending and delivery routines
*/
#define DBG_TAG "LWP_SIGNAL"
#define DBG_LVL DBG_INFO
#define DBG_TAG "lwp.signal"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#include <rthw.h>
#include <rtthread.h>
#include <string.h>
#include "lwp.h"
#include "lwp_arch.h"
#include "lwp_signal.h"
#include "lwp_internal.h"
#include "sys/signal.h"
#include "syscall_generic.h"
@@ -362,7 +360,7 @@ static void _thread_signal_mask(rt_thread_t thread, lwp_sig_mask_cmd_t how,
lwp_sigset_t new_set;
/**
* @note POSIX wants this API to be capable to query the current mask
* Note: POSIX wants this API to be capable to query the current mask
* by passing NULL in `sigset`
*/
if (oset)
@@ -408,28 +406,24 @@ static void lwp_signal_notify(rt_slist_t *list_head, lwp_siginfo_t siginfo)
rt_err_t lwp_signal_init(struct lwp_signal *sig)
{
rt_err_t rc;
rc = rt_mutex_init(&sig->sig_lock, "lwpsig", RT_IPC_FLAG_FIFO);
if (rc == RT_EOK)
{
memset(&sig->sig_dispatch_thr, 0, sizeof(sig->sig_dispatch_thr));
rt_err_t rc = RT_EOK;
memset(&sig->sig_action, 0, sizeof(sig->sig_action));
memset(&sig->sig_action_nodefer, 0, sizeof(sig->sig_action_nodefer));
memset(&sig->sig_action_onstack, 0, sizeof(sig->sig_action_onstack));
memset(&sig->sig_action_restart, 0, sizeof(sig->sig_action_restart));
memset(&sig->sig_action_siginfo, 0, sizeof(sig->sig_action_siginfo));
lwp_sigqueue_init(&sig->sig_queue);
}
memset(&sig->sig_dispatch_thr, 0, sizeof(sig->sig_dispatch_thr));
memset(&sig->sig_action, 0, sizeof(sig->sig_action));
memset(&sig->sig_action_nodefer, 0, sizeof(sig->sig_action_nodefer));
memset(&sig->sig_action_onstack, 0, sizeof(sig->sig_action_onstack));
memset(&sig->sig_action_restart, 0, sizeof(sig->sig_action_restart));
memset(&sig->sig_action_siginfo, 0, sizeof(sig->sig_action_siginfo));
lwp_sigqueue_init(&sig->sig_queue);
return rc;
}
rt_err_t lwp_signal_detach(struct lwp_signal *signal)
{
rt_err_t ret;
rt_err_t ret = RT_EOK;
lwp_sigqueue_clear(&signal->sig_queue);
ret = rt_mutex_detach(&signal->sig_lock);
return ret;
}
@@ -475,7 +469,6 @@ int lwp_thread_signal_suspend_check(rt_thread_t thread, int suspend_flag)
void lwp_thread_signal_catch(void *exp_frame)
{
rt_base_t level;
int signo = 0;
struct rt_thread *thread;
struct rt_lwp *lwp;
@@ -492,7 +485,7 @@ void lwp_thread_signal_catch(void *exp_frame)
lwp = (struct rt_lwp*)thread->lwp;
RT_ASSERT(!!lwp);
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
/* check if signal exist */
if (!sigqueue_isempty(_SIGQ(thread)))
@@ -541,7 +534,7 @@ void lwp_thread_signal_catch(void *exp_frame)
p_usi = RT_NULL;
}
}
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
if (pending && signo)
{
@@ -556,7 +549,7 @@ void lwp_thread_signal_catch(void *exp_frame)
/**
* enter signal action of user
* @note that the p_usi is release before entering signal action by
* Note: that the p_usi is release before entering signal action by
* reseting the kernel sp.
*/
LOG_D("%s: enter signal handler(signo=%d) at %p", __func__, signo, handler);
@@ -611,7 +604,7 @@ static rt_thread_t _signal_find_catcher(struct rt_lwp *lwp, int signo)
{
candidate = rt_thread_self();
/** @note: lwp of current is a const value that can be safely read */
/** Note: lwp of current is a const value that can be safely read */
if (candidate->lwp == lwp &&
!_sigismember(&candidate->signal.sigset_mask, signo))
{
@@ -682,7 +675,7 @@ rt_inline rt_bool_t _sighandler_cannot_caught(struct rt_lwp *lwp, int signo)
rt_err_t lwp_signal_kill(struct rt_lwp *lwp, long signo, long code, long value)
{
rt_err_t ret = -1;
rt_base_t level;
lwp_siginfo_t siginfo;
rt_bool_t terminated;
rt_bool_t need_schedule;
@@ -701,8 +694,7 @@ rt_err_t lwp_signal_kill(struct rt_lwp *lwp, long signo, long code, long value)
need_schedule = RT_FALSE;
/* FIXME: acquire READ lock to lwp */
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
terminated = lwp->terminated;
/* short-circuit code for inactive task, ignored signals */
@@ -727,7 +719,7 @@ rt_err_t lwp_signal_kill(struct rt_lwp *lwp, long signo, long code, long value)
}
}
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
if (need_schedule)
rt_schedule();
@@ -771,12 +763,12 @@ rt_err_t lwp_signal_action(struct rt_lwp *lwp, int signo,
lwp_sigqueue_t thread_sigq;
rt_list_t *thread_list;
rt_err_t ret = RT_EOK;
rt_base_t level;
if (lwp)
{
/** acquire READ access to lwp */
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
if (oact)
{
@@ -788,7 +780,7 @@ rt_err_t lwp_signal_action(struct rt_lwp *lwp, int signo,
if (act)
{
/**
* @note POSIX.1-2017 requires calls to sigaction() that supply a NULL act
* Note: POSIX.1-2017 requires calls to sigaction() that supply a NULL act
* argument succeed, even in the case of signals that cannot be caught or ignored
*/
if (_sighandler_cannot_caught(lwp, signo))
@@ -805,9 +797,9 @@ rt_err_t lwp_signal_action(struct rt_lwp *lwp, int signo,
_signal_action_flag_u2k(signo, &lwp->signal, act);
/**
* @brief Discard the pending signal if signal action is set to SIG_IGN
* Brief: Discard the pending signal if signal action is set to SIG_IGN
*
* @note POSIX.1-2017: Setting a signal action to SIG_IGN for a signal
* Note: POSIX.1-2017: Setting a signal action to SIG_IGN for a signal
* that is pending shall cause the pending signal to be discarded,
* whether or not it is blocked.
*/
@@ -826,7 +818,7 @@ rt_err_t lwp_signal_action(struct rt_lwp *lwp, int signo,
}
}
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
}
else
ret = -RT_EINVAL;
@@ -837,7 +829,7 @@ rt_err_t lwp_signal_action(struct rt_lwp *lwp, int signo,
rt_err_t lwp_thread_signal_kill(rt_thread_t thread, long signo, long code, long value)
{
rt_err_t ret = -1;
rt_base_t level;
struct rt_lwp *lwp;
lwp_siginfo_t siginfo;
rt_bool_t need_schedule;
@@ -845,6 +837,8 @@ rt_err_t lwp_thread_signal_kill(rt_thread_t thread, long signo, long code, long
/** must be able to be suspended */
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
LOG_D("%s(signo=%d)", __func__, signo);
if (!thread || signo < 0 || signo >= _LWP_NSIG)
{
ret = -RT_EINVAL;
@@ -856,8 +850,7 @@ rt_err_t lwp_thread_signal_kill(rt_thread_t thread, long signo, long code, long
RT_ASSERT(lwp);
/* FIXME: acquire READ lock to lwp */
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
if (!lwp)
ret = -RT_EPERM;
@@ -870,8 +863,8 @@ rt_err_t lwp_thread_signal_kill(rt_thread_t thread, long signo, long code, long
if (siginfo)
{
need_schedule = _siginfo_deliver_to_thread(thread, siginfo);
ret = 0;
lwp_signal_notify(&lwp->signalfd_notify_head, siginfo);
ret = 0;
}
else
{
@@ -880,7 +873,7 @@ rt_err_t lwp_thread_signal_kill(rt_thread_t thread, long signo, long code, long
}
}
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
if (need_schedule)
rt_schedule();
@@ -906,15 +899,13 @@ rt_err_t lwp_thread_signal_mask(rt_thread_t thread, lwp_sig_mask_cmd_t how,
const lwp_sigset_t *sigset, lwp_sigset_t *oset)
{
rt_err_t ret = -1;
rt_base_t level;
struct rt_lwp *lwp;
if (thread)
{
/** FIXME: acquire READ access to rt_thread */
level = rt_hw_interrupt_disable();
lwp = (struct rt_lwp*)thread->lwp;
LWP_LOCK(lwp);
if (!lwp)
{
ret = -RT_EPERM;
@@ -925,7 +916,7 @@ rt_err_t lwp_thread_signal_mask(rt_thread_t thread, lwp_sig_mask_cmd_t how,
_thread_signal_mask(thread, how, sigset, oset);
}
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
}
else
ret = -RT_EINVAL;
@@ -968,14 +959,14 @@ static int _dequeue_signal(rt_thread_t thread, lwp_sigset_t *mask, siginfo_t *us
rt_err_t lwp_thread_signal_timedwait(rt_thread_t thread, lwp_sigset_t *sigset,
siginfo_t *usi, struct timespec *timeout)
{
rt_base_t level;
rt_err_t ret;
lwp_sigset_t saved_sigset;
lwp_sigset_t blocked_sigset;
int sig;
struct rt_lwp *lwp = thread->lwp;
/**
* @brief POSIX
* Brief: POSIX
* If one of the signals in set is already pending for the calling thread,
* sigwaitinfo() will return immediately
*/
@@ -985,21 +976,19 @@ rt_err_t lwp_thread_signal_timedwait(rt_thread_t thread, lwp_sigset_t *sigset,
_sigdelset(sigset, SIGSTOP);
_signotsets(sigset, sigset);
/* FIXME: acquire READ lock to lwp */
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
sig = _dequeue_signal(thread, sigset, usi);
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
if (sig)
return sig;
/**
* @brief POSIX
* Brief: POSIX
* if none of the signals specified by set are pending, sigtimedwait() shall
* wait for the time interval specified in the timespec structure referenced
* by timeout.
*
* @note If the pending signal arrives before thread suspend, the suspend
* Note: If the pending signal arrives before thread suspend, the suspend
* operation will return a failure
*/
_sigandsets(&blocked_sigset, &thread->signal.sigset_mask, sigset);
@@ -1010,7 +999,7 @@ rt_err_t lwp_thread_signal_timedwait(rt_thread_t thread, lwp_sigset_t *sigset,
time = rt_timespec_to_tick(timeout);
/**
* @brief POSIX
* Brief: POSIX
* If the timespec structure pointed to by timeout is zero-valued and
* if none of the signals specified by set are pending, then
* sigtimedwait() shall return immediately with an error
@@ -1043,17 +1032,15 @@ rt_err_t lwp_thread_signal_timedwait(rt_thread_t thread, lwp_sigset_t *sigset,
/* else ret == -EINTR */
_thread_signal_mask(thread, LWP_SIG_MASK_CMD_SET_MASK, &saved_sigset, RT_NULL);
/* FIXME: acquire READ lock to lwp */
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
sig = _dequeue_signal(thread, sigset, usi);
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
return sig ? sig : ret;
}
void lwp_thread_signal_pending(rt_thread_t thread, lwp_sigset_t *pending)
{
rt_base_t level;
struct rt_lwp *lwp;
lwp = thread->lwp;
@@ -1061,10 +1048,10 @@ void lwp_thread_signal_pending(rt_thread_t thread, lwp_sigset_t *pending)
{
memset(pending, 0, sizeof(*pending));
level = rt_hw_interrupt_disable();
LWP_LOCK(lwp);
sigqueue_examine(_SIGQ(thread), pending);
sigqueue_examine(_SIGQ(lwp), pending);
rt_hw_interrupt_enable(level);
LWP_UNLOCK(lwp);
_sigandsets(pending, pending, &thread->signal.sigset_mask);
}
-2
View File
@@ -40,8 +40,6 @@ typedef enum {
* LwP implementation of POSIX signal
*/
struct lwp_signal {
struct rt_mutex sig_lock;
struct lwp_sigqueue sig_queue;
rt_thread_t sig_dispatch_thr[_LWP_NSIG];
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -11,7 +11,11 @@
#ifndef __LWP_SYSCALL_H__
#define __LWP_SYSCALL_H__
#include <syscall_generic.h>
#ifdef RT_USING_MUSLLIBC
#include "libc_musl.h"
#endif
#include "syscall_generic.h"
#include <stdint.h>
#include <rtthread.h>
+65 -18
View File
@@ -8,19 +8,19 @@
* 2021-01-15 shaojinchun first version
*/
#define DBG_TAG "lwp.tid"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#include <rthw.h>
#include <rtthread.h>
#include "lwp.h"
#include "lwp_internal.h"
#ifdef ARCH_MM_MMU
#include "lwp_user_mm.h"
#endif
#define DBG_TAG "LWP_TID"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define TID_MAX 10000
#define TID_CT_ASSERT(name, x) \
@@ -35,13 +35,19 @@ static int lwp_tid_ary_alloced = 0;
static struct lwp_avl_struct *lwp_tid_root = RT_NULL;
static int current_tid = 0;
static struct rt_mutex tid_lock;
int lwp_tid_init(void)
{
return rt_mutex_init(&tid_lock, "tidmtx", RT_IPC_FLAG_PRIO);
}
int lwp_tid_get(void)
{
rt_base_t level;
struct lwp_avl_struct *p;
int tid = 0;
level = rt_hw_interrupt_disable();
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
p = lwp_tid_free_head;
if (p)
{
@@ -80,53 +86,94 @@ int lwp_tid_get(void)
lwp_avl_insert(p, &lwp_tid_root);
current_tid = tid;
}
rt_hw_interrupt_enable(level);
lwp_mutex_release_safe(&tid_lock);
return tid;
}
void lwp_tid_put(int tid)
{
rt_base_t level;
struct lwp_avl_struct *p;
rt_thread_t thread;
rt_thread_t current;
level = rt_hw_interrupt_disable();
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
p = lwp_avl_find(tid, lwp_tid_root);
if (p)
{
thread = p->data;
p->data = RT_NULL;
lwp_avl_remove(p, &lwp_tid_root);
p->avl_right = lwp_tid_free_head;
lwp_tid_free_head = p;
}
rt_hw_interrupt_enable(level);
else
thread = RT_NULL;
if (thread && thread->tid_ref_count)
{
current = rt_thread_self();
RT_ASSERT(thread->susp_recycler == RT_NULL);
thread->susp_recycler = current;
rt_enter_critical();
rt_thread_suspend_with_flag(current, RT_UNINTERRUPTIBLE);
lwp_mutex_release_safe(&tid_lock);
rt_exit_critical();
rt_schedule();
}
else
lwp_mutex_release_safe(&tid_lock);
}
rt_thread_t lwp_tid_get_thread(int tid)
rt_thread_t lwp_tid_get_thread_and_inc_ref(int tid)
{
rt_base_t level;
struct lwp_avl_struct *p;
rt_thread_t thread = RT_NULL;
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
level = rt_hw_interrupt_disable();
p = lwp_avl_find(tid, lwp_tid_root);
if (p)
{
thread = (rt_thread_t)p->data;
if (thread != RT_NULL)
{
thread->tid_ref_count += 1;
}
}
rt_hw_interrupt_enable(level);
lwp_mutex_release_safe(&tid_lock);
return thread;
}
void lwp_tid_dec_ref(rt_thread_t thread)
{
rt_thread_t susp_putter;
if (thread)
{
RT_ASSERT(rt_object_get_type(&thread->parent) == RT_Object_Class_Thread);
susp_putter = thread->susp_recycler;
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
RT_ASSERT(thread->tid_ref_count > 0);
thread->tid_ref_count -= 1;
if (!thread->tid_ref_count && susp_putter)
{
rt_thread_resume(susp_putter);
}
lwp_mutex_release_safe(&tid_lock);
}
}
void lwp_tid_set_thread(int tid, rt_thread_t thread)
{
rt_base_t level;
struct lwp_avl_struct *p;
level = rt_hw_interrupt_disable();
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
p = lwp_avl_find(tid, lwp_tid_root);
if (p)
{
RT_ASSERT(p->data == RT_NULL);
p->data = thread;
}
rt_hw_interrupt_enable(level);
lwp_mutex_release_safe(&tid_lock);
}
+19 -18
View File
@@ -42,6 +42,7 @@ static struct rt_varea mpr_varea;
static struct rt_page *page_list_low[RT_PAGE_MAX_ORDER];
static struct rt_page *page_list_high[RT_PAGE_MAX_ORDER];
static RT_DEFINE_SPINLOCK(_spinlock);
#define page_start ((rt_page_t)rt_mpr_start)
@@ -502,9 +503,9 @@ int rt_page_ref_get(void *addr, rt_uint32_t size_bits)
int ref;
p = rt_page_addr2page(addr);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
ref = _pages_ref_get(p, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return ref;
}
@@ -514,9 +515,9 @@ void rt_page_ref_inc(void *addr, rt_uint32_t size_bits)
rt_base_t level;
p = rt_page_addr2page(addr);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
_pages_ref_inc(p, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
}
static rt_page_t (*pages_alloc_handler)(rt_page_t page_list[], rt_uint32_t size_bits);
@@ -545,18 +546,18 @@ rt_inline void *_do_pages_alloc(rt_uint32_t size_bits, size_t flags)
rt_base_t level;
rt_page_t *page_list = _flag_to_page_list(flags);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
p = pages_alloc_handler(page_list, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
if (!p && page_list != page_list_low)
{
/* fall back */
page_list = page_list_low;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
p = pages_alloc_handler(page_list, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
}
if (p)
@@ -564,9 +565,9 @@ rt_inline void *_do_pages_alloc(rt_uint32_t size_bits, size_t flags)
alloc_buf = page_to_addr(p);
#ifdef RT_DEBUGING_PAGE_LEAK
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
TRACE_ALLOC(p, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
#endif
}
return alloc_buf;
@@ -592,11 +593,11 @@ int rt_pages_free(void *addr, rt_uint32_t size_bits)
if (p)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
real_free = _pages_free(page_list, p, size_bits);
if (real_free)
TRACE_FREE(p, size_bits);
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
}
return real_free;
@@ -613,7 +614,7 @@ void list_page(void)
rt_size_t installed = page_nr;
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (i = 0; i < RT_PAGE_MAX_ORDER; i++)
{
@@ -637,7 +638,7 @@ void list_page(void)
LOG_RAW("\n");
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
LOG_RAW("-------------------------------\n");
LOG_RAW("Page Summary:\n => free/installed: 0x%lx/0x%lx (%ld/%ld KB)\n", free, installed, PGNR2SIZE(free), PGNR2SIZE(installed));
LOG_RAW("-------------------------------\n");
@@ -650,7 +651,7 @@ void rt_page_get_info(rt_size_t *total_nr, rt_size_t *free_nr)
rt_size_t total_free = 0;
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (i = 0; i < RT_PAGE_MAX_ORDER; i++)
{
struct rt_page *p = page_list_low[i];
@@ -671,7 +672,7 @@ void rt_page_get_info(rt_size_t *total_nr, rt_size_t *free_nr)
p = p->next;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
*total_nr = page_nr;
*free_nr = total_free;
}
@@ -682,7 +683,7 @@ void rt_page_high_get_info(rt_size_t *total_nr, rt_size_t *free_nr)
rt_size_t total_free = 0;
rt_base_t level;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (i = 0; i < RT_PAGE_MAX_ORDER; i++)
{
struct rt_page *p = page_list_high[i];
@@ -693,7 +694,7 @@ void rt_page_high_get_info(rt_size_t *total_nr, rt_size_t *free_nr)
p = p->next;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
*total_nr = _high_pages_nr;
*free_nr = total_free;
}
+7 -6
View File
@@ -564,6 +564,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
return -RT_ERROR;
}
rt_spin_lock_init(&(dev->spinlock));
/* set netif */
dev->netif = netif;
dev->flags = flags;
@@ -838,13 +839,13 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
RT_ASSERT(dev != RT_NULL);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(dev->spinlock));
dev->link_changed = 0x01;
if (up == RT_TRUE)
dev->link_status = 0x01;
else
dev->link_status = 0x00;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(dev->spinlock), level);
/* post message to ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_ubase_t)dev);
@@ -912,10 +913,10 @@ static void eth_rx_thread_entry(void* parameter)
{
int status;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(device->spinlock));
status = device->link_status;
device->link_changed = 0x00;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(device->spinlock), level);
if (status)
netifapi_netif_set_link_up(device->netif);
@@ -923,10 +924,10 @@ static void eth_rx_thread_entry(void* parameter)
netifapi_netif_set_link_down(device->netif);
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(device->spinlock));
/* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(device->spinlock), level);
/* receive all of buffer */
while (1)
@@ -42,6 +42,8 @@ struct eth_device
rt_uint8_t link_status;
rt_uint8_t rx_notice;
struct rt_spinlock spinlock;
/* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev);
rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p);
+4 -2
View File
@@ -511,16 +511,18 @@ sys_thread_t sys_thread_new(const char *name,
return t;
}
static RT_DEFINE_SPINLOCK(_spinlock);
sys_prot_t sys_arch_protect(void)
{
rt_base_t level;
level = rt_hw_interrupt_disable(); /* disable interrupt */
level = rt_spin_lock_irqsave(&_spinlock); /* disable interrupt */
return level;
}
void sys_arch_unprotect(sys_prot_t pval)
{
rt_hw_interrupt_enable(pval); /* enable interrupt */
rt_spin_unlock_irqrestore(&_spinlock, pval); /* enable interrupt */
}
void sys_arch_assert(const char *file, int line)
+18 -17
View File
@@ -34,6 +34,7 @@ struct netdev *netdev_default = RT_NULL;
/* The global network register callback */
static netdev_callback_fn g_netdev_register_callback = RT_NULL;
static netdev_callback_fn g_netdev_default_change_callback = RT_NULL;
static RT_DEFINE_SPINLOCK(_spinlock);
/**
* This function will register network interface device and
@@ -96,7 +97,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
/* initialize current network interface device single list */
rt_slist_init(&(netdev->list));
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
if (netdev_list == RT_NULL)
{
@@ -108,7 +109,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_slist_append(&(netdev_list->list), &(netdev->list));
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
if (netdev_default == RT_NULL)
{
@@ -146,7 +147,7 @@ int netdev_unregister(struct netdev *netdev)
return -RT_ERROR;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -169,7 +170,7 @@ int netdev_unregister(struct netdev *netdev)
break;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
if (netdev_default == RT_NULL)
{
@@ -219,19 +220,19 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
return RT_NULL;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (netdev->flags & flags) != 0)
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -256,19 +257,19 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
return RT_NULL;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr))
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -293,19 +294,19 @@ struct netdev *netdev_get_by_name(const char *name)
return RT_NULL;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name) < RT_NAME_MAX ? rt_strlen(netdev->name) : RT_NAME_MAX) == 0))
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -332,7 +333,7 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -340,7 +341,7 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
@@ -351,12 +352,12 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev))
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
+4 -2
View File
@@ -79,6 +79,8 @@ struct lwip_sock {
};
#endif /* LWIP_VERSION >= 0x20100ff */
static RT_DEFINE_SPINLOCK(_spinlock);
extern struct lwip_sock *lwip_tryget_socket(int s);
static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
@@ -262,7 +264,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
rt_poll_add(&sock->wait_head, req);
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&_spinlock);
#if LWIP_VERSION >= 0x20100ff
if ((void*)(sock->lastdata.pbuf) || sock->rcvevent)
@@ -282,7 +284,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
/* clean error event */
sock->errevent = 0;
}
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
}
return mask;
+8 -7
View File
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-08-25 RT-Thread First version
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
#include <rtthread.h>
@@ -19,6 +20,7 @@ void resource_id_init(resource_id_t *mgr, int size, void **res)
mgr->_res = res;
mgr->noused = 0;
mgr->_free = RT_NULL;
rt_spin_lock_init(&(mgr->spinlock));
}
}
@@ -27,21 +29,21 @@ int resource_id_get(resource_id_t *mgr)
rt_base_t level;
void **cur;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(mgr->spinlock));
if (mgr->_free)
{
cur = mgr->_free;
mgr->_free = (void **)*mgr->_free;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
return cur - mgr->_res;
}
else if (mgr->noused < mgr->size)
{
cur = &mgr->_res[mgr->noused++];
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
return cur - mgr->_res;
}
rt_hw_interrupt_enable(level);
return -1;
}
@@ -52,11 +54,10 @@ void resource_id_put(resource_id_t *mgr, int no)
if (no >= 0 && no < mgr->size)
{
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(mgr->spinlock));
cur = &mgr->_res[no];
*cur = (void *)mgr->_free;
mgr->_free = cur;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
}
}

Some files were not shown because too many files have changed in this diff Show More