Skip to content

Commit ee0d851

Browse files
committed
a tradeoff to remove re-arm mechanism. frequent syscall to rearm is
still time consuming
1 parent 5637657 commit ee0d851

File tree

3 files changed

+4
-48
lines changed

3 files changed

+4
-48
lines changed

aio_bsd.go

-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ func (p *poller) Watch(fd int) error {
8282
return p.wakeup()
8383
}
8484

85-
func (p *poller) Rearm(fd int, read bool, write bool) (err error) {
86-
return nil
87-
}
88-
8985
// wakeup interrupt kevent
9086
func (p *poller) wakeup() error {
9187
p.mu.Lock()

aio_linux.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,7 @@ func (p *poller) Close() error {
9191

9292
func (p *poller) Watch(fd int) (err error) {
9393
p.mu.Lock()
94-
err = syscall.EpollCtl(p.pfd, syscall.EPOLL_CTL_ADD, int(fd), &syscall.EpollEvent{Fd: int32(fd), Events: syscall.EPOLLONESHOT | syscall.EPOLLRDHUP | syscall.EPOLLIN | syscall.EPOLLOUT | _EPOLLET})
95-
p.mu.Unlock()
96-
return
97-
}
98-
99-
func (p *poller) Rearm(fd int, read bool, write bool) (err error) {
100-
p.mu.Lock()
101-
var flag uint32
102-
flag = syscall.EPOLLONESHOT | _EPOLLET
103-
if read {
104-
flag |= syscall.EPOLLIN | syscall.EPOLLRDHUP
105-
}
106-
if write {
107-
flag |= syscall.EPOLLOUT
108-
}
109-
110-
err = syscall.EpollCtl(p.pfd, syscall.EPOLL_CTL_MOD, int(fd), &syscall.EpollEvent{Fd: int32(fd), Events: flag})
94+
err = syscall.EpollCtl(p.pfd, syscall.EPOLL_CTL_ADD, int(fd), &syscall.EpollEvent{Fd: int32(fd), Events: syscall.EPOLLRDHUP | syscall.EPOLLIN | syscall.EPOLLOUT | _EPOLLET})
11195
p.mu.Unlock()
11296
return
11397
}

watcher.go

+3-27
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ const (
5353

5454
// fdDesc contains all data structures associated to fd
5555
type fdDesc struct {
56-
readers list.List // all read/write requests
57-
writers list.List
58-
ptr uintptr // pointer to net.Conn
59-
armState uint8
56+
readers list.List // all read/write requests
57+
writers list.List
58+
ptr uintptr // pointer to net.Conn
6059
}
6160

6261
// watcher will monitor events and process async-io request(s),
@@ -650,7 +649,6 @@ func (w *watcher) handlePending(pending []*aiocb) {
650649
}
651650

652651
// as the file descriptor is registered, we can proceed to IO operations
653-
currentState := desc.armState
654652
switch pcb.op {
655653
case OpRead:
656654
// if there's no pending read requests
@@ -666,7 +664,6 @@ func (w *watcher) handlePending(pending []*aiocb) {
666664
// if the request is not fulfilled, we should queue it
667665
pcb.l = &desc.readers
668666
pcb.elem = pcb.l.PushBack(pcb)
669-
currentState |= ARM_READ
670667

671668
case OpWrite:
672669
if desc.writers.Len() == 0 {
@@ -678,13 +675,6 @@ func (w *watcher) handlePending(pending []*aiocb) {
678675

679676
pcb.l = &desc.writers
680677
pcb.elem = pcb.l.PushBack(pcb)
681-
currentState |= ARM_WRITE
682-
}
683-
684-
// state changed, try rearm descriptor
685-
if currentState != desc.armState {
686-
desc.armState = currentState
687-
w.pfd.Rearm(ident, desc.armState&ARM_READ != 0, desc.armState&ARM_WRITE != 0)
688678
}
689679

690680
// if the request has deadline set, we should push it to timeout heap
@@ -710,7 +700,6 @@ func (w *watcher) handleEvents(pe pollerEvents) {
710700
//log.Println(e)
711701
for _, e := range pe {
712702
if desc, ok := w.descs[e.ident]; ok {
713-
desc.armState = 0
714703
if e.ev&EV_READ != 0 {
715704
var next *list.Element
716705
// try to complete all read requests
@@ -727,10 +716,6 @@ func (w *watcher) handleEvents(pe pollerEvents) {
727716
}
728717

729718
}
730-
// if there's still read requests pending, rearm.
731-
if desc.readers.Len() > 0 {
732-
desc.armState |= ARM_READ
733-
}
734719

735720
if e.ev&EV_WRITE != 0 {
736721
var next *list.Element
@@ -746,15 +731,6 @@ func (w *watcher) handleEvents(pe pollerEvents) {
746731
}
747732

748733
}
749-
if desc.writers.Len() > 0 {
750-
desc.armState |= ARM_WRITE
751-
}
752-
753-
// rearm
754-
if desc.armState != 0 {
755-
w.pfd.Rearm(e.ident, desc.armState&ARM_READ != 0, desc.armState&ARM_WRITE != 0)
756-
}
757734
}
758735
}
759-
760736
}

0 commit comments

Comments
 (0)