Commit e9bebe25 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add simple cache benchmark application

parent 22f23352
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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
+12 −1
Original line number Diff line number Diff line
#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;
+4 −1
Original line number Diff line number Diff line
#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;
+3 −1
Original line number Diff line number Diff line
@@ -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;

src/app/bench/main.cc

0 → 100644
+68 −0
Original line number Diff line number Diff line
#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;
}
Loading