Helper Reference Manual  1.7.1
threads.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2013-2018 Linaro Limited
3  * Copyright (c) 2019-2024 Nokia
4  */
5 
6 
17 #ifndef ODPH_LINUX_H_
18 #define ODPH_LINUX_H_
19 
20 #include <odp_api.h>
21 
22 #include <pthread.h>
23 #include <getopt.h>
24 #include <sys/types.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
38 typedef struct {
39  void *(*start)(void *);
40  void *arg;
41  odp_thread_type_t thr_type;
42  odp_instance_t instance;
44 
46 typedef struct {
47  pthread_t thread;
48  pthread_attr_t attr;
49  int cpu;
53 
55 typedef struct {
56  pid_t pid;
57  int cpu;
58  int status;
60 
62 typedef struct {
64  int (*start)(void *arg);
65 
67  void *arg;
68 
70  odp_thread_type_t thr_type;
71 
73  uint64_t stack_size;
74 
76 
79 typedef struct {
81  uint32_t status;
82 
84  odp_atomic_u32_t *init_status;
85 
87  odp_mem_model_t mem_model;
88 
90  odp_instance_t instance;
91 
94 
96 
98 typedef struct {
101 
103  int cpu;
104 
106  uint8_t last;
107 
109  union {
111  struct {
112  pthread_t thread_id;
113  pthread_attr_t attr;
114  } thread;
115 
117  struct {
118  pid_t pid;
119  int status;
120  } proc;
121  };
122 
123 } odph_thread_t;
124 
126 typedef struct {
127  odp_mem_model_t mem_model;
129 
131 typedef struct {
138  odp_instance_t instance;
139 
143  const odp_cpumask_t *cpumask;
144 
154 
165  int sync;
166 
178  uint64_t sync_timeout;
179 
191 
193 
195 typedef struct {
197  odp_bool_t is_sig;
198 
205  int ret;
207 
216 
226 
267  const odph_thread_common_param_t *param,
268  const odph_thread_param_t thr_param[],
269  int num);
270 
291 int odph_thread_join(odph_thread_t thread[], int num);
292 
312 
323 int odph_odpthread_setaffinity(const int cpu);
324 
334 
358 int odph_parse_options(int argc, char *argv[]);
359 
373 
378 #ifdef __cplusplus
379 }
380 #endif
381 
382 #endif
int odph_thread_create(odph_thread_t thread[], const odph_thread_common_param_t *param, const odph_thread_param_t thr_param[], int num)
Create and pin threads (as Linux pthreads or processes)
int odph_thread_join(odph_thread_t thread[], int num)
Wait previously launched threads to exit.
int odph_parse_options(int argc, char *argv[])
Parse linux helper options.
int odph_options(odph_helper_options_t *options)
Get linux helper options.
int odph_odpthread_setaffinity(const int cpu)
Set CPU affinity of the current odp thread.
int odph_thread_join_result(odph_thread_t thread[], odph_thread_join_result_t res[], int num)
Wait previously launched threads to exit.
void odph_thread_param_init(odph_thread_param_t *param)
Initialize thread params.
int odph_odpthread_getaffinity(void)
Get CPU affinity of the current odp thread.
void odph_thread_common_param_init(odph_thread_common_param_t *param)
Initialize thread common params.
ODP Linux helper for pthreads.
Linux helper options.
Definition: threads.h:126
odp_mem_model_t mem_model
Process or thread.
Definition: threads.h:127
Linux process state information.
Definition: threads.h:55
int status
Process state change status.
Definition: threads.h:58
int cpu
CPU ID.
Definition: threads.h:57
pid_t pid
Process ID.
Definition: threads.h:56
Linux pthread state information.
Definition: threads.h:46
int cpu
CPU ID.
Definition: threads.h:49
odph_linux_thr_params_t thr_params
Copy of thread params.
Definition: threads.h:51
pthread_attr_t attr
Pthread attributes.
Definition: threads.h:48
pthread_t thread
Pthread ID.
Definition: threads.h:47
Thread parameter for Linux pthreads and processes.
Definition: threads.h:38
odp_thread_type_t thr_type
ODP thread type.
Definition: threads.h:41
odp_instance_t instance
ODP instance handle.
Definition: threads.h:42
void * arg
Argument for the function.
Definition: threads.h:40
Common parameters for odph_thread_create() call.
Definition: threads.h:131
int share_param
Thread parameter sharing.
Definition: threads.h:190
const odp_cpumask_t * cpumask
CPU mask for thread pinning.
Definition: threads.h:143
uint64_t sync_timeout
Synchronized thread creation timeout in nanoseconds.
Definition: threads.h:178
int thread_model
Select between Linux pthreads and processes.
Definition: threads.h:153
odp_instance_t instance
ODP instance handle.
Definition: threads.h:138
int sync
Synchronized thread creation.
Definition: threads.h:165
Thread join result.
Definition: threads.h:195
odp_bool_t is_sig
Exit caused by signal.
Definition: threads.h:197
int ret
Exit status of the joined thread/process.
Definition: threads.h:205
Thread parameters (pthreads and processes)
Definition: threads.h:62
void * arg
Argument for the function.
Definition: threads.h:67
uint64_t stack_size
Minimum stack size in bytes.
Definition: threads.h:73
odp_thread_type_t thr_type
ODP thread type.
Definition: threads.h:70
Helper internal thread start arguments.
Definition: threads.h:79
odp_instance_t instance
ODP instance handle.
Definition: threads.h:90
odph_thread_param_t thr_params
Thread parameters.
Definition: threads.h:93
odp_mem_model_t mem_model
Process or thread.
Definition: threads.h:87
odp_atomic_u32_t * init_status
Thread initialization status.
Definition: threads.h:84
uint32_t status
Thread status.
Definition: threads.h:81
Thread state information.
Definition: threads.h:98
pid_t pid
Process ID.
Definition: threads.h:118
int cpu
CPU ID.
Definition: threads.h:103
pthread_t thread_id
Pthread ID.
Definition: threads.h:112
int status
Process state chge status.
Definition: threads.h:119
pthread_attr_t attr
Pthread attributes.
Definition: threads.h:113
uint8_t last
1: last table entry
Definition: threads.h:106
odph_thread_start_args_t start_args
Start arguments.
Definition: threads.h:100