Skip to content

Commit

Permalink
test: performance: unify test rounds option for bench applications
Browse files Browse the repository at this point in the history
Use the same 'rounds' option with all odp_bench_* applications.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
  • Loading branch information
MatiasElo committed Sep 20, 2023
1 parent 520417f commit 42d90f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
30 changes: 15 additions & 15 deletions test/performance/odp_bench_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
/** Default pool user area size in bytes */
#define TEST_UAREA_SIZE 8

/** Number of function calls per test cycle */
/** Number of API function calls per test case */
#define TEST_REPEAT_COUNT 1000

/** Default number of test cycles */
#define TEST_CYCLES 1000
/** Default number of rounds per test case */
#define TEST_ROUNDS 1000u

/** Maximum burst size for *_multi operations */
#define TEST_MAX_BURST 64
Expand All @@ -52,7 +52,7 @@ typedef struct {
int bench_idx; /** Benchmark index to run indefinitely */
int burst_size; /** Burst size for *_multi operations */
int cache_size; /** Pool cache size */
int test_cycles; /** Test cycles per tested function */
uint32_t rounds; /** Rounds per test case */
} appl_args_t;

/**
Expand Down Expand Up @@ -463,9 +463,9 @@ static void usage(char *progname)
" -b, --burst <num> Test burst size.\n"
" -c, --cache_size <num> Pool cache size.\n"
" -i, --index <idx> Benchmark index to run indefinitely.\n"
" -t, --test_cycles <num> Run each test 'num' times (default %d).\n"
" -r, --rounds <num> Run each test case 'num' times (default %u).\n"
" -h, --help Display help and exit.\n\n"
"\n", NO_PATH(progname), NO_PATH(progname), TEST_CYCLES);
"\n", NO_PATH(progname), NO_PATH(progname), TEST_ROUNDS);
}

/**
Expand All @@ -483,17 +483,17 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
{"burst", required_argument, NULL, 'b'},
{"cache_size", required_argument, NULL, 'c'},
{"index", required_argument, NULL, 'i'},
{"test_cycles", required_argument, NULL, 't'},
{"rounds", required_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};

static const char *shortopts = "c:b:i:t:h";
static const char *shortopts = "c:b:i:r:h";

appl_args->bench_idx = 0; /* Run all benchmarks */
appl_args->burst_size = TEST_DEF_BURST;
appl_args->cache_size = -1;
appl_args->test_cycles = TEST_CYCLES;
appl_args->rounds = TEST_ROUNDS;

while (1) {
opt = getopt_long(argc, argv, shortopts, longopts, &long_index);
Expand All @@ -515,8 +515,8 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
case 'i':
appl_args->bench_idx = atoi(optarg);
break;
case 't':
appl_args->test_cycles = atoi(optarg);
case 'r':
appl_args->rounds = atoi(optarg);
break;
default:
break;
Expand All @@ -529,8 +529,8 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
exit(EXIT_FAILURE);
}

if (appl_args->test_cycles < 1) {
printf("Invalid test cycle repeat count: %d\n", appl_args->test_cycles);
if (appl_args->rounds < 1) {
printf("Invalid number test rounds: %d\n", appl_args->rounds);
exit(EXIT_FAILURE);
}

Expand All @@ -555,7 +555,7 @@ static void print_info(void)
printf("Pool cache size: default\n");
else
printf("Pool cache size: %d\n", gbl_args->appl.cache_size);
printf("Test cycles: %d\n", gbl_args->appl.test_cycles);
printf("Test rounds: %u\n", gbl_args->appl.rounds);
printf("\n");
}

Expand Down Expand Up @@ -652,7 +652,7 @@ int main(int argc, char *argv[])
gbl_args->suite.bench = test_suite;
gbl_args->suite.num_bench = sizeof(test_suite) / sizeof(test_suite[0]);
gbl_args->suite.indef_idx = gbl_args->appl.bench_idx;
gbl_args->suite.rounds = gbl_args->appl.test_cycles;
gbl_args->suite.rounds = gbl_args->appl.rounds;
gbl_args->suite.repeat_count = TEST_REPEAT_COUNT;

