Skip to content

Commit

Permalink
perf: do not add offline CPUs
Browse files Browse the repository at this point in the history
Adding nil to rings and eventFds for offline CPUs can cause issues when
iterating over these elements.
Therefore skip adding to rings and eventFds if the CPU is offline at the
time of initalization.

Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl authored and lmb committed Jul 15, 2024
1 parent 7e18818 commit fbb9ed8
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions perf/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ func NewReaderWithOptions(array *ebpf.Map, perCPUBuffer int, opts ReaderOptions)
event, ring, err := newPerfEventRing(i, perCPUBuffer, opts)
if errors.Is(err, unix.ENODEV) {
// The requested CPU is currently offline, skip it.
rings = append(rings, nil)
eventFds = append(eventFds, nil)
continue
}

Expand Down Expand Up @@ -288,14 +286,10 @@ func (pr *Reader) Close() error {
defer pr.pauseMu.Unlock()

for _, ring := range pr.rings {
if ring != nil {
ring.Close()
}
ring.Close()
}
for _, event := range pr.eventFds {
if event != nil {
event.Close()
}
event.Close()
}
pr.rings = nil
pr.eventFds = nil
Expand Down Expand Up @@ -386,11 +380,6 @@ func (pr *Reader) ReadInto(rec *Record) error {
// Waking up userspace is expensive, make the most of it by checking
// all rings.
for _, ring := range pr.rings {
// Skip rings that are not currently enabled.
if ring == nil {
continue
}

ring.loadHead()
pr.epollRings = append(pr.epollRings, ring)
}
Expand Down

0 comments on commit fbb9ed8

Please sign in to comment.