aboutsummaryrefslogtreecommitdiff
path: root/helper/test/odpthreads.c
diff options
context:
space:
mode:
Diffstat (limited to 'helper/test/odpthreads.c')
-rw-r--r--helper/test/odpthreads.c66
1 files changed, 57 insertions, 9 deletions
diff --git a/helper/test/odpthreads.c b/helper/test/odpthreads.c
index 1540ad503..aa06df188 100644
--- a/helper/test/odpthreads.c
+++ b/helper/test/odpthreads.c
@@ -1,4 +1,5 @@
/* Copyright (c) 2016-2018, Linaro Limited
+ * Copyright (c) 2021, Nokia
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
@@ -12,6 +13,11 @@
#include <unistd.h>
#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#include <string.h>
+#include <inttypes.h>
#include <odp_api.h>
#include <odp/helper/odph_api.h>
@@ -62,14 +68,18 @@ static int worker_fn(void *arg ODP_UNUSED)
int main(int argc, char *argv[])
{
odph_helper_options_t helper_options;
- odph_odpthread_params_t thr_params;
- odph_odpthread_t thread_tbl[NUMBER_WORKERS];
+ odph_thread_t thread_tbl[NUMBER_WORKERS];
+ odph_thread_common_param_t thr_common;
+ odph_thread_param_t thr_param;
odp_cpumask_t cpu_mask;
odp_init_t init_param;
int num_workers;
int cpu, affinity;
int ret;
char cpumaskstr[ODP_CPUMASK_STR_SIZE];
+ struct rlimit rlimit;
+ pthread_attr_t attr;
+ size_t stack_size;
/* Let helper collect its own arguments (e.g. --odph_proc) */
argc = odph_parse_options(argc, argv);
@@ -143,18 +153,56 @@ int main(int argc, char *argv[])
printf("new cpu mask: %s\n", cpumaskstr);
printf("new num worker threads: %i\n\n", num_workers);
- memset(&thr_params, 0, sizeof(thr_params));
- thr_params.start = worker_fn;
- thr_params.arg = NULL;
- thr_params.thr_type = ODP_THREAD_WORKER;
- thr_params.instance = odp_instance;
+ odph_thread_common_param_init(&thr_common);
+ thr_common.instance = odp_instance;
+ thr_common.cpumask = &cpu_mask;
+ thr_common.share_param = 1;
- odph_odpthreads_create(&thread_tbl[0], &cpu_mask, &thr_params);
+ odph_thread_param_init(&thr_param);
+ thr_param.start = worker_fn;
+ thr_param.arg = NULL;
+ thr_param.thr_type = ODP_THREAD_WORKER;
- ret = odph_odpthreads_join(thread_tbl);
+ odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers);
+
+ ret = odph_thread_join(thread_tbl, num_workers);
if (ret < 0)
exit(EXIT_FAILURE);
+ /* Test threads with non-default stack size and sync timeout. */
+
+ pthread_attr_init(&attr);
+
+ if (pthread_attr_getstacksize(&attr, &stack_size)) {
+ ODPH_ERR("pthread_attr_getstacksize() failed\n");
+ return -1;
+ }
+
+ printf("\n");
+ printf("pthread default stack size: %zu\n", stack_size);
+
+ if (getrlimit(RLIMIT_STACK, &rlimit)) {
+ ODPH_ERR("getrlimit() failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ printf("stack size soft limit (rlim_cur): %lu\n", rlimit.rlim_cur);
+
+ if (rlimit.rlim_cur < stack_size)
+ stack_size = rlimit.rlim_cur;
+
+ thr_param.stack_size = stack_size - ODP_PAGE_SIZE;
+ printf("use stack size: %" PRIu64 "\n", thr_param.stack_size);
+ thr_common.sync_timeout = 5 * ODP_TIME_SEC_IN_NS;
+ printf("use sync timeout: %" PRIu64 "\n", thr_common.sync_timeout);
+ printf("\n");
+
+ if (odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers) != num_workers)
+ exit(EXIT_FAILURE);
+
+ if (odph_thread_join(thread_tbl, num_workers) != num_workers)
+ exit(EXIT_FAILURE);
+
return 0;
}