Skip to content

Commit

Permalink
add comments explaining the updateMaxTelemetry function
Browse files Browse the repository at this point in the history
  • Loading branch information
usamasaqib committed Dec 23, 2024
1 parent 0f1ed30 commit fed0a57
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/ebpf/perf/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,18 @@ func UpgradePerfBuffer(mgr *manager.Manager, mgrOpts *manager.Options, mapName s
})
}

// implement the CAS algorithm to atomically update a max value
func updateMaxTelemetry(a *atomic.Uint64, val uint64) {
for {
oldVal := a.Load()
if val <= oldVal {
return
}
// if the value at a is not `oldVal`, then `CompareAndSwap` returns
// false indicating that the value of the atomic has changed between
// the above check and this invocation.
// In this case we retry the above test, to see if the value still needs
// to be updated.
if a.CompareAndSwap(oldVal, val) {
return
}
Expand Down

0 comments on commit fed0a57

Please sign in to comment.