mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)
Signed-off-by: Shell <smokewood@qq.com> Co-authored-by: Shell <smokewood@qq.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ struct tty_struct
|
||||
|
||||
#define RT_TTY_BUF 1024
|
||||
rt_list_t tty_drivers;
|
||||
struct rt_spinlock spinlock;
|
||||
};
|
||||
|
||||
enum
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@
|
||||
* 2023-07-16 Shell update signal generation routine for lwp
|
||||
* adapt to new api and do the signal handling in thread context
|
||||
* 2023-08-12 Meco Man re-implement RT-Thread lightweight timezone API
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include "sys/time.h"
|
||||
@@ -136,21 +137,12 @@ static volatile int32_t _current_tz_offset_sec = \
|
||||
/* return current timezone offset in seconds */
|
||||
void rt_tz_set(int32_t offset_sec)
|
||||
{
|
||||
rt_base_t level;
|
||||
level = rt_hw_interrupt_disable();
|
||||
_current_tz_offset_sec = offset_sec;
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
int32_t rt_tz_get(void)
|
||||
{
|
||||
int32_t offset_sec;
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
offset_sec = _current_tz_offset_sec;
|
||||
rt_hw_interrupt_enable(level);
|
||||
return offset_sec;
|
||||
return _current_tz_offset_sec;
|
||||
}
|
||||
|
||||
int8_t rt_tz_is_dst(void)
|
||||
@@ -796,11 +788,15 @@ static void _lwp_timer_event_from_tid(struct rt_work *work, void *param)
|
||||
|
||||
RT_ASSERT(data->tid);
|
||||
|
||||
thread = lwp_tid_get_thread(data->tid);
|
||||
/* stop others from delete thread */
|
||||
thread = lwp_tid_get_thread_and_inc_ref(data->tid);
|
||||
/** The tid of thread is a READ ONLY value, but here still facing the risk of thread already been delete error */
|
||||
ret = lwp_thread_signal_kill(thread, data->signo, SI_TIMER, 0);
|
||||
lwp_tid_dec_ref(thread);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
LOG_W("%s: Do kill failed(tid %d) returned %d", __func__, data->tid, ret);
|
||||
LOG_D("%s: Do kill failed(tid %d) returned %d", __func__, data->tid, ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,11 +804,21 @@ static void _lwp_timer_event_from_pid(struct rt_work *work, void *param)
|
||||
{
|
||||
rt_err_t ret;
|
||||
struct lwp_timer_event_param *data = rt_container_of(work, struct lwp_timer_event_param, work);
|
||||
struct rt_lwp *lwp;
|
||||
|
||||
lwp_pid_lock_take();
|
||||
lwp = lwp_from_pid_locked(data->pid);
|
||||
if (lwp)
|
||||
lwp_ref_inc(lwp);
|
||||
lwp_pid_lock_release();
|
||||
|
||||
ret = lwp_signal_kill(lwp, data->signo, SI_TIMER, 0);
|
||||
if (lwp)
|
||||
lwp_ref_dec(lwp);
|
||||
|
||||
ret = lwp_signal_kill(lwp_from_pid(data->pid), data->signo, SI_TIMER, 0);
|
||||
if (ret)
|
||||
{
|
||||
LOG_W("%s: Do kill failed(pid %d) returned %d", __func__, data->pid, ret);
|
||||
LOG_D("%s: Do kill failed(pid %d) returned %d", __func__, data->pid, ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ struct rt_poll_node
|
||||
struct rt_poll_node *next;
|
||||
};
|
||||
|
||||
static RT_DEFINE_SPINLOCK(_spinlock);
|
||||
|
||||
static int __wqueue_pollwake(struct rt_wqueue_node *wait, void *key)
|
||||
{
|
||||
struct rt_poll_node *pn;
|
||||
@@ -85,7 +87,7 @@ static int poll_wait_timeout(struct rt_poll_table *pt, int msec)
|
||||
|
||||
timeout = rt_tick_from_millisecond(msec);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
|
||||
if (timeout != 0 && !pt->triggered)
|
||||
{
|
||||
@@ -99,16 +101,16 @@ static int poll_wait_timeout(struct rt_poll_table *pt, int msec)
|
||||
rt_timer_start(&(thread->thread_timer));
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
|
||||
rt_schedule();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
}
|
||||
}
|
||||
|
||||
ret = !pt->triggered;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
#include <sys/time.h>
|
||||
#include "pthread_internal.h"
|
||||
|
||||
RT_DEFINE_SPINLOCK(pth_lock);
|
||||
RT_DEFINE_HW_SPINLOCK(pth_lock);
|
||||
_pthread_data_t *pth_table[PTHREAD_NUM_MAX] = {NULL};
|
||||
static int concurrency_level;
|
||||
|
||||
_pthread_data_t *_pthread_get_data(pthread_t thread)
|
||||
{
|
||||
RT_DECLARE_SPINLOCK(pth_lock);
|
||||
_pthread_data_t *ptd;
|
||||
|
||||
if (thread >= PTHREAD_NUM_MAX) return NULL;
|
||||
@@ -40,7 +39,6 @@ _pthread_data_t *_pthread_get_data(pthread_t thread)
|
||||
pthread_t _pthread_data_get_pth(_pthread_data_t *ptd)
|
||||
{
|
||||
int index;
|
||||
RT_DECLARE_SPINLOCK(pth_lock);
|
||||
|
||||
rt_hw_spin_lock(&pth_lock);
|
||||
for (index = 0; index < PTHREAD_NUM_MAX; index ++)
|
||||
@@ -56,7 +54,6 @@ pthread_t _pthread_data_create(void)
|
||||
{
|
||||
int index;
|
||||
_pthread_data_t *ptd = NULL;
|
||||
RT_DECLARE_SPINLOCK(pth_lock);
|
||||
|
||||
ptd = (_pthread_data_t*)rt_malloc(sizeof(_pthread_data_t));
|
||||
if (!ptd) return PTHREAD_NUM_MAX;
|
||||
@@ -90,8 +87,6 @@ pthread_t _pthread_data_create(void)
|
||||
|
||||
void _pthread_data_destroy(_pthread_data_t *ptd)
|
||||
{
|
||||
RT_DECLARE_SPINLOCK(pth_lock);
|
||||
|
||||
extern _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];
|
||||
pthread_t pth;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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);
|
||||
|
||||
@@ -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__ */
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
+239
-151
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -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];
|
||||
|
||||
|
||||
+142
-90
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(ð_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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
#ifndef RESOURCE_ID_H__
|
||||
@@ -14,7 +15,7 @@
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#define RESOURCE_ID_INIT(size, pool) {size, pool, 0, RT_NULL}
|
||||
#define RESOURCE_ID_INIT(size, pool) {size, pool, 0, RT_NULL, RT_SPINLOCK_INIT}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -22,6 +23,7 @@ typedef struct
|
||||
void **_res;
|
||||
int noused;
|
||||
void **_free;
|
||||
struct rt_spinlock spinlock;
|
||||
} resource_id_t;
|
||||
|
||||
void resource_id_init(resource_id_t *mgr, int size, void **res);
|
||||
|
||||
@@ -138,6 +138,7 @@ static const char * const color_output_info[] =
|
||||
|
||||
/* ulog local object */
|
||||
static struct rt_ulog ulog = { 0 };
|
||||
static RT_DEFINE_SPINLOCK(_spinlock);
|
||||
|
||||
rt_size_t ulog_strcpy(rt_size_t cur_len, char *dst, const char *src)
|
||||
{
|
||||
@@ -197,7 +198,7 @@ static void output_unlock(void)
|
||||
else
|
||||
{
|
||||
#ifdef ULOG_USING_ISR_LOG
|
||||
rt_hw_interrupt_enable(ulog.output_locker_isr_lvl);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, ulog.output_locker_isr_lvl);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -218,7 +219,7 @@ static void output_lock(void)
|
||||
else
|
||||
{
|
||||
#ifdef ULOG_USING_ISR_LOG
|
||||
ulog.output_locker_isr_lvl = rt_hw_interrupt_disable();
|
||||
ulog.output_locker_isr_lvl = rt_spin_lock_irqsave(&_spinlock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1273,9 +1274,9 @@ rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool
|
||||
backend->out_level = LOG_FILTER_LVL_ALL;
|
||||
rt_strncpy(backend->name, name, RT_NAME_MAX);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
rt_slist_append(&ulog.backend_list, &backend->list);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -1292,9 +1293,9 @@ rt_err_t ulog_backend_unregister(ulog_backend_t backend)
|
||||
backend->deinit(backend);
|
||||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
rt_slist_remove(&ulog.backend_list, &backend->list);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -1304,9 +1305,9 @@ rt_err_t ulog_backend_set_filter(ulog_backend_t backend, ulog_backend_filter_t f
|
||||
rt_base_t level;
|
||||
RT_ASSERT(backend);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
backend->filter = filter;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -1319,18 +1320,18 @@ ulog_backend_t ulog_backend_find(const char *name)
|
||||
|
||||
RT_ASSERT(ulog.init_ok);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
for (node = rt_slist_first(&ulog.backend_list); node; node = rt_slist_next(node))
|
||||
{
|
||||
backend = rt_slist_entry(node, struct ulog_backend, list);
|
||||
if (rt_strncmp(backend->name, name, RT_NAME_MAX) == 0)
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
return backend;
|
||||
}
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&_spinlock, level);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2022-07-27 flybreak the first version
|
||||
* 2023-03-21 WangShun add atomic test
|
||||
* 2023-09-15 xqyjlj change stack size in cpu64
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-08-15 liukang the first version
|
||||
* 2023-09-15 xqyjlj change stack size in cpu64
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "utest.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define THREAD_STACKSIZE UTEST_THR_STACK_SIZE
|
||||
#define EVENT_FLAG3 (1 << 3)
|
||||
#define EVENT_FLAG5 (1 << 5)
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09-08 liukang the first version
|
||||
* 2023-09-15 xqyjlj change stack size in cpu64
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "utest.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define THREAD_STACKSIZE UTEST_THR_STACK_SIZE
|
||||
|
||||
static struct rt_mailbox test_static_mb;
|
||||
static char mb_pool[128];
|
||||
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-08-28 Sherman the first version
|
||||
* 2023-09-15 xqyjlj change stack size in cpu64
|
||||
* fix in smp
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "utest.h"
|
||||
|
||||
#define THREAD_STACKSIZE UTEST_THR_STACK_SIZE
|
||||
|
||||
#define MSG_SIZE 4
|
||||
#define MAX_MSGS 5
|
||||
|
||||
@@ -202,6 +206,11 @@ static rt_err_t utest_tc_init(void)
|
||||
if(ret != RT_EOK)
|
||||
return -RT_ERROR;
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
rt_thread_control(&mq_send_thread, RT_THREAD_CTRL_BIND_CPU, (void *)0);
|
||||
rt_thread_control(&mq_recv_thread, RT_THREAD_CTRL_BIND_CPU, (void *)0);
|
||||
#endif
|
||||
|
||||
ret = rt_event_init(&finish_e, "finish", RT_IPC_FLAG_FIFO);
|
||||
if(ret != RT_EOK)
|
||||
return -RT_ERROR;
|
||||
|
||||
@@ -6,12 +6,19 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-09.01 luckyzjq the first version
|
||||
* 2023-09-15 xqyjlj change stack size in cpu64
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stdlib.h>
|
||||
#include "utest.h"
|
||||
|
||||
#ifdef ARCH_CPU_64BIT
|
||||
#define THREAD_STACKSIZE 4096
|
||||
#else
|
||||
#define THREAD_STACKSIZE 1024
|
||||
#endif
|
||||
|
||||
static struct rt_mutex static_mutex;
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
@@ -84,7 +91,7 @@ static void test_static_mutex_take(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
static_mutex_take_entry,
|
||||
&static_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
@@ -145,7 +152,7 @@ static void test_static_mutex_release(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
static_mutex_release_entry,
|
||||
&static_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
@@ -200,7 +207,7 @@ static void test_static_mutex_trytake(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
static_mutex_trytake_entry,
|
||||
&static_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
@@ -397,7 +404,7 @@ static void test_dynamic_mutex_take(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
dynamic_mutex_take_entry,
|
||||
dynamic_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
@@ -458,7 +465,7 @@ static void test_dynamic_mutex_release(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
dynamic_mutex_release_entry,
|
||||
dynamic_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
@@ -513,7 +520,7 @@ static void test_dynamic_mutex_trytake(void)
|
||||
rt_thread_t tid = rt_thread_create("mutex_th",
|
||||
dynamic_mutex_trytake_entry,
|
||||
dynamic_mutex,
|
||||
2048,
|
||||
THREAD_STACKSIZE,
|
||||
10,
|
||||
10);
|
||||
if (RT_NULL == tid)
|
||||
|
||||
@@ -27,13 +27,6 @@ void rt_hw_atomic_flag_clear(volatile rt_atomic_t *ptr);
|
||||
rt_atomic_t rt_hw_atomic_flag_test_and_set(volatile rt_atomic_t *ptr);
|
||||
rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr, rt_atomic_t *expected, rt_atomic_t desired);
|
||||
|
||||
/* To detect stdatomic */
|
||||
#if !defined(RT_USING_HW_ATOMIC) && !defined(RT_USING_STDC_ATOMIC)
|
||||
#if defined(__GNUC__) && defined(RT_USING_LIBC) && !defined(__STDC_NO_ATOMICS__)
|
||||
#define RT_USING_STDC_ATOMIC
|
||||
#endif /* __GNUC__ && .. */
|
||||
#endif /* !RT_USING_HW_ATOMIC && !RT_USING_STDC_ATOMIC */
|
||||
|
||||
#if defined(RT_USING_HW_ATOMIC)
|
||||
#define rt_atomic_load(ptr) rt_hw_atomic_load(ptr)
|
||||
#define rt_atomic_store(ptr, v) rt_hw_atomic_store(ptr, v)
|
||||
|
||||
+81
-37
File diff suppressed because it is too large
Load Diff
+14
-15
@@ -13,6 +13,7 @@
|
||||
* 2018-11-17 Jesven add rt_hw_spinlock_t
|
||||
* add smp support
|
||||
* 2019-05-18 Bernard add empty definition for not enable cache case
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
* 2023-10-16 Shell Support a new backtrace framework
|
||||
*/
|
||||
|
||||
@@ -111,6 +112,9 @@ struct rt_irq_desc
|
||||
#ifdef RT_USING_INTERRUPT_INFO
|
||||
char name[RT_NAME_MAX];
|
||||
rt_uint32_t counter;
|
||||
#ifdef RT_USING_SMP
|
||||
rt_ubase_t cpu_counter[RT_CPUS_NR];
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -129,11 +133,18 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector,
|
||||
rt_base_t rt_hw_local_irq_disable();
|
||||
void rt_hw_local_irq_enable(rt_base_t level);
|
||||
|
||||
rt_base_t rt_cpus_lock(void);
|
||||
void rt_cpus_unlock(rt_base_t level);
|
||||
|
||||
#define rt_hw_interrupt_disable rt_cpus_lock
|
||||
#define rt_hw_interrupt_enable rt_cpus_unlock
|
||||
#else
|
||||
rt_base_t rt_hw_interrupt_disable(void);
|
||||
void rt_hw_interrupt_enable(rt_base_t level);
|
||||
|
||||
#define rt_hw_local_irq_disable rt_hw_interrupt_disable
|
||||
#define rt_hw_local_irq_enable rt_hw_interrupt_enable
|
||||
|
||||
#endif /*RT_USING_SMP*/
|
||||
rt_bool_t rt_hw_interrupt_is_disabled(void);
|
||||
|
||||
@@ -187,25 +198,18 @@ void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask);
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
|
||||
struct rt_spinlock
|
||||
{
|
||||
rt_hw_spinlock_t lock;
|
||||
};
|
||||
|
||||
void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock);
|
||||
void rt_hw_spin_lock(rt_hw_spinlock_t *lock);
|
||||
void rt_hw_spin_unlock(rt_hw_spinlock_t *lock);
|
||||
|
||||
extern rt_hw_spinlock_t _cpus_lock;
|
||||
extern rt_hw_spinlock_t _rt_critical_lock;
|
||||
|
||||
#define __RT_HW_SPIN_LOCK_INITIALIZER(lockname) {0}
|
||||
|
||||
#define __RT_HW_SPIN_LOCK_UNLOCKED(lockname) \
|
||||
(rt_hw_spinlock_t) __RT_HW_SPIN_LOCK_INITIALIZER(lockname)
|
||||
|
||||
#define RT_DEFINE_SPINLOCK(x) rt_hw_spinlock_t x = __RT_HW_SPIN_LOCK_UNLOCKED(x)
|
||||
#define RT_DECLARE_SPINLOCK(x)
|
||||
#define RT_DEFINE_HW_SPINLOCK(x) rt_hw_spinlock_t x = __RT_HW_SPIN_LOCK_UNLOCKED(x)
|
||||
|
||||
/**
|
||||
* boot secondary cpu
|
||||
@@ -218,17 +222,12 @@ void rt_hw_secondary_cpu_up(void);
|
||||
void rt_hw_secondary_cpu_idle_exec(void);
|
||||
#else
|
||||
|
||||
#define RT_DEFINE_SPINLOCK(x) rt_ubase_t x
|
||||
#define RT_DECLARE_SPINLOCK(x)
|
||||
#define RT_DEFINE_HW_SPINLOCK(x) rt_ubase_t x
|
||||
|
||||
#define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable()
|
||||
#define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock))
|
||||
|
||||
typedef rt_ubase_t rt_spinlock_t;
|
||||
struct rt_spinlock
|
||||
{
|
||||
rt_spinlock_t lock;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef RT_USING_CACHE
|
||||
|
||||
+5
-14
@@ -553,11 +553,11 @@ void rt_spin_unlock(struct rt_spinlock *lock);
|
||||
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock);
|
||||
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level);
|
||||
#else
|
||||
#define rt_spin_lock_init(lock) /* nothing */
|
||||
#define rt_spin_lock(lock) rt_enter_critical()
|
||||
#define rt_spin_unlock(lock) rt_exit_critical()
|
||||
#define rt_spin_lock_irqsave(lock) rt_hw_interrupt_disable()
|
||||
#define rt_spin_unlock_irqrestore(lock, level) rt_hw_interrupt_enable(level)
|
||||
#define rt_spin_lock_init(lock) { RT_UNUSED(lock); }
|
||||
#define rt_spin_lock(lock) { RT_UNUSED(lock); }
|
||||
#define rt_spin_unlock(lock) { RT_UNUSED(lock); }
|
||||
#define rt_spin_lock_irqsave(lock) ({ RT_UNUSED(lock); rt_hw_interrupt_disable(); })
|
||||
#define rt_spin_unlock_irqrestore(lock, level) { RT_UNUSED(lock); rt_hw_interrupt_enable(level); }
|
||||
#endif /* RT_USING_SMP */
|
||||
|
||||
/**@}*/
|
||||
@@ -742,14 +742,11 @@ if (!(EX)) \
|
||||
#define RT_DEBUG_NOT_IN_INTERRUPT \
|
||||
do \
|
||||
{ \
|
||||
rt_base_t level; \
|
||||
level = rt_hw_interrupt_disable(); \
|
||||
if (rt_interrupt_get_nest() != 0) \
|
||||
{ \
|
||||
rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \
|
||||
RT_ASSERT(0) \
|
||||
} \
|
||||
rt_hw_interrupt_enable(level); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -760,8 +757,6 @@ while (0)
|
||||
#define RT_DEBUG_IN_THREAD_CONTEXT \
|
||||
do \
|
||||
{ \
|
||||
rt_base_t level; \
|
||||
level = rt_hw_interrupt_disable(); \
|
||||
if (rt_thread_self() == RT_NULL) \
|
||||
{ \
|
||||
rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
|
||||
@@ -769,7 +764,6 @@ do \
|
||||
RT_ASSERT(0) \
|
||||
} \
|
||||
RT_DEBUG_NOT_IN_INTERRUPT; \
|
||||
rt_hw_interrupt_enable(level); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -785,9 +779,7 @@ do \
|
||||
if (need_check) \
|
||||
{ \
|
||||
rt_bool_t interrupt_disabled; \
|
||||
rt_base_t level; \
|
||||
interrupt_disabled = rt_hw_interrupt_is_disabled(); \
|
||||
level = rt_hw_interrupt_disable(); \
|
||||
if (rt_critical_level() != 0) \
|
||||
{ \
|
||||
rt_kprintf("Function[%s]: scheduler is not available\n", \
|
||||
@@ -801,7 +793,6 @@ do \
|
||||
RT_ASSERT(0) \
|
||||
} \
|
||||
RT_DEBUG_IN_THREAD_CONTEXT; \
|
||||
rt_hw_interrupt_enable(level); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -192,6 +192,7 @@ config ARCH_ARMV8
|
||||
bool
|
||||
select ARCH_ARM
|
||||
select ARCH_ARM_MMU
|
||||
select RT_USING_CPU_FFS
|
||||
|
||||
config ARCH_MIPS
|
||||
bool
|
||||
|
||||
@@ -9,10 +9,14 @@
|
||||
* 2023-06-24 WangXiaoyao Support backtrace for user thread
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#define __ASSEMBLY__
|
||||
#endif
|
||||
|
||||
#include "rtconfig.h"
|
||||
#include "asm-generic.h"
|
||||
|
||||
#include "asm-fpu.h"
|
||||
#include "armv8.h"
|
||||
|
||||
.text
|
||||
.weak rt_hw_cpu_id_set
|
||||
@@ -279,12 +283,30 @@ START_POINT_END(_thread_start)
|
||||
1:
|
||||
.endm
|
||||
|
||||
.macro RESTORE_USER_CTX, ctx
|
||||
LDR X1, [\ctx, #CONTEXT_OFFSET_SPSR_EL1]
|
||||
AND X1, X1, 0x1f
|
||||
CMP X1, XZR
|
||||
|
||||
BNE 1f
|
||||
BL lwp_uthread_ctx_restore
|
||||
1:
|
||||
.endm
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
#define rt_hw_interrupt_disable rt_hw_local_irq_disable
|
||||
#define rt_hw_interrupt_enable rt_hw_local_irq_enable
|
||||
#endif
|
||||
|
||||
.text
|
||||
|
||||
.global rt_hw_interrupt_is_disabled
|
||||
rt_hw_interrupt_is_disabled:
|
||||
MRS X0, DAIF
|
||||
TST X0, #0xc0
|
||||
CSET X0, NE
|
||||
RET
|
||||
|
||||
/*
|
||||
* rt_base_t rt_hw_interrupt_disable();
|
||||
*/
|
||||
@@ -387,8 +409,7 @@ rt_hw_context_switch_interrupt:
|
||||
vector_fiq:
|
||||
B .
|
||||
|
||||
.globl vector_irq
|
||||
vector_irq:
|
||||
START_POINT(vector_irq)
|
||||
SAVE_CONTEXT
|
||||
STP X0, X1, [SP, #-0x10]! /* X0 is thread sp */
|
||||
|
||||
@@ -399,13 +420,15 @@ vector_irq:
|
||||
#endif
|
||||
BL rt_hw_trap_irq
|
||||
#ifdef RT_USING_LWP
|
||||
BL lwp_uthread_ctx_restore
|
||||
LDP X0, X1, [SP]
|
||||
RESTORE_USER_CTX X0
|
||||
#endif
|
||||
BL rt_interrupt_leave
|
||||
|
||||
LDP X0, X1, [SP], #0x10
|
||||
BL rt_scheduler_do_irq_switch
|
||||
B rt_hw_context_switch_exit
|
||||
START_POINT_END(vector_irq)
|
||||
|
||||
.global rt_hw_context_switch_exit
|
||||
rt_hw_context_switch_exit:
|
||||
@@ -540,7 +563,8 @@ START_POINT(vector_exception)
|
||||
|
||||
BL rt_hw_trap_exception
|
||||
#ifdef RT_USING_LWP
|
||||
BL lwp_uthread_ctx_restore
|
||||
LDP X0, X1, [SP]
|
||||
RESTORE_USER_CTX X0
|
||||
#endif
|
||||
|
||||
LDP X0, X1, [SP], #0x10
|
||||
|
||||
+50
-37
@@ -59,52 +59,65 @@ rt_weak rt_uint64_t rt_cpu_mpidr_early[] =
|
||||
};
|
||||
#endif /* RT_USING_SMART */
|
||||
|
||||
void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock)
|
||||
{
|
||||
lock->slock = 0;
|
||||
}
|
||||
typedef rt_hw_spinlock_t arch_spinlock_t;
|
||||
|
||||
#define TICKET_SHIFT 16
|
||||
void rt_hw_spin_lock(rt_hw_spinlock_t *lock)
|
||||
static inline void arch_spin_lock(arch_spinlock_t *lock)
|
||||
{
|
||||
unsigned int tmp;
|
||||
struct __arch_tickets lockval, newval;
|
||||
|
||||
asm volatile(
|
||||
/* Atomically increment the next ticket. */
|
||||
" prfm pstl1strm, %3\n"
|
||||
"1: ldaxr %w0, %3\n"
|
||||
" add %w1, %w0, %w5\n"
|
||||
" stxr %w2, %w1, %3\n"
|
||||
" cbnz %w2, 1b\n"
|
||||
/* Did we get the lock? */
|
||||
" eor %w1, %w0, %w0, ror #16\n"
|
||||
" cbz %w1, 3f\n"
|
||||
/*
|
||||
* No: spin on the owner. Send a local event to avoid missing an
|
||||
* unlock before the exclusive load.
|
||||
*/
|
||||
" sevl\n"
|
||||
"2: wfe\n"
|
||||
" ldaxrh %w2, %4\n"
|
||||
" eor %w1, %w2, %w0, lsr #16\n"
|
||||
" cbnz %w1, 2b\n"
|
||||
/* We got the lock. Critical section starts here. */
|
||||
"3:"
|
||||
: "=&r"(lockval), "=&r"(newval), "=&r"(tmp), "+Q"(*lock)
|
||||
: "Q"(lock->tickets.owner), "I"(1 << TICKET_SHIFT)
|
||||
: "memory");
|
||||
rt_hw_dmb();
|
||||
" sevl\n"
|
||||
"1: wfe\n"
|
||||
"2: ldaxr %w0, %1\n"
|
||||
" cbnz %w0, 1b\n"
|
||||
" stxr %w0, %w2, %1\n"
|
||||
" cbnz %w0, 2b\n"
|
||||
: "=&r" (tmp), "+Q" (lock->lock)
|
||||
: "r" (1)
|
||||
: "cc", "memory");
|
||||
}
|
||||
|
||||
static inline int arch_spin_trylock(arch_spinlock_t *lock)
|
||||
{
|
||||
unsigned int tmp;
|
||||
|
||||
asm volatile(
|
||||
" ldaxr %w0, %1\n"
|
||||
" cbnz %w0, 1f\n"
|
||||
" stxr %w0, %w2, %1\n"
|
||||
"1:\n"
|
||||
: "=&r" (tmp), "+Q" (lock->lock)
|
||||
: "r" (1)
|
||||
: "cc", "memory");
|
||||
|
||||
return !tmp;
|
||||
}
|
||||
|
||||
static inline void arch_spin_unlock(arch_spinlock_t *lock)
|
||||
{
|
||||
asm volatile(
|
||||
" stlr %w1, %0\n"
|
||||
: "=Q" (lock->lock) : "r" (0) : "memory");
|
||||
}
|
||||
|
||||
void rt_hw_spin_lock_init(arch_spinlock_t *lock)
|
||||
{
|
||||
lock->lock = 0;
|
||||
}
|
||||
|
||||
void rt_hw_spin_lock(rt_hw_spinlock_t *lock)
|
||||
{
|
||||
arch_spin_lock(lock);
|
||||
}
|
||||
|
||||
void rt_hw_spin_unlock(rt_hw_spinlock_t *lock)
|
||||
{
|
||||
rt_hw_dmb();
|
||||
asm volatile(
|
||||
" stlrh %w1, %0\n"
|
||||
: "=Q"(lock->tickets.owner)
|
||||
: "r"(lock->tickets.owner + 1)
|
||||
: "memory");
|
||||
arch_spin_unlock(lock);
|
||||
}
|
||||
|
||||
rt_bool_t rt_hw_spin_trylock(rt_hw_spinlock_t *lock)
|
||||
{
|
||||
return arch_spin_trylock(lock);
|
||||
}
|
||||
|
||||
static int _cpus_init_data_hardcoded(int num_cpus, rt_uint64_t *cpu_hw_ids, struct cpu_ops_t *cpu_ops[])
|
||||
|
||||
@@ -14,12 +14,8 @@
|
||||
#include <rtdef.h>
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
typedef union {
|
||||
unsigned long slock;
|
||||
struct __arch_tickets {
|
||||
unsigned short owner;
|
||||
unsigned short next;
|
||||
} tickets;
|
||||
typedef struct {
|
||||
volatile unsigned int lock;
|
||||
} rt_hw_spinlock_t;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ extern void *system_vectors;
|
||||
#ifdef RT_USING_SMP
|
||||
#define rt_interrupt_nest rt_cpu_self()->irq_nest
|
||||
#else
|
||||
extern volatile rt_uint8_t rt_interrupt_nest;
|
||||
extern volatile rt_atomic_t rt_interrupt_nest;
|
||||
#endif
|
||||
|
||||
#ifdef SOC_BCM283x
|
||||
@@ -85,7 +85,7 @@ void rt_hw_interrupt_init(void)
|
||||
}
|
||||
|
||||
/* init interrupt nest, and context in thread sp */
|
||||
rt_interrupt_nest = 0;
|
||||
rt_atomic_store(&rt_interrupt_nest, 0);
|
||||
rt_interrupt_from_thread = 0;
|
||||
rt_interrupt_to_thread = 0;
|
||||
rt_thread_switch_interrupt_flag = 0;
|
||||
@@ -415,3 +415,48 @@ void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler)
|
||||
rt_hw_interrupt_install(ipi_vector, ipi_isr_handler, 0, "IPI_HANDLER");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FINSH_USING_MSH) && defined(RT_USING_INTERRUPT_INFO)
|
||||
int list_isr()
|
||||
{
|
||||
int idx;
|
||||
|
||||
rt_kprintf("%-*.*s nr handler param counter ", RT_NAME_MAX, RT_NAME_MAX, "irq");
|
||||
#ifdef RT_USING_SMP
|
||||
for (int i = 0; i < RT_CPUS_NR; i++)
|
||||
{
|
||||
rt_kprintf(" cpu%2d ", i);
|
||||
}
|
||||
#endif
|
||||
rt_kprintf("\n");
|
||||
for (int i = 0; i < RT_NAME_MAX; i++)
|
||||
{
|
||||
rt_kprintf("-");
|
||||
}
|
||||
rt_kprintf(" ---- ------------------ ------------------ ----------------");
|
||||
#ifdef RT_USING_SMP
|
||||
for (int i = 0; i < RT_CPUS_NR; i++)
|
||||
{
|
||||
rt_kprintf(" -------");
|
||||
}
|
||||
#endif
|
||||
rt_kprintf("\n");
|
||||
for (idx = 0; idx < MAX_HANDLERS; idx++)
|
||||
{
|
||||
if (isr_table[idx].handler != RT_NULL)
|
||||
{
|
||||
rt_kprintf("%*.s %4d %p %p %16d", RT_NAME_MAX, isr_table[idx].name, idx, isr_table[idx].handler,
|
||||
isr_table[idx].param, isr_table[idx].counter);
|
||||
#ifdef RT_USING_SMP
|
||||
for (int i = 0; i < RT_CPUS_NR; i++)
|
||||
rt_kprintf(" %7d", isr_table[idx].cpu_counter[i]);
|
||||
#endif
|
||||
rt_kprintf("\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "finsh.h"
|
||||
MSH_CMD_EXPORT(list_isr, list isr)
|
||||
#endif
|
||||
|
||||
@@ -274,6 +274,9 @@ void rt_hw_trap_irq(void)
|
||||
isr_func = isr_table[ir_self].handler;
|
||||
#ifdef RT_USING_INTERRUPT_INFO
|
||||
isr_table[ir_self].counter++;
|
||||
#ifdef RT_USING_SMP
|
||||
isr_table[ir_self].cpu_counter[rt_hw_cpu_id()]++;
|
||||
#endif
|
||||
#endif
|
||||
if (isr_func)
|
||||
{
|
||||
|
||||
@@ -219,6 +219,13 @@ menuconfig RT_USING_DEBUG
|
||||
bool "Enable page leaking tracer"
|
||||
depends on ARCH_MM_MMU
|
||||
default n
|
||||
|
||||
if RT_USING_SMP
|
||||
config RT_DEBUGING_SPINLOCK
|
||||
bool "Enable spinlock debugging"
|
||||
default n
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
menu "Inter-Thread communication"
|
||||
|
||||
+16
-20
@@ -15,16 +15,18 @@
|
||||
* 2018-11-22 Jesven add per cpu tick
|
||||
* 2020-12-29 Meco Man implement rt_tick_get_millisecond()
|
||||
* 2021-06-01 Meco Man add critical section projection for rt_tick_increase()
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
* 2023-10-16 RiceChen fix: only the main core detection rt_timer_check(), in SMP mode
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtatomic.h>
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
#define rt_tick rt_cpu_index(0)->tick
|
||||
#else
|
||||
static volatile rt_tick_t rt_tick = 0;
|
||||
static volatile rt_atomic_t rt_tick = 0;
|
||||
#endif /* RT_USING_SMP */
|
||||
|
||||
#ifndef __on_rt_tick_hook
|
||||
@@ -67,7 +69,7 @@ void rt_tick_sethook(void (*hook)(void))
|
||||
rt_tick_t rt_tick_get(void)
|
||||
{
|
||||
/* return the global tick */
|
||||
return rt_tick;
|
||||
return (rt_tick_t)rt_atomic_load(&(rt_tick));
|
||||
}
|
||||
RTM_EXPORT(rt_tick_get);
|
||||
|
||||
@@ -78,11 +80,7 @@ RTM_EXPORT(rt_tick_get);
|
||||
*/
|
||||
void rt_tick_set(rt_tick_t tick)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_tick = tick;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_atomic_store(&(rt_tick), tick);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,34 +91,32 @@ void rt_tick_increase(void)
|
||||
{
|
||||
struct rt_thread *thread;
|
||||
rt_base_t level;
|
||||
rt_atomic_t oldval = 0;
|
||||
|
||||
RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
/* increase the global tick */
|
||||
#ifdef RT_USING_SMP
|
||||
rt_cpu_self()->tick ++;
|
||||
rt_atomic_add(&(rt_cpu_self()->tick), 1);
|
||||
#else
|
||||
++ rt_tick;
|
||||
rt_atomic_add(&(rt_tick), 1);
|
||||
#endif /* RT_USING_SMP */
|
||||
|
||||
/* check time slice */
|
||||
thread = rt_thread_self();
|
||||
|
||||
-- thread->remaining_tick;
|
||||
if (thread->remaining_tick == 0)
|
||||
rt_get_thread_struct(thread);
|
||||
level = rt_spin_lock_irqsave(&(thread->spinlock));
|
||||
rt_atomic_sub(&(thread->remaining_tick), 1);
|
||||
if (rt_atomic_compare_exchange_strong(&(thread->remaining_tick), &oldval, thread->init_tick))
|
||||
{
|
||||
/* change to initialized tick */
|
||||
thread->remaining_tick = thread->init_tick;
|
||||
thread->stat |= RT_THREAD_STAT_YIELD;
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
||||
rt_put_thread_struct(thread);
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
||||
rt_put_thread_struct(thread);
|
||||
}
|
||||
|
||||
/* check timer */
|
||||
|
||||
+5
-1
@@ -15,6 +15,7 @@
|
||||
* in some IDEs.
|
||||
* 2015-07-29 Arda.Fu Add support to use RT_USING_USER_MAIN with IAR
|
||||
* 2018-11-22 Jesven Add secondary cpu boot up
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -235,7 +236,10 @@ void rt_application_init(void)
|
||||
*/
|
||||
int rtthread_startup(void)
|
||||
{
|
||||
rt_hw_interrupt_disable();
|
||||
#ifdef RT_USING_SMP
|
||||
rt_hw_spin_lock_init(&_cpus_lock);
|
||||
#endif
|
||||
rt_hw_local_irq_disable();
|
||||
|
||||
/* board level initialization
|
||||
* NOTE: please initialize heap inside board initialization.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-10-30 Bernard The first version
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
@@ -17,57 +18,19 @@
|
||||
#ifdef RT_USING_SMP
|
||||
static struct rt_cpu _cpus[RT_CPUS_NR];
|
||||
rt_hw_spinlock_t _cpus_lock;
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
void *_cpus_lock_owner = 0;
|
||||
void *_cpus_lock_pc = 0;
|
||||
|
||||
/*
|
||||
* @brief disable scheduler
|
||||
*/
|
||||
static void _cpu_preempt_disable(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
struct rt_thread *current_thread;
|
||||
#define __OWNER_MAGIC ((void *)0xdeadbeaf)
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_local_irq_disable();
|
||||
#if defined (__GNUC__)
|
||||
#define __GET_RETURN_ADDRESS __builtin_return_address(0)
|
||||
#else
|
||||
#define __GET_RETURN_ADDRESS RT_NULL
|
||||
#endif
|
||||
|
||||
current_thread = rt_thread_self();
|
||||
if (!current_thread)
|
||||
{
|
||||
rt_hw_local_irq_enable(level);
|
||||
return;
|
||||
}
|
||||
|
||||
/* lock scheduler for local cpu */
|
||||
current_thread->scheduler_lock_nest ++;
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_local_irq_enable(level);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief enable scheduler
|
||||
*/
|
||||
static void _cpu_preempt_enable(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
struct rt_thread *current_thread;
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_local_irq_disable();
|
||||
|
||||
current_thread = rt_thread_self();
|
||||
if (!current_thread)
|
||||
{
|
||||
rt_hw_local_irq_enable(level);
|
||||
return;
|
||||
}
|
||||
|
||||
/* unlock scheduler for local cpu */
|
||||
current_thread->scheduler_lock_nest --;
|
||||
|
||||
rt_schedule();
|
||||
/* enable interrupt */
|
||||
rt_hw_local_irq_enable(level);
|
||||
}
|
||||
#endif /* RT_DEBUGING_SPINLOCK */
|
||||
|
||||
/**
|
||||
* @brief Initialize a static spinlock object.
|
||||
@@ -90,8 +53,14 @@ RTM_EXPORT(rt_spin_lock_init)
|
||||
*/
|
||||
void rt_spin_lock(struct rt_spinlock *lock)
|
||||
{
|
||||
_cpu_preempt_disable();
|
||||
rt_hw_spin_lock(&lock->lock);
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
if (rt_cpu_self() != RT_NULL)
|
||||
{
|
||||
lock->owner = rt_cpu_self()->current_thread;
|
||||
}
|
||||
lock->pc = __GET_RETURN_ADDRESS;
|
||||
#endif /* RT_DEBUGING_SPINLOCK */
|
||||
}
|
||||
RTM_EXPORT(rt_spin_lock)
|
||||
|
||||
@@ -103,7 +72,10 @@ RTM_EXPORT(rt_spin_lock)
|
||||
void rt_spin_unlock(struct rt_spinlock *lock)
|
||||
{
|
||||
rt_hw_spin_unlock(&lock->lock);
|
||||
_cpu_preempt_enable();
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
lock->owner = __OWNER_MAGIC;
|
||||
lock->pc = RT_NULL;
|
||||
#endif /* RT_DEBUGING_SPINLOCK */
|
||||
}
|
||||
RTM_EXPORT(rt_spin_unlock)
|
||||
|
||||
@@ -121,11 +93,15 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
|
||||
{
|
||||
unsigned long level;
|
||||
|
||||
_cpu_preempt_disable();
|
||||
|
||||
level = rt_hw_local_irq_disable();
|
||||
rt_hw_spin_lock(&lock->lock);
|
||||
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
if (rt_cpu_self() != RT_NULL)
|
||||
{
|
||||
lock->owner = rt_cpu_self()->current_thread;
|
||||
lock->pc = __GET_RETURN_ADDRESS;
|
||||
}
|
||||
#endif /* RT_DEBUGING_SPINLOCK */
|
||||
return level;
|
||||
}
|
||||
RTM_EXPORT(rt_spin_lock_irqsave)
|
||||
@@ -139,10 +115,12 @@ RTM_EXPORT(rt_spin_lock_irqsave)
|
||||
*/
|
||||
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
|
||||
{
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
lock->owner = __OWNER_MAGIC;
|
||||
lock->pc = RT_NULL;
|
||||
#endif /* RT_DEBUGING_SPINLOCK */
|
||||
rt_hw_spin_unlock(&lock->lock);
|
||||
rt_hw_local_irq_enable(level);
|
||||
|
||||
_cpu_preempt_enable();
|
||||
}
|
||||
RTM_EXPORT(rt_spin_unlock_irqrestore)
|
||||
|
||||
@@ -183,13 +161,16 @@ rt_base_t rt_cpus_lock(void)
|
||||
pcpu = rt_cpu_self();
|
||||
if (pcpu->current_thread != RT_NULL)
|
||||
{
|
||||
register rt_ubase_t lock_nest = pcpu->current_thread->cpus_lock_nest;
|
||||
register rt_ubase_t lock_nest = rt_atomic_load(&(pcpu->current_thread->cpus_lock_nest));
|
||||
|
||||
pcpu->current_thread->cpus_lock_nest++;
|
||||
rt_atomic_add(&(pcpu->current_thread->cpus_lock_nest), 1);
|
||||
if (lock_nest == 0)
|
||||
{
|
||||
pcpu->current_thread->scheduler_lock_nest++;
|
||||
rt_hw_spin_lock(&_cpus_lock);
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
_cpus_lock_owner = pcpu->current_thread;
|
||||
_cpus_lock_pc = __GET_RETURN_ADDRESS;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,12 +189,15 @@ void rt_cpus_unlock(rt_base_t level)
|
||||
|
||||
if (pcpu->current_thread != RT_NULL)
|
||||
{
|
||||
RT_ASSERT(pcpu->current_thread->cpus_lock_nest > 0);
|
||||
pcpu->current_thread->cpus_lock_nest--;
|
||||
RT_ASSERT(rt_atomic_load(&(pcpu->current_thread->cpus_lock_nest)) > 0);
|
||||
rt_atomic_sub(&(pcpu->current_thread->cpus_lock_nest), 1);
|
||||
|
||||
if (pcpu->current_thread->cpus_lock_nest == 0)
|
||||
{
|
||||
pcpu->current_thread->scheduler_lock_nest--;
|
||||
#if defined(RT_DEBUGING_SPINLOCK)
|
||||
_cpus_lock_owner = __OWNER_MAGIC;
|
||||
_cpus_lock_pc = RT_NULL;
|
||||
#endif
|
||||
rt_hw_spin_unlock(&_cpus_lock);
|
||||
}
|
||||
}
|
||||
@@ -235,11 +219,18 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread)
|
||||
#if defined(ARCH_MM_MMU) && defined(RT_USING_SMART)
|
||||
lwp_aspace_switch(thread);
|
||||
#endif
|
||||
pcpu->current_thread = thread;
|
||||
if (!thread->cpus_lock_nest)
|
||||
if (pcpu->current_thread != RT_NULL )
|
||||
{
|
||||
rt_hw_spin_unlock(&_cpus_lock);
|
||||
rt_spin_unlock(&(pcpu->current_thread->spinlock));
|
||||
if ((pcpu->current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
|
||||
{
|
||||
rt_schedule_insert_thread(pcpu->current_thread);
|
||||
}
|
||||
rt_put_thread_struct(pcpu->current_thread);
|
||||
|
||||
}
|
||||
pcpu->current_thread = thread;
|
||||
rt_get_thread_struct(thread);
|
||||
}
|
||||
RTM_EXPORT(rt_cpus_lock_status_restore);
|
||||
#endif
|
||||
#endif /* RT_USING_SMP */
|
||||
|
||||
+20
-19
@@ -16,6 +16,7 @@
|
||||
* 2018-11-22 Jesven add per cpu idle task
|
||||
* combine the code of primary and secondary cpu
|
||||
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -42,7 +43,8 @@
|
||||
#define _CPUS_NR RT_CPUS_NR
|
||||
|
||||
static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);
|
||||
|
||||
static struct rt_mutex _defunct_mutex;
|
||||
static rt_atomic_t _idle_inited = 0;
|
||||
static struct rt_thread idle_thread[_CPUS_NR];
|
||||
rt_align(RT_ALIGN_SIZE)
|
||||
static rt_uint8_t idle_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE];
|
||||
@@ -78,12 +80,8 @@ static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void);
|
||||
rt_err_t rt_thread_idle_sethook(void (*hook)(void))
|
||||
{
|
||||
rt_size_t i;
|
||||
rt_base_t level;
|
||||
rt_err_t ret = -RT_EFULL;
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
|
||||
{
|
||||
if (idle_hook_list[i] == RT_NULL)
|
||||
@@ -93,9 +91,6 @@ rt_err_t rt_thread_idle_sethook(void (*hook)(void))
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -110,12 +105,8 @@ rt_err_t rt_thread_idle_sethook(void (*hook)(void))
|
||||
rt_err_t rt_thread_idle_delhook(void (*hook)(void))
|
||||
{
|
||||
rt_size_t i;
|
||||
rt_base_t level;
|
||||
rt_err_t ret = -RT_ENOSYS;
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
|
||||
{
|
||||
if (idle_hook_list[i] == hook)
|
||||
@@ -125,9 +116,6 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -142,7 +130,13 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
|
||||
*/
|
||||
void rt_thread_defunct_enqueue(rt_thread_t thread)
|
||||
{
|
||||
if (rt_atomic_load(&_idle_inited) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
rt_mutex_take(&_defunct_mutex, RT_WAITING_FOREVER);
|
||||
rt_list_insert_after(&_rt_thread_defunct, &thread->tlist);
|
||||
rt_mutex_release(&_defunct_mutex);
|
||||
#ifdef RT_USING_SMP
|
||||
rt_sem_release(&system_sem);
|
||||
#endif
|
||||
@@ -158,8 +152,7 @@ rt_thread_t rt_thread_defunct_dequeue(void)
|
||||
rt_list_t *l = &_rt_thread_defunct;
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_mutex_take(&_defunct_mutex, RT_WAITING_FOREVER);
|
||||
if (l->next != l)
|
||||
{
|
||||
thread = rt_list_entry(l->next,
|
||||
@@ -167,7 +160,8 @@ rt_thread_t rt_thread_defunct_dequeue(void)
|
||||
tlist);
|
||||
rt_list_remove(&(thread->tlist));
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_mutex_release(&_defunct_mutex);
|
||||
RT_UNUSED(level);
|
||||
#else
|
||||
if (l->next != l)
|
||||
{
|
||||
@@ -204,6 +198,11 @@ static void rt_defunct_execute(void)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
while (rt_atomic_load(&(thread->ref_count)))
|
||||
{
|
||||
rt_thread_delay(5);
|
||||
}
|
||||
#ifdef RT_USING_MODULE
|
||||
module = (struct rt_dlmodule*)thread->parent.module_id;
|
||||
if (module)
|
||||
@@ -341,7 +340,7 @@ void rt_thread_idle_init(void)
|
||||
#ifdef RT_USING_SMP
|
||||
RT_ASSERT(RT_THREAD_PRIORITY_MAX > 2);
|
||||
|
||||
rt_sem_init(&system_sem, "defunct", 1, RT_IPC_FLAG_FIFO);
|
||||
rt_sem_init(&system_sem, "defunct", 0, RT_IPC_FLAG_FIFO);
|
||||
|
||||
/* create defunct thread */
|
||||
rt_thread_init(&rt_system_thread,
|
||||
@@ -355,6 +354,8 @@ void rt_thread_idle_init(void)
|
||||
/* startup */
|
||||
rt_thread_startup(&rt_system_thread);
|
||||
#endif
|
||||
rt_mutex_init(&_defunct_mutex, "defunct_mutex", RT_IPC_FLAG_FIFO);
|
||||
rt_atomic_store(&(_idle_inited), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
* 2021-08-15 Supperthomas fix the comment
|
||||
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to irq.c
|
||||
* 2022-07-04 Yunjie fix RT_DEBUG_LOG
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -71,7 +72,7 @@ void rt_interrupt_leave_sethook(void (*hook)(void))
|
||||
#ifdef RT_USING_SMP
|
||||
#define rt_interrupt_nest rt_cpu_self()->irq_nest
|
||||
#else
|
||||
volatile rt_uint8_t rt_interrupt_nest = 0;
|
||||
volatile rt_atomic_t rt_interrupt_nest = 0;
|
||||
#endif /* RT_USING_SMP */
|
||||
|
||||
|
||||
@@ -84,15 +85,10 @@ volatile rt_uint8_t rt_interrupt_nest = 0;
|
||||
*/
|
||||
rt_weak void rt_interrupt_enter(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_interrupt_nest ++;
|
||||
rt_atomic_add(&(rt_interrupt_nest), 1);
|
||||
RT_OBJECT_HOOK_CALL(rt_interrupt_enter_hook,());
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
LOG_D("irq has come..., irq current nest:%d",
|
||||
(rt_int32_t)rt_interrupt_nest);
|
||||
(rt_int32_t)rt_atomic_load(&(rt_interrupt_nest)));
|
||||
}
|
||||
RTM_EXPORT(rt_interrupt_enter);
|
||||
|
||||
@@ -106,15 +102,11 @@ RTM_EXPORT(rt_interrupt_enter);
|
||||
*/
|
||||
rt_weak void rt_interrupt_leave(void)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
LOG_D("irq is going to leave, irq current nest:%d",
|
||||
(rt_int32_t)rt_interrupt_nest);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
(rt_int32_t)rt_atomic_load(&(rt_interrupt_nest)));
|
||||
RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,());
|
||||
rt_interrupt_nest --;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_atomic_sub(&(rt_interrupt_nest), 1);
|
||||
|
||||
}
|
||||
RTM_EXPORT(rt_interrupt_leave);
|
||||
|
||||
@@ -129,13 +121,7 @@ RTM_EXPORT(rt_interrupt_leave);
|
||||
*/
|
||||
rt_weak rt_uint8_t rt_interrupt_get_nest(void)
|
||||
{
|
||||
rt_uint8_t ret;
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
ret = rt_interrupt_nest;
|
||||
rt_hw_interrupt_enable(level);
|
||||
return ret;
|
||||
return rt_atomic_load(&rt_interrupt_nest);
|
||||
}
|
||||
RTM_EXPORT(rt_interrupt_get_nest);
|
||||
|
||||
|
||||
+15
-27
@@ -15,6 +15,7 @@
|
||||
* 2011-01-24 Bernard add object allocation check.
|
||||
* 2012-03-22 Bernard fix align issue in rt_mp_init and rt_mp_create.
|
||||
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to mempool.c
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -131,6 +132,7 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
|
||||
RT_NULL;
|
||||
|
||||
mp->block_list = block_ptr;
|
||||
rt_spin_lock_init(&(mp->spinlock));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -153,11 +155,10 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
|
||||
RT_ASSERT(rt_object_get_type(&mp->parent) == RT_Object_Class_MemPool);
|
||||
RT_ASSERT(rt_object_is_systemobject(&mp->parent));
|
||||
|
||||
level = rt_spin_lock_irqsave(&(mp->spinlock));
|
||||
/* wake up all suspended threads */
|
||||
while (!rt_list_isempty(&(mp->suspend_thread)))
|
||||
{
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
/* get next suspend thread */
|
||||
thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist);
|
||||
@@ -170,13 +171,11 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
|
||||
* suspend list
|
||||
*/
|
||||
rt_thread_resume(thread);
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
/* detach object */
|
||||
rt_object_detach(&(mp->parent));
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -249,6 +248,7 @@ rt_mp_t rt_mp_create(const char *name,
|
||||
= RT_NULL;
|
||||
|
||||
mp->block_list = block_ptr;
|
||||
rt_spin_lock_init(&(mp->spinlock));
|
||||
|
||||
return mp;
|
||||
}
|
||||
@@ -273,12 +273,10 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||
RT_ASSERT(rt_object_get_type(&mp->parent) == RT_Object_Class_MemPool);
|
||||
RT_ASSERT(rt_object_is_systemobject(&mp->parent) == RT_FALSE);
|
||||
|
||||
level = rt_spin_lock_irqsave(&(mp->spinlock));
|
||||
/* wake up all suspended threads */
|
||||
while (!rt_list_isempty(&(mp->suspend_thread)))
|
||||
{
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
/* get next suspend thread */
|
||||
thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist);
|
||||
/* set error code to -RT_ERROR */
|
||||
@@ -290,9 +288,6 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||
* suspend list
|
||||
*/
|
||||
rt_thread_resume(thread);
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
/* release allocated room */
|
||||
@@ -300,6 +295,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||
|
||||
/* detach object */
|
||||
rt_object_delete(&(mp->parent));
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -329,16 +325,14 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
|
||||
/* get current thread */
|
||||
thread = rt_thread_self();
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(mp->spinlock));
|
||||
|
||||
while (mp->block_free_count == 0)
|
||||
{
|
||||
/* memory block is unavailable. */
|
||||
if (time == 0)
|
||||
{
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
rt_set_errno(-RT_ETIMEOUT);
|
||||
|
||||
@@ -366,7 +360,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
|
||||
}
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
/* do a schedule */
|
||||
rt_schedule();
|
||||
@@ -380,8 +374,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
|
||||
if (time < 0)
|
||||
time = 0;
|
||||
}
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(mp->spinlock));
|
||||
}
|
||||
|
||||
/* memory block is available. decrease the free block counter */
|
||||
@@ -397,8 +390,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
|
||||
/* point to memory pool */
|
||||
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
RT_OBJECT_HOOK_CALL(rt_mp_alloc_hook,
|
||||
(mp, (rt_uint8_t *)(block_ptr + sizeof(rt_uint8_t *))));
|
||||
@@ -428,8 +420,7 @@ void rt_mp_free(void *block)
|
||||
|
||||
RT_OBJECT_HOOK_CALL(rt_mp_free_hook, (mp, block));
|
||||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(mp->spinlock));
|
||||
|
||||
/* increase the free block count */
|
||||
mp->block_free_count ++;
|
||||
@@ -451,17 +442,14 @@ void rt_mp_free(void *block)
|
||||
/* resume thread */
|
||||
rt_thread_resume(thread);
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
|
||||
/* do a schedule */
|
||||
rt_schedule();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(mp->spinlock), level);
|
||||
}
|
||||
RTM_EXPORT(rt_mp_free);
|
||||
|
||||
|
||||
+46
-50
File diff suppressed because it is too large
Load Diff
+286
-218
File diff suppressed because it is too large
Load Diff
@@ -53,17 +53,6 @@ static void _signal_entry(void *parameter)
|
||||
rt_thread_handle_sig(RT_FALSE);
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
{
|
||||
struct rt_cpu* pcpu = rt_cpu_self();
|
||||
|
||||
RT_ASSERT(pcpu->current_thread->cpus_lock_nest > 0);
|
||||
pcpu->current_thread->cpus_lock_nest--;
|
||||
if (pcpu->current_thread->cpus_lock_nest == 0)
|
||||
{
|
||||
pcpu->current_thread->scheduler_lock_nest--;
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
/* return to thread */
|
||||
tid->sp = tid->sig_ret;
|
||||
|
||||
+72
-98
File diff suppressed because it is too large
Load Diff
+95
-76
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user