blob: 067bd996c29e7e4bc827869875cb5c7bdef8c289 (
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
|
/* Copyright (c) 2013, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sched.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <helper/odp_linux.h>
#include <odp_internal.h>
#include <odp_thread.h>
#include <odp_init.h>
#include <odp_system_info.h>
#include <rte_lcore.h>
typedef struct {
int thr_id;
void *(*start_routine) (void *);
void *arg;
} odp_start_args_t;
static void *odp_run_start_routine(void *arg)
{
odp_start_args_t *start_args = arg;
/* ODP thread local init */
odp_init_local(start_args->thr_id);
return start_args->start_routine(start_args->arg);
}
void odp_linux_pthread_create(odp_linux_pthread_t *thread_tbl, int num,
int first_core, void *(*start_routine) (void *), void *arg)
{
int i;
cpu_set_t cpu_set;
odp_start_args_t *start_args;
int core_count;
int cpu;
(void) cpu_set;
(void) thread_tbl;
core_count = odp_sys_core_count();
assert((first_core >= 0) && (first_core < core_count));
assert((num >= 0) && (num <= core_count));
for (i = 0; i < num; i++) {
cpu = (first_core + i) % core_count;
start_args = malloc(sizeof(odp_start_args_t));
memset(start_args, 0, sizeof(odp_start_args_t));
start_args->start_routine = start_routine;
start_args->arg = arg;
odp_thread_create(cpu);
start_args->thr_id = cpu;
/* If not master core */
if (cpu != 0) {
rte_eal_remote_launch(
(int(*)(void *))odp_run_start_routine,
start_args, cpu);
} else {
lcore_config[cpu].ret = (int)(uint64_t)
odp_run_start_routine(start_args);
lcore_config[cpu].state = FINISHED;
}
}
}
void odp_linux_pthread_join(odp_linux_pthread_t *thread_tbl, int num)
{
uint32_t lcore_id;
(void) thread_tbl;
(void) num;
RTE_LCORE_FOREACH_SLAVE(lcore_id) {
if (rte_eal_wait_lcore(lcore_id) < 0)
return;
}
}
|