添加coremark romlib dtest
This commit is contained in:
@@ -15,8 +15,11 @@ ADD_INCLUDE += $(TOPDIR)/plc/halphy/inc $(TOPDIR)/inc/compiler/gcc $(TOPDIR)/com
|
|||||||
PRE_MARCO += _MODULE_NAME_=\"COREMARK\"
|
PRE_MARCO += _MODULE_NAME_=\"COREMARK\"
|
||||||
PRE_MARCO += _MODULE_VERSION_=\"V1.0.0\"
|
PRE_MARCO += _MODULE_VERSION_=\"V1.0.0\"
|
||||||
|
|
||||||
|
OPT_FLAG_ = -Os
|
||||||
LD_SCRIPT = coremark_link_soc.lds
|
LD_SCRIPT = coremark_link_soc.lds
|
||||||
OPT_FLAG = -O3
|
OPT_FLAG = $(OPT_FLAG_) # -fno-default-inline
|
||||||
|
PRE_MARCO += COMPILER_FLAGS=\"$(OPT_FLAG_)\"
|
||||||
|
OUTPUT_NAME = kl3_core_mark$(OPT_FLAG_)
|
||||||
|
|
||||||
ifeq ($(gcc), arm)
|
ifeq ($(gcc), arm)
|
||||||
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/ARM_CM3
|
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/ARM_CM3
|
||||||
|
@@ -27,6 +27,10 @@
|
|||||||
#include "iot_clock.h"
|
#include "iot_clock.h"
|
||||||
#include "clk.h"
|
#include "clk.h"
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
#include "hw_reg_api.h"
|
||||||
|
#include "ahb_rf.h"
|
||||||
|
|
||||||
extern void _start(void);
|
extern void _start(void);
|
||||||
extern void core_main(void);
|
extern void core_main(void);
|
||||||
|
|
||||||
@@ -39,25 +43,95 @@ void delay_us(uint32_t us)
|
|||||||
gp_timer_stop(0);
|
gp_timer_stop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ahb_core0_branch_pred_enable(int enable)
|
||||||
|
{
|
||||||
|
uint32_t tmp;
|
||||||
|
|
||||||
|
tmp = AHB_REG_LITE0_READ_REG(CFG_AHB_CORE0_CFG0_ADDR);
|
||||||
|
REG_FIELD_SET(CORE0_BTB_EB, tmp, enable);
|
||||||
|
AHB_REG_LITE0_WRITE_REG(CFG_AHB_CORE0_CFG0_ADDR, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char g_buff[4096*2] = { 0 };
|
||||||
|
static char g_buff2[4096*2] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void memcpy_test(int times) {
|
||||||
|
uint32_t tick1,tick2;
|
||||||
|
register int var = times;
|
||||||
|
tick1 = gp_timer_get_current_val(0);
|
||||||
|
for (int i = 0;i < var;i++) {
|
||||||
|
memcpy(g_buff, g_buff2, 4096);
|
||||||
|
}
|
||||||
|
tick2 = gp_timer_get_current_val(0);
|
||||||
|
iot_printf("memcpy %d times cost %d us\n", times, tick2 - tick1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void memset_test(int times) {
|
||||||
|
uint32_t tick1,tick2;
|
||||||
|
register int var = times;
|
||||||
|
tick1 = gp_timer_get_current_val(0);
|
||||||
|
for (int i = 0;i < var;i++) {
|
||||||
|
memset(g_buff, 0, 4096);
|
||||||
|
}
|
||||||
|
tick2 = gp_timer_get_current_val(0);
|
||||||
|
iot_printf("memset %d times cost %d us\n", times, tick2 - tick1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 在cpu为150m时
|
||||||
|
// 如果在memcpy之后不使用g_buff,则memcpy 100000次 耗时为 1954000 us
|
||||||
|
// 如果在memcpy之后使用了g_buff,则memcpy 100000次 耗时为 2036668 us
|
||||||
|
// O3优化比O0优化效率低 好像是因为内联了
|
||||||
|
void mem_check() {
|
||||||
|
if (memcmp(g_buff, g_buff2, 4) != 0) {
|
||||||
|
iot_printf("memcopy failed\n");
|
||||||
|
}
|
||||||
|
// memset(g_buff, 0, 4096);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
iot_interrupt_init(0);
|
iot_interrupt_init(0);
|
||||||
|
|
||||||
dbg_uart_init();
|
dbg_uart_init();
|
||||||
|
wdg_deinit(0);
|
||||||
|
wdg_deinit(1);
|
||||||
|
wdg_deinit(2);
|
||||||
|
|
||||||
clk_core_init();
|
clk_core_init();
|
||||||
clk_core_freq_set(CLK_FRQ_150M);
|
clk_core_freq_set(CLK_FRQ_150M);
|
||||||
iot_printf("start\r\n" );
|
iot_printf("start\r\n" );
|
||||||
ahb_core0_set_start((uint32_t) _start);
|
ahb_core0_set_start((uint32_t) _start);
|
||||||
gp_timer_init();
|
gp_timer_init();
|
||||||
|
iot_printf("Compiler flags : %s\n", COMPILER_FLAGS);
|
||||||
|
iot_printf("cpu clk frq : %d\n", CLK_FRQ_150M);
|
||||||
|
|
||||||
// int t = 0;
|
gp_timer_set(0, 0xffffffff, 1);
|
||||||
// while (1) {
|
gp_timer_start(0);
|
||||||
// iot_printf("%d\r\n", t++);
|
memset(g_buff2, 0xff, 4096);
|
||||||
// delay_us(1000000);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
ahb_core0_branch_pred_enable(1);
|
||||||
|
iot_printf("branch prediction on\n");
|
||||||
|
memcpy_test(100000);
|
||||||
|
mem_check();
|
||||||
|
|
||||||
|
iot_printf("\n");
|
||||||
|
|
||||||
|
ahb_core0_branch_pred_enable(0);
|
||||||
|
iot_printf("branch prediction off\n");
|
||||||
|
memcpy_test(100000);
|
||||||
|
mem_check();
|
||||||
|
|
||||||
|
ahb_core0_branch_pred_enable(1);
|
||||||
|
iot_printf("branch prediction on\n");
|
||||||
|
core_main();
|
||||||
|
iot_printf("\n");
|
||||||
|
|
||||||
|
ahb_core0_branch_pred_enable(0);
|
||||||
|
iot_printf("branch prediction off\n");
|
||||||
core_main();
|
core_main();
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
|
63
dtest/dtest3/romlib_test/Makefile
Normal file
63
dtest/dtest3/romlib_test/Makefile
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
# OUTPUT type
|
||||||
|
# 1 - .out
|
||||||
|
# 2 - .a
|
||||||
|
# 3 - .so
|
||||||
|
OUTPUT_TYPE = 1
|
||||||
|
OUTPUT_NAME = kl3_romlib_test
|
||||||
|
|
||||||
|
#SUB_DIRS = $(TOPDIR)/common/os_shim/dtestos
|
||||||
|
SUB_DIRS = $(TOPDIR)/dtest/dtest3/common
|
||||||
|
|
||||||
|
# .h files dir
|
||||||
|
ADD_INCLUDE += $(TOPDIR)/plc/halphy/inc $(TOPDIR)/inc/compiler/gcc $(TOPDIR)/common/io_lib/inc $(TOPDIR)/inc $(TOPDIR)/inc/io_lib $(TOPDIR)/inc/driver $(TOPDIR)/inc/uart $(TOPDIR)/inc/plc_lib $(TOPDIR)/inc/ipc $(TOPDIR)/inc/os_shim $(TOPDIR)/inc/pkt $(TOPDIR)/inc/utils $(TOPDIR)/plc/inc $(TOPDIR)/inc/cli $(TOPDIR)/cli/communicator $(TOPDIR)/inc/dbglog $(TOPDIR)/inc/ftm $(TOPDIR)/plc/halmac/inc $(TOPDIR)/plc/halmac/hw/inc/desc $(TOPDIR)/driver/inc $(TOPDIR)/driver/inc/pib
|
||||||
|
|
||||||
|
PRE_MARCO += _MODULE_NAME_=\"LEDC\" _MODULE_VERSION_=\"V1.0.0\"
|
||||||
|
|
||||||
|
LD_SCRIPT = link_soc.lds
|
||||||
|
OPT_FLAG = -Os -Wno-error=int-conversion
|
||||||
|
|
||||||
|
ifeq ($(gcc), arm)
|
||||||
|
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/ARM_CM3
|
||||||
|
else
|
||||||
|
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/RISCV $(TOPDIR)/dtest/dtest3/common
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(gcc),arm)
|
||||||
|
ADD_LIB = cm3
|
||||||
|
ADD_LIBDIR = $(TOPDIR)/startup/cm3
|
||||||
|
else
|
||||||
|
ifeq ($(target), kunlun3)
|
||||||
|
ADD_LIB = riscv
|
||||||
|
ADD_LIBDIR =$(TOPDIR)/startup/riscv3
|
||||||
|
ADD_INCLUDE += $(TOPDIR)/driver/src/hw3/inc
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# lib dir
|
||||||
|
ADD_LIBDIR += $(TOPDIR)/driver $(TOPDIR)/common $(TOPDIR)/os
|
||||||
|
# lib need to ld together
|
||||||
|
ADD_LIB += os driver common
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
|
||||||
|
ifdef TOPDIR
|
||||||
|
include $(TOPDIR)/build/makefile.cfg
|
||||||
|
else
|
||||||
|
include $(CURDIR)/build/makefile.cfg
|
||||||
|
TOPDIR = $(CURDIR)
|
||||||
|
export TOPDIR
|
||||||
|
endif
|
||||||
|
|
||||||
|
dump:
|
||||||
|
$(OBJDUMP) -D -S -l $(OUTPUT_FULL_NAME) > $(OUTPUT_FULL_NAME).dump
|
||||||
|
|
||||||
|
# display the obj files and output name
|
||||||
|
debug:
|
||||||
|
@echo TOPDIR=$(TOPDIR)
|
||||||
|
@echo OUTPUT_LIB=$(OUTPUT_FULL_NAME)
|
||||||
|
@echo DEPS=$(DEPS)
|
||||||
|
@echo OBJECTS=$(OBJECTS)
|
||||||
|
@echo SRCS=$(SRCS)
|
||||||
|
@echo OBJECTS folder=$(foreach dirname, $(SUB_DIRS), $(addprefix $(BIN_DIR)/, $(dirname)))
|
||||||
|
@echo output_name=$(OUTPUT_FULL_NAME)
|
140
dtest/dtest3/romlib_test/romlib_test.c
Normal file
140
dtest/dtest3/romlib_test/romlib_test.c
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
|
||||||
|
#include "os_types.h"
|
||||||
|
#include "dbg_io.h"
|
||||||
|
#include "iot_io.h"
|
||||||
|
#include "cpu.h"
|
||||||
|
#include "watchdog.h"
|
||||||
|
// #include "platform.h"
|
||||||
|
#include "iot_gptmr_api.h"
|
||||||
|
#include "iot_clock.h"
|
||||||
|
#include "clk.h"
|
||||||
|
#include "strformat.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
typedef int (*iot_sprintf_t)(char* str, const char* format, ...);
|
||||||
|
typedef int (*iot_snprintf_t)(char* str, size_t size, const char* format, ...);
|
||||||
|
typedef int (*iot_vsnprintf_t)(char* str, size_t size, const char* format, va_list ap);
|
||||||
|
typedef int32_t (*iot_printf_t)(const char* fmt, ...);
|
||||||
|
|
||||||
|
typedef int (*format_str_t)(const str_format_context* ctxt, const char* format, ...);
|
||||||
|
typedef int (*format_str_v_t)(const str_format_context* ctxt, const char* format, va_list ap);
|
||||||
|
|
||||||
|
typedef void* (*memmove_t)(void* dest, const void* src, size_t n);
|
||||||
|
|
||||||
|
iot_sprintf_t rom_iot_sprintf;
|
||||||
|
iot_snprintf_t rom_iot_snprintf;
|
||||||
|
iot_vsnprintf_t rom_iot_vsnprintf;
|
||||||
|
iot_printf_t rom_iot_printf;
|
||||||
|
iot_printf_t dtest_iot_printf;
|
||||||
|
format_str_t rom_format_str;
|
||||||
|
format_str_v_t rom_format_str_v;
|
||||||
|
str_format_context* rom_log_ctxt;
|
||||||
|
extern struct uart_ctrl uart_e_ctrl;
|
||||||
|
|
||||||
|
memmove_t rom_memmove;
|
||||||
|
|
||||||
|
#define PROVIDE(s) rom_##s
|
||||||
|
|
||||||
|
#define PUT_PORT 0
|
||||||
|
|
||||||
|
static void uart_flush(void)
|
||||||
|
{
|
||||||
|
while (uart_e_ctrl.tx_fifo_cnt(PUT_PORT)) __asm volatile("nop\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static StrFormatResult uart_puts(void *user_data, const char *data, unsigned int len)
|
||||||
|
{
|
||||||
|
(void)user_data;
|
||||||
|
uint8_t c;
|
||||||
|
int i = 0;
|
||||||
|
while (i < len) {
|
||||||
|
c = *(data+i);
|
||||||
|
if (c == '\n'){
|
||||||
|
uart_e_ctrl.try_putc(PUT_PORT,'\r');
|
||||||
|
}
|
||||||
|
uart_e_ctrl.try_putc(PUT_PORT,c);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
uart_flush();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rom_iot_vsnprintf_test(char *str, size_t size, const char *format, ...)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
res = rom_iot_vsnprintf(str, size, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic ignored "-Wint-conversion"
|
||||||
|
void fun_pointer_init() {
|
||||||
|
PROVIDE(iot_sprintf = 0x0004455e);
|
||||||
|
PROVIDE(iot_printf = 0x00044616);
|
||||||
|
PROVIDE(iot_snprintf = 0x000445f6);
|
||||||
|
PROVIDE(iot_vsnprintf = 0x000445ca);
|
||||||
|
PROVIDE(log_ctxt = 0x100005a4);
|
||||||
|
PROVIDE(format_str = 0x0004451e);
|
||||||
|
PROVIDE(format_str_v = 0x0004451e);
|
||||||
|
PROVIDE(memmove = 0x0004654e);
|
||||||
|
rom_log_ctxt->write_str = uart_puts;
|
||||||
|
dtest_iot_printf = (int)&iot_printf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rom_format_str_v_test(const char *format, ...)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
res = rom_format_str_v(rom_log_ctxt, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char g_buff[1024];
|
||||||
|
static char g_buff2[1024];
|
||||||
|
int main(void) {
|
||||||
|
iot_interrupt_init();
|
||||||
|
dbg_uart_init();
|
||||||
|
clk_core_init();
|
||||||
|
clk_core_freq_set(CLK_FRQ_150M);
|
||||||
|
fun_pointer_init();
|
||||||
|
|
||||||
|
|
||||||
|
iot_printf("print by iot_printf()\n");
|
||||||
|
|
||||||
|
dtest_iot_printf("print by dtest_iot_printf()\n");
|
||||||
|
|
||||||
|
iot_snprintf(g_buff, 1024, "print by iot_snprintf()\n");
|
||||||
|
iot_printf("%s", g_buff);
|
||||||
|
|
||||||
|
rom_iot_snprintf(g_buff, 1024, "print by rom_iot_snprintf()\n");
|
||||||
|
iot_printf("%s", g_buff);
|
||||||
|
|
||||||
|
rom_iot_vsnprintf_test(g_buff, 1024, "print by rom_iot_vsnprintf()\n");
|
||||||
|
iot_printf("%s", g_buff);
|
||||||
|
|
||||||
|
iot_printf("rom_iot_printf() test\n");
|
||||||
|
rom_iot_printf("print by rom_iot_printf()\n");
|
||||||
|
|
||||||
|
iot_printf("rom_format_str() test\n");
|
||||||
|
rom_format_str(rom_log_ctxt, "print by rom_format_str()\n");
|
||||||
|
|
||||||
|
iot_printf("rom_format_str_v() test\n");
|
||||||
|
rom_format_str_v_test("print by rom_format_str_v()\n");
|
||||||
|
|
||||||
|
iot_printf("print test end\n");
|
||||||
|
|
||||||
|
memmove(g_buff, g_buff2, 1024);
|
||||||
|
iot_printf("%s", g_buff);
|
||||||
|
rom_memmove(g_buff, "print by rom_memmove()\n", 24);
|
||||||
|
iot_printf("%s", g_buff);
|
||||||
|
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user