aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2016-05-27 22:50:22 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2016-05-30 09:44:22 +0300
commit3e7e52c96521358b479e46e566310fefe9861c7f (patch)
tree6b77ecfc8e6b1b5e9a3c96ed5a2329151120032b /test
parent2fadf477f2fb029b025ff2d3fdd620ee0c951af1 (diff)
validation: sched: fix out of array reference
If MAX_CPUS defined to less then current cpus, then odp call calculates current available cpus and references to array on thread creation. Do change to allocate array dynamically. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
Diffstat (limited to 'test')
-rw-r--r--test/performance/odp_scheduling.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c
index 1d3bfd114..c575b70df 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -27,8 +27,6 @@
/* GNU lib C */
#include <getopt.h>
-
-#define MAX_WORKERS 32 /**< Max worker threads */
#define MSG_POOL_SIZE (4*1024*1024) /**< Message pool size */
#define MAX_ALLOCS 35 /**< Alloc burst size */
#define QUEUES_PER_PRIO 64 /**< Queue per priority */
@@ -775,7 +773,7 @@ static void parse_args(int argc, char *argv[], test_args_t *args)
*/
int main(int argc, char *argv[])
{
- odph_odpthread_t thread_tbl[MAX_WORKERS];
+ odph_odpthread_t *thread_tbl;
test_args_t args;
int num_workers;
odp_cpumask_t cpumask;
@@ -795,8 +793,6 @@ int main(int argc, char *argv[])
memset(&args, 0, sizeof(args));
parse_args(argc, argv, &args);
- memset(thread_tbl, 0, sizeof(thread_tbl));
-
/* ODP global init */
if (odp_init_global(&instance, NULL, NULL)) {
LOG_ERR("ODP global init failed.\n");
@@ -825,19 +821,20 @@ int main(int argc, char *argv[])
printf("\n");
- /* Default to system CPU count unless user specified */
- num_workers = MAX_WORKERS;
- if (args.cpu_count)
- num_workers = args.cpu_count;
-
/* Get default worker cpumask */
- num_workers = odp_cpumask_default_worker(&cpumask, num_workers);
+ num_workers = odp_cpumask_default_worker(&cpumask, args.cpu_count);
(void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));
printf("num worker threads: %i\n", num_workers);
printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
printf("cpu mask: %s\n", cpumaskstr);
+ thread_tbl = calloc(sizeof(odph_odpthread_t), num_workers);
+ if (!thread_tbl) {
+ LOG_ERR("no memory for thread_tbl\n");
+ return -1;
+ }
+
/* Test cycle count frequency */
test_cpu_freq();
@@ -947,6 +944,7 @@ int main(int argc, char *argv[])
/* Wait for worker threads to terminate */
odph_odpthreads_join(thread_tbl);
+ free(thread_tbl);
printf("ODP example complete\n\n");