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

feat: agent - eBPF Add delay threshold check for push period #7607

Merged
merged 1 commit into from
Jul 30, 2024
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
3 changes: 0 additions & 3 deletions agent/src/ebpf/kernel/include/task_struct_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#include <math.h>
#include "utils.h"

#define NSEC_PER_SEC 1000000000L
#define USER_HZ 100

static __inline void *get_socket_file_addr_with_check(struct task_struct *task,
int fd_num,
int files_off,
Expand Down
20 changes: 19 additions & 1 deletion agent/src/ebpf/kernel/socket_trace.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,14 @@ static __inline int output_data_common(void *ctx)
offsetof(typeof(struct __socket_data), data) + v->data_len;
v_buff->events_num++;

if (v_buff->events_num >= EVENT_BURST_NUM ||
/*
* If the delay of the periodic push event exceeds the threshold, it
* will be pushed immediately.
*/
__u64 curr_time = bpf_ktime_get_ns();
__u64 diff = curr_time - tracer_ctx->last_period_timestamp;
if (diff > PERIODIC_PUSH_DELAY_THRESHOLD_NS ||
v_buff->events_num >= EVENT_BURST_NUM ||
((sizeof(v_buff->data) - v_buff->len) < sizeof(*v))) {
__u32 buf_size =
(v_buff->len +
Expand All @@ -2399,6 +2406,17 @@ static __inline int output_data_common(void *ctx)

v_buff->events_num = 0;
v_buff->len = 0;
if (diff > PERIODIC_PUSH_DELAY_THRESHOLD_NS) {
struct trace_stats *stats;
tracer_ctx->last_period_timestamp =
tracer_ctx->period_timestamp;
tracer_ctx->period_timestamp = curr_time;
stats = trace_stats_map__lookup(&k0);
if (stats == NULL)
goto clear_args_map_1;
if (diff > stats->period_event_max_delay)
stats->period_event_max_delay = diff;
}
}

clear_args_map_1:
Expand Down
18 changes: 18 additions & 0 deletions agent/src/ebpf/user/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,22 @@ enum {
#define STACKMAP_SCALING_FACTOR 3.0
#define STACKMAP_CAPACITY_THRESHOLD 32768 // The capacity limit of the Stack trace map, power of two.

/*
* eBPF utilizes perf event's periodic events to push all data residing in the kernel
* cache. We have set this to push data from the kernel buffer every 10 milliseconds.
* This periodic event is implemented using the kernel's high-resolution timer (hrtimer),
* which triggers a timer interrupt when the specified time elapses. However, in practice,
* this timer does not always trigger interrupts precisely every 10 milliseconds to execute
* the eBPF program. This discrepancy occurs because timer interrupts may be masked off
* during certain operations, such as when interrupts are disabled during locking operations.
* Therefore, the timer may trigger interrupts after the expected time, resulting in latency
* for periodic events.
*
* The system call phase will check the time delay of the push period, and if it exceeds this
* threshold, the data will be pushed immediately. From the tests, the maximum delay is
* approximately in the range of 30 to 60 milliseconds. Therefore, it is appropriate to set the
* threshold for the system call phase check to 60 milliseconds.
*/
#define PERIODIC_PUSH_DELAY_THRESHOLD_NS 60000000ULL // 60 milliseconds

#endif /* DF_EBPF_CONFIG_H */
Loading