-
Notifications
You must be signed in to change notification settings - Fork 367
Add support for /sys/class/mei/mei0
#792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
micgor32
wants to merge
12
commits into
prometheus:master
Choose a base branch
from
micgor32:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+321
−0
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2af5d2d
feat: add MEIClass for Management Engine Interface
micgor32 6ce5ffb
feat(testdata): update fixtures with sample mei data
micgor32 af774c8
fix: remove perms check for mei
micgor32 be02b70
feat: add test for MEIClass
micgor32 e2f72a7
chore: add license header and buildtag
micgor32 e927209
fix(mei): remove leftover DMI mentions
micgor32 f7d360a
fix(testdata): remove trailing whitespace in dev_state
micgor32 a4e4885
feat: add support for multiple MEI's
micgor32 303fd2e
feat: update test for MEIClass
micgor32 38e1002
fix: remove Name field from MEIDev
micgor32 a9a09b9
feat: add mei1 in MEIClass test
micgor32 8c5fa05
feat(testdata): add sample mei1 data
micgor32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build linux | ||
|
|
||
| package sysfs | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/prometheus/procfs/internal/util" | ||
| ) | ||
|
|
||
| const meiClassPath = "class/mei" | ||
|
|
||
| type MEIDev struct { | ||
| Dev *string | ||
| DevState *string | ||
| FWStatus *string | ||
| FWVersion *string | ||
| HBMVersion *string | ||
| HBMVersionDrv *string | ||
| Kind *string | ||
| Trc *string | ||
| TxQueueLimit *string | ||
| } | ||
|
|
||
| type MEIClass map[string]MEIDev | ||
|
|
||
| // MEIClass returns Management Engine Interface (MEI) information read from /sys/class/mei/. | ||
| func (fs FS) MEIClass() (*MEIClass, error) { | ||
| path := fs.sys.Path(meiClassPath) | ||
|
|
||
| subdirs, err := os.ReadDir(path) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to list MEI devices at %q: %w", path, err) | ||
| } | ||
|
|
||
| mei := make(MEIClass, len(subdirs)) | ||
| for _, d := range subdirs { | ||
| dev, err := fs.parseMEI(d.Name()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| mei[d.Name()] = dev | ||
| } | ||
|
|
||
| return &mei, nil | ||
| } | ||
|
|
||
| func (fs FS) parseMEI(meiDev string) (MEIDev, error) { | ||
| path := fs.sys.Path(meiClassPath, meiDev) | ||
|
|
||
| var mei MEIDev | ||
|
|
||
| files, err := os.ReadDir(path) | ||
| if err != nil { | ||
| return mei, fmt.Errorf("failed to read directory %q: %w", path, err) | ||
| } | ||
|
|
||
| for _, f := range files { | ||
| if !f.Type().IsRegular() { | ||
| continue | ||
| } | ||
|
|
||
| name := f.Name() | ||
| if name == "uevent" { | ||
| continue | ||
| } | ||
|
|
||
| filename := filepath.Join(path, name) | ||
| value, err := util.SysReadFile(filename) | ||
| if err != nil { | ||
| if os.IsPermission(err) { | ||
| continue | ||
| } | ||
|
|
||
| return mei, fmt.Errorf("failed to read file %q: %w", filename, err) | ||
| } | ||
|
|
||
| switch name { | ||
| case "dev": | ||
| mei.Dev = &value | ||
| case "dev_state": | ||
| mei.DevState = &value | ||
| case "fw_status": | ||
| mei.FWStatus = &value | ||
| case "fw_ver": | ||
| mei.FWVersion = &value | ||
| case "hbm_ver": | ||
| mei.HBMVersion = &value | ||
| case "hbm_ver_drv": | ||
| mei.HBMVersionDrv = &value | ||
| case "kind": | ||
| mei.Kind = &value | ||
| case "trc": | ||
| mei.Trc = &value | ||
| case "tx_queue_limit": | ||
| mei.TxQueueLimit = &value | ||
| } | ||
| } | ||
|
|
||
| return mei, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build linux | ||
|
|
||
| package sysfs | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestMEIClass(t *testing.T) { | ||
| fs, err := NewFS(sysTestFixtures) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| got, err := fs.MEIClass() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| dev0 := "244:0" | ||
| dev1 := "243:0" | ||
| devState := "ENABLED" | ||
| fwStatus0 := "90000245\n00110500\n00000020\n00000000\n02F41F03\n40000000" | ||
| fwStatus1 := "90000245\n00110500\n00000020\n00000004\n02F61F03\n40000000" | ||
| fwVer0 := "0:18.0.5.2098\n0:18.0.5.2098\n0:18.0.5.2098" | ||
| fwVer1 := "0:18.1.18.2595\n0:18.1.18.2595\n0:18.1.18.2599" | ||
| hbmVer := "2.2" | ||
| hbmVerDrv := "2.2" | ||
| kind := "mei" | ||
| trc0 := "00000889" | ||
| trc1 := "00000879" | ||
| txQueueLimit := "50" | ||
|
|
||
| want := &MEIClass{ | ||
| "mei0": MEIDev{ | ||
| Dev: &dev0, | ||
| DevState: &devState, | ||
| FWStatus: &fwStatus0, | ||
| FWVersion: &fwVer0, | ||
| HBMVersion: &hbmVer, | ||
| HBMVersionDrv: &hbmVerDrv, | ||
| Kind: &kind, | ||
| Trc: &trc0, | ||
| TxQueueLimit: &txQueueLimit, | ||
| }, | ||
| "mei1": MEIDev{ | ||
| Dev: &dev1, | ||
| DevState: &devState, | ||
| FWStatus: &fwStatus1, | ||
| FWVersion: &fwVer1, | ||
| HBMVersion: &hbmVer, | ||
| HBMVersionDrv: &hbmVerDrv, | ||
| Kind: &kind, | ||
| Trc: &trc1, | ||
| TxQueueLimit: &txQueueLimit, | ||
| }, | ||
| } | ||
|
|
||
| if diff := cmp.Diff(want, got); diff != "" { | ||
| t.Fatalf("unexpected MEI class (-want +got):\n%s", diff) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.