forked from Iceber/iouring-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
81 lines (68 loc) · 2.22 KB
/
options.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
// +build linux
package iouring
import (
"time"
iouring_syscall "github.com/iceber/iouring-go/syscall"
)
type IOURingOption func(*IOURing)
// WithSQPoll a kernel thread is created to perform submission queue polling
// In Version 5.10 and later, allow using this as non-root,
// if the user has the CAP_SYS_NICE capability
func WithSQPoll() IOURingOption {
return func(iour *IOURing) {
iour.params.Flags |= iouring_syscall.IORING_SETUP_SQPOLL
}
}
// WithSQPollThreadCPU the poll thread will be bound to the cpu set, only meaningful when WithSQPoll option
func WithSQPollThreadCPU(cpu uint32) IOURingOption {
return func(iour *IOURing) {
iour.params.Flags |= iouring_syscall.IORING_SETUP_SQ_AFF
iour.params.SQThreadCPU = cpu
}
}
func WithSQPollThreadIdle(idle time.Duration) IOURingOption {
return func(iour *IOURing) {
iour.params.SQThreadIdle = uint32(idle / time.Millisecond)
}
}
// WithParams use params
func WithParams(params *iouring_syscall.IOURingParams) IOURingOption {
return func(iour *IOURing) {
iour.params = params
}
}
// WithCQSize create the completion queue with size entries
// size must bue greater than entries
func WithCQSize(size uint32) IOURingOption {
return func(iour *IOURing) {
iour.params.Flags |= iouring_syscall.IORING_SETUP_CQSIZE
iour.params.CQEntries = size
}
}
// WithAttachWQ new iouring instance being create will share the asynchronous worker thread
// backend of the specified io_uring ring, rather than create a new separate thread pool
func WithAttachWQ(iour *IOURing) IOURingOption {
return func(iour *IOURing) {
iour.params.Flags |= iouring_syscall.IORING_SETUP_ATTACH_WQ
iour.params.WQFd = uint32(iour.fd)
}
}
func WithAsync() IOURingOption {
return func(iour *IOURing) {
iour.async = true
}
}
// WithDisableRing the io_uring ring starts in a disabled state
// In this state, restrictions can be registered, but submissions are not allowed
// Available since 5.10
func WithDisableRing() IOURingOption {
return func(iour *IOURing) {
iour.params.Flags |= iouring_syscall.IORING_SETUP_R_DISABLED
}
}
// WithDrain every SQE will not be started before previously submitted SQEs have completed
func WithDrain() IOURingOption {
return func(iour *IOURing) {
iour.drain = true
}
}