benchmark: move benchmark impl to a private header
There is no need to expose the implementation details of both
BENCHMARK_START and BENCHMARK_STOP macros via public header.
This change moves them to a separate private header 'bench.h'.
diff --git a/include/Makefile.am b/include/Makefile.am
index f64faeb..81419f7 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,5 +1,6 @@
noinst_HEADERS = \
osmocom/gapk/utils.h \
+ osmocom/gapk/bench.h \
$(NULL)
nobase_include_HEADERS = \
diff --git a/include/osmocom/gapk/bench.h b/include/osmocom/gapk/bench.h
new file mode 100644
index 0000000..02c28db
--- /dev/null
+++ b/include/osmocom/gapk/bench.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of gapk (GSM Audio Pocket Knife).
+ *
+ * (C) 2014 Harald Welte <laforge@gnumonks.org>
+ *
+ * gapk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gapk is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gapk. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/gapk/get_cycles.h>
+#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/codecs.h>
+
+static inline void benchmark_store(enum osmo_gapk_codec_type codec,
+ int encode, unsigned long cycles)
+{
+ struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[codec];
+
+ if (encode) {
+ bc->enc_used = (bc->enc_used + 1) % OSMO_GAPK_CYCLES_NUM_AVG;
+ bc->enc[bc->enc_used] = cycles;
+ } else {
+ bc->dec_used = (bc->dec_used + 1) % OSMO_GAPK_CYCLES_NUM_AVG;
+ bc->dec[bc->dec_used] = cycles;
+ }
+}
+
+#define BENCHMARK_START \
+ do { \
+ cycles_t _cycles_start, _cycles_stop; \
+ _cycles_start = get_cycles()
+
+#define BENCHMARK_STOP(codec, enc) \
+ _cycles_stop = get_cycles(); \
+ benchmark_store(codec, enc, \
+ _cycles_stop - _cycles_start); \
+ } while (0)
diff --git a/include/osmocom/gapk/benchmark.h b/include/osmocom/gapk/benchmark.h
index 6cfc074..b64a3b5 100644
--- a/include/osmocom/gapk/benchmark.h
+++ b/include/osmocom/gapk/benchmark.h
@@ -22,35 +22,13 @@
#include <osmocom/gapk/get_cycles.h>
#include <osmocom/gapk/codecs.h>
-#define NUM_AVG 102400
+#define OSMO_GAPK_CYCLES_NUM_AVG 102400
struct osmo_gapk_bench_cycles {
- cycles_t enc[NUM_AVG];
+ cycles_t enc[OSMO_GAPK_CYCLES_NUM_AVG];
unsigned int enc_used;
- cycles_t dec[NUM_AVG];
+ cycles_t dec[OSMO_GAPK_CYCLES_NUM_AVG];
unsigned int dec_used;
};
extern struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX];
-
-static inline void benchmark_stop(enum osmo_gapk_codec_type codec,
- int encode, unsigned long cycles)
-{
- struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[codec];
-
- if (encode) {
- bc->enc_used = (bc->enc_used + 1) % NUM_AVG;
- bc->enc[bc->enc_used] = cycles;
- } else {
- bc->dec_used = (bc->dec_used + 1) % NUM_AVG;
- bc->dec[bc->dec_used] = cycles;
- }
-}
-
-#define BENCHMARK_START do { \
- cycles_t _cycles_start, _cycles_stop; \
- _cycles_start = get_cycles()
-
-#define BENCHMARK_STOP(x,y) _cycles_stop = get_cycles(); \
- benchmark_stop(x, y, _cycles_stop - _cycles_start); \
- } while (0)
diff --git a/src/codec_amr.c b/src/codec_amr.c
index 9cbeba6..2fa7a2f 100644
--- a/src/codec_amr.c
+++ b/src/codec_amr.c
@@ -20,6 +20,7 @@
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/bench.h>
#include "config.h"
diff --git a/src/codec_efr.c b/src/codec_efr.c
index ba39f61..f5b7f83 100644
--- a/src/codec_efr.c
+++ b/src/codec_efr.c
@@ -19,6 +19,7 @@
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/bench.h>
#include "config.h"
diff --git a/src/codec_fr.c b/src/codec_fr.c
index 6fc0af1..2a4936d 100644
--- a/src/codec_fr.c
+++ b/src/codec_fr.c
@@ -21,6 +21,7 @@
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/bench.h>
#include "config.h"
diff --git a/src/codec_hr.c b/src/codec_hr.c
index 7c1484e..ef66f57 100644
--- a/src/codec_hr.c
+++ b/src/codec_hr.c
@@ -21,6 +21,7 @@
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/bench.h>
#include "config.h"