aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-04 03:33:48 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-09-04 04:37:21 +0700
commitea53827e34b3d223c053289f7ef39f3105712a18 (patch)
tree371262962cd6c897b9b8e4d322c0eed32edf9319
parent36e92c49c510711bd7e88beb2935a2a298def9fe (diff)
benchmark: allocate memory dynamically
Having statically allocated memory for benchmark data of every codec causes high memory usage, especially if actual benchmarking is not required for a particular use case. Instead of that, let's provide an optional opportunity to enable benchmarking for a particular codec by calling the osmo_gapk_bench_enable(). The required amount of memory would be allocated, and then can be freed by calling the osmo_gapk_bench_free() or manually.
-rw-r--r--include/osmocom/gapk/bench.h3
-rw-r--r--include/osmocom/gapk/benchmark.h5
-rw-r--r--src/benchmark.c30
-rw-r--r--src/main.c11
4 files changed, 45 insertions, 4 deletions
diff --git a/include/osmocom/gapk/bench.h b/include/osmocom/gapk/bench.h
index 1cfbeb3..404760e 100644
--- a/include/osmocom/gapk/bench.h
+++ b/include/osmocom/gapk/bench.h
@@ -32,7 +32,8 @@
#define BENCHMARK_STOP(codec, encode) \
_cycles_stop = get_cycles(); \
- _bc = &osmo_gapk_bench_codec[codec]; \
+ _bc = osmo_gapk_bench_codec[codec]; \
+ if (!_bc) break; \
\
if (encode) { \
_bc->enc_used = (_bc->enc_used + 1) \
diff --git a/include/osmocom/gapk/benchmark.h b/include/osmocom/gapk/benchmark.h
index b64a3b5..cce7076 100644
--- a/include/osmocom/gapk/benchmark.h
+++ b/include/osmocom/gapk/benchmark.h
@@ -31,4 +31,7 @@ struct osmo_gapk_bench_cycles {
unsigned int dec_used;
};
-extern struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX];
+extern struct osmo_gapk_bench_cycles *osmo_gapk_bench_codec[_CODEC_MAX];
+
+int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec);
+void osmo_gapk_bench_free(void);
diff --git a/src/benchmark.c b/src/benchmark.c
index 3dead5a..8896a3b 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -18,7 +18,35 @@
*/
#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
#include <osmocom/gapk/benchmark.h>
+#include <osmocom/gapk/codecs.h>
-struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX];
+struct osmo_gapk_bench_cycles *
+ osmo_gapk_bench_codec[_CODEC_MAX] = { NULL };
+
+int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec)
+{
+ struct osmo_gapk_bench_cycles *bench;
+
+ /* Allocate zero-initialized memory */
+ bench = (struct osmo_gapk_bench_cycles *)
+ calloc(1, sizeof(struct osmo_gapk_bench_cycles));
+ if (!bench)
+ return -ENOMEM;
+
+ /* Set up pointer */
+ osmo_gapk_bench_codec[codec] = bench;
+
+ return 0;
+}
+
+void osmo_gapk_bench_free(void)
+{
+ int i;
+
+ for (i = 0; i < _CODEC_MAX; i++)
+ free(osmo_gapk_bench_codec[i]);
+}
diff --git a/src/main.c b/src/main.c
index b893f34..623926f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -316,7 +316,7 @@ benchmark_dump(void)
int i, j;
for (i = 0; i < _CODEC_MAX; i++) {
- struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[i];
+ struct osmo_gapk_bench_cycles *bc = osmo_gapk_bench_codec[i];
unsigned long long total;
if (bc->enc_used) {
@@ -498,6 +498,9 @@ make_processing_chain(struct gapk_state *gs)
/* Do decoding */
osmo_gapk_pq_queue_codec(gs->pq, codec_in, 0);
+
+ /* Allocate memory for benchmarking */
+ osmo_gapk_bench_enable(fmt_in->codec_type);
}
else if (fmt_in->type != fmt_out->type)
{
@@ -511,6 +514,9 @@ make_processing_chain(struct gapk_state *gs)
/* Do encoding */
osmo_gapk_pq_queue_codec(gs->pq, codec_out, 1);
+ /* Allocate memory for benchmarking */
+ osmo_gapk_bench_enable(fmt_out->codec_type);
+
/* Convert encoder output to output fmt */
if (fmt_out->type != codec_out->codec_enc_format_type)
{
@@ -649,6 +655,9 @@ error:
osmo_gapk_pq_destroy(gs->pq);
benchmark_dump();
+
+ /* Free memory taken by benchmark data */
+ osmo_gapk_bench_free();
return rv;
}