summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorxqyjlj <[email protected]>2023-10-25 20:31:25 +0800
committerGitHub <[email protected]>2023-10-25 20:31:25 +0800
commit3283f54c7a0444b2e51ec79a4da57e7871528f05 (patch)
treee4bcd748ad2362f16d0dea5c5da62922de466999 /components/drivers
parent91fc52df3635d5dda8285616420f08efa79cea04 (diff)
🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)
Signed-off-by: Shell <[email protected]> Co-authored-by: Shell <[email protected]>
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/include/drivers/serial.h2
-rw-r--r--components/drivers/include/ipc/completion.h1
-rw-r--r--components/drivers/include/ipc/dataqueue.h1
-rw-r--r--components/drivers/include/ipc/ringblk_buf.h1
-rw-r--r--components/drivers/include/ipc/waitqueue.h2
-rw-r--r--components/drivers/include/ipc/workqueue.h1
-rw-r--r--components/drivers/ipc/completion.c20
-rw-r--r--components/drivers/ipc/dataqueue.c49
-rw-r--r--components/drivers/ipc/ringblk_buf.c22
-rw-r--r--components/drivers/ipc/waitqueue.c33
-rw-r--r--components/drivers/ipc/workqueue.c36
-rw-r--r--components/drivers/ktime/src/hrtimer.c11
-rw-r--r--components/drivers/serial/serial.c45
-rw-r--r--components/drivers/tty/console.c17
-rw-r--r--components/drivers/tty/include/tty.h1
-rw-r--r--components/drivers/tty/n_tty.c42
-rw-r--r--components/drivers/tty/pty.c7
-rw-r--r--components/drivers/tty/tty.c17
-rw-r--r--components/drivers/tty/tty_ioctl.c10
-rw-r--r--components/drivers/tty/tty_ldisc.c23
20 files changed, 176 insertions, 165 deletions
diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h
index 09d7c2f083..9435249cd8 100644
--- a/components/drivers/include/drivers/serial.h
+++ b/components/drivers/include/drivers/serial.h
@@ -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;
diff --git a/components/drivers/include/ipc/completion.h b/components/drivers/include/ipc/completion.h
index bdddbb6d83..b8d765027e 100644
--- a/components/drivers/include/ipc/completion.h
+++ b/components/drivers/include/ipc/completion.h
@@ -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);
diff --git a/components/drivers/include/ipc/dataqueue.h b/components/drivers/include/ipc/dataqueue.h
index e49c6343f9..4bf848350d 100644
--- a/components/drivers/include/ipc/dataqueue.h
+++ b/components/drivers/include/ipc/dataqueue.h
@@ -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;
diff --git a/components/drivers/include/ipc/ringblk_buf.h b/components/drivers/include/ipc/ringblk_buf.h
index a541bdd5b0..81d1866989 100644
--- a/components/drivers/include/ipc/ringblk_buf.h
+++ b/components/drivers/include/ipc/ringblk_buf.h
@@ -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;
diff --git a/components/drivers/include/ipc/waitqueue.h b/components/drivers/include/ipc/waitqueue.h
index 05ee5e0813..073300a72e 100644
--- a/components/drivers/include/ipc/waitqueue.h
+++ b/components/drivers/include/ipc/waitqueue.h
@@ -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);
diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h
index 9d30cd3f34..e05a7ab63f 100644
--- a/components/drivers/include/ipc/workqueue.h
+++ b/components/drivers/include/ipc/workqueue.h
@@ -41,6 +41,7 @@ struct rt_workqueue
struct rt_semaphore sem;
rt_thread_t work_thread;
+ struct rt_spinlock spinlock;
};
struct rt_work
diff --git a/components/drivers/ipc/completion.c b/components/drivers/ipc/completion.c
index d8c90429af..2c9b2797a3 100644
--- a/components/drivers/ipc/completion.c
+++ b/components/drivers/ipc/completion.c
@@ -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);
diff --git a/components/drivers/ipc/dataqueue.c b/components/drivers/ipc/dataqueue.c
index 36c381d136..bd3fce0c6e 100644
--- a/components/drivers/ipc/dataqueue.c
+++ b/components/drivers/ipc/dataqueue.c
@@ -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;
}
diff --git a/components/drivers/ipc/ringblk_buf.c b/components/drivers/ipc/ringblk_buf.c
index 719865ac5c..ab160270c4 100644
--- a/components/drivers/ipc/ringblk_buf.c
+++ b/components/drivers/ipc/ringblk_buf.c
@@ -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;
}
diff --git a/components/drivers/ipc/waitqueue.c b/components/drivers/ipc/waitqueue.c
index 44554700c6..03901a9ba3 100644
--- a/components/drivers/ipc/waitqueue.c
+++ b/components/drivers/ipc/waitqueue.c
@@ -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);
diff --git a/components/drivers/ipc/workqueue.c b/components/drivers/ipc/workqueue.c
index 9f688d230f..3f191fb9e2 100644
--- a/components/drivers/ipc/workqueue.c
+++ b/components/drivers/ipc/workqueue.c
@@ -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;
diff --git a/components/drivers/ktime/src/hrtimer.c b/components/drivers/ktime/src/hrtimer.c
index 5905d5e34b..f22f39e128 100644
--- a/components/drivers/ktime/src/hrtimer.c
+++ b/components/drivers/ktime/src/hrtimer.c
@@ -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);
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index 1777a231b3..0382f3c856 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -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)
{
diff --git a/components/drivers/tty/console.c b/components/drivers/tty/console.c
index ffc9ab71ec..a9c9b88731 100644
--- a/components/drivers/tty/console.c
+++ b/components/drivers/tty/console.c
@@ -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;
}
diff --git a/components/drivers/tty/include/tty.h b/components/drivers/tty/include/tty.h
index 1c0fa09ca3..79e30b6f51 100644
--- a/components/drivers/tty/include/tty.h
+++ b/components/drivers/tty/include/tty.h
@@ -166,6 +166,7 @@ struct tty_struct
#define RT_TTY_BUF 1024
rt_list_t tty_drivers;
+ struct rt_spinlock spinlock;
};
enum
diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c
index 067d587746..bf1156ba38 100644
--- a/components/drivers/tty/n_tty.c
+++ b/components/drivers/tty/n_tty.c
@@ -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;
}
diff --git a/components/drivers/tty/pty.c b/components/drivers/tty/pty.c
index 89a83096d6..b6cbda5574 100644
--- a/components/drivers/tty/pty.c
+++ b/components/drivers/tty/pty.c
@@ -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;
}
diff --git a/components/drivers/tty/tty.c b/components/drivers/tty/tty.c
index 6e05f95033..075b177d5c 100644
--- a/components/drivers/tty/tty.c
+++ b/components/drivers/tty/tty.c
@@ -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;
diff --git a/components/drivers/tty/tty_ioctl.c b/components/drivers/tty/tty_ioctl.c
index 4a537f2e53..92206266c3 100644
--- a/components/drivers/tty/tty_ioctl.c
+++ b/components/drivers/tty/tty_ioctl.c
@@ -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:
diff --git a/components/drivers/tty/tty_ldisc.c b/components/drivers/tty/tty_ldisc.c
index 5fb05a923c..f2aef64bcc 100644
--- a/components/drivers/tty/tty_ldisc.c
+++ b/components/drivers/tty/tty_ldisc.c
@@ -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);
}
/**