Skip to content

Commit

Permalink
Add file mode support for MSRs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hodges <[email protected]>
  • Loading branch information
hodgesds committed Jan 14, 2023
1 parent e392454 commit 9dbdad2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions msr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func MSRPaths() ([]string, error) {
}

// MSRs attemps to return all available MSRs.
func MSRs(onErr func(error)) []*MSR {
func MSRs(flag int, perm os.FileMode, onErr func(error)) []*MSR {
paths, err := MSRPaths()
if err != nil {
onErr(err)
return nil
}
msrs := []*MSR{}
for _, path := range paths {
msr, err := NewMSR(path)
msr, err := NewMSR(path, flag, perm)
if err != nil {
onErr(err)
continue
Expand All @@ -51,8 +51,8 @@ type MSR struct {
}

// NewMSR returns a MSR.
func NewMSR(path string) (*MSR, error) {
f, err := os.OpenFile(path, os.O_RDWR, 0660)
func NewMSR(path string, flag int, perm os.FileMode) (*MSR, error) {
f, err := os.OpenFile(path, flag, perm)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions msr_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package perf

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,7 +16,7 @@ func TestMSR(t *testing.T) {
msrs, err := MSRPaths()
require.Nil(t, err)

msr, err := NewMSR(msrs[0])
msr, err := NewMSR(msrs[0], os.O_RDWR, 0660)
require.Nil(t, err)

// TODO: This may only work on certain architectures :(
Expand All @@ -28,7 +29,7 @@ func TestMSR(t *testing.T) {
}

func TestMSRs(t *testing.T) {
MSRs(func(err error) {
MSRs(os.O_RDWR, 0660, func(err error) {
require.Nil(t, err)
})
}

0 comments on commit 9dbdad2

Please sign in to comment.