From 1ea9610ffd133f52303121334f18574826065779 Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Mon, 19 Apr 2021 11:50:23 +0800 Subject: [PATCH] code optimization Change-Id: I8d2e9f96e86f4130474da9898791240b5d42328e --- arch/arm/arm/include/arm.h | 4 - arch/arm/arm/include/hal_timer.h | 1 - arch/arm/arm/include/los_hw_cpu.h | 1 + arch/arm/arm/src/arm_generic_timer.c | 2 +- arch/arm/arm/src/los_hw.c | 21 +---- arch/arm/include/los_exc.h | 2 +- arch/arm/include/los_hw.h | 128 --------------------------- compat/posix/src/time.c | 6 +- drivers/char/random/src/random.c | 2 +- kernel/base/core/los_task.c | 2 +- kernel/base/include/los_vm_iomap.h | 5 -- kernel/base/vm/los_vm_iomap.c | 108 ---------------------- kernel/extended/vdso/src/los_vdso.c | 4 +- kernel/include/los_base.h | 24 ++--- kernel/include/los_toolchain.h | 24 +++++ 15 files changed, 49 insertions(+), 285 deletions(-) diff --git a/arch/arm/arm/include/arm.h b/arch/arm/arm/include/arm.h index c8a10ade..9d8aeb6a 100755 --- a/arch/arm/arm/include/arm.h +++ b/arch/arm/arm/include/arm.h @@ -36,10 +36,6 @@ #define CPSR_MODE_USR 0x10 #define CPSR_MODE_MASK 0x1f -#define DSB __asm__ volatile("dsb" ::: "memory") -#define ISB __asm__ volatile("isb" ::: "memory") -#define DMB __asm__ volatile("dmb" ::: "memory") - STATIC INLINE UINT32 OsArmReadSctlr(VOID) { UINT32 val; diff --git a/arch/arm/arm/include/hal_timer.h b/arch/arm/arm/include/hal_timer.h index 380b3621..fd218f9a 100644 --- a/arch/arm/arm/include/hal_timer.h +++ b/arch/arm/arm/include/hal_timer.h @@ -45,7 +45,6 @@ extern VOID HalClockIrqClear(VOID); extern VOID HalClockInit(VOID); extern UINT64 HalClockGetCycles(VOID); extern VOID HalDelayUs(UINT32 usecs); -extern UINT64 hi_sched_clock(VOID); extern UINT32 HalClockGetTickTimerCycles(VOID); extern VOID HalClockTickTimerReload(UINT64 cycles); diff --git a/arch/arm/arm/include/los_hw_cpu.h b/arch/arm/arm/include/los_hw_cpu.h index 45ecb23e..02c7ea4d 100755 --- a/arch/arm/arm/include/los_hw_cpu.h +++ b/arch/arm/arm/include/los_hw_cpu.h @@ -51,6 +51,7 @@ extern "C" { #define DSB __asm__ volatile("dsb" ::: "memory") #define DMB __asm__ volatile("dmb" ::: "memory") #define ISB __asm__ volatile("isb" ::: "memory") +#define WFI __asm__ volatile("wfi" ::: "memory") #define BARRIER __asm__ volatile("":::"memory") #define ARM_SYSREG_READ(REG) \ diff --git a/arch/arm/arm/src/arm_generic_timer.c b/arch/arm/arm/src/arm_generic_timer.c index f7d0a9bc..e3a732fa 100644 --- a/arch/arm/arm/src/arm_generic_timer.c +++ b/arch/arm/arm/src/arm_generic_timer.c @@ -162,7 +162,7 @@ VOID HalDelayUs(UINT32 usecs) } } -UINT64 hi_sched_clock(VOID) +DEPRECATED UINT64 hi_sched_clock(VOID) { return LOS_CurrNanosec(); } diff --git a/arch/arm/arm/src/los_hw.c b/arch/arm/arm/src/los_hw.c index 800bf1b9..7dddd038 100755 --- a/arch/arm/arm/src/los_hw.c +++ b/arch/arm/arm/src/los_hw.c @@ -143,32 +143,17 @@ LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_F context->PC = (UINTPTR)taskEntry; } -VOID Sev(VOID) -{ - __asm__ __volatile__ ("sev" : : : "memory"); -} - -VOID Wfe(VOID) -{ - __asm__ __volatile__ ("wfe" : : : "memory"); -} - -VOID Wfi(VOID) -{ - __asm__ __volatile__ ("wfi" : : : "memory"); -} - -VOID Dmb(VOID) +DEPRECATED VOID Dmb(VOID) { __asm__ __volatile__ ("dmb" : : : "memory"); } -VOID Dsb(VOID) +DEPRECATED VOID Dsb(VOID) { __asm__ __volatile__("dsb" : : : "memory"); } -VOID Isb(VOID) +DEPRECATED VOID Isb(VOID) { __asm__ __volatile__("isb" : : : "memory"); } diff --git a/arch/arm/include/los_exc.h b/arch/arm/include/los_exc.h index 980e7af1..28e83f59 100755 --- a/arch/arm/include/los_exc.h +++ b/arch/arm/include/los_exc.h @@ -183,7 +183,7 @@ extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook); * los_exc.h: the header file that contains the API declaration. * @see None. */ -VOID LOS_Panic(const CHAR *fmt, ...) __attribute__ ((noreturn)); +VOID LOS_Panic(const CHAR *fmt, ...) NORETURN; /** * @ingroup los_exc diff --git a/arch/arm/include/los_hw.h b/arch/arm/include/los_hw.h index ad30d5a1..18f13e43 100755 --- a/arch/arm/include/los_hw.h +++ b/arch/arm/include/los_hw.h @@ -77,134 +77,6 @@ extern UINT64 g_cpuMap[]; #define CPU_MAP_GET(cpuid) g_cpuMap[(cpuid)] #define CPU_MAP_SET(cpuid, hwid) g_cpuMap[(cpuid)] = (hwid) -/** - * @ingroup los_hw - * @brief Set Event. - * - * @par Description: - * - * @attention - * - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see wfe. - */ -extern VOID Sev(VOID); - -/** - * @ingroup los_hw - * @brief Wait for event. - * - * @par Description: - * - * @attention - * - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see sev. - */ -extern VOID Wfe(VOID); - -/** - * @ingroup los_hw - * @brief Wait for interrupt. - * - * @par Description: - * - * @attention None. - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see None. - */ -extern VOID Wfi(VOID); - -/** - * @ingroup los_hw - * @brief Data Memory Barrier. - * - * @par Description: - * - * @attention None. - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see None. - */ -extern VOID Dmb(VOID); - -/** - * @ingroup los_hw - * @brief Data Synchronization Barrier. - * - * @par Description: - * - * @attention None. - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see None. - */ -extern VOID Dsb(VOID); - -/** - * @ingroup los_hw - * @brief Instruction Synchronization Barrier. - * - * @par Description: - * - * @attention None. - * - * @param None. - * - * @retval #None. - * - * @par Dependency: - * los_hw.h: the header file that contains the API declaration. - * @see None. - */ -extern VOID Isb(VOID); - /** * @ingroup los_hw * @brief Invalidate instruction cache. diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c index cf9c9a76..538a2bf3 100755 --- a/compat/posix/src/time.c +++ b/compat/posix/src/time.c @@ -280,7 +280,7 @@ STATIC VOID OsGetHwTime(struct timespec64 *hwTime) { UINT64 nowNsec; - nowNsec = hi_sched_clock(); + nowNsec = LOS_CurrNanosec(); hwTime->tv_sec = nowNsec / OS_SYS_NS_PER_SECOND; hwTime->tv_nsec = nowNsec - hwTime->tv_sec * OS_SYS_NS_PER_SECOND; } @@ -865,8 +865,8 @@ clock_t clock(VOID) clock_t clockMsec; UINT64 nowNsec; - nowNsec = hi_sched_clock(); - clockMsec = (clock_t)(nowNsec / OS_SYS_NS_PER_MS); + nowNsec = LOS_CurrNanosec(); + clockMsec = (clock_t)(nowNsec / (OS_SYS_NS_PER_SECOND / CLOCKS_PER_SEC)); return clockMsec; } diff --git a/drivers/char/random/src/random.c b/drivers/char/random/src/random.c index ef12427a..a0944083 100644 --- a/drivers/char/random/src/random.c +++ b/drivers/char/random/src/random.c @@ -58,7 +58,7 @@ static unsigned long g_seed = 1; int RanOpen(struct file *filep) { - g_seed = (unsigned long)(hi_sched_clock() & 0xffffffff); + g_seed = (unsigned long)(LOS_CurrNanosec() & 0xffffffff); return 0; } diff --git a/kernel/base/core/los_task.c b/kernel/base/core/los_task.c index a90da284..9478d0e0 100755 --- a/kernel/base/core/los_task.c +++ b/kernel/base/core/los_task.c @@ -117,7 +117,7 @@ VOID OsSetMainTask() LITE_OS_SEC_TEXT WEAK VOID OsIdleTask(VOID) { while (1) { - Wfi(); + WFI; } } diff --git a/kernel/base/include/los_vm_iomap.h b/kernel/base/include/los_vm_iomap.h index b10e3462..bf5fea03 100755 --- a/kernel/base/include/los_vm_iomap.h +++ b/kernel/base/include/los_vm_iomap.h @@ -46,11 +46,6 @@ enum DmaMemType { DMA_NOCACHE }; -#define IS_PERIPH_ADDR(addr) \ - (((addr) >= U32_C(PERIPH_PMM_BASE)) && ((addr) <= U32_C(PERIPH_PMM_BASE) + U32_C(PERIPH_PMM_SIZE))) -#define IS_MEMORY_ADDR(addr) \ - (((addr) >= U32_C(DDR_MEM_ADDR)) && ((addr) <= U32_C(DDR_MEM_ADDR) + U32_C(DDR_MEM_SIZE))) - /* thread safety */ VOID *LOS_DmaMemAlloc(DMA_ADDR_T *dmaAddr, size_t size, size_t align, enum DmaMemType type); VOID LOS_DmaMemFree(VOID *vaddr); diff --git a/kernel/base/vm/los_vm_iomap.c b/kernel/base/vm/los_vm_iomap.c index d63284aa..c93d406e 100644 --- a/kernel/base/vm/los_vm_iomap.c +++ b/kernel/base/vm/los_vm_iomap.c @@ -43,114 +43,6 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -VOID *ioremap(PADDR_T paddr, unsigned long size) -{ - if (IS_PERIPH_ADDR(paddr) && IS_PERIPH_ADDR(paddr + size)) { - return (VOID *)(UINTPTR)IO_DEVICE_ADDR(paddr); - } - - VM_ERR("ioremap failed invalid addr or size %p %d", paddr, size); - return (VOID *)(UINTPTR)paddr; -} - -VOID iounmap(VOID *vaddr) {} - -VOID *ioremap_nocache(PADDR_T paddr, unsigned long size) -{ - if (IS_PERIPH_ADDR(paddr) && IS_PERIPH_ADDR(paddr + size)) { - return (VOID *)(UINTPTR)IO_UNCACHED_ADDR(paddr); - } - - if (IS_MEMORY_ADDR(paddr) && IS_MEMORY_ADDR(paddr + size)) { - return (VOID *)(UINTPTR)MEM_UNCACHED_ADDR(paddr); - } - - VM_ERR("ioremap_nocache failed invalid addr or size %p %d", paddr, size); - return (VOID *)(UINTPTR)paddr; -} - -VOID *ioremap_cached(PADDR_T paddr, unsigned long size) -{ - if (IS_PERIPH_ADDR(paddr) && IS_PERIPH_ADDR(paddr + size)) { - return (VOID *)(UINTPTR)IO_CACHED_ADDR(paddr); - } - - if (IS_MEMORY_ADDR(paddr) && IS_MEMORY_ADDR(paddr + size)) { - return (VOID *)(UINTPTR)MEM_CACHED_ADDR(paddr); - } - - VM_ERR("ioremap_cached failed invalid addr or size %p %d", paddr, size); - return (VOID *)(UINTPTR)paddr; -} - -#ifdef LOSCFG_KERNEL_VM -int remap_pfn_range(VADDR_T vaddr, unsigned long pfn, unsigned long size, unsigned long prot) -{ - STATUS_T status = LOS_OK; - int ret; - LosVmMapRegion *region = NULL; - unsigned long vpos; - unsigned long end; - unsigned long paddr = pfn << PAGE_SHIFT; - LosVmSpace *space = LOS_SpaceGet(vaddr); - - if (size == 0) { - VM_ERR("invalid map size %u", size); - return LOS_ERRNO_VM_INVALID_ARGS; - } - size = ROUNDUP(size, PAGE_SIZE); - - if (!IS_PAGE_ALIGNED(vaddr) || pfn == 0) { - VM_ERR("invalid map map vaddr %x or pfn %x", vaddr, pfn); - return LOS_ERRNO_VM_INVALID_ARGS; - } - - if (space == NULL) { - VM_ERR("aspace not exists"); - return LOS_ERRNO_VM_NOT_FOUND; - } - - (VOID)LOS_MuxAcquire(&space->regionMux); - - region = LOS_RegionFind(space, vaddr); - if (region == NULL) { - VM_ERR("region not exists"); - status = LOS_ERRNO_VM_NOT_FOUND; - goto OUT; - } - end = vaddr + size; - if (region->range.base + region->range.size < end) { - VM_ERR("out of range:base=%x size=%d vaddr=%x len=%u", - region->range.base, region->range.size, vaddr, size); - status = LOS_ERRNO_VM_INVALID_ARGS; - goto OUT; - } - - /* check */ - for (vpos = vaddr; vpos < end; vpos += PAGE_SIZE) { - status = LOS_ArchMmuQuery(&space->archMmu, (VADDR_T)vpos, NULL, NULL); - if (status == LOS_OK) { - VM_ERR("remap_pfn_range, address mapping already exist"); - status = LOS_ERRNO_VM_INVALID_ARGS; - goto OUT; - } - } - - /* map all */ - ret = LOS_ArchMmuMap(&space->archMmu, vaddr, paddr, size >> PAGE_SHIFT, prot); - if (ret <= 0) { - VM_ERR("ioremap LOS_ArchMmuMap failed err = %d", ret); - goto OUT; - } - - status = LOS_OK; - -OUT: - (VOID)LOS_MuxRelease(&space->regionMux); - return status; -} -#endif - VOID *LOS_DmaMemAlloc(DMA_ADDR_T *dmaAddr, size_t size, size_t align, enum DmaMemType type) { VOID *kVaddr = NULL; diff --git a/kernel/extended/vdso/src/los_vdso.c b/kernel/extended/vdso/src/los_vdso.c index 378632cb..8275b43f 100755 --- a/kernel/extended/vdso/src/los_vdso.c +++ b/kernel/extended/vdso/src/los_vdso.c @@ -108,12 +108,12 @@ LOCK_RELEASE: STATIC VOID OsLockVdso(VdsoDataPage *vdsoDataPage) { vdsoDataPage->lockCount = 1; - Dmb(); + DMB; } STATIC VOID OsUnlockVdso(VdsoDataPage *vdsoDataPage) { - Dmb(); + DMB; vdsoDataPage->lockCount = 0; } diff --git a/kernel/include/los_base.h b/kernel/include/los_base.h index 436e9419..e72ef1df 100755 --- a/kernel/include/los_base.h +++ b/kernel/include/los_base.h @@ -93,73 +93,73 @@ extern VOID PrintExcInfo(const CHAR *fmt, ...); * @ingroup los_base * Read a UINT8 value from addr and stroed in value. */ -#define READ_UINT8(value, addr) ({ (value) = *((volatile UINT8 *)((UINTPTR)(addr))); Dsb(); }) +#define READ_UINT8(value, addr) ({ (value) = *((volatile UINT8 *)((UINTPTR)(addr))); DSB; }) /** * @ingroup los_base * Read a UINT16 value from addr and stroed in addr. */ -#define READ_UINT16(value, addr) ({ (value) = *((volatile UINT16 *)((UINTPTR)(addr))); Dsb(); }) +#define READ_UINT16(value, addr) ({ (value) = *((volatile UINT16 *)((UINTPTR)(addr))); DSB; }) /** * @ingroup los_base * Read a UINT32 value from addr and stroed in value. */ -#define READ_UINT32(value, addr) ({ (value) = *((volatile UINT32 *)((UINTPTR)(addr))); Dsb(); }) +#define READ_UINT32(value, addr) ({ (value) = *((volatile UINT32 *)((UINTPTR)(addr))); DSB; }) /** * @ingroup los_base * Read a UINT64 value from addr and stroed in value. */ -#define READ_UINT64(value, addr) ({ (value) = *((volatile UINT64 *)((UINTPTR)(addr))); Dsb(); }) +#define READ_UINT64(value, addr) ({ (value) = *((volatile UINT64 *)((UINTPTR)(addr))); DSB; }) /** * @ingroup los_base * Write a UINT8 value to addr. */ -#define WRITE_UINT8(value, addr) ({ Dsb(); *((volatile UINT8 *)((UINTPTR)(addr))) = (value); }) +#define WRITE_UINT8(value, addr) ({ DSB; *((volatile UINT8 *)((UINTPTR)(addr))) = (value); }) /** * @ingroup los_base * Write a UINT16 value to addr. */ -#define WRITE_UINT16(value, addr) ({ Dsb(); *((volatile UINT16 *)((UINTPTR)(addr))) = (value); }) +#define WRITE_UINT16(value, addr) ({ DSB; *((volatile UINT16 *)((UINTPTR)(addr))) = (value); }) /** * @ingroup los_base * Write a UINT32 value to addr. */ -#define WRITE_UINT32(value, addr) ({ Dsb(); *((volatile UINT32 *)((UINTPTR)(addr))) = (value); }) +#define WRITE_UINT32(value, addr) ({ DSB; *((volatile UINT32 *)((UINTPTR)(addr))) = (value); }) /** * @ingroup los_base * Write a UINT64 addr to addr. */ -#define WRITE_UINT64(value, addr) ({ Dsb(); *((volatile UINT64 *)((UINTPTR)(addr))) = (value); }) +#define WRITE_UINT64(value, addr) ({ DSB; *((volatile UINT64 *)((UINTPTR)(addr))) = (value); }) /** * @ingroup los_base * Get a UINT8 value from addr. */ -#define GET_UINT8(addr) ({ UINT8 r = *((volatile UINT8 *)((UINTPTR)(addr))); Dsb(); r; }) +#define GET_UINT8(addr) ({ UINT8 r = *((volatile UINT8 *)((UINTPTR)(addr))); DSB; r; }) /** * @ingroup los_base * Get a UINT16 value from addr. */ -#define GET_UINT16(addr) ({ UINT16 r = *((volatile UINT16 *)((UINTPTR)(addr))); Dsb(); r; }) +#define GET_UINT16(addr) ({ UINT16 r = *((volatile UINT16 *)((UINTPTR)(addr))); DSB; r; }) /** * @ingroup los_base * Get a UINT32 value from addr. */ -#define GET_UINT32(addr) ({ UINT32 r = *((volatile UINT32 *)((UINTPTR)(addr))); Dsb(); r; }) +#define GET_UINT32(addr) ({ UINT32 r = *((volatile UINT32 *)((UINTPTR)(addr))); DSB; r; }) /** * @ingroup los_base * Get a UINT64 value from addr. */ -#define GET_UINT64(addr) ({ UINT64 r = *((volatile UINT64 *)((UINTPTR)(addr))); Dsb(); r; }) +#define GET_UINT64(addr) ({ UINT64 r = *((volatile UINT64 *)((UINTPTR)(addr))); l; r; }) #ifdef LOSCFG_DEBUG_VERSION #define LOS_ASSERT(judge) do { \ diff --git a/kernel/include/los_toolchain.h b/kernel/include/los_toolchain.h index f118498c..a54f00a2 100644 --- a/kernel/include/los_toolchain.h +++ b/kernel/include/los_toolchain.h @@ -73,6 +73,14 @@ extern "C" { #define CLZ(value) (__clz(value)) #endif +#ifndef NORETURN +#define NORETURN __declspec(noreturn) +#endif + +#ifndef DEPRECATED +#define DEPRECATED __attribute__((deprecated)) +#endif + /* for IAR Compiler */ #elif defined ( __ICCARM__ ) @@ -104,6 +112,14 @@ extern "C" { #define CTZ(value) (__UNDEFINED(value)) #endif +#ifndef NORETURN +#define NORETURN __attribute__ ((__noreturn__)) +#endif + +#ifndef DEPRECATED +#define DEPRECATED __attribute__((deprecated)) +#endif + /* for GNU Compiler */ #elif defined ( __GNUC__ ) @@ -135,6 +151,14 @@ extern "C" { #define CTZ(value) (__builtin_ctz(value)) #endif +#ifndef NORETURN +#define NORETURN __attribute__ ((__noreturn__)) +#endif + +#ifndef DEPRECATED +#define DEPRECATED __attribute__((deprecated)) +#endif + #else #error Unknown compiler. #endif -- GitLab