diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-12-13 15:29:23 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-12-13 15:29:23 +0100 |
commit | e9bebe253fdecee009414bdce7ccdfba83f980e6 (patch) | |
tree | 49330d7108869ddfbe8682fb6f20ff79794f57b5 | |
parent | 22f2335259594569ba4a95544939ef72f3d1bb9d (diff) |
add simple cache benchmark application
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | include/esp8266/driver/uptime.h | 13 | ||||
-rw-r--r-- | include/msp430fr5969lp/driver/uptime.h | 5 | ||||
-rw-r--r-- | include/posix/driver/uptime.h | 4 | ||||
-rw-r--r-- | src/app/bench/main.cc | 68 | ||||
-rw-r--r-- | src/arch/esp8266/Makefile.inc | 5 | ||||
-rw-r--r-- | src/arch/esp8266/driver/uptime.cc | 9 | ||||
-rw-r--r-- | src/arch/msp430fr5969lp/Makefile.inc | 5 | ||||
-rw-r--r-- | src/arch/msp430fr5969lp/arch.cc | 19 | ||||
-rw-r--r-- | src/arch/msp430fr5969lp/driver/uptime.cc | 5 | ||||
-rw-r--r-- | src/arch/posix/Makefile.inc | 6 | ||||
-rw-r--r-- | src/arch/posix/driver/uptime.cc | 18 |
12 files changed, 144 insertions, 25 deletions
@@ -7,6 +7,18 @@ CXXFLAGS = -std=c++14 TARGETS = src/app/${app}/main.cc src/os/object/cpp_helpers.cc src/os/object/outputstream.cc +ifeq (${timer_cycles}, 1) + COMMON_FLAGS += -DTIMER_CYCLES +endif + +ifeq (${timer_us}, 1) + COMMON_FLAGS += -DTIMER_US +endif + +ifeq (${timer_s}, 1) + COMMON_FLAGS += -DTIMER_S +endif + ifeq (${loop}, 1) COMMON_FLAGS += -DWITH_LOOP endif diff --git a/include/esp8266/driver/uptime.h b/include/esp8266/driver/uptime.h index 7da10cb..21740c9 100644 --- a/include/esp8266/driver/uptime.h +++ b/include/esp8266/driver/uptime.h @@ -1,6 +1,10 @@ #ifndef UPTIME_H #define UPTIME_H +extern "C" { +#include "osapi.h" +#include "user_interface.h" +} #include "c_types.h" class Uptime { @@ -9,7 +13,14 @@ class Uptime { public: Uptime () {} - uint32_t get(); + inline uint32_t get_us() { return system_get_time(); } + + inline uint32_t get_cycles() + { + uint32_t ccount; + asm volatile ("esync; rsr %0,ccount":"=a" (ccount)); + return ccount; + } }; extern Uptime uptime; diff --git a/include/msp430fr5969lp/driver/uptime.h b/include/msp430fr5969lp/driver/uptime.h index f18a7fe..eaa7203 100644 --- a/include/msp430fr5969lp/driver/uptime.h +++ b/include/msp430fr5969lp/driver/uptime.h @@ -1,6 +1,7 @@ #ifndef UPTIME_H #define UPTIME_H +#include <msp430.h> #include <stdint.h> class Uptime { @@ -9,7 +10,9 @@ class Uptime { public: Uptime () {} - uint32_t get(); + inline uint16_t get_us() { return TA0R; } + inline uint16_t get_s() { return 0; } + inline uint16_t get_cycles() { return TA2R; } }; extern Uptime uptime; diff --git a/include/posix/driver/uptime.h b/include/posix/driver/uptime.h index c92ccf1..93711b9 100644 --- a/include/posix/driver/uptime.h +++ b/include/posix/driver/uptime.h @@ -9,7 +9,9 @@ class Uptime { public: Uptime () {} - uint64_t get(); + uint64_t get_s(); + uint64_t get_us(); + uint64_t get_cycles(); }; extern Uptime uptime; diff --git a/src/app/bench/main.cc b/src/app/bench/main.cc new file mode 100644 index 0000000..cdbc00f --- /dev/null +++ b/src/app/bench/main.cc @@ -0,0 +1,68 @@ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#include "driver/uptime.h" + +#ifndef TIMER_CYCLES +#error makeflag timer_cycles=1 required +#endif + + +/* + * For ESP8266: Flash reads must be 4-Byte-aligned -> uint32_t array + */ + +__attribute__ ((section(".text"))) uint32_t arr[4096]; +//uint32_t arr[1024]; +uint16_t frob; + +inline uint16_t bench_read(uint32_t *arr) +{ + uint16_t ts_pre, ts_post; + ts_pre = uptime.get_cycles(); + frob += *arr; + ts_post = uptime.get_cycles(); + return ts_post - ts_pre; +} + +int main(void) +{ + arch.setup(); + gpio.setup(); + kout.setup(); + + uint16_t ts1 = uptime.get_cycles(); + uint16_t ts2 = uptime.get_cycles(); + uint16_t ts3 = uptime.get_cycles(); + uint16_t ts4 = uptime.get_cycles(); + uint16_t i; + + //for (i = 0; i < 1024; i++) { + // arr[i] = 1; + //} + + gpio.led_on(0); + kout << "Hello, World!" << endl; + kout << "Test, World!" << endl; + kout << dec << ts1 << endl; + kout << dec << ts2 << endl; + kout << dec << ts3 << endl; + kout << dec << ts4 << endl; + + for (int i = 0; i < sizeof(arr) / sizeof(uint32_t); i++) { + kout << i << ": " << bench_read(&arr[i]) << endl; + } + for (signed int i = (sizeof(arr) / sizeof(uint32_t)) - 1; i >= 0; i--) { + kout << i << ": " << bench_read(&arr[i]) << endl; + } + kout << frob << endl; + + arch.idle_loop(); + + //uart_setup(); + //uart_puts("\n" COL_YELLOW "dOS" COL_GREEN " > " COL_RESET); + + //arch_idle_loop(); + + return 0; +} diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index 3b1c8cb..0484985 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -46,4 +46,7 @@ arch_clean: rm -f ${OBJECTS} rm -f build/system.ar -.PHONY: arch_clean program +monitor: + screen /dev/ttyUSB0 115200 + +.PHONY: arch_clean monitor program diff --git a/src/arch/esp8266/driver/uptime.cc b/src/arch/esp8266/driver/uptime.cc index 51cc617..388edb6 100644 --- a/src/arch/esp8266/driver/uptime.cc +++ b/src/arch/esp8266/driver/uptime.cc @@ -1,12 +1,3 @@ #include "driver/uptime.h" -extern "C" { -#include "osapi.h" -#include "user_interface.h" -} - -uint32_t Uptime::get() -{ - return system_get_time(); -} Uptime uptime; diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index 81c8fdf..36d19c6 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -35,4 +35,7 @@ arch_clean: rm -f ${OBJECTS} rm -f build/system.hex -.PHONY: arch_clean program +monitor: + screen /dev/ttyACM1 115200 + +.PHONY: arch_clean monitor program diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc index be821a6..44a22c6 100644 --- a/src/arch/msp430fr5969lp/arch.cc +++ b/src/arch/msp430fr5969lp/arch.cc @@ -38,13 +38,14 @@ void Arch::setup(void) __delay_cycles(1000000); #endif +#ifdef TIMER_US // 16MHz/16 -> ~1MHz timer TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; TA0EX0 = 1; TA0CTL |= TACLR; +#endif -#ifdef WITH_LOOP - +#if defined(WITH_LOOP) || defined(TIMER_S) // 1s per wakeup for loop TA1CTL = TASSEL__ACLK | ID__8 | MC__UP; TA1EX0 = 0; @@ -52,6 +53,12 @@ void Arch::setup(void) TA1CTL |= TACLR | TAIE; #endif +#ifdef TIMER_CYCLES + TA2CTL = TASSEL__SMCLK | ID__1 | MC__CONTINUOUS; + TA2EX0 = 0; + TA2CTL |= TACLR; +#endif + //P1OUT = 0; //P4OUT = 0; } @@ -64,14 +71,20 @@ void Arch::idle_loop(void) Arch arch; -#ifdef WITH_LOOP +#if defined(WITH_LOOP) || defined(TIMER_S) +#include "driver/uptime.h" extern void loop(); __attribute__((interrupt(TIMER1_A1_VECTOR))) __attribute__((wakeup)) void handle_timer0_overflow() { if (TA1IV == 0x0e) { +#ifdef WITH_LOOP loop(); +#endif +#ifdef TIMER_S + uptime.tick_s(); +#endif } } diff --git a/src/arch/msp430fr5969lp/driver/uptime.cc b/src/arch/msp430fr5969lp/driver/uptime.cc index 6d16441..05154f9 100644 --- a/src/arch/msp430fr5969lp/driver/uptime.cc +++ b/src/arch/msp430fr5969lp/driver/uptime.cc @@ -1,9 +1,4 @@ #include "driver/uptime.h" #include <msp430.h> -uint32_t Uptime::get() -{ - return TA0R; -} - Uptime uptime; diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc index 7553fd4..03b6f67 100644 --- a/src/arch/posix/Makefile.inc +++ b/src/arch/posix/Makefile.inc @@ -19,7 +19,11 @@ build/system.elf: ${OBJECTS} run: build/system.elf build/system.elf +monitor: run + +program: run + arch_clean: rm -f ${OBJECTS} -.PHONY: arch_clean program +.PHONY: arch_clean monitor program run diff --git a/src/arch/posix/driver/uptime.cc b/src/arch/posix/driver/uptime.cc index 040b51c..00b1d34 100644 --- a/src/arch/posix/driver/uptime.cc +++ b/src/arch/posix/driver/uptime.cc @@ -1,11 +1,25 @@ #include "driver/uptime.h" #include <time.h> -uint64_t Uptime::get() +uint64_t Uptime::get_s() { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - return (uint64_t)ts.tv_nsec + (1000000ULL * ((uint64_t)ts.tv_sec % 256)); + return ts.tv_sec; +} + +uint64_t Uptime::get_us() +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ts.tv_nsec / 1000; +} + +uint64_t Uptime::get_cycles() +{ + struct timespec ts; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); + return ts.tv_nsec; } Uptime uptime; |