diff --git a/repos/os/run/cache.run b/repos/os/run/cache.run new file mode 100644 index 0000000000..a7b4f72225 --- /dev/null +++ b/repos/os/run/cache.run @@ -0,0 +1,49 @@ +# +# \brief Simple cache benchmark +# \author Johannes Schlatow +# + + +set build_components { core init test/cache } + +lappend_if [have_spec arndale] build_components drivers/platform + +build $build_components + +create_boot_directory + +set config { + + + + + + + + + + + + } + +append_if [have_spec arndale] config { + + + + } + +append config { + + + + } + +install_config $config + +set boot_modules { core ld.lib.so init test-cache } + +lappend_if [have_spec arndale] boot_modules platform_drv + +build_boot_image $boot_modules + +run_genode_until "done.*\n" 300 diff --git a/repos/os/src/test/cache/main.cc b/repos/os/src/test/cache/main.cc new file mode 100644 index 0000000000..24a82fa821 --- /dev/null +++ b/repos/os/src/test/cache/main.cc @@ -0,0 +1,107 @@ +/* + * \brief Test for cache performance + * \author Johannes Schlatow + * \date 2019-05-02 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Genode includes */ +#include +#include +#include +#include + +using namespace Genode::Trace; + +class Test +{ + private: + Genode::Heap &_alloc; + Genode::size_t _size; + + unsigned *_data { 0 }; + + Timestamp ts_to_time(Timestamp start, Timestamp end) + { + Timestamp diff = end - start; + if (end < start) diff--; + + return diff; + } + + Test(const Test &); + void operator=(const Test&); + + public: + + Test(Genode::Heap &alloc, Genode::size_t size_bytes) + : _alloc(alloc), + _size(size_bytes/sizeof(unsigned)) + { + _data = new (_alloc) unsigned[_size]; + } + + ~Test() + { + destroy(_alloc, _data); + } + + Timestamp read_write(unsigned iterations=100) + { + Timestamp start_ts = timestamp(); + + for (Genode::size_t i=0; i < iterations; i++) { + for (Genode::size_t index=0; index < _size; index++) { + _data[index]++; + } + } + + return ts_to_time(start_ts, timestamp()) / iterations; + } +}; + +struct Main +{ + Genode::Env &env; + + Genode::Heap heap { env.ram(), env.rm() }; + + Main(Genode::Env &env); +}; + + +Main::Main(Genode::Env &env) : env(env) +{ + using namespace Genode; + + log("--- test-cache started ---"); + + enum { + START_SIZE = 8, + END_SIZE = 1024 * 4, + THRESHOLD_PERCENT = 10, + }; + + size_t size = START_SIZE; + while (size <= END_SIZE) + { + log("\n--- Running tests for size ", size, "KB ---"); + + Test test(heap, size*1024); + log("Read/write: ", test.read_write() / size, " cycles on average per KB"); + + size = size << 1; + } + + log("--- test-cache done ---"); +} + +void Component::construct(Genode::Env &env) { static Main inst(env); } +Genode::size_t Component::stack_size() { return 32*1024*sizeof(long); } + diff --git a/repos/os/src/test/cache/target.mk b/repos/os/src/test/cache/target.mk new file mode 100644 index 0000000000..b1158d9aee --- /dev/null +++ b/repos/os/src/test/cache/target.mk @@ -0,0 +1,3 @@ +TARGET = test-cache +SRC_CC = main.cc +LIBS = base