Skip to content

Commit

Permalink
os/board/rtl8730e: Refine driver layer critical zone usage
Browse files Browse the repository at this point in the history
- Reduce overhead of implementation in osdep_service_critical.c
- Previously BSP layer is using irqsave/irqrestore, change to use enter/leave_critical_section instead
  • Loading branch information
edwakuwaku committed Apr 11, 2024
1 parent 130b587 commit 81aa34e
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 79 deletions.
16 changes: 16 additions & 0 deletions os/board/rtl8730e/src/component/os_dep/device_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,45 @@ static _mutex device_mutex[RT_DEV_LOCK_MAX];
static void device_mutex_init(RT_DEV_LOCK_E device)
{
if (!DEVICE_MUTEX_IS_INIT(device)) {
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_lock lock;
_irqL irqL;
rtw_enter_critical(&lock, &irqL);
#endif
if (!DEVICE_MUTEX_IS_INIT(device)) {
rtw_mutex_init(&device_mutex[device]);
DEVICE_MUTEX_SET_INIT(device);
}
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&lock, &irqL);
#endif
}
}

//======================================================
void device_mutex_free(RT_DEV_LOCK_E device)
{
if (DEVICE_MUTEX_IS_INIT(device)) {
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_lock lock;
_irqL irqL;
rtw_enter_critical(&lock, &irqL);
#endif
if (DEVICE_MUTEX_IS_INIT(device)) {
rtw_mutex_free(&device_mutex[device]);
DEVICE_MUTEX_CLR_INIT(device);
}
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&lock, &irqL);
#endif
}
}

Expand Down
64 changes: 13 additions & 51 deletions os/board/rtl8730e/src/component/os_dep/osdep_service_critical.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,17 @@
#endif
#endif

#if 1 //Justin: temporary solution for enter critical code for tizenRT
static irqstate_t initial_tizen_flags, up_tizen_flag;
static int flagcnt = 0;
#endif

#if 1 //Justin: temporary solution for enter critical code for tizenRT
void save_and_cli_temp(void);
void restore_flags_temp(void);
void save_and_cli_temp()
{
if(flagcnt){
up_tizen_flag = irqsave();
}else{
initial_tizen_flags = irqsave();
}
flagcnt++;
}

void restore_flags_temp()
{
flagcnt--;
if(flagcnt){
irqrestore(up_tizen_flag);
}else{
irqrestore(initial_tizen_flags);
}
}
#endif

#ifndef CONFIG_PLATFORM_TIZENRT_OS
void rtw_enter_critical(_lock *plock, _irqL *pirqL)
{
/* To avoid gcc warnings */
(void) pirqL;
(void) plock;

if (rtw_in_interrupt()) {
DBG_INFO("\n");
} else {
#if 1 //temporary solution for enter critical code for tizenRT
save_and_cli_temp();
#else
//printf("\n"); //suppress meaningless printout
#endif
}
/* In TizenRT kernel, enter_critical_section will handle entering critical zone
In single core cases: enter_critical_section behaves as irqsave
In multi core cases: enter_critical_section adds spinlock mechanism among cores
*/
}

void rtw_exit_critical(_lock *plock, _irqL *pirqL)
Expand All @@ -67,16 +34,12 @@ void rtw_exit_critical(_lock *plock, _irqL *pirqL)
(void) pirqL;
(void) plock;

if (rtw_in_interrupt()) {
DBG_INFO("\n");
} else {
#if 1 //temporary solution for enter critical code for tizenRT
restore_flags_temp();
#else
//printf("\n"); //suppress meaningless printout
#endif
}
/* In TizenRT kernel, leave_critical_section will handle exiting critical zone
In single core cases: enter_critical_section behaves as irqsave
In multi core cases: enter_critical_section adds spinlock mechanism among cores
*/
}
#endif

