[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1272808519-4743-2-git-send-email-mitake@dcl.info.waseda.ac.jp>
Date: Sun, 2 May 2010 22:55:16 +0900
From: Hitoshi Mitake <mitake@....info.waseda.ac.jp>
To: Ingo Molnar <mingo@...e.hu>
Cc: linux-kernel@...r.kernel.org, mitake@....info.waseda.ac.jp,
h.mitake@...il.com, Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Paul Mackerras <paulus@...ba.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>
Subject: [PATCH 1/4][RFC] perf bench: add "sample" subsystem and "sample" suite as sample benchmark program
This patch implements "sample" subsystem and "sample" suite
for perf bench. As the name describes, these are sample stuff.
Detailed descriptions about new structure of perf bench
will be written in 4/4 of this patch series.
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Signed-off-by: Hitoshi Mitake <mitake@....info.waseda.ac.jp>
---
tools/perf/bench/sample-sample.c | 98 ++++++++++++++++++++++++++++++++++++++
tools/perf/bench/sample.h | 4 ++
2 files changed, 102 insertions(+), 0 deletions(-)
create mode 100644 tools/perf/bench/sample-sample.c
create mode 100644 tools/perf/bench/sample.h
diff --git a/tools/perf/bench/sample-sample.c b/tools/perf/bench/sample-sample.c
new file mode 100644
index 0000000..b5ad090
--- /dev/null
+++ b/tools/perf/bench/sample-sample.c
@@ -0,0 +1,98 @@
+/*
+ * sample benchmark suite for perf bench
+ */
+
+#include "../perf.h"
+#include "bench.h"
+#include "../util/util.h"
+#include "../util/parse-options.h"
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+struct sample_param {
+ int boolean;
+ int integer;
+ const char *string;
+};
+
+struct sample_ctx {
+ int count;
+};
+
+static const char * const sample_sample_usage[] = {
+ "perf bench sample sample <options>",
+ NULL
+};
+
+static void *__sample_sample_parse_arg(int argc, const char **argv,
+ const char *prefix __used,
+ struct sample_param *param)
+{
+ struct option options[] = {
+ OPT_BOOLEAN('b', "boolean", ¶m->boolean,
+ "Sample boolean argument"),
+ OPT_INTEGER('i', "integer", ¶m->integer,
+ "Sample integer argument"),
+ OPT_STRING('s', "string", ¶m->string, "string-default",
+ "Sample string argument"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options,
+ sample_sample_usage, PARSE_OPT_KEEP_ARGV0);
+
+ printf("parameters for sample benchmark:\n");
+ printf("\tboolean:%d\n", param->boolean);
+ printf("\tinteger:%d\n", param->integer);
+ printf("\tstring:%s\n", param->string ? param->string : "(NULL)");
+
+ return param;
+}
+
+/*
+ * parse arguments
+ * returned object will be shared between every thread/process of benchmark
+ */
+void *sample_sample_parse_arg(int argc, const char **argv, const char *prefix)
+{
+ struct sample_param *param;
+
+ param = zalloc(sizeof(struct sample_param));
+ if (!param)
+ die("Memory allocation failed\n");
+
+ return __sample_sample_parse_arg(argc, argv, prefix, param);
+}
+
+/*
+ * prepare own state of thread/process
+ * returned object will not be shared
+ */
+void sample_sample_prepare(struct bench_ctx *ctx)
+{
+ struct sample_ctx *priv;
+
+ priv = zalloc(sizeof(struct sample_ctx));
+ if (!priv)
+ die("Memory allocation failed\n");
+
+ priv->count = ((struct sample_param *)ctx->param)->integer;
+ ctx->priv = priv;
+}
+
+void sample_sample_bench(struct bench_ctx *ctx)
+{
+ struct sample_ctx *priv = (struct sample_ctx *)ctx->priv;
+
+ while (priv->count--) {
+ printf("pid %d: %d...\n", getpid(), priv->count);
+ sleep(1);
+ }
+}
+
+void sample_sample_clean(struct bench_ctx *ctx)
+{
+ free(ctx->priv);
+}
diff --git a/tools/perf/bench/sample.h b/tools/perf/bench/sample.h
new file mode 100644
index 0000000..b514956
--- /dev/null
+++ b/tools/perf/bench/sample.h
@@ -0,0 +1,4 @@
+
+BENCH("sample", "Sample implementation of perf bench",
+ sample_sample_parse_arg, sample_sample_prepare,
+ sample_sample_bench, sample_sample_clean)
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists