aboutsummaryrefslogtreecommitdiff
path: root/helper/include/odph_linux.h
blob: 8671dc0dcd45e48e77575a1bb92717cd151d05e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright (c) 2013, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */


/**
 * @file
 *
 * ODP Linux helper API
 *
 * This file is an optional helper to odp.h APIs. These functions are provided
 * to ease common setups in a Linux system. User is free to implement the same
 * setups in otherways (not via this API).
 */

#ifndef ODP_LINUX_H_
#define ODP_LINUX_H_

#ifdef __cplusplus
extern "C" {
#endif


#include <pthread.h>
#include <sys/types.h>

/** Linux pthread state information */
typedef struct {
	pthread_t      thread; /**< Pthread ID */
	pthread_attr_t attr;   /**< Pthread attributes */
	int            core;   /**< Core ID */
} odph_linux_pthread_t;


/** Linux process state information */
typedef struct {
	pid_t pid;      /**< Process ID */
	int   core;     /**< Core ID */
	int   status;   /**< Process state change status */
} odph_linux_process_t;


/**
 * Creates and launches pthreads
 *
 * Creates, pins and launches num threads to separate cores starting from
 * first_core.
 *
 * @param thread_tbl    Thread table
 * @param num           Number of threads to create
 * @param first_core    First physical core
 * @param start_routine Thread start function
 * @param arg           Thread argument
 */
void odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl,
			      int num, int first_core,
			      void *(*start_routine) (void *), void *arg);


/**
 * Waits pthreads to exit
 *
 * Returns when all threads have been exit.
 *
 * @param thread_tbl    Thread table
 * @param num           Number of threads to create
 *
 */
void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num);


/**
 * Fork a process
 *
 * Forks and sets core affinity for the child process
 *
 * @param proc          Pointer to process state info (for output)
 * @param core          Destination core for the child process
 *
 * @return On success: 1 for the parent, 0 for the child
 *         On failure: -1 for the parent, -2 for the child
 */
int odph_linux_process_fork(odph_linux_process_t *proc, int core);


/**
 * Fork a number of processes
 *
 * Forks and sets core affinity for child processes
 *
 * @param proc_tbl      Process state info table (for output)
 * @param num           Number of processes to create
 * @param first_core    Destination core for the first process
 *
 * @return On success: 1 for the parent, 0 for the child
 *         On failure: -1 for the parent, -2 for the child
 */
int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl,
			      int num, int first_core);


/**
 * Wait for a number of processes
 *
 * Waits for a number of child processes to terminate. Records process state
 * change status into the process state info structure.
 *
 * @param proc_tbl      Process state info table (previously filled by fork)
 * @param num           Number of processes to wait
 *
 * @return 0 on success, -1 on failure
 */
int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num);


#ifdef __cplusplus
}
#endif

#endif