bpf

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventsMapName   = "cilium_events"
	MAX_POLL_EVENTS = 32

	PERF_TYPE_HARDWARE   = 0
	PERF_TYPE_SOFTWARE   = 1
	PERF_TYPE_TRACEPOINT = 2
	PERF_TYPE_HW_CACHE   = 3
	PERF_TYPE_RAW        = 4
	PERF_TYPE_BREAKPOINT = 5

	PERF_SAMPLE_IP           = 1 << 0
	PERF_SAMPLE_TID          = 1 << 1
	PERF_SAMPLE_TIME         = 1 << 2
	PERF_SAMPLE_ADDR         = 1 << 3
	PERF_SAMPLE_READ         = 1 << 4
	PERF_SAMPLE_CALLCHAIN    = 1 << 5
	PERF_SAMPLE_ID           = 1 << 6
	PERF_SAMPLE_CPU          = 1 << 7
	PERF_SAMPLE_PERIOD       = 1 << 8
	PERF_SAMPLE_STREAM_ID    = 1 << 9
	PERF_SAMPLE_RAW          = 1 << 10
	PERF_SAMPLE_BRANCH_STACK = 1 << 11
	PERF_SAMPLE_REGS_USER    = 1 << 12
	PERF_SAMPLE_STACK_USER   = 1 << 13
	PERF_SAMPLE_WEIGHT       = 1 << 14
	PERF_SAMPLE_DATA_SRC     = 1 << 15
	PERF_SAMPLE_IDENTIFIER   = 1 << 16
	PERF_SAMPLE_TRANSACTION  = 1 << 17
	PERF_SAMPLE_REGS_INTR    = 1 << 18

	PERF_COUNT_SW_BPF_OUTPUT = 10
)

Variables

This section is empty.

Functions

func CreateMap

func CreateMap(mapType int, keySize, valueSize, maxEntries uint32) (int, error)

CreateMap creates a Map of type mapType, with key size keySize, a value size of valueSize and the maximum amount of entries of maxEntries. mapType should be one of the bpf_map_type in "uapi/linux/bpf.h"

func DeleteElement

func DeleteElement(fd int, key unsafe.Pointer) error

DeleteElement deletes the map element with the given key.

func GetMapPrefix

func GetMapPrefix() string

func GetMapRoot

func GetMapRoot() string

func GetMtime added in v0.9.0

func GetMtime() (uint64, error)

GetMtime returns monotonic time that can be used to compare values with ktime_get_ns() BPF helper, e.g. needed to check the timeout in sec for BPF entries. We return the raw nsec, although that is not quite usable for comparison. Go has runtime.nanotime() but doesn't expose it as API.

func GetNextKey

func GetNextKey(fd int, key, nextKey unsafe.Pointer) error

GetNextKey stores, in nextKey, the next key after the key of the map in fd.

func LookupElement

func LookupElement(fd int, key, value unsafe.Pointer) error

LookupElement looks up for the map value stored in fd with the given key. The value is stored in the value unsafe.Pointer.

func MapPath

func MapPath(name string) string

func MapPrefixPath

func MapPrefixPath() string

func MountFS

func MountFS() error

func ObjClose added in v0.9.0

func ObjClose(fd int) error

ObjClose closes the map's fd.

func ObjGet

func ObjGet(pathname string) (int, error)

ObjGet reads the pathname and returns the map's fd read.

func ObjPin

func ObjPin(fd int, pathname string) error

ObjPin stores the map's fd in pathname.

func OpenOrCreateMap

func OpenOrCreateMap(path string, mapType int, keySize, valueSize, maxEntries uint32) (int, bool, error)

func SetMapPrefix

func SetMapPrefix(path string)

func SetMapRoot

func SetMapRoot(path string)

func UpdateElement

func UpdateElement(fd int, key, value unsafe.Pointer, flags uint64) error

UpdateElement updates the map in fd with the given value in the given key. The flags can have the following values (if you include "uapi/linux/bpf.h"): C.BPF_ANY to create new element or update existing; C.BPF_NOEXIST to create new element if it didn't exist; C.BPF_EXIST to update existing element.

Types

type DumpCallback

type DumpCallback func(key MapKey, value MapValue)

type DumpParser

type DumpParser func(key []byte, value []byte) (MapKey, MapValue, error)

type EPoll

type EPoll struct {
	// contains filtered or unexported fields
}

func (*EPoll) AddFD

func (ep *EPoll) AddFD(fd int, events uint32) error

func (*EPoll) Close

func (ep *EPoll) Close()

func (*EPoll) Poll

func (ep *EPoll) Poll(timeout int) (int, error)

type EventMap

type EventMap struct {
	// contains filtered or unexported fields
}

func (*EventMap) Close

func (e *EventMap) Close()

func (*EventMap) Update

func (e *EventMap) Update(ev *PerfEvent) error

type LostFunc

type LostFunc func(msg *PerfEventLost, cpu int)

type Map

type Map struct {
	MapInfo
	// contains filtered or unexported fields
}

func NewMap

