github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/options.go (about) 1 //go:build linux 2 // +build linux 3 4 package iouring 5 6 import ( 7 "time" 8 9 iouring_syscall "github.com/iceber/iouring-go/syscall" 10 ) 11 12 type IOURingOption func(*IOURing) 13 14 // WithSQPoll a kernel thread is created to perform submission queue polling 15 // In Version 5.10 and later, allow using this as non-root, 16 // if the user has the CAP_SYS_NICE capability 17 func WithSQPoll() IOURingOption { 18 return func(iour *IOURing) { 19 iour.params.Flags |= iouring_syscall.IORING_SETUP_SQPOLL 20 } 21 } 22 23 // WithSQPollThreadCPU the poll thread will be bound to the cpu set, only meaningful when WithSQPoll option 24 func WithSQPollThreadCPU(cpu uint32) IOURingOption { 25 return func(iour *IOURing) { 26 iour.params.Flags |= iouring_syscall.IORING_SETUP_SQ_AFF 27 iour.params.SQThreadCPU = cpu 28 } 29 } 30 31 func WithSQPollThreadIdle(idle time.Duration) IOURingOption { 32 return func(iour *IOURing) { 33 iour.params.SQThreadIdle = uint32(idle / time.Millisecond) 34 } 35 } 36 37 // WithParams use params 38 func WithParams(params *iouring_syscall.IOURingParams) IOURingOption { 39 return func(iour *IOURing) { 40 iour.params = params 41 } 42 } 43 44 // WithCQSize create the completion queue with size entries 45 // size must bue greater than entries 46 func WithCQSize(size uint32) IOURingOption { 47 return func(iour *IOURing) { 48 iour.params.Flags |= iouring_syscall.IORING_SETUP_CQSIZE 49 iour.params.CQEntries = size 50 } 51 } 52 53 // WithAttachWQ new iouring instance being create will share the asynchronous worker thread 54 // backend of the specified io_uring ring, rather than create a new separate thread pool 55 func WithAttachWQ(iour *IOURing) IOURingOption { 56 return func(iour *IOURing) { 57 iour.params.Flags |= iouring_syscall.IORING_SETUP_ATTACH_WQ 58 iour.params.WQFd = uint32(iour.fd) 59 } 60 } 61 62 func WithAsync() IOURingOption { 63 return func(iour *IOURing) { 64 iour.async = true 65 } 66 } 67 68 // WithDisableRing the io_uring ring starts in a disabled state 69 // In this state, restrictions can be registered, but submissions are not allowed 70 // Available since 5.10 71 func WithDisableRing() IOURingOption { 72 return func(iour *IOURing) { 73 iour.params.Flags |= iouring_syscall.IORING_SETUP_R_DISABLED 74 } 75 } 76 77 // WithDrain every SQE will not be started before previously submitted SQEs have completed 78 func WithDrain() IOURingOption { 79 return func(iour *IOURing) { 80 iour.drain = true 81 } 82 } 83 84 // WithSQE128 every SQE will have 128B entry size to append IOCTL command 85 func WithSQE128() IOURingOption { 86 return func(iour *IOURing) { 87 iour.params.Flags |= iouring_syscall.IORING_SETUP_SQE128 88 } 89 } 90 91 // WithCQE32 every CQE will have 32B entry size to append IOCTL return data 92 func WithCQE32() IOURingOption { 93 return func(iour *IOURing) { 94 iour.params.Flags |= iouring_syscall.IORING_SETUP_CQE32 95 } 96 }