Skip to content

Commit a0ed6d6

Browse files
committed
chore(sync): do some updates and sync
Signed-off-by: huhong-web <2420524547@qq.com>
1 parent 3f90bc3 commit a0ed6d6

51 files changed

Lines changed: 1965 additions & 475 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bpf/dropwatch.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
#define SK_FL_TYPE_SHIFT 16
2222
#define SK_FL_TYPE_MASK 0xffff0000
2323

24-
/* Reserved for future kernel skb_drop_reason (SKB_DROP_REASON_NOT_SPECIFIED,
25-
* ...) passthrough; (u32)-1 is out of band: kernel reason values grow upward
26-
* from 0 (low 16 bits code, high 16 bits subsystem since v6.4) and can never
27-
* reach it. */
28-
#define SKB_DROP_REASON_UNSUPPORT ((u32)-1)
2924
#define PKT_RAW_LEN 120
3025

3126
struct packet_meta {
@@ -38,11 +33,10 @@ struct packet_meta {
3833
u32 dev_flags; /* 4 */
3934
u32 queue_mapping; /* 4 */
4035
u32 drop_reason; /* 4 */
41-
u32 type; /* 4 */
4236
u32 net_inum; /* 4 */
4337
u8 dev_name[IFNAMSIZ]; /* 16 */
4438
u8 comm[COMPAT_TASK_COMM_LEN]; /* 16 */
45-
}; /* total: 96 bytes */
39+
}; /* 92 bytes + 4 tail pad = 96 */
4640

