Skip to content

Commit 86e4bf8

Browse files
committed
make max tails configurable
1 parent 004fa15 commit 86e4bf8

9 files changed

Lines changed: 18 additions & 6 deletions

File tree

support/ebpf/tracemgmt.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ static inline PerCPURecord *get_per_cpu_record(void)
204204
static inline PerCPURecord *get_pristine_per_cpu_record()
205205
{
206206
PerCPURecord *record = get_per_cpu_record();
207+
int key0 = 0;
208+
SystemConfig *syscfg = bpf_map_lookup_elem(&system_config, &key0);
209+
if (!syscfg)
210+
return NULL;
207211
if (!record)
208212
return record;
209213

@@ -235,7 +239,7 @@ static inline PerCPURecord *get_pristine_per_cpu_record()
235239
record->luajitUnwindState.cframe = 0;
236240
record->luajitUnwindState.is_jit = false;
237241
record->unwindersDone = 0;
238-
record->tailCalls = 0;
242+
record->tailCallsRemaining = syscfg->max_tail_calls;
239243
record->ratelimitAction = RATELIMIT_ACTION_DEFAULT;
240244
record->customLabelsState.go_m_ptr = NULL;
241245

@@ -516,7 +520,7 @@ static inline __attribute__((__always_inline__)) void tail_call(void *ctx, int n
516520
return;
517521
}
518522

519-
if (record->tailCalls >= 58) {
523+
if (!record->tailCallsRemaining) {
520524
// At this point
521525
// there is a chance that continuing unwinding the stack would further increase the number of
522526
// tail calls. As a result we might lose the unwound stack as no further tail calls are left
@@ -526,7 +530,7 @@ static inline __attribute__((__always_inline__)) void tail_call(void *ctx, int n
526530
record->state.unwind_error = ERR_MAX_TAIL_CALLS;
527531
increment_metric(metricID_MaxTailCalls);
528532
}
529-
record->tailCalls += 1;
533+
--record->tailCallsRemaining;
530534

531535
bpf_tail_call(ctx, &perf_progs, next);
532536
}
1.85 KB
Binary file not shown.
1.86 KB
Binary file not shown.
576 Bytes
Binary file not shown.
-1.05 KB
Binary file not shown.

support/ebpf/types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ typedef struct PerCPURecord {
886886
u32 unwindersDone;
887887

888888
// tailCalls tracks the number of calls to bpf_tail_call().
889-
u8 tailCalls;
889+
u8 tailCallsRemaining;
890890

891891
// ratelimitAction determines the PID event rate limiting mode
892892
u8 ratelimitAction;
@@ -1051,6 +1051,9 @@ typedef struct SystemConfig {
10511051

10521052
// Enables the temporary hack that drops pure errors frames in unwind_stop.
10531053
bool drop_error_only_traces;
1054+
1055+
// Maximum number of eBPF tail calls before giving up.
1056+
u8 max_tail_calls;
10541057
} SystemConfig;
10551058

10561059
// Avoid including all of arch/arm64/include/uapi/asm/ptrace.h by copying the

testutils/helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func StartTracer(ctx context.Context, t *testing.T, et tracertypes.IncludedTrace
5050
SamplesPerSecond: 20,
5151
ProbabilisticInterval: 100,
5252
ProbabilisticThreshold: 100,
53+
MaxTailCalls: 29,
5354
})
5455
require.NoError(t, err)
5556

tracer/systemconfig.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ func determineStackLayout(coll *cebpf.CollectionSpec, maps map[string]*cebpf.Map
227227

228228
func loadSystemConfig(coll *cebpf.CollectionSpec, maps map[string]*cebpf.Map,
229229
kernelSymbols *libpf.SymbolMap, includeTracers types.IncludedTracers,
230-
offCPUThreshold uint32, filterErrorFrames bool) error {
230+
offCPUThreshold uint32, filterErrorFrames bool,
231+
maxTailCalls uint8) error {
231232
pacMask := pacmask.GetPACMask()
232233
if pacMask != 0 {
233234
log.Infof("Determined PAC mask to be 0x%016X", pacMask)
@@ -238,6 +239,7 @@ func loadSystemConfig(coll *cebpf.CollectionSpec, maps map[string]*cebpf.Map,
238239
inverse_pac_mask: ^C.u64(pacMask),
239240
drop_error_only_traces: C.bool(filterErrorFrames),
240241
off_cpu_threshold: C.u32(offCPUThreshold),
242+
max_tail_calls: C.u8(maxTailCalls),
241243
}
242244

243245
if err := parseBTF(&syscfg); err != nil {

tracer/tracer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ type Config struct {
159159
ProbabilisticThreshold uint
160160
// OffCPUThreshold is the user defined threshold for off-cpu profiling.
161161
OffCPUThreshold uint32
162+
// MaxTailCalls is the number of tail calls the eBPF is allowed to make before giving up.
163+
MaxTailCalls uint8
162164
}
163165

164166
// hookPoint specifies the group and name of the hooked point in the kernel.
@@ -511,7 +513,7 @@ func initializeMapsAndPrograms(kernelSymbols *libpf.SymbolMap, cfg *Config) (
511513
}
512514

513515
if err = loadSystemConfig(coll, ebpfMaps, kernelSymbols, cfg.IncludeTracers,
514-
cfg.OffCPUThreshold, cfg.FilterErrorFrames); err != nil {
516+
cfg.OffCPUThreshold, cfg.FilterErrorFrames, cfg.MaxTailCalls); err != nil {
515517
return nil, nil, fmt.Errorf("failed to load system config: %v", err)
516518
}
517519

0 commit comments

Comments
 (0)