void rtw_enter_critical_bh(_lock *plock, _irqL *pirqL)
{
Expand Down Expand Up @@ -167,16 +130,15 @@ void rtw_spin_unlock(_lock *plock)

unsigned int save_and_cli(void)
{
return irqsave();
return enter_critical_section();
}

void restore_flags(unsigned int flag)
{
irqrestore(flag);
leave_critical_section(flag);
}

/* For definition in rtw_skbuff.h->ASSERT(0) */
void cli()
{
}


Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef void *_lock;
typedef unsigned long _irqL;

/*************************** SchedulerControl *******************************/
#ifndef CONFIG_PLATFORM_TIZENRT_OS
/**
* @brief This function marks the start of a critical code region.
* Preemptive context switches cannot occur when in a critical region.
Expand All @@ -36,7 +37,8 @@ typedef unsigned long _irqL;
* so must be used with care!
*/
void rtw_enter_critical(_lock *plock, _irqL *pirqL);

#endif
#ifndef CONFIG_PLATFORM_TIZENRT_OS
/**
* @brief This function marks end of a critical code region. Preemptive context
* switches cannot occur when in a critical region.
Expand All @@ -47,6 +49,7 @@ void rtw_enter_critical(_lock *plock, _irqL *pirqL);
* so must be used with care!
*/
void rtw_exit_critical(_lock *plock, _irqL *pirqL);
#endif

/**
* @brief This function obtains a spin lock semaphore.
Expand Down Expand Up @@ -130,7 +133,4 @@ void rtw_spin_unlock(_lock *plock);
#ifdef __cplusplus
}
#endif
// void save_and_cli(void);
// void restore_flags(void);
// void cli(void);
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ SRAMDRAM_ONLY_TEXT_SECTION
void FLASH_Write_Lock(void)
{
/* disable irq */
PrevIrqStatus = save_and_cli();
/* We do not need to acquire lock for this core, as the other core will enter gating */
PrevIrqStatus = irqsave();

/* Add This Code For XIP when ca32 Program Flah */
#if (defined(ARM_CORE_CA32) && defined(CONFIG_XIP_FLASH))
Expand Down Expand Up @@ -137,7 +138,7 @@ void FLASH_Write_Unlock(void)
#endif

/* restore irq */
restore_flags(PrevIrqStatus);
irqrestore(PrevIrqStatus);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ void tizenrt_pre_sleep_processing(uint32_t *expected_idle_time)
#ifndef CONFIG_PLATFORM_TIZENRT_OS
vTaskStepTick(ms_passed); /* update kernel tick */
#else
irqstate_t flags = irqsave();
irqstate_t flags = enter_critical_section();
g_system_timer += (u64)ms_passed; /* update kernel tick */
irqrestore(flags);
leave_critical_section(flags);
#endif

sysactive_timeout_flag = 0;
Expand Down
19 changes: 18 additions & 1 deletion os/board/rtl8730e/src/component/wifi/inic/inic_ipc_host_trx.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ struct skb_info *host_skb_info;
*/
static sint inic_enqueue_recvbuf(struct host_recv_buf *precvbuf, _queue *queue)
{
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_irqL irqL;

rtw_enter_critical(&queue->lock, &irqL);
#endif
rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&queue->lock, &irqL);
#endif

return _SUCCESS;
}
Expand All @@ -94,11 +102,16 @@ static sint inic_enqueue_recvbuf(struct host_recv_buf *precvbuf, _queue *queue)
*/
static struct host_recv_buf *inic_dequeue_recvbuf(_queue *queue)
{
_irqL irqL;
struct host_recv_buf *precvbuf;
_list *plist, *phead;

#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_irqL irqL;

rtw_enter_critical(&queue->lock, &irqL);
#endif

if (rtw_queue_empty(queue) == _TRUE) {
precvbuf = NULL;
Expand All @@ -109,7 +122,11 @@ static struct host_recv_buf *inic_dequeue_recvbuf(_queue *queue)
rtw_list_delete(&precvbuf->list);
}

#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&queue->lock, &irqL);
#endif

return precvbuf;
}
Expand Down
55 changes: 36 additions & 19 deletions os/board/rtl8730e/src/component/wifi/inic/inic_ipc_msg_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,24 @@ static sint enqueue_ipc_msg_node(struct ipc_msg_node *p_node, _queue *p_queue)
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
/* this function is called in ISR, no need to mask interrupt since gic already do it*/
spin_lock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_irqL irqL;
rtw_enter_critical(&(p_queue->lock), &irqL);
#endif
#endif
/* put the ipc message to the tail of the queue */
rtw_list_insert_tail(&(p_node->list), get_list_head(p_queue));
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
spin_unlock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&(p_queue->lock), &irqL);
#endif
#endif
return _SUCCESS;
}
Expand All @@ -101,15 +109,16 @@ static struct ipc_msg_node *dequeue_ipc_msg_node(_queue *p_queue)
_list *plist, *phead;

#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
#ifdef CONFIG_PLATFORM_TIZENRT_OS
u32 isr_status = irqsave();
#else
u32 isr_status = portDISABLE_INTERRUPTS();
#endif
/* We just need to prevent from being interrupted here, so use irqsave instead of enter_critical_section */
irqstate_t flags = irqsave();
spin_lock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_irqL irqL;
rtw_enter_critical(&(p_queue->lock), &irqL);
#endif
#endif

if (rtw_queue_empty(p_queue) == _TRUE) {
Expand All @@ -123,13 +132,13 @@ static struct ipc_msg_node *dequeue_ipc_msg_node(_queue *p_queue)

#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
spin_unlock(&ipc_msg_queue_lock);
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqrestore(isr_status);
irqrestore(flags);
#else
portRESTORE_INTERRUPTS(isr_status);
#endif
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&(p_queue->lock), &irqL);
#endif
#endif

return p_node;
Expand Down Expand Up @@ -161,26 +170,27 @@ static void inic_ipc_msg_q_task(void)
}
/* release the memory for this ipc message. */
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
#ifdef CONFIG_PLATFORM_TIZENRT_OS
u32 isr_status = irqsave();
#else
u32 isr_status = portDISABLE_INTERRUPTS();
#endif
/* We just need to prevent from being interrupted here, so use irqsave instead of enter_critical_section */
irqstate_t flags = irqsave();
spin_lock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
rtw_enter_critical(NULL, NULL);
#endif
#endif
p_node->is_used = 0;
g_ipc_msg_q_priv.queue_free++;
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
spin_unlock(&ipc_msg_queue_lock);
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqrestore(isr_status);
irqrestore(flags);
#else
portRESTORE_INTERRUPTS(isr_status);
#endif
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(NULL, NULL);
#endif
#endif
}
} while (g_ipc_msg_q_priv.b_queue_working);
Expand Down Expand Up @@ -242,9 +252,13 @@ sint inic_ipc_msg_enqueue(inic_ipc_ex_msg_t *p_ipc_msg)
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
/* this function is called in ISR, no need to mask interrupt since gic already do it*/
spin_lock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
irqstate_t flags = enter_critical_section();
#else
_irqL irqL;
rtw_enter_critical(&(p_queue->lock), &irqL);
#endif
#endif
/* allocate memory for message node */
for (i = 0; i < IPC_MSG_QUEUE_DEPTH; i++) {
Expand All @@ -258,10 +272,13 @@ sint inic_ipc_msg_enqueue(inic_ipc_ex_msg_t *p_ipc_msg)
}
#if defined(CONFIG_SMP_NCPUS) && (CONFIG_SMP_NCPUS > 1)
spin_unlock(&ipc_msg_queue_lock);
#else
#ifdef CONFIG_PLATFORM_TIZENRT_OS
leave_critical_section(flags);
#else
rtw_exit_critical(&(p_queue->lock), &irqL);
#endif

#endif
if (p_node == NULL) {
DBG_8195A("NO buffer for new nodes, waiting!\n\r");
goto func_out;
Expand Down

0 comments on commit 81aa34e

Please sign in to comment.