Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor nits #32

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ import (
var log = logger.Get()

type Events struct {
RingBuffers []*RingBuffer
PageSize int
RingCnt int
stopRingBufferChan chan struct{}
updateRingBufferChan chan *RingBuffer
eventsStopChannel chan struct{}
wg sync.WaitGroup
eventsDataChannel chan []byte
RingBuffers []*RingBuffer
PageSize int
RingCnt int
eventsStopChannel chan struct{}
wg sync.WaitGroup
eventsDataChannel chan []byte

epoller *poller.EventPoller
}
Expand Down Expand Up @@ -165,13 +163,7 @@ func (ev *Events) CleanupRingBuffer() {
return
}

func (ev *Events) reconcileEventsDataChannel() {

pollerCh := ev.epoller.EpollStart()
defer func() {
ev.wg.Done()
}()

func (ev *Events) reconcileEventsDataChannelHandler(pollerCh <-chan int) {
for {
select {
case bufferPtr, ok := <-pollerCh:
Expand All @@ -187,6 +179,16 @@ func (ev *Events) reconcileEventsDataChannel() {
}
}

func (ev *Events) reconcileEventsDataChannel() {

pollerCh := ev.epoller.EpollStart()
defer ev.wg.Done()

go ev.reconcileEventsDataChannelHandler(pollerCh)

<-ev.eventsStopChannel
}

// Similar to libbpf poll ring
func (ev *Events) ReadRingBuffer(eventRing *RingBuffer) {
readDone := true
Expand Down
37 changes: 20 additions & 17 deletions pkg/events/poll/epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ type EventPoller struct {
epollEvent []unix.EpollEvent
bufferCnt int

stopEventPollerChan chan struct{}
updateEventPollerChan chan int
stopEventPollerChan chan struct{}
fdEventPollerChan chan int
}

func NewEventPoller() (*EventPoller, error) {
epollFD, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
if err != nil {
return nil, fmt.Errorf("Failed to create epoll instance: %s", err)
return nil, fmt.Errorf("failed to create epoll instance: %s", err)
}
e := &EventPoller{
epollFd: epollFD,
epollFd: epollFD,
stopEventPollerChan: make(chan struct{}),
fdEventPollerChan: make(chan int),
}
return e, nil
}
Expand All @@ -52,12 +54,21 @@ func (e *EventPoller) AddEpollCtl(mapFD, eventFD int) error {

func (e *EventPoller) EpollStart() <-chan int {

e.stopEventPollerChan = make(chan struct{})
e.updateEventPollerChan = make(chan int)
e.wg.Add(1)
go e.eventsPoller()

return e.updateEventPollerChan
return e.fdEventPollerChan
}

func (e *EventPoller) getEventFDs(totalEvents int) {
for _, event := range e.epollEvent[:totalEvents] {
select {
case e.fdEventPollerChan <- int(event.Fd):

case <-e.stopEventPollerChan:
return
}
}
}

func (e *EventPoller) eventsPoller() {
Expand All @@ -69,20 +80,12 @@ func (e *EventPoller) eventsPoller() {
default:
break
}
numEvents := e.poll(e.epollEvent[:e.bufferCnt])
for _, event := range e.epollEvent[:numEvents] {
select {
case e.updateEventPollerChan <- int(event.Fd):

case <-e.stopEventPollerChan:
return
}
}
totalEvents := e.poll(e.epollEvent[:e.bufferCnt])
e.getEventFDs(totalEvents)
}
}

func (e *EventPoller) poll(events []unix.EpollEvent) int {

timeoutMs := 150
n, err := unix.EpollWait(e.epollFd, events, timeoutMs)
if err != nil {
Expand Down