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
This commit is contained in:
Martin Stein 2017-01-04 16:35:04 +01:00 committed by Norman Feske
parent 5aad63c6e8
commit 7bebb9cfb7
13 changed files with 34 additions and 195 deletions

View File

@ -5,7 +5,7 @@
build {
core init
drivers/timer
drivers/sd_card
test/sd_card_bench
}
create_boot_directory

View File

@ -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),

View File

@ -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<Block::Exynos5_driver *>(driver)); }
static_cast<Block::Sdhci_driver *>(driver)); }
} factory { env.ep(), heap };
Regulator::Connection regulator { env, Regulator::CLK_MMC0 };

View File

@ -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),

View File

@ -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<Block::Imx53_driver*>(driver)); }
static_cast<Block::Sdhci_driver*>(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));
}

View File

@ -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 <base/sleep.h>
#include <base/log.h>
#include <timer_session/connection.h>
#include <os/attached_ram_dataspace.h>
/* local includes */
#include <driver.h>
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<char>();
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); }
}

View File

@ -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<void>(),

View File

@ -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<Block::Omap4_driver*>(driver)); }
static_cast<Block::Sdhci_driver*>(driver)); }
} factory { env.ep(), heap };
Block::Root root { env.ep(), heap, factory };

View File

@ -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<void>(),
_delayer, Board_base::SDHCI_IRQ, use_dma, set_voltage),

View File

@ -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,

View File

@ -0,0 +1,3 @@
/*
* Dummy compilation unit needed to link a valid target.
*/

View File

@ -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 ---");
}
};

View File

@ -0,0 +1,3 @@
TARGET = sd_card_bench
LIBS = sd_card_bench
SRC_CC = empty.cc