-
Notifications
You must be signed in to change notification settings - Fork 20
/
launch.go
96 lines (79 loc) · 2.31 KB
/
launch.go
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
package dpdk
/*
#cgo CFLAGS: -m64 -pthread -O3 -march=native -I/usr/local/include/dpdk
#cgo LDFLAGS: -L/usr/local/lib -ldpdk -lz -lrt -lm -ldl -lfuse
extern int go_remote_launch(void *);
extern int go_mp_remote_launch(void *);
#include <stdlib.h>
#include <limits.h>
#include <rte_config.h>
#include <rte_common.h>
#include <rte_launch.h>
#include <rte_lcore.h>
#include <rte_per_lcore.h>
*/
import "C"
import "unsafe"
const (
WAIT = iota
RUNNING
FINISHED
)
const (
SKIP_MASTER = iota
CALL_MASTER
)
var lCoreFuncs [](func(unsafe.Pointer) int)
var lCoreFunc func(unsafe.Pointer) int
var lCoreFuncMp func(unsafe.Pointer) int
//export go_remote_launch
func go_remote_launch(arg unsafe.Pointer) C.int {
return C.int(lCoreFunc(arg))
}
//export go_mp_remote_launch
func go_mp_remote_launch(arg unsafe.Pointer) C.int {
return C.int(lCoreFuncMp(arg))
}
func RteEalRemoteLaunch(fn func(unsafe.Pointer) int, arg unsafe.Pointer, slave_id uint) int {
if len(lCoreFuncs) == 0 {
lCoreFuncs = make([](func(unsafe.Pointer) int), 128)
}
lCoreFuncs[int(slave_id)] = fn
lCoreFunc = fn
return int(C.rte_eal_remote_launch((*C.lcore_function_t)(C.go_remote_launch),
arg, C.unsigned(slave_id)))
}
func RteEalLaunchAllSlave(fn func(unsafe.Pointer) int, arg unsafe.Pointer) {
for lcoreID := C.rte_get_next_lcore(C.UINT_MAX, 1, 0); lcoreID < C.RTE_MAX_LCORE; lcoreID = C.rte_get_next_lcore(C.uint(lcoreID), 1, 0) {
RteEalRemoteLaunch(fn, arg, uint(lcoreID))
}
}
func RteEalMpRemoteLaunch(fn func(unsafe.Pointer) int, arg unsafe.Pointer, call_master int) int {
lCoreFuncMp = fn
return int(C.rte_eal_mp_remote_launch((*C.lcore_function_t)(C.go_mp_remote_launch),
arg, C.enum_rte_rmt_call_master_t(call_master)))
}
func RteEalGetLCoreState(slave_id uint) int {
return int(C.rte_eal_get_lcore_state(C.unsigned(slave_id)))
}
func RteEalWaitLCore(slave_id uint) int {
return int(C.rte_eal_wait_lcore(C.unsigned(slave_id)))
}
func RteEalWaitAllSlave() int {
for lcoreID := C.rte_get_next_lcore(C.UINT_MAX, 1, 0); lcoreID < C.RTE_MAX_LCORE; lcoreID = C.rte_get_next_lcore(C.uint(lcoreID), 1, 0) {
ret := RteEalWaitLCore(uint(lcoreID))
if ret < 0 {
return ret
}
}
return 0
}
func RteSocketID() int {
return int(C.rte_socket_id())
}
func RteEalMpWaitLCore() {
C.rte_eal_mp_wait_lcore()
}
func RteLcoreID() uint {
return uint(C.rte_lcore_id())
}