func NewMap(name string, mapType MapType, keySize int, valueSize int, maxEntries int) *Map

func OpenMap

func OpenMap(name string) (*Map, error)

func (*Map) Close

func (m *Map) Close() error

func (*Map) Delete

func (m *Map) Delete(key MapKey) error

func (*Map) DeleteAll

func (m *Map) DeleteAll() error

DeleteAll deletes all entries of a map by traversing the map and deleting individual entries. Note that if entries are added while the taversal is in progress, such entries may survive the deletion process.

func (*Map) Dump

func (m *Map) Dump(parser DumpParser, cb DumpCallback) error

func (*Map) GetFd

func (m *Map) GetFd() int

func (*Map) GetNextKey added in v0.9.0

func (m *Map) GetNextKey(key MapKey, nextKey MapKey) error

GetNextKey returns the next key in the Map after key.

func (*Map) Lookup

func (m *Map) Lookup(key MapKey) (MapValue, error)

func (*Map) Open

func (m *Map) Open() error

func (*Map) OpenOrCreate

func (m *Map) OpenOrCreate() (bool, error)

func (*Map) Update

func (m *Map) Update(key MapKey, value MapValue) error

type MapInfo

type MapInfo struct {
	MapType    MapType
	KeySize    uint32
	ValueSize  uint32
	MaxEntries uint32
	Flags      uint32
}

func GetMapInfo

func GetMapInfo(pid int, fd int) (*MapInfo, error)

type MapKey

type MapKey interface {
	// Returns pointer to start of key
	GetKeyPtr() unsafe.Pointer

	// Allocates a new value matching the key type
	NewValue() MapValue
}

type MapType

type MapType int
const (
	MapTypeUnspec MapType = iota
	MapTypeHash
	MapTypeArray
	MapTypeProgArray
	MapTypePerfEventArray
	MapTypePerCPUHash
	MapTypePerCPUArray
	MapTypeStackTrace
	MapTypeCgroupArray
	MapTypeLRUHash
	MapTypeLRUPerCPUHash
	MapTypeLPMTrie
	MapTypeArrayOfMaps
	MapTypeHashOfMaps
)

This enumeration must be in sync with <linux/bpf.h>

func (MapType) String

func (t MapType) String() string

type MapValue

type MapValue interface {
	// Returns pointer to start of value
	GetValuePtr() unsafe.Pointer
}

type PerCpuEvents

type PerCpuEvents struct {
	Cpus     int
	Npages   int
	Pagesize int
	// contains filtered or unexported fields
}

func NewPerCpuEvents

func NewPerCpuEvents(config *PerfEventConfig) (*PerCpuEvents, error)

func (*PerCpuEvents) CloseAll

func (e *PerCpuEvents) CloseAll() error

func (*PerCpuEvents) Poll

func (e *PerCpuEvents) Poll(timeout int) (int, error)

func (*PerCpuEvents) ReadAll

func (e *PerCpuEvents) ReadAll(receive ReceiveFunc, lost LostFunc) error

func (*PerCpuEvents) Stats

func (e *PerCpuEvents) Stats() (uint64, uint64)

type PerfEvent

type PerfEvent struct {
	Fd int
	// contains filtered or unexported fields
}

func PerfEventOpen

func PerfEventOpen(config *PerfEventConfig, pid int, cpu int, groupFD int, flags int) (*PerfEvent, error)

func (*PerfEvent) Close

func (e *PerfEvent) Close()

func (*PerfEvent) Disable

func (e *PerfEvent) Disable() error

func (*PerfEvent) Enable

func (e *PerfEvent) Enable() error

func (*PerfEvent) Mmap

func (e *PerfEvent) Mmap(pagesize int, npages int) error

func (*PerfEvent) Read

func (e *PerfEvent) Read(receive ReceiveFunc, lostFn LostFunc) error

type PerfEventConfig

type PerfEventConfig struct {
	NumCpus      int
	NumPages     int
	MapName      string
	Type         int
	Config       int
	SampleType   int
	WakeupEvents int
}

func DefaultPerfEventConfig

func DefaultPerfEventConfig() *PerfEventConfig

type PerfEventHeader

type PerfEventHeader struct {
	Type      uint32
	Misc      uint16
	TotalSize uint16
}

PerfEventHeader must match 'struct perf_event_header in <linux/perf_event.h>.

type PerfEventLost

type PerfEventLost struct {
	PerfEventHeader
	Id   uint64
	Lost uint64
}

PerfEventLost must match 'struct perf_event_lost in kernel sources.

type PerfEventSample

type PerfEventSample struct {
	PerfEventHeader
	Size uint32
	// contains filtered or unexported fields
}

PerfEventSample must match 'struct perf_event_sample in kernel sources.

func (*PerfEventSample) DataCopy

func (e *PerfEventSample) DataCopy() []byte

func (*PerfEventSample) DataDirect

func (e *PerfEventSample) DataDirect() []byte

type ReceiveFunc

type ReceiveFunc func(msg *PerfEventSample, cpu int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL