From b94cd3038a6b1841d008690a83ed14cc0f3ff89c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 29 Nov 2015 12:19:58 +0100 Subject: add support for perf events --- sys/decl.go | 6 ++++-- sys/sys.go | 1 + sys/sys.txt | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) (limited to 'sys') diff --git a/sys/decl.go b/sys/decl.go index fd8f6089b..1cb866f62 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -75,6 +75,7 @@ const ( FdKdbus FdBpfMap FdBpfProg + FdPerf IPCMsq IPCSem @@ -172,8 +173,9 @@ func (t ResourceType) Size() uintptr { func (t ResourceType) SubKinds() []ResourceSubkind { switch t.Kind { case ResFD: - return []ResourceSubkind{FdFile, FdSock, FdPipe, FdSignal, FdEvent, FdTimer, FdEpoll, - FdDir, FdMq, FdInotify, FdFanotify, FdTty, FdDRI, FdFuse, FdKdbus, FdBpfMap, FdBpfProg} + return []ResourceSubkind{FdFile, FdSock, FdPipe, FdSignal, FdEvent, + FdTimer, FdEpoll, FdDir, FdMq, FdInotify, FdFanotify, FdTty, + FdDRI, FdFuse, FdKdbus, FdBpfMap, FdBpfProg, FdPerf} case ResIPC: return []ResourceSubkind{IPCMsq, IPCSem, IPCShm} case ResIOCtx, ResKey, ResInotifyDesc, ResPid, ResUid, ResGid, ResTimerid: diff --git a/sys/sys.go b/sys/sys.go index e902f61bf..e1163bb19 100644 --- a/sys/sys.go +++ b/sys/sys.go @@ -531,4 +531,5 @@ var Calls = []*Call{ &Call{ID: 526, Name: "bpf$OBJ_PIN_PROG", CallName: "bpf", Args: []Type{ConstType{TypeCommon: TypeCommon{TypeName: "cmd", IsOptional: false}, TypeSize: 0, Val: uintptr(6)}, PtrType{TypeCommon: TypeCommon{TypeName: "arg", IsOptional: false}, Type: StructType{TypeCommon: TypeCommon{TypeName: "bpf_obj_pin_prog", IsOptional: false}, Fields: []Type{PtrType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}, Dir: DirIn, Type: FilenameType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}}}, ResourceType{TypeCommon: TypeCommon{TypeName: "fd", IsOptional: false}, Kind: ResFD, Subkind: FdBpfProg}}}, Dir: DirIn}, LenType{TypeCommon: TypeCommon{TypeName: "size", IsOptional: false}, Buf: "arg", TypeSize: 0}}}, &Call{ID: 527, Name: "bpf$OBJ_GET_MAP", CallName: "bpf", Ret: ResourceType{TypeCommon: TypeCommon{TypeName: "ret", IsOptional: false}, Kind: ResFD, Subkind: FdBpfMap}, Args: []Type{ConstType{TypeCommon: TypeCommon{TypeName: "cmd", IsOptional: false}, TypeSize: 0, Val: uintptr(7)}, PtrType{TypeCommon: TypeCommon{TypeName: "arg", IsOptional: false}, Type: StructType{TypeCommon: TypeCommon{TypeName: "bpf_obj_get", IsOptional: false}, Fields: []Type{PtrType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}, Dir: DirIn, Type: FilenameType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}}}, ConstType{TypeCommon: TypeCommon{TypeName: "fd", IsOptional: false}, TypeSize: 4, Val: uintptr(0)}}}, Dir: DirIn}, LenType{TypeCommon: TypeCommon{TypeName: "size", IsOptional: false}, Buf: "arg", TypeSize: 0}}}, &Call{ID: 528, Name: "bpf$OBJ_GET_PROG", CallName: "bpf", Ret: ResourceType{TypeCommon: TypeCommon{TypeName: "ret", IsOptional: false}, Kind: ResFD, Subkind: FdBpfProg}, Args: []Type{ConstType{TypeCommon: TypeCommon{TypeName: "cmd", IsOptional: false}, TypeSize: 0, Val: uintptr(7)}, PtrType{TypeCommon: TypeCommon{TypeName: "arg", IsOptional: false}, Type: StructType{TypeCommon: TypeCommon{TypeName: "bpf_obj_get", IsOptional: false}, Fields: []Type{PtrType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}, Dir: DirIn, Type: FilenameType{TypeCommon: TypeCommon{TypeName: "path", IsOptional: false}}}, ConstType{TypeCommon: TypeCommon{TypeName: "fd", IsOptional: false}, TypeSize: 4, Val: uintptr(0)}}}, Dir: DirIn}, LenType{TypeCommon: TypeCommon{TypeName: "size", IsOptional: false}, Buf: "arg", TypeSize: 0}}}, + &Call{ID: 529, Name: "perf_event_open", CallName: "perf_event_open", Ret: ResourceType{TypeCommon: TypeCommon{TypeName: "ret", IsOptional: false}, Kind: ResFD, Subkind: FdPerf}, Args: []Type{PtrType{TypeCommon: TypeCommon{TypeName: "attr", IsOptional: false}, Type: StructType{TypeCommon: TypeCommon{TypeName: "perf_event_attr", IsOptional: false}, Fields: []Type{FlagsType{TypeCommon: TypeCommon{TypeName: "type", IsOptional: false}, TypeSize: 4, Vals: []uintptr{0, 1, 2, 3, 4, 5}}, LenType{TypeCommon: TypeCommon{TypeName: "size", IsOptional: false}, Buf: "parent", TypeSize: 4}, IntType{TypeCommon: TypeCommon{TypeName: "config", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "freq", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "sample", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "format", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "flags0", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags1", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags2", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags3", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags4", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags5", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags6", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "flags7", IsOptional: false}, TypeSize: 1}, IntType{TypeCommon: TypeCommon{TypeName: "wakeup", IsOptional: false}, TypeSize: 4}, FlagsType{TypeCommon: TypeCommon{TypeName: "bptype", IsOptional: false}, TypeSize: 4, Vals: []uintptr{0, 1, 2, 4}}, IntType{TypeCommon: TypeCommon{TypeName: "config1", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "config2", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "bsample", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "regs", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "stack", IsOptional: false}, TypeSize: 8}, FlagsType{TypeCommon: TypeCommon{TypeName: "clockid", IsOptional: false}, TypeSize: 4, Vals: []uintptr{0, 5, 1, 6, 4, 7, 2, 3}}, ConstType{TypeCommon: TypeCommon{TypeName: "pad", IsOptional: false}, TypeSize: 4, Val: uintptr(0)}, IntType{TypeCommon: TypeCommon{TypeName: "regs2", IsOptional: false}, TypeSize: 8}, IntType{TypeCommon: TypeCommon{TypeName: "auxwm", IsOptional: false}, TypeSize: 4}, ConstType{TypeCommon: TypeCommon{TypeName: "pad", IsOptional: false}, TypeSize: 4, Val: uintptr(0)}}}, Dir: DirIn}, ResourceType{TypeCommon: TypeCommon{TypeName: "pid", IsOptional: false}, Kind: ResPid}, IntType{TypeCommon: TypeCommon{TypeName: "cpu", IsOptional: false}, TypeSize: 8}, ResourceType{TypeCommon: TypeCommon{TypeName: "group", IsOptional: false}, Kind: ResFD, Subkind: FdPerf}, FlagsType{TypeCommon: TypeCommon{TypeName: "flags", IsOptional: false}, TypeSize: 0, Vals: []uintptr{1, 2, 4, 8}}}}, } diff --git a/sys/sys.txt b/sys/sys.txt index d7e8168b5..4f28c9efe 100644 --- a/sys/sys.txt +++ b/sys/sys.txt @@ -69,6 +69,8 @@ include include include include +include +include include @@ -1405,7 +1407,6 @@ define F_SEAL_WRITE 0x0008 #define __NR_swapoff 168 #define __NR_quotactl 179 #define __NR_nfsservctl 180 -#define __NR_perf_event_open 298 #define __NR_getcpu 309 #define __NR_process_vm_readv 310 #define __NR_process_vm_writev 311 @@ -2442,3 +2443,47 @@ define BPF_PROG_TYPE_SCHED_CLS 3 define BPF_PROG_TYPE_SCHED_ACT 4 define SO_ATTACH_BPF 50 + + + + +# Perf + +perf_event_open(attr ptr[in, perf_event_attr], pid pid, cpu intptr, group fd[perf], flags flags[perf_flags]) fd[perf] + +perf_flags = PERF_FLAG_FD_NO_GROUP, PERF_FLAG_FD_OUTPUT, PERF_FLAG_PID_CGROUP, PERF_FLAG_FD_CLOEXEC +perf_event_type = PERF_TYPE_HARDWARE, PERF_TYPE_SOFTWARE, PERF_TYPE_TRACEPOINT, PERF_TYPE_HW_CACHE, PERF_TYPE_RAW, PERF_TYPE_BREAKPOINT +perf_bp_type = HW_BREAKPOINT_EMPTY, HW_BREAKPOINT_R, HW_BREAKPOINT_W, HW_BREAKPOINT_X + +perf_event_attr { + type flags[perf_event_type, int32] + size len[parent, int32] + config int64 + freq int64 + sample int64 + format int64 +# Lots of various bit flags. +# Split into int8's because for int64 large values generated less frequently than small ones. + flags0 int8 + flags1 int8 + flags2 int8 + flags3 int8 + flags4 int8 + flags5 int8 + flags6 int8 + flags7 int8 + wakeup int32 + bptype flags[perf_bp_type, int32] + config1 int64 + config2 int64 + bsample int64 + regs int64 + stack int64 + clockid flags[clock_type, int32] + pad const[0, int32] + regs2 int64 + auxwm int32 + pad const[0, int32] +} + +define PERF_FLAG_FD_CLOEXEC (1UL << 3) -- cgit mrf-deployment