aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2011-01-04 17:58:42 +0100
committerArnd Bergmann <arnd@arndb.de>2011-01-04 17:58:42 +0100
commiteb050cc1b46c6fed0db61f2f5fb7b50afa87153f (patch)
tree484922a7013bd26c2301b8a8794f1423060a8298
parentc95ea1903edac9851a976a2bb0e35037b66020a5 (diff)
flashbench: interface main program with vm
Finally, we can actually read from the device to do measurements with the vm. Start with a simple test case using the '-p' option in the main flashbench. Signed-off-by: Arnd Bergmann <arnd@arndb.de>
-rw-r--r--Makefile10
-rw-r--r--flashbench.c61
-rw-r--r--vm.c55
-rw-r--r--vm.h1
4 files changed, 81 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index eb5af93..c5ac438 100644
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,13 @@ CC := gcc
CFLAGS := -O2 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -g2
LDFLAGS := -lrt
-all: flashbench vm
+all: flashbench
-flashbench: flashbench.o dev.o
+dev.o: dev.c dev.h
+vm.o: vm.c vm.h dev.h
+flashbench.o: flashbench.c vm.h dev.h
-vm: vm.o dev.o
+flashbench: flashbench.o dev.o vm.o
clean:
- rm flashbench vm
+ rm flashbench flashbench.o dev.o vm.o
diff --git a/flashbench.c b/flashbench.c
index 7a9b6d9..ccdb715 100644
--- a/flashbench.c
+++ b/flashbench.c
@@ -15,6 +15,7 @@
#include <stdbool.h>
#include "dev.h"
+#include "vm.h"
typedef long long ns_t;
@@ -411,6 +412,51 @@ static int try_read_alignments(struct device *dev, int tries, int blocksize)
return 0;
}
+static int try_program(struct device *dev)
+{
+#if 0
+ struct operation program[] = {
+ {O_REPEAT, 4},
+ {O_SEQUENCE, 3},
+ {O_PRINT, .string = "Hello, World!\n"},
+ {O_DROP},
+ {O_PRINTF},
+ {O_FORMAT},
+ {O_REDUCE, 8, .aggregate = A_AVERAGE},
+ {O_LEN_POW2, 8, 512},
+ {O_OFF_LIN, 8, 4096 },
+ {O_SEQUENCE, 3},
+ {O_PRINTF},
+ {O_READ},
+ {O_NEWLINE},
+ {O_DROP},
+ {O_READ},
+ {O_END},
+ {O_NEWLINE},
+ {O_END},
+ {O_END},
+ };
+#endif
+
+ struct operation program[] = {
+ {O_SEQUENCE, 3},
+ {O_PRINT, .string="read by size\n"},
+ {O_PRINTF},
+ {O_FORMAT},
+ {O_LEN_POW2, 12, 512},
+ {O_REDUCE, .aggregate = A_MINIMUM},
+ {O_OFF_LIN, 128, 4096 * 1024},
+ {O_READ},
+ {O_NEWLINE},
+ {O_END},
+ {O_END},
+ };
+
+ call(program, dev, 0, 4096 * 1024, 1);
+
+ return 0;
+}
+
static void print_help(const char *name)
{
printf("%s [OPTION]... [DEVICE]\n", name);
@@ -426,7 +472,7 @@ static void print_help(const char *name)
struct arguments {
const char *dev;
const char *out;
- bool scatter, rcache, align, interval;
+ bool scatter, rcache, align, interval, program;
int verbosity;
int count;
int blocksize;
@@ -461,7 +507,7 @@ static int parse_arguments(int argc, char **argv, struct arguments *args)
while (1) {
int c;
- c = getopt_long(argc, argv, "o:sraivc:b:", long_options, &optind);
+ c = getopt_long(argc, argv, "o:sraivc:b:p", long_options, &optind);
if (c == -1)
break;
@@ -499,6 +545,10 @@ static int parse_arguments(int argc, char **argv, struct arguments *args)
args->interval_order = atoi(optarg);
break;
+ case 'p':
+ args->program = 1;
+ break;
+
case 'v':
args->verbosity++;
break;
@@ -526,7 +576,8 @@ static int parse_arguments(int argc, char **argv, struct arguments *args)
args->dev = argv[optind];
if (!(args->scatter || args->rcache ||
- args->align || args->interval)) {
+ args->align || args->interval ||
+ args->program)) {
fprintf(stderr, "%s: need at least one action\n", argv[0]);
return -EINVAL;
}
@@ -606,5 +657,9 @@ int main(int argc, char **argv)
}
}
+ if (args.program) {
+ try_program(&dev);
+ }
+
return 0;
}
diff --git a/vm.c b/vm.c
index b321a91..62090bd 100644
--- a/vm.c
+++ b/vm.c
@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <stdlib.h>
+#include "dev.h"
#include "vm.h"
static inline res_t *res_ptr(res_t r)
@@ -65,11 +66,13 @@ struct operation *call(struct operation *op, struct device *dev,
if (!(syntax[op->code].param & P_AGGREGATE) != !op->aggregate)
return_err("need .aggregate= argument\n");
- if (op->num && res_ptr(op->result))
- return_err("%s already has result\n", syntax[op->code].name);
+ if (op->num) {
+ res_t *data;
- if (op->num && !res_ptr(op->result)) {
- res_t *data = calloc(sizeof (res_t), op->num);
+ if (res_ptr(op->result))
+ return_err("%s already has result\n", syntax[op->code].name);
+
+ data = calloc(sizeof (res_t), op->num);
if (!data)
return_err("out of memory");
@@ -116,19 +119,21 @@ static struct operation *call_aggregate(struct operation *op, struct device *dev
res[this->size_x] = op->result;
+ /* no result */
if (op->r_type == R_NONE)
return next;
this->size_x++;
-
+ /* first data in this aggregation: set type */
if (type == R_NONE) {
type = op->r_type;
this->result = to_res(res, type);
}
- if (type != op->r_type)
+ if (type != op->r_type) {
return_err("cannot aggregate return type %d with %d\n",
type, op->r_type);
+ }
if (op->r_type == R_ARRAY) {
if (this->size_y && this->size_y != op->size_x)
@@ -141,9 +146,11 @@ static struct operation *call_aggregate(struct operation *op, struct device *dev
this->size_y = op->size_x;
op->size_x = op->size_y = 0;
- op->result = res_null;
}
+ op->r_type = R_NONE;
+ op->result = res_null;
+
return next;
}
@@ -156,9 +163,7 @@ static struct operation *nop(struct operation *op, struct device *dev,
static struct operation *do_read(struct operation *op, struct device *dev,
off_t off, off_t max, size_t len)
{
- /* FIXME */
- pr_debug("read %ld %ld %ld\n", off, max, len);
- op->result.l = 0;
+ op->result.l = time_read(dev, off, len);
op->r_type = R_NS;
return op+1;
}
@@ -478,35 +483,7 @@ static struct syntax syntax[] = {
{ O_MAX_POW2, "MAX_POW2", nop, P_NUM | P_VAL },
{ O_MAX_LIN, "MAX_LIN", nop, P_NUM | P_VAL },
- { O_REDUCE, "REDUCE", reduce, P_NUM | P_AGGREGATE },
+ { O_REDUCE, "REDUCE", reduce, P_AGGREGATE },
{ O_DROP, "DROP", drop, },
};
-struct operation program[] = {
- {O_REPEAT, 4},
- {O_SEQUENCE, 3},
- {O_PRINT, .string = "Hello, World!\n"},
- {O_DROP},
- {O_PRINTF},
- {O_FORMAT},
- {O_REDUCE, 8, .aggregate = A_AVERAGE},
- {O_LEN_POW2, 4, 4096},
- {O_OFF_LIN, 8, 4096 },
- {O_SEQUENCE, 3},
- {O_PRINTF},
- {O_READ},
- {O_NEWLINE},
- {O_DROP},
- {O_READ},
- {O_END},
- {O_NEWLINE},
- {O_END},
- {O_END},
-};
-
-int main(void)
-{
- call(program, NULL, 0, 4096 * 1024, 512);
-
- return 0;
-}
diff --git a/vm.h b/vm.h
index ac23ead..3bb6475 100644
--- a/vm.h
+++ b/vm.h
@@ -73,6 +73,7 @@ struct operation {
/* aggregation of results from children */
enum {
+ A_NONE,
A_MINIMUM,
A_MAXIMUM,
A_AVERAGE,