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.
This commit is contained in:
Vadim Yanitskiy 2017-09-04 03:33:48 +07:00
parent c9a75e59c6
commit 72218e7da0
4 changed files with 45 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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