8000 rewrite bpf const · lx1036/code@93876f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93876f4

Browse files
author
shenming
committed
rewrite bpf const
1 parent d1ef50e commit 93876f4

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

go/k8s/bpf/xdp-l4lb/xdp-cilium-l4lb/cilium/test/tproxy/socket-service/tcphdr/rewrite-constant/main.go

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package main
22

33
import (
44
"github.com/cilium/ebpf"
5-
"github.com/cilium/ebpf/btf"
65
"github.com/cilium/ebpf/link"
76
"github.com/sirupsen/logrus"
87
"net"
98
"os"
109
"os/signal"
1110
"syscall"
11+
"time"
1212
)
1313

1414
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -type bpf_test_option bpf test_rewrite_const.c -- -I.
@@ -63,22 +63,51 @@ func main() {
6363
}
6464
defer l.Close()
6565

66-
/*for name, mapSpec := range spec.Maps {
67-
logrus.Infof("map name: %s, mapSpec: %+v", name, *mapSpec)
68-
if name == ".bss" {
69-
for _, varSecinfo := range mapSpec.Value.(*btf.Datasec).Vars {
70-
//logrus.Infof("%+v", varSecinfo.Type.(*btf.Var))
71-
v := varSecinfo.Type.(*btf.Var)
72-
logrus.Infof("%+v", v.Type)
73-
u32 := v.Type.(*btf.Volatile).Type.(*btf.Typedef)
74-
logrus.Infof("%+v", u32.Type.(*btf.Int))
75-
}
76-
}
77-
}*/
66+
time.Sleep(time.Second)
67+
68+
for name, mapSpec := range spec.Maps {
69+
logrus.Infof("map name: %s, mapSpec: %+v", name, *mapSpec)
70+
//if name == ".bss" { // 有两个 .bss map
71+
m, err := ebpf.NewMap(mapSpec)
72+
if err != nil {
73+
logrus.Errorf("err: %v", err)
74+
continue
75+
}
76+
77+
mapInfo, err := m.Info()
78+
if err != nil {
79+
logrus.Error(err)
80+
}
81+
logrus.Infof("map.Info: %+v", mapInfo)
82+
83+
var val uint32
84+
err = m.Lookup(uint32(0), &val)
85+
if err != nil {
86+
logrus.Errorf("err: %v", err)
87+
}
88+
logrus.Infof("val: %d", val)
89+
90+
//iterator := m.Iterate()
91+
//var key uint32
92+
//var value uint32
93+
//for iterator.Next(&key, &value) {
94+
// logrus.Infof("key: %v, value: %v", key, value)
95+
//}
96+
97+
//for _, varSecinfo := range mapSpec.Value.(*btf.Datasec).Vars {
98+
// //logrus.Infof("%+v", varSecinfo.Type.(*btf.Var))
99+
// v := varSecinfo.Type.(*btf.Var)
100+
// logrus.Infof("%+v", v.Type)
101+
// u32 := v.Type.(*btf.Volatile).Type.(*btf.Typedef)
102+
// logrus.Infof("%+v", u32.Type.(*btf.Int))
103+
//}
104+
//}
105+
}
106+
78107
// TODO: 无法访问 bpf 里 inherit_cb_flags 变量值
79-
typ, err := spec.Types.AnyTypeByName("inherit_cb_flags")
80-
logrus.Infof("%+v", typ)
81-
logrus.Infof("%+v", typ.(*btf.Var).Type.(*btf.Volatile).Type.(*btf.Typedef).Type.(*btf.Int))
108+
//typ, err := spec.Types.AnyTypeByName("inherit_cb_flags")
109+
//logrus.Infof("%+v", typ)
110+
//logrus.Infof("%+v", typ.(*btf.Var).Type.(*btf.Volatile).Type.(*btf.Typedef).Type.(*btf.Int))
82111

83112
// Wait
84113
<-stopCh

go/k8s/bpf/xdp-l4lb/xdp-cilium-l4lb/cilium/test/tproxy/socket-service/tcphdr/rewrite-constant/test_rewrite_const.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
#include <bpf/bpf_endian.h>
1515

1616

17-
static volatile __u32 inherit_cb_flags = 0;
17+
/**
18+
* bpftool gen skeleton bpf_bpfel.o > bpf_bpfel.skel.h
19+
* readelf -a bpf_bpfel.o
20+
*/
21+
// https://cilium.slack.com/archives/C4XCTGYEM/p1709030644794629?thread_ts=1709025000.815169&cid=C4XCTGYEM
22+
__u32 inherit_cb_flags = 0;
23+
//static volatile __u32 inherit_cb_flags = 0;
1824

1925
struct bpf_test_option {
2026
__u8 flags;

go/k8s/刘祥-简化.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
### (1) 在离线混合部署项目开发
3030
开发人员:2个人开发整个项目,目前还没生产使用。
3131

32-
(1.1.1) CPU 资源隔离
33-
前期阶段:早期阶段基于社区 linux 4.19 kernel,使用 cpuset 物理核完全隔离来避免超线程干扰。
32+
(1.1) CPU 资源隔离
33+
前期阶段基于社区 linux 4.19 kernel,使用 cpuset 物理核完全隔离来避免超线程干扰。后期阶段基于 Aliyun linux 4.19 kernel,
34+
基于 GroupIdentity 进程优先级的调度功能,开发的 agent 设置 cpu.bvt_warp_ns cgroup,来避免超线程干扰。同时,使用 cpu.cfs_quota_us
35+
来实现 CPU Suppress 压制。
3436

35-
后期阶段:基于 Aliyun linux 4.19 kernel,基于 GroupIdentity 进程优先级的调度功能,开发的 agent 设置 cpu.bvt_warp_ns cgroup,来避免超线程干扰。
36-
同时,使用 cpu.cfs_quota_us 来实现 CPU Suppress 压制。
37-
38-
(1.1.2) Memory 资源隔离
37+
(1.2) Memory 资源隔离
3938
后期阶段基于 Aliyun linux 4.19 kernel: 通过设置 cgroup memory.wmark_ratio(0-100) 值来实现内存异步回收。
4039

41-
(1.1.3) Disk I/O 资源隔离
40+
(1.3) Disk I/O 资源隔离
4241
直接使用两块盘做隔离,离线业务 Pod 使用一个盘,在线业务 Pod 使用另一个盘。
4342

4443
(1.1.4) 网络带宽隔离和限制相关的调研
@@ -91,6 +90,16 @@
9190
现状:fusefs 和 fusefs-csi 目前是公司内部容器云默认的分布式文件存储系统,已经在所有生产 K8S 上部署支持。
9291

9392
## 阿里云(2022-12 ~ 至今)
93+
在全球加速项目组日常业务开发。
94+
### 转发项目开发
95+
96+
97+
### ebpf acl 项目
98+
99+
100+
### 使用 ebpf 来优雅升级 tengine 项目
101+
102+
94103

95104

96105

0 commit comments

Comments
 (0)
0