-
Notifications
You must be signed in to change notification settings - Fork 851
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (42 loc) · 1.15 KB
/
main.go
File metadata and controls
53 lines (42 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build linux
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/cilium/ebpf/link"
"github.com/cilium/ebpf/rlimit"
)
const ScxOpsSwitchPartial = 1 << 3
//go:generate go tool bpf2go -tags linux bpf sched_ext.c -- -I../headers/
// Load a minimal defining sched_ext_ops map
//
// After run this program, you can find the current status of the BPF scheduler can be determined as follows:
//
// # cat /sys/kernel/sched_ext/state
// enabled
// # cat /sys/kernel/sched_ext/root/ops
// miminal
func main() {
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
objs := bpfObjects{}
objs.bpfStructOps.StructOpsMinimalSched.Flags = ScxOpsSwitchPartial
objs.bpfStructOps.StructOpsMinimalSched.TimeoutMs = 1000
if err := loadBpfObjects(&objs, nil); err != nil {
log.Fatalf("loading objects: %v", err)
}
defer objs.Close()
m := objs.MinimalSched
l, err := link.AttachStructOps(link.StructOpsOptions{Map: m})
if err != nil {
log.Fatalf("failed to attach sched_ext: %s", err)
}
defer l.Close()
stopper := make(chan os.Signal, 1)
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
<-stopper
log.Print("quit sched_ext")
}