From 7bebb9cfb7dd80ed635968dba68efea707b42197 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 4 Jan 2017 16:35:04 +0100 Subject: [PATCH] sd_card_bench: make generic + move to os/src/test The test was previously implemented platform specific in sub-dirs of drivers/sd_card. Ref #2206 --- repos/os/run/sd_card_bench.run | 2 +- .../src/drivers/sd_card/spec/exynos5/driver.h | 6 +- .../src/drivers/sd_card/spec/exynos5/main.cc | 4 +- .../src/drivers/sd_card/spec/imx53/driver.h | 6 +- .../os/src/drivers/sd_card/spec/imx53/main.cc | 6 +- .../drivers/sd_card/spec/omap4/bench/main.cc | 168 ------------------ .../src/drivers/sd_card/spec/omap4/driver.h | 6 +- .../os/src/drivers/sd_card/spec/omap4/main.cc | 4 +- .../os/src/drivers/sd_card/spec/rpi/driver.h | 2 +- repos/os/src/drivers/sd_card/spec/rpi/main.cc | 2 +- repos/os/src/test/sd_card_bench/empty.cc | 3 + .../bench => test/sd_card_bench}/main.cc | 17 +- repos/os/src/test/sd_card_bench/target.mk | 3 + 13 files changed, 34 insertions(+), 195 deletions(-) delete mode 100644 repos/os/src/drivers/sd_card/spec/omap4/bench/main.cc create mode 100644 repos/os/src/test/sd_card_bench/empty.cc rename repos/os/src/{drivers/sd_card/spec/imx53/bench => test/sd_card_bench}/main.cc (93%) create mode 100644 repos/os/src/test/sd_card_bench/target.mk diff --git a/repos/os/run/sd_card_bench.run b/repos/os/run/sd_card_bench.run index e498d97053..d96991cc5e 100644 --- a/repos/os/run/sd_card_bench.run +++ b/repos/os/run/sd_card_bench.run @@ -5,7 +5,7 @@ build { core init drivers/timer - drivers/sd_card + test/sd_card_bench } create_boot_directory diff --git a/repos/os/src/drivers/sd_card/spec/exynos5/driver.h b/repos/os/src/drivers/sd_card/spec/exynos5/driver.h index 47fbd7cb06..a12192ce54 100644 --- a/repos/os/src/drivers/sd_card/spec/exynos5/driver.h +++ b/repos/os/src/drivers/sd_card/spec/exynos5/driver.h @@ -26,11 +26,11 @@ namespace Block { using namespace Genode; - class Exynos5_driver; + class Sdhci_driver; } -class Block::Exynos5_driver : public Block::Driver +class Block::Sdhci_driver : public Block::Driver { private: @@ -67,7 +67,7 @@ class Block::Exynos5_driver : public Block::Driver public: - Exynos5_driver(Server::Entrypoint &ep, bool use_dma) + Sdhci_driver(Server::Entrypoint &ep, bool use_dma) : _ep(ep), _mmio(MSH_BASE, MSH_SIZE), diff --git a/repos/os/src/drivers/sd_card/spec/exynos5/main.cc b/repos/os/src/drivers/sd_card/spec/exynos5/main.cc index ffc1dcbecf..64bb13cf94 100644 --- a/repos/os/src/drivers/sd_card/spec/exynos5/main.cc +++ b/repos/os/src/drivers/sd_card/spec/exynos5/main.cc @@ -34,11 +34,11 @@ struct Main : ep(ep), heap(heap) { } Block::Driver *create() { - return new (&heap) Block::Exynos5_driver(ep, true); } + return new (&heap) Block::Sdhci_driver(ep, true); } void destroy(Block::Driver *driver) { Genode::destroy(&heap, - static_cast(driver)); } + static_cast(driver)); } } factory { env.ep(), heap }; Regulator::Connection regulator { env, Regulator::CLK_MMC0 }; diff --git a/repos/os/src/drivers/sd_card/spec/imx53/driver.h b/repos/os/src/drivers/sd_card/spec/imx53/driver.h index 4b89993a9c..caef1d6491 100644 --- a/repos/os/src/drivers/sd_card/spec/imx53/driver.h +++ b/repos/os/src/drivers/sd_card/spec/imx53/driver.h @@ -27,11 +27,11 @@ namespace Block { using namespace Genode; - class Imx53_driver; + class Sdhci_driver; } -class Block::Imx53_driver : public Block::Driver +class Block::Sdhci_driver : public Block::Driver { private: @@ -50,7 +50,7 @@ class Block::Imx53_driver : public Block::Driver public: - Imx53_driver(bool use_dma) + Sdhci_driver(Entrypoint &, bool use_dma) : _esdhcv2_1_mmio(Genode::Board_base::ESDHCV2_1_MMIO_BASE, Genode::Board_base::ESDHCV2_1_MMIO_SIZE), diff --git a/repos/os/src/drivers/sd_card/spec/imx53/main.cc b/repos/os/src/drivers/sd_card/spec/imx53/main.cc index 8b600e3ee9..16e93b6a67 100644 --- a/repos/os/src/drivers/sd_card/spec/imx53/main.cc +++ b/repos/os/src/drivers/sd_card/spec/imx53/main.cc @@ -33,18 +33,18 @@ struct Main : ep(ep), heap(heap) { } Block::Driver *create() { - return new (&heap) Block::Imx53_driver(true); } + return new (&heap) Block::Sdhci_driver(ep, true); } void destroy(Block::Driver *driver) { Genode::destroy(&heap, - static_cast(driver)); } + static_cast(driver)); } } factory { env.ep(), heap }; Block::Root root { env.ep(), heap, factory }; Main(Genode::Env &env) : env(env) { - Genode::log("--- Imx53 SD card driver ---"); + Genode::log("--- SD card driver ---"); env.parent().announce(env.ep().manage(root)); } diff --git a/repos/os/src/drivers/sd_card/spec/omap4/bench/main.cc b/repos/os/src/drivers/sd_card/spec/omap4/bench/main.cc deleted file mode 100644 index 56532c73da..0000000000 --- a/repos/os/src/drivers/sd_card/spec/omap4/bench/main.cc +++ /dev/null @@ -1,168 +0,0 @@ -/* - * \brief SD-card benchmark OMAP4 platform - * \author Norman Feske - * \date 2012-07-19 - */ - -/* - * Copyright (C) 2012-2015 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include -#include -#include -#include - -/* local includes */ -#include - - -struct Operation -{ - virtual void operator () (Block::Driver &driver, - Genode::addr_t block_number, - Genode::size_t block_count, - Genode::addr_t buffer_phys, - char *buffer_virt) = 0; -}; - - -/* - * \param total_size total number of bytes to read - * \param request_size number of bytes per request - */ -static void run_benchmark(Block::Driver &driver, - Timer::Session &timer, - char *buffer_virt, - Genode::addr_t buffer_phys, - Genode::size_t buffer_size, - Genode::size_t request_size, - Operation &operation) -{ - using namespace Genode; - - log("request_size=", request_size, " bytes"); - - size_t const time_before_ms = timer.elapsed_ms(); - - size_t num_requests = buffer_size / request_size; - - for (size_t i = 0; i < num_requests; i++) - { - size_t const block_count = request_size / driver.block_size(); - addr_t const block_number = i*block_count; - - operation(driver, block_number, block_count, - buffer_phys + i*request_size, - buffer_virt + i*request_size); - } - - size_t const time_after_ms = timer.elapsed_ms(); - size_t const duration_ms = time_after_ms - time_before_ms; - - /* - * Convert bytes per milliseconds to kilobytes per seconds - * - * (total_size / 1024) / (duration_ms / 1000) - */ - size_t const buffer_size_kb = buffer_size / 1024; - size_t const throughput_kb_per_sec = (1000*buffer_size_kb) / duration_ms; - - log(" -> duration: ", duration_ms, " ms"); - log(" throughput: ", throughput_kb_per_sec, " KiB/sec"); -} - - -struct Main -{ - Main(Server::Entrypoint &ep) - { - using namespace Genode; - - log("--- OMAP4 SD card benchmark ---"); - - bool const use_dma = false; - - static Block::Omap4_driver driver(use_dma); - - static Timer::Connection timer; - - long const request_sizes[] = { - 512, 1024, 2048, 4096, 8192, 16384, 32768, 64*1024, 128*1024, 0 }; - - /* total size of communication buffer */ - size_t const buffer_size = 10*1024*1024; - - /* allocate read/write buffer */ - static Attached_ram_dataspace buffer(env()->ram_session(), buffer_size, Genode::UNCACHED); - char * const buffer_virt = buffer.local_addr(); - addr_t const buffer_phys = Dataspace_client(buffer.cap()).phys_addr(); - - /* - * Benchmark reading from SD card - */ - - log("\n-- reading from SD card --"); - - struct Read : Operation - { - void operator () (Block::Driver &driver, - addr_t number, size_t count, addr_t phys, char *virt) - { - Block::Packet_descriptor p; - if (driver.dma_enabled()) - driver.read_dma(number, count, phys, p); - else - driver.read(number, count, virt, p); - } - } read_operation; - - for (unsigned i = 0; request_sizes[i]; i++) - run_benchmark(driver, timer, buffer_virt, buffer_phys, buffer_size, - request_sizes[i], read_operation); - - /* - * Benchmark writing to SD card - * - * We write back the content of the buffer, which we just filled during the - * read benchmark. If both read and write succeed, the SD card will retain - * its original content. - */ - - log("\n-- writing to SD card --"); - - struct Write : Operation - { - void operator () (Block::Driver &driver, - addr_t number, size_t count, addr_t phys, char *virt) - { - Block::Packet_descriptor p; - if (driver.dma_enabled()) - driver.write_dma(number, count, phys, p); - else - driver.write(number, count, virt, p); - } - } write_operation; - - for (unsigned i = 0; request_sizes[i]; i++) - run_benchmark(driver, timer, buffer_virt, buffer_phys, buffer_size, - request_sizes[i], write_operation); - - log("\n--- OMAP4 SD card benchmark finished ---"); - } -}; - - -/************ - ** Server ** - ************/ - -namespace Server { - char const *name() { return "sd_card_bench_ep"; } - size_t stack_size() { return 16*1024*sizeof(long); } - void construct(Entrypoint &ep) { static Main server(ep); } -} diff --git a/repos/os/src/drivers/sd_card/spec/omap4/driver.h b/repos/os/src/drivers/sd_card/spec/omap4/driver.h index 37cebc87f8..2aca791a55 100644 --- a/repos/os/src/drivers/sd_card/spec/omap4/driver.h +++ b/repos/os/src/drivers/sd_card/spec/omap4/driver.h @@ -26,11 +26,11 @@ namespace Block { using namespace Genode; - class Omap4_driver; + class Sdhci_driver; } -class Block::Omap4_driver : public Block::Driver +class Block::Sdhci_driver : public Block::Driver { private: @@ -58,7 +58,7 @@ class Block::Omap4_driver : public Block::Driver public: - Omap4_driver(bool use_dma) + Sdhci_driver(Entrypoint &, bool use_dma) : _mmchs1_mmio(MMCHS1_MMIO_BASE, MMCHS1_MMIO_SIZE), _controller((addr_t)_mmchs1_mmio.local_addr(), diff --git a/repos/os/src/drivers/sd_card/spec/omap4/main.cc b/repos/os/src/drivers/sd_card/spec/omap4/main.cc index 307aa5bf30..17ea313cbf 100644 --- a/repos/os/src/drivers/sd_card/spec/omap4/main.cc +++ b/repos/os/src/drivers/sd_card/spec/omap4/main.cc @@ -33,11 +33,11 @@ struct Main : ep(ep), heap(heap) { } Block::Driver *create() { - return new (&heap) Block::Omap4_driver(true); } + return new (&heap) Block::Sdhci_driver(ep, true); } void destroy(Block::Driver *driver) { Genode::destroy(&heap, - static_cast(driver)); } + static_cast(driver)); } } factory { env.ep(), heap }; Block::Root root { env.ep(), heap, factory }; diff --git a/repos/os/src/drivers/sd_card/spec/rpi/driver.h b/repos/os/src/drivers/sd_card/spec/rpi/driver.h index 90bbfe27af..0ae95a8cd1 100644 --- a/repos/os/src/drivers/sd_card/spec/rpi/driver.h +++ b/repos/os/src/drivers/sd_card/spec/rpi/driver.h @@ -54,7 +54,7 @@ class Block::Sdhci_driver : public Block::Driver public: - Sdhci_driver(bool use_dma, const bool set_voltage = false) + Sdhci_driver(Entrypoint &, bool use_dma, const bool set_voltage = false) : _controller((addr_t)_sdhci_mmio.local_addr(), _delayer, Board_base::SDHCI_IRQ, use_dma, set_voltage), diff --git a/repos/os/src/drivers/sd_card/spec/rpi/main.cc b/repos/os/src/drivers/sd_card/spec/rpi/main.cc index 54241f1d05..6b2da02ace 100644 --- a/repos/os/src/drivers/sd_card/spec/rpi/main.cc +++ b/repos/os/src/drivers/sd_card/spec/rpi/main.cc @@ -35,7 +35,7 @@ struct Main : ep(ep), heap(heap) { } Block::Driver *create() { - return new (&heap) Block::Sdhci_driver(false); } + return new (&heap) Block::Sdhci_driver(ep, false); } void destroy(Block::Driver *driver) { Genode::destroy(&heap, diff --git a/repos/os/src/test/sd_card_bench/empty.cc b/repos/os/src/test/sd_card_bench/empty.cc new file mode 100644 index 0000000000..066c1bf825 --- /dev/null +++ b/repos/os/src/test/sd_card_bench/empty.cc @@ -0,0 +1,3 @@ +/* + * Dummy compilation unit needed to link a valid target. + */ diff --git a/repos/os/src/drivers/sd_card/spec/imx53/bench/main.cc b/repos/os/src/test/sd_card_bench/main.cc similarity index 93% rename from repos/os/src/drivers/sd_card/spec/imx53/bench/main.cc rename to repos/os/src/test/sd_card_bench/main.cc index d9aa2afdcb..03e71fa1b5 100644 --- a/repos/os/src/drivers/sd_card/spec/imx53/bench/main.cc +++ b/repos/os/src/test/sd_card_bench/main.cc @@ -1,11 +1,12 @@ /* - * \brief SD-card benchmark Imx53 platform + * \brief SD-card benchmark + * \author Norman Feske * \author Martin Stein - * \date 2015-03-04 + * \date 2012-07-19 */ /* - * Copyright (C) 2012-2015 Genode Labs GmbH + * Copyright (C) 2012-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -55,8 +56,8 @@ static void run_benchmark(Block::Driver &driver, /* * Trim number of requests if it would take to much time */ - if (num_requests > 1280) { - buffer_size = 1280 * request_size; + if (num_requests > 320) { + buffer_size = 320 * request_size; num_requests = buffer_size / request_size; } @@ -93,11 +94,11 @@ struct Main { using namespace Genode; - log("--- i.MX53 SD card benchmark ---"); + log("--- SD card benchmark ---"); bool const use_dma = true; - static Block::Imx53_driver driver(use_dma); + static Block::Sdhci_driver driver(ep, use_dma); static Timer::Connection timer; @@ -163,7 +164,7 @@ struct Main run_benchmark(driver, timer, buffer_virt, buffer_phys, buffer_size, request_sizes[i], write_operation); - log("\n--- i.MX53 SD card benchmark finished ---"); + log("\n--- SD card benchmark finished ---"); } }; diff --git a/repos/os/src/test/sd_card_bench/target.mk b/repos/os/src/test/sd_card_bench/target.mk new file mode 100644 index 0000000000..727948d36c --- /dev/null +++ b/repos/os/src/test/sd_card_bench/target.mk @@ -0,0 +1,3 @@ +TARGET = sd_card_bench +LIBS = sd_card_bench +SRC_CC = empty.cc