Skip to content

Commit

Permalink
fix lock contention asset names (DataDog#29884)
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle authored Oct 9, 2024
1 parent 81e640e commit ab07d08
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions pkg/ebpf/lockcontention.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,9 @@ const (
// or just system-probe resources
TrackAllEBPFResources = true

lockContetionBpfObjectFile = "bytecode/build/co-re/lock_contention.o"
ksymsIterBpfObjectFile = "bytecode/build/co-re/ksyms_iter.o"

// bpf map names
mapAddrFdBpfMap = "map_addr_fd"
lockStatBpfMap = "lock_stat"
rangesBpfMap = "ranges"
timeStampBpfMap = "tstamp"

// bpf probe name
fnDoVfsIoctl = "do_vfs_ioctl"

// ioctl trigget code
// ioctl trigger code
ioctlCollectLocksCmd = 0x70c13

// bpf global constants
numCpus = "num_cpus"
numRanges = "num_of_ranges"
logTwoNumOfRanges = "log2_num_of_ranges"

// maximum lock ranges to track
maxTrackedRanges = 16384
)
Expand Down Expand Up @@ -335,7 +318,7 @@ func (l *LockContentionCollector) Initialize(trackAllResources bool) error {

var ranges uint32
var cpus uint32
if err := LoadCOREAsset(lockContetionBpfObjectFile, func(bc bytecode.AssetReader, managerOptions manager.Options) error {
if err := LoadCOREAsset("lock_contention.o", func(bc bytecode.AssetReader, managerOptions manager.Options) error {
collectionSpec, err := ebpf.LoadCollectionSpecFromReader(bc)
if err != nil {
return fmt.Errorf("failed to load collection spec: %w", err)
Expand All @@ -350,21 +333,21 @@ func (l *LockContentionCollector) Initialize(trackAllResources bool) error {

ranges = constrainMaxRanges(estimateNumOfLockRanges(maps, cpus))
l.ranges = ranges
collectionSpec.Maps[mapAddrFdBpfMap].MaxEntries = ranges
collectionSpec.Maps[lockStatBpfMap].MaxEntries = ranges
collectionSpec.Maps[rangesBpfMap].MaxEntries = ranges
collectionSpec.Maps["map_addr_fd"].MaxEntries = ranges
collectionSpec.Maps["lock_stat"].MaxEntries = ranges
collectionSpec.Maps["ranges"].MaxEntries = ranges

// Ideally we would want this to be the max number of proccesses allowed
// Ideally we would want this to be the max number of processes allowed
// by the kernel, however verifier constraints force us to choose a smaller
// value. This value has been experimentally determined to pass the verifier.
collectionSpec.Maps[timeStampBpfMap].MaxEntries = 16384
collectionSpec.Maps["tstamp"].MaxEntries = 16384

constants[numCpus] = uint64(cpus)
constants["num_cpus"] = uint64(cpus)
for ksym, addr := range kaddrs {
constants[ksym] = addr
}
constants[numRanges] = uint64(ranges)
constants[logTwoNumOfRanges] = uint64(math.Log2(float64(ranges)))
constants["num_of_ranges"] = uint64(ranges)
constants["log2_num_of_ranges"] = uint64(math.Log2(float64(ranges)))

if err := collectionSpec.RewriteConstants(constants); err != nil {
return fmt.Errorf("failed to write constant: %w", err)
Expand All @@ -382,15 +365,15 @@ func (l *LockContentionCollector) Initialize(trackAllResources bool) error {
if errors.As(err, &ve) {
return fmt.Errorf("verfier error loading collection: %s\n%+v", err, ve)
}
return fmt.Errorf("failed to load objects: %w", err)
return fmt.Errorf("failed to load objects (%d ranges): %w", l.ranges, err)
}

return nil
}); err != nil {
return err
}

kp, err := link.Kprobe(fnDoVfsIoctl, l.objects.KprobeVfsIoctl, nil)
kp, err := link.Kprobe("do_vfs_ioctl", l.objects.KprobeVfsIoctl, nil)
if err != nil {
return fmt.Errorf("failed to attack kprobe: %w", err)
}
Expand Down Expand Up @@ -548,7 +531,7 @@ type ksymIterProgram struct {
func getKernelSymbolsAddressesWithKallsymsIterator(kernelAddresses ...string) (map[string]uint64, error) {
var prog ksymIterProgram

if err := LoadCOREAsset(ksymsIterBpfObjectFile, func(bc bytecode.AssetReader, managerOptions manager.Options) error {
if err := LoadCOREAsset("ksyms_iter.o", func(bc bytecode.AssetReader, managerOptions manager.Options) error {
collectionSpec, err := ebpf.LoadCollectionSpecFromReader(bc)
if err != nil {
return fmt.Errorf("failed to load collection spec: %w", err)
Expand Down

0 comments on commit ab07d08

Please sign in to comment.