Skip to content

Commit

Permalink
Revert "combine kernel spec structs"
Browse files Browse the repository at this point in the history
This reverts commit 80f49f8.
  • Loading branch information
brycekahle committed Jan 12, 2024
1 parent a1fe308 commit b02c8ed
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions btf/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Spec struct {
}

func init() {
kernelBTF.kmods = make(map[string]*Spec)
kernelModuleBTF.spec = make(map[string]*Spec)
}

// LoadSpec opens file and calls LoadSpecFromReader on it.
Expand Down Expand Up @@ -280,19 +280,25 @@ func LoadKernelModuleSpec(module string) (*Spec, error) {

var kernelBTF struct {
sync.RWMutex
spec *Spec
kmods map[string]*Spec
spec *Spec
// True if the spec was read from an ELF instead of raw BTF in /sys.
fallback bool
}

var kernelModuleBTF struct {
sync.RWMutex
spec map[string]*Spec
}

// FlushKernelSpec removes any cached kernel type information.
func FlushKernelSpec() {
kernelBTF.Lock()
kernelModuleBTF.Lock()
defer kernelBTF.Unlock()
defer kernelModuleBTF.Unlock()

kernelBTF.spec, kernelBTF.fallback = nil, false
kernelBTF.kmods = make(map[string]*Spec)
kernelModuleBTF.spec = make(map[string]*Spec)
}

func kernelSpec() (*Spec, bool, error) {
Expand Down Expand Up @@ -321,15 +327,15 @@ func kernelSpec() (*Spec, bool, error) {
}

func kernelModuleSpec(module string) (*Spec, error) {
kernelBTF.RLock()
spec := kernelBTF.kmods[module]
kernelBTF.RUnlock()
kernelModuleBTF.RLock()
spec := kernelModuleBTF.spec[module]
kernelModuleBTF.RUnlock()

if spec == nil {
kernelBTF.Lock()
defer kernelBTF.Unlock()
kernelModuleBTF.Lock()
defer kernelModuleBTF.Unlock()

spec = kernelBTF.kmods[module]
spec = kernelModuleBTF.spec[module]
}

if spec != nil {
Expand All @@ -341,7 +347,7 @@ func kernelModuleSpec(module string) (*Spec, error) {
return nil, err
}

kernelBTF.kmods[module] = spec
kernelModuleBTF.spec[module] = spec
return spec, nil
}

Expand Down

0 comments on commit b02c8ed

Please sign in to comment.