Skip to content

Commit efb1588

Browse files
committed
Added a kernel-mode switch for the feature.
Signed-off-by: skw <2438567342@qq.com>
1 parent 008e9b5 commit efb1588

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

bpf/include/bpf_common.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
/* Ip(0.0.0.2 | ::2) used for control command, e.g. KmeshControl */
1818
#define CONTROL_CMD_IP 2
1919

20-
#define PERF_MONITOR 0
21-
2220
#define MAP_SIZE_OF_OUTTER_MAP (1 << 20)
2321

2422
#define BPF_DATA_MAX_LEN \
@@ -189,36 +187,4 @@ static inline void *kmesh_get_ptr_val(const void *ptr)
189187
/* get inner_map_instance value */
190188
return kmesh_map_lookup_elem(inner_map_instance, &inner_idx);
191189
}
192-
193-
enum {
194-
SOCK_TRAFFIC_CONTROL = 1,
195-
XDP_SHUTDOWN = 2,
196-
ENABLE_ENCODING_METADATA = 3,
197-
};
198-
199-
struct operation_usage_data {
200-
__u64 start_time;
201-
__u64 end_time;
202-
__u64 pid_tgid;
203-
__u32 operation_type;
204-
};
205-
206-
struct operation_usage_key {
207-
__u64 socket_cookie;
208-
__u32 operation_type;
209-
};
210-
211-
struct {
212-
__uint(type, BPF_MAP_TYPE_HASH);
213-
__type(key, struct operation_usage_key);
214-
__type(value, struct operation_usage_data);
215-
__uint(map_flags, BPF_F_NO_PREALLOC);
216-
__uint(max_entries, 131072);
217-
} kmesh_perf_map SEC(".maps");
218-
219-
struct {
220-
__uint(type, BPF_MAP_TYPE_RINGBUF);
221-
__uint(max_entries, 4096);
222-
} kmesh_perf_info SEC(".maps");
223-
224190
#endif

bpf/kmesh/probes/performance_probe.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,41 @@
44
#ifndef __KMESH_BPF_PERFORMANCE_MONITOR_H__
55
#define __KMESH_BPF_PERFORMANCE_MONITOR_H__
66

7+
#define PERF_MONITOR 0
8+
79
#include "bpf_common.h"
810

11+
enum {
12+
SOCK_TRAFFIC_CONTROL = 1,
13+
XDP_SHUTDOWN = 2,
14+
ENABLE_ENCODING_METADATA = 3,
15+
};
16+
17+
struct operation_usage_data {
18+
__u64 start_time;
19+
__u64 end_time;
20+
__u64 pid_tgid;
21+
__u32 operation_type;
22+
};
23+
24+
struct operation_usage_key {
25+
__u64 socket_cookie;
26+
__u32 operation_type;
27+
};
28+
29+
struct {
30+
__uint(type, BPF_MAP_TYPE_HASH);
31+
__type(key, struct operation_usage_key);
32+
__type(value, struct operation_usage_data);
33+
__uint(map_flags, BPF_F_NO_PREALLOC);
34+
__uint(max_entries, 131072);
35+
} kmesh_perf_map SEC(".maps");
36+
37+
struct {
38+
__uint(type, BPF_MAP_TYPE_RINGBUF);
39+
__uint(max_entries, RINGBUF_SIZE);
40+
} kmesh_perf_info SEC(".maps");
41+
942
static inline void performance_report(struct operation_usage_data *data)
1043
{
1144
struct operation_usage_data *info = NULL;
@@ -23,6 +56,7 @@ static inline void performance_report(struct operation_usage_data *data)
2356

2457
static inline void observe_on_operation_start(__u32 operation_type, struct kmesh_context *kmesh_ctx)
2558
{
59+
#if PERF_MONITOR
2660
struct operation_usage_data data = {};
2761
struct operation_usage_key key = {};
2862
struct bpf_sock_addr *ctx = kmesh_ctx->ctx;
@@ -33,10 +67,14 @@ static inline void observe_on_operation_start(__u32 operation_type, struct kmesh
3367
data.operation_type = operation_type;
3468
bpf_map_update_elem(&kmesh_perf_map, &key, &data, BPF_ANY);
3569
return;
70+
#else
71+
return;
72+
#endif
3673
}
3774

3875
static inline void observe_on_operation_end(__u32 operation_type, struct kmesh_context *kmesh_ctx)
3976
{
77+
#if PERF_MONITOR
4078
struct operation_usage_key key = {};
4179
__u64 pid_tgid = bpf_get_current_pid_tgid();
4280
struct bpf_sock_addr *ctx = kmesh_ctx->ctx;
@@ -52,5 +90,8 @@ static inline void observe_on_operation_end(__u32 operation_type, struct kmesh_c
5290
}
5391
bpf_map_delete_elem(&kmesh_perf_map, &key);
5492
return;
93+
#else
94+
return;
95+
#endif
5596
}
5697
#endif

bpf/kmesh/probes/probe.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
#define __KMESH_BPF_PROBE_H__
66

77
#include "tcp_probe.h"
8-
9-
#if PERF_MONITOR
108
#include "performance_probe.h"
11-
#endif
129

1310
static inline void observe_on_pre_connect(struct bpf_sock *sk)
1411
{

bpf/kmesh/workload/cgroup_sock.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
static inline int sock_traffic_control(struct kmesh_context *kmesh_ctx)
1515
{
16-
#if PERF_MONITOR
1716
observe_on_operation_start(SOCK_TRAFFIC_CONTROL, kmesh_ctx);
18-
#endif
1917
int ret;
2018
frontend_value *frontend_v = NULL;
2119
frontend_key frontend_k = {0};
@@ -64,9 +62,7 @@ static inline int sock_traffic_control(struct kmesh_context *kmesh_ctx)
6462
BPF_LOG(ERR, KMESH, "frontend_manager failed, ret:%d\n", ret);
6563
return ret;
6664
}
67-
#if PERF_MONITOR
6865
observe_on_operation_end(SOCK_TRAFFIC_CONTROL, kmesh_ctx);
69-
#endif
7066
return 0;
7167
}
7268

0 commit comments

Comments
 (0)