4741
struct packet_raw {
4842
u16 eth_proto; /* 2 */
@@ -86,6 +80,31 @@ char __license[] SEC("license") = "Dual MIT/GPL";
8680
static const struct drop_packet_event zero_data = {};
8781
static const u32 stackmap_key = 0;
8882

83+
/* kfree_skb gained an skb drop reason field in v5.17, absent from the BTF this
84+
* object is compiled against. Carry it in a CO-RE flavor relocated at load time:
85+
* the anonymous enum field matches the kernel's enum skb_drop_reason by the name
86+
* "reason". No reason constants are hardcoded (their values shift across kernels);
87+
* names are resolved at runtime from kernel BTF in userspace (loadDropReasonNames).
88+
*
89+
* SKB_DROP_REASON_UNSUPPORT = -1 satisfies C's "enum needs >=1 enumerator" rule
90+
* and is the out-of-band fallback for kernels predating the field: as (u32)-1 it
91+
* can never collide with real reasons (which grow from 0). */
92+
struct trace_event_raw_kfree_skb___reason {
93+
enum { SKB_DROP_REASON_UNSUPPORT = -1 } reason;
94+
} __attribute__((preserve_access_index));
95+
96+
/* Return the kernel skb drop reason when the running kernel supports it,
97+
* otherwise the out-of-band SKB_DROP_REASON_UNSUPPORT sentinel. */
98+
static inline u32 skb_get_drop_reason(struct trace_event_raw_kfree_skb *ctx)
99+
{
100+
struct trace_event_raw_kfree_skb___reason *ctx_reason = (void *)ctx;
101+
102+
if (bpf_core_field_exists(ctx_reason->reason))
103+
return BPF_CORE_READ(ctx_reason, reason);
104+
105+
return SKB_DROP_REASON_UNSUPPORT;
106+
}
107+
89108
struct sock___5_10 {
90109
u16 sk_type;
91110
u16 sk_protocol;
@@ -187,7 +206,7 @@ int bpf_kfree_skb_prog(struct trace_event_raw_kfree_skb *ctx)
187206
return 0;
188207

189208
/* pcap filter via bpf_pcap_stub.h: pass-through stub patched at load
190-
* time by internal/pcapinject with the compiled tcpdump expression.
209+
* time by internal/pcapfilter with the compiled tcpdump expression.
191210
*/
192211
if (!PCAP_STUB_PASS_SKB(skb))
193212
return 0;
@@ -205,16 +224,11 @@ int bpf_kfree_skb_prog(struct trace_event_raw_kfree_skb *ctx)
205224

206225
/* meta */
207226
data->meta.ktime_ns = bpf_ktime_get_ns();
208-
/* tgid_pid and comm in SoftIRQ Context do not accurately reflect
209-
* the process where the drop occurred, only for reference.
210-
*/
211227
data->meta.tgid_pid = bpf_get_current_pid_tgid();
212228
bpf_get_current_comm(&data->meta.comm, sizeof(data->meta.comm));
213-
214229
data->meta.kfree_skb_addr = (u64)(unsigned long)ctx->location;
215230
data->meta.queue_mapping = BPF_CORE_READ(skb, queue_mapping);
216-
data->meta.drop_reason = SKB_DROP_REASON_UNSUPPORT;
217-
data->meta.type = 0;
231+
data->meta.drop_reason = skb_get_drop_reason(ctx);
218232

219233
data->pkt_hdr.pkt_len = BPF_CORE_READ(skb, len);
220234

bpf/hungtask.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <bpf/bpf_tracing.h>
66

77
#include "bpf_common.h"
8-
#include "bpf_compat_7_0.h"
98
#include "bpf_ratelimit.h"
109

1110
char __license[] SEC("license") = "Dual MIT/GPL";
@@ -27,15 +26,7 @@ int tracepoint_sched_process_hang(struct trace_event_raw_sched_process_hang *ctx
2726
struct hungtask_info info = {};
2827

2928
info.pid = ctx->pid;
30-
{
31-
struct trace_event_raw_sched_process_hang___7_0 *ctx7 = (void *)ctx;
32-
if (bpf_core_field_exists(ctx7->__data_loc_comm)) {
33-
bpf_probe_read_str(info.comm, sizeof(info.comm),
34-
(void *)ctx7 + (ctx7->__data_loc_comm & 0xffff));
35-
} else {
36-
BPF_CORE_READ_STR_INTO(&info.comm, ctx, comm);
37-
}
38-
}
29+
BPF_CORE_READ_STR_INTO(&info.comm, ctx, comm);
3930
bpf_perf_event_output(ctx, &hungtask_perf_events,
4031
COMPAT_BPF_F_CURRENT_CPU, &info, sizeof(info));
4132
return 0;

bpf/include/bpf_pcap_stub.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/*
1111
* pcap_stub_l{2,3}: reserved-NOP stub functions patched at load time by
12-
* internal/pcapinject with compiled tcpdump filter bytecode. The three
12+
* internal/pcapfilter with compiled tcpdump filter bytecode. The three
1313
* ctx parameters reserve R1/R2/R3; the patched bytecode overwrites them.
1414
* Unpatched body is a pass-through: data != data_end && three-way ctx
1515
* equality both hold, so the stub always returns true.
@@ -20,7 +20,7 @@
2020
static __noinline bool pcap_stub_l3(void *_ctx, void *__ctx, void *___ctx,
2121
void *data, void *data_end)
2222
{
23-
/* 512 × 8-byte NOP insns; must equal nopAreaSize in internal/pcapinject/elfpatch.go */
23+
/* 512 × 8-byte NOP insns; must equal stubReservedInsns in internal/pcapfilter/elfpatch.go */
2424
asm volatile(".rept 512\n\t"
2525
".byte 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n\t"
2626
".endr\n\t");
@@ -30,7 +30,7 @@ static __noinline bool pcap_stub_l3(void *_ctx, void *__ctx, void *___ctx,
3030
static __noinline bool pcap_stub_l2(void *_ctx, void *__ctx, void *___ctx,
3131
void *data, void *data_end)
3232
{
33-
/* 512 × 8-byte NOP insns; must equal nopAreaSize in internal/pcapinject/elfpatch.go */
33+
/* 512 × 8-byte NOP insns; must equal stubReservedInsns in internal/pcapfilter/elfpatch.go */
3434
asm volatile(".rept 512\n\t"
3535
".byte 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n\t"
3636
".endr\n\t");

bpf/include/vmlinux_net.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#define IP_MF 0x2000 /* Flag: "More Fragments" */
1818
#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
1919

20+
// skb_mac_header - return the MAC header pointer from sk_buff
21+
static inline unsigned char *skb_mac_header(struct sk_buff *skb)
22+
{
23+
return BPF_CORE_READ(skb, head) + BPF_CORE_READ(skb, mac_header);
24+
}
25+
2026
// skb_network_header - get the network header from sk_buff
2127
static inline unsigned char *skb_network_header(struct sk_buff *skb)
2228
{
@@ -28,10 +34,4 @@ static inline unsigned char *skb_transport_header(struct sk_buff *skb)
2834
{
2935
return BPF_CORE_READ(skb, head) + BPF_CORE_READ(skb, transport_header);
3036
}
31-
32-
// skb_mac_header - return the MAC header pointer from sk_buff
33-
static inline unsigned char *skb_mac_header(struct sk_buff *skb)
34-
{
35-
return BPF_CORE_READ(skb, head) + BPF_CORE_READ(skb, mac_header);
36-
}
3737
#endif

bpf/iolatency_tracing.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "bpf_blkio.h"
88
#include "bpf_common.h"
9-
#include "bpf_compat_7_0.h"
109

1110
#define LATENCY_20MS_NS 20000000
1211
#define LATENCY_30MS_NS 30000000
@@ -114,16 +113,7 @@ static __always_inline int q2c_latency_index(struct bio *bio, u64 now)
114113
{
115114
u64 bi_issue, val;
116115

117-
{
118-
struct bio___7_0 *bio7 = (struct bio___7_0 *)bio;
119-
if (bpf_core_field_exists(bio7->issue_time_ns)) {
120-
if (bpf_probe_read(&val, sizeof(val), &bio7->issue_time_ns))
121-
return -1;
122-
} else if (bpf_probe_read(&val, sizeof(val), &bio->bi_issue)) {
123-
return -1;
124-
}
125-
}
126-
if (0)
116+
if (bpf_probe_read(&val, sizeof(val), &bio->bi_issue))
127117
return -1;
128118

129119
bi_issue = val & TIMESTAMP_MASK;

build/docker/grafana/dashboards/metrics-container.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3952,4 +3952,4 @@
39523952
"title": "Metric 大盘 - 容器视图",
39533953
"uid": "metrics-container",
39543954
"version": 1
3955-
}
3955+
}

core/events/memory_reclaim_events.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626
"huatuo-bamai/pkg/tracing"
2727
)
2828

29-
type memoryReclaimTracing struct{}
30-
31-
type memoryReclaimPerfEvent struct {
32-
Comm [bpf.TaskCommLen]byte
33-
Deltatime uint64
34-
CSS uint64
35-
Pid uint64
36-
}
29+
type (
30+
memoryReclaimTracing struct{}
31+
memoryReclaimPerfEvent struct {
32+
Comm [bpf.TaskCommLen]byte
33+
Deltatime uint64
34+
CSS uint64
35+
Pid uint64
36+
}
37+
)
3738

3839
// MemoryReclaimTracingData is the full data structure.
3940
type MemoryReclaimTracingData struct {
@@ -56,9 +57,9 @@ func newMemoryReclaim() (*tracing.EventTracingAttr, error) {
5657

5758
const cssCacheTTL = 5 * time.Second
5859

59-
//go:generate $BPF_COMPILE $BPF_INCLUDE -s $BPF_DIR/memory_reclaim_events.c -o $BPF_DIR/memory_reclaim_events.o
60-
6160
// Start detect work, load bpf and wait data form perfevent
61+
//
62+
//go:generate $BPF_COMPILE $BPF_INCLUDE -s $BPF_DIR/memory_reclaim_events.c -o $BPF_DIR/memory_reclaim_events.o
6263
func (c *memoryReclaimTracing) Start(ctx context.Context) error {
6364
b, err := bpf.LoadBpf(bpf.ThisBpfOBJ(), map[string]any{
6465
"deltath": cfg.MemoryReclaim.BlockedThreshold,

core/events/net_rx_latency.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ func (c *netRecvLatTracing) Start(ctx context.Context) error {
124124

125125
log.Debugf("net_rx_latency offset of mono to walltime: %v ns", monoWallOffset)
126126

127-
// Enable skb software RX timestamps before starting the tracer.
127+
// for tracing 'net_rx_latency' keep the skb timestamp enabled,
128+
// kernel func net_enable_timestamp() is system wide, can enable by set SOF_TIMESTAMPING_RX_SOFTWARE,
129+
// ref: https://www.kernel.org/doc/html/latest/networking/timestamping.html.
128130
tsfd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
129131
if err != nil {
130132
return fmt.Errorf("create timestamp socket: %w", err)
@@ -234,6 +236,7 @@ func (c *netRecvLatTracing) Start(ctx context.Context) error {
234236
}
235237
log.Debugf("net_rx_latency tracerData: %+v", tracerData)
236238

239+
// save storage
237240
if err := tracing.Save(&tracing.WriteRequest{
238241
TracerName: "net_rx_latency",
239242
ContainerID: containerID,
@@ -251,7 +254,7 @@ func ignore(pid uint64, comm string, hostNetnsInode uint64) (containerID string,
251254
dstInode, err := netutil.NetNSInodeByPid(int(pid))
252255
if err != nil {
253256
// ignore the missing program
254-
if errors.Is(err, syscall.ENOENT) {
257+
if errors.Is(err, syscall.ENOENT) || errors.Is(err, unix.EACCES) || errors.Is(err, unix.ESRCH) {
255258
return "", true, nil
256259
}
257260
return "", skip, fmt.Errorf("get netns inode of pid %v failed: %w", pid, err)

integration/env.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export WAIT_HUATUO_BAMAI_TIMEOUT
6262
WAIT_HUATUO_BAMAI_INTERVAL=2 # second
6363
export WAIT_HUATUO_BAMAI_INTERVAL
6464

65+
# Arrays cannot be exported to child processes via environment variables.
66+
# Convert the array to a space-separated string that can be exported and later reconstructed.
67+
HUATUO_BAMAI_INTEGRATION_ARGS_STR="${HUATUO_BAMAI_ARGS_INTEGRATION[*]}"
68+
export HUATUO_BAMAI_INTEGRATION_ARGS_STR
69+
HUATUO_BAMAI_E2E_ARGS_STR="${HUATUO_BAMAI_ARGS_E2E[*]}"
70+
export HUATUO_BAMAI_E2E_ARGS_STR
71+
6572
# k8s: metadata.name == pod-name, ct-hostname
6673
# huatuo-bamai: name == ct-hostname, hostname == pod-name == metadata.name
6774
BUSINESS_POD_NS="default"

0 commit comments

Comments
 (0)