/* Get default worker cpumask */
Expand Down
36 changes: 25 additions & 11 deletions test/performance/odp_bench_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
/** Maximum test packet size */
#define TEST_MAX_PKT_SIZE 2048

/** Number of test runs per individual benchmark */
/** Number of API function calls per test case */
#define TEST_REPEAT_COUNT 1000

/** Number of times to run tests for each packet size */
#define TEST_SIZE_RUN_COUNT 10
/** Number of rounds per test case */
#define TEST_ROUNDS 10u

/** Maximum burst size for *_multi operations */
#define TEST_MAX_BURST 64
Expand Down Expand Up @@ -85,6 +85,7 @@ typedef struct {
int bench_idx; /** Benchmark index to run indefinitely */
int burst_size; /** Burst size for *_multi operations */
int cache_size; /** Pool cache size */
uint32_t rounds; /** Rounds per test case */
} appl_args_t;

/**
Expand Down Expand Up @@ -1359,8 +1360,9 @@ static void usage(char *progname)
" -b, --burst <num> Test packet burst size.\n"
" -c, --cache_size <num> Pool cache size.\n"
" -i, --index <idx> Benchmark index to run indefinitely.\n"
" -r, --rounds <num> Run each test case 'num' times (default %u).\n"
" -h, --help Display help and exit.\n\n"
"\n", NO_PATH(progname), NO_PATH(progname));
"\n", NO_PATH(progname), NO_PATH(progname), TEST_ROUNDS);
}

/**
Expand All @@ -1377,16 +1379,18 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
static const struct option longopts[] = {
{"burst", required_argument, NULL, 'b'},
{"cache_size", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"index", required_argument, NULL, 'i'},
{"rounds", required_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};

static const char *shortopts = "c:b:i:h";
static const char *shortopts = "c:b:i:r:h";

appl_args->bench_idx = 0; /* Run all benchmarks */
appl_args->burst_size = TEST_DEF_BURST;
appl_args->cache_size = -1;
appl_args->rounds = TEST_ROUNDS;

while (1) {
opt = getopt_long(argc, argv, shortopts, longopts, &long_index);
Expand All @@ -1401,15 +1405,19 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
case 'b':
appl_args->burst_size = atoi(optarg);
break;
case 'i':
appl_args->bench_idx = atoi(optarg);
break;
case 'r':
appl_args->rounds = atoi(optarg);
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
break;
case 'i':
appl_args->bench_idx = atoi(optarg);
break;
default:
break;
usage(argv[0]);
exit(EXIT_FAILURE);
}
}

Expand All @@ -1419,6 +1427,11 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
exit(EXIT_FAILURE);
}

if (appl_args->rounds < 1) {
printf("Invalid number test rounds: %d\n", appl_args->rounds);
exit(EXIT_FAILURE);
}

optind = 1; /* Reset 'extern optind' from the getopt lib */
}

Expand Down Expand Up @@ -1598,7 +1611,7 @@ int main(int argc, char *argv[])
gbl_args->suite.bench = test_suite;
gbl_args->suite.num_bench = sizeof(test_suite) / sizeof(test_suite[0]);
gbl_args->suite.indef_idx = gbl_args->appl.bench_idx;
gbl_args->suite.rounds = TEST_SIZE_RUN_COUNT;
gbl_args->suite.rounds = gbl_args->appl.rounds;
gbl_args->suite.repeat_count = TEST_REPEAT_COUNT;

/* Print both system and application information */
Expand Down Expand Up @@ -1670,6 +1683,7 @@ int main(int argc, char *argv[])
printf("CPU mask: %s\n", cpumaskstr);
printf("Burst size: %d\n", gbl_args->appl.burst_size);
printf("Bench repeat: %d\n", TEST_REPEAT_COUNT);
printf("Test rounds: %u\n", gbl_args->appl.rounds);
if (gbl_args->appl.cache_size < 0)
printf("Pool cache size: default\n");
else
Expand Down

0 comments on commit 42d90f1

Please sign in to comment.