From fed0a5700b9dc270ee173ea09b217217c9bbdade Mon Sep 17 00:00:00 2001 From: usamasaqib Date: Mon, 23 Dec 2024 12:36:59 +0100 Subject: [PATCH] add comments explaining the `updateMaxTelemetry` function --- pkg/ebpf/perf/event.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/ebpf/perf/event.go b/pkg/ebpf/perf/event.go index ad0a0318e2f25e..6ca3591c9dc1c3 100644 --- a/pkg/ebpf/perf/event.go +++ b/pkg/ebpf/perf/event.go @@ -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 }