From 81aa34e4449f0ebc9380e15c9a67a8ac56a4cbe5 Mon Sep 17 00:00:00 2001 From: edwakuwaku Date: Mon, 18 Mar 2024 10:03:33 +0800 Subject: [PATCH] os/board/rtl8730e: Refine driver layer critical zone usage - Reduce overhead of implementation in osdep_service_critical.c - Previously BSP layer is using irqsave/irqrestore, change to use enter/leave_critical_section instead --- .../src/component/os_dep/device_lock.c | 16 +++++ .../component/os_dep/osdep_service_critical.c | 64 ++++--------------- .../component/os_dep/osdep_service_critical.h | 8 +-- .../fwlib/ram_common/ameba_flash_ram.c | 5 +- .../soc/amebad2/misc/ameba_tizenrt_pmu.c | 4 +- .../component/wifi/inic/inic_ipc_host_trx.c | 19 +++++- .../component/wifi/inic/inic_ipc_msg_queue.c | 55 ++++++++++------ 7 files changed, 92 insertions(+), 79 deletions(-) diff --git a/os/board/rtl8730e/src/component/os_dep/device_lock.c b/os/board/rtl8730e/src/component/os_dep/device_lock.c index d0a98e7bf3..2d4bd1947b 100755 --- a/os/board/rtl8730e/src/component/os_dep/device_lock.c +++ b/os/board/rtl8730e/src/component/os_dep/device_lock.c @@ -22,14 +22,22 @@ 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 } } @@ -37,14 +45,22 @@ static void device_mutex_init(RT_DEV_LOCK_E device) 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 } } diff --git a/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.c b/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.c index aa841afd0a..8d6cd85251 100644 --- a/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.c +++ b/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.c @@ -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) @@ -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) { @@ -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() { } - - diff --git a/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.h b/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.h index cac35e2365..f5f1a32108 100755 --- a/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.h +++ b/os/board/rtl8730e/src/component/os_dep/osdep_service_critical.h @@ -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. @@ -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. @@ -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. @@ -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 diff --git a/os/board/rtl8730e/src/component/soc/amebad2/fwlib/ram_common/ameba_flash_ram.c b/os/board/rtl8730e/src/component/soc/amebad2/fwlib/ram_common/ameba_flash_ram.c index fe711ceb5e..ce756c123e 100755 --- a/os/board/rtl8730e/src/component/soc/amebad2/fwlib/ram_common/ameba_flash_ram.c +++ b/os/board/rtl8730e/src/component/soc/amebad2/fwlib/ram_common/ameba_flash_ram.c @@ -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)) @@ -137,7 +138,7 @@ void FLASH_Write_Unlock(void) #endif /* restore irq */ - restore_flags(PrevIrqStatus); + irqrestore(PrevIrqStatus); } /** diff --git a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.c b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.c index 3c66cfecb1..03ffe84285 100644 --- a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.c +++ b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.c @@ -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; diff --git a/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_host_trx.c b/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_host_trx.c index 290647806d..f8ab92c36e 100644 --- a/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_host_trx.c +++ b/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_host_trx.c @@ -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; } @@ -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; @@ -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; } diff --git a/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_msg_queue.c b/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_msg_queue.c index 10a4529f0b..6ec0976584 100644 --- a/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_msg_queue.c +++ b/os/board/rtl8730e/src/component/wifi/inic/inic_ipc_msg_queue.c @@ -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; } @@ -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) { @@ -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; @@ -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); @@ -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++) { @@ -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;