Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,31 @@ jobs:
- name: Test
run: make test

- name: Cross-build linux/arm64
run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ./...

- name: Codecov report
run: bash <(curl -s https://codecov.io/bash)

arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod

- uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: v2.13.2

- name: Verify
run: make verify

- name: Test
run: make test

trivy:
permissions:
contents: read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This file is used for auto-generation of types_amd64.go
// This file is used for auto-generation of types.go. The generated
// declarations follow the Linux/amd64 ABI but compile on every architecture
// so that importers build everywhere. Only the amd64 ioctl transport can
// execute them.
package isst

// #if !defined(__linux__) || !defined(__x86_64__)
// #error "ISST types must be generated with a Linux amd64 C compiler"
// #endif
// #include <linux/isst_if.h>
// #include <linux/ioctl.h>
//
Expand Down
12 changes: 11 additions & 1 deletion pkg/sst/internal/isst/gen_types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ set -o pipefail
tmpfile="_types_out.go"
trap "rm -f $tmpfile" EXIT

# types.go compiles on every architecture so that importers of pkg/sst build
# everywhere, but its contents are the Linux/amd64 ABI. Refuse to generate it
# for anything else.
target_os="$(go env GOOS)"
target_arch="$(go env GOARCH)"
if [ "$target_os" != "linux" ] || [ "$target_arch" != "amd64" ]; then
echo "ERROR: ISST types must be generated for the linux/amd64 ABI, not $target_os/$target_arch" >&2
exit 1
fi

generate() {
local target="$1"
shift
Expand All @@ -21,7 +31,7 @@ KERNEL_SRC_DIR="${KERNEL_SRC_DIR:-/usr/src/linux}"
echo "INFO: using kernel sources at $KERNEL_SRC_DIR"

# Generate types from Linux kernel (public) headers
generate types_amd64.go -I"$KERNEL_SRC_DIR/include/uapi" "-I$KERNEL_SRC_DIR/include"
generate types.go -I"$KERNEL_SRC_DIR/include/uapi" "-I$KERNEL_SRC_DIR/include"
generate types_msr_amd64.go -I"$KERNEL_SRC_DIR/include/uapi" "-I$KERNEL_SRC_DIR/include"

# Generate constants from Linux kernel private headers (isst tool sources)
Expand Down
38 changes: 38 additions & 0 deletions pkg/sst/internal/isst/ioctl_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2026 Intel Corporation

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.
*/

package isst

import (
"fmt"
"os"
"syscall"
"unsafe"
)

// Ioctl executes an ioctl on the Linux isst_if device driver.
func Ioctl(ioctl uintptr, req unsafe.Pointer) error {
devPath := DevPath()
f, err := os.Open(devPath)
if err != nil {
return fmt.Errorf("failed to open isst device %q: %v", devPath, err)
}
defer f.Close() //nolint:errcheck
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), ioctl, uintptr(req)); errno != 0 {
return errno
}
return nil
}
32 changes: 32 additions & 0 deletions pkg/sst/internal/isst/ioctl_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build !amd64

/*
Copyright 2026 Intel Corporation

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.
*/

package isst

import (
"errors"
"unsafe"
)

var errUnsupportedArchitecture = errors.New("SST ioctls are not supported on non-amd64 architectures")

// Ioctl rejects SST ioctl requests on architectures where the transport is
// unavailable.
func Ioctl(_ uintptr, _ unsafe.Pointer) error {
return errUnsupportedArchitecture
}
44 changes: 44 additions & 0 deletions pkg/sst/internal/isst/ioctl_unsupported_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//go:build !amd64

/*
Copyright 2026 Intel Corporation

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.
*/

package isst

import (
"os"
"path/filepath"
"testing"

goresctrlpath "github.com/intel/goresctrl/pkg/path"
)

func TestIoctlUnsupportedArchitecture(t *testing.T) {
root := t.TempDir()
devDir := filepath.Join(root, "dev")
if err := os.MkdirAll(devDir, 0o755); err != nil {
t.Fatalf("failed to create fake dev directory: %v", err)
}
if err := os.WriteFile(filepath.Join(devDir, "isst_interface"), nil, 0o600); err != nil {
t.Fatalf("failed to create fake isst device: %v", err)
}
goresctrlpath.SetPrefix(root)
t.Cleanup(func() { goresctrlpath.SetPrefix("/") })

if err := Ioctl(0, nil); err != errUnsupportedArchitecture {
t.Fatalf("Ioctl returned unexpected error on a non-amd64 architecture: %v", err)
}
}
20 changes: 4 additions & 16 deletions pkg/sst/internal/isst/isst.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ limitations under the License.

package isst

// The generated fixed-width ISST UAPI declarations compile on all
// architectures so packages can import SST everywhere. They are generated
// from the Linux/amd64 ABI, while the ioctl transport rejects execution
// outside amd64.
//go:generate ./gen_types.sh

import (
"fmt"
"log/slog"
"os"
"sync"
"syscall"
"unsafe"

goresctrlpath "github.com/intel/goresctrl/pkg/path"
Expand All @@ -37,20 +39,6 @@ func SetLogger(l *slog.Logger) { log = l }
// DevPath returns the path to the isst_interface device.
func DevPath() string { return goresctrlpath.Path("dev/isst_interface") }

// Ioctl executes an ioctl on the linux isst_if device driver.
func Ioctl(ioctl uintptr, req unsafe.Pointer) error {
devPath := DevPath()
f, err := os.Open(devPath)
if err != nil {
return fmt.Errorf("failed to open isst device %q: %v", devPath, err)
}
defer f.Close() //nolint:errcheck
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), ioctl, uintptr(req)); errno != 0 {
return errno
}
return nil
}

var (
cpuMapMu sync.RWMutex
cpuMap = make(map[uint16]uint16)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions pkg/sst/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ package sst

import (
"fmt"
"os"
"slices"

"github.com/intel/goresctrl/pkg/sst/internal/isst"
"github.com/intel/goresctrl/pkg/utils"
)

Expand All @@ -31,21 +29,6 @@ type Platform struct {
packages map[int]*cpuPackageInfo
}

// SstSupported returns true if Intel Speed Select Technologies (SST) is
// supported by the system and can be interfaced via the Linux kernel device.
func SstSupported() bool {
devPath := isst.DevPath()
if _, err := os.Stat(devPath); err != nil {
if !os.IsNotExist(err) {
sstlog.Error("failed to access sst device", "path", devPath, "error", err)
} else {
sstlog.Debug("sst device does not exist", "path", devPath)
}
return false
}
return true
}

// Init initializes SST and returns a handle. The handle stores a snapshot of
// CPU topology of online CPUs at init time and is not updated on CPU hotplug.
func Init() (*Platform, error) {
Expand Down
38 changes: 38 additions & 0 deletions pkg/sst/platform_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2026 Intel Corporation

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.
*/

package sst

import (
"os"

"github.com/intel/goresctrl/pkg/sst/internal/isst"
)

// SstSupported returns true if Intel Speed Select Technologies (SST) is
// supported by the system and can be interfaced via the Linux kernel device.
func SstSupported() bool {
devPath := isst.DevPath()
if _, err := os.Stat(devPath); err != nil {
if !os.IsNotExist(err) {
sstlog.Error("failed to access sst device", "path", devPath, "error", err)
} else {
sstlog.Debug("sst device does not exist", "path", devPath)
}
return false
}
return true
}
47 changes: 47 additions & 0 deletions pkg/sst/platform_amd64_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2026 Intel Corporation

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.
*/

package sst

import (
"os"
"path/filepath"
"testing"

goresctrlpath "github.com/intel/goresctrl/pkg/path"
)

func TestSstSupported(t *testing.T) {
root := t.TempDir()
goresctrlpath.SetPrefix(root)
t.Cleanup(func() { goresctrlpath.SetPrefix("/") })

if SstSupported() {
t.Fatal("SstSupported returned true with no isst device")
}

devDir := filepath.Join(root, "dev")
if err := os.MkdirAll(devDir, 0o755); err != nil {
t.Fatalf("failed to create fake dev directory: %v", err)
}
if err := os.WriteFile(filepath.Join(devDir, "isst_interface"), nil, 0o600); err != nil {
t.Fatalf("failed to create fake isst device: %v", err)
}

if !SstSupported() {
t.Fatal("SstSupported returned false with an isst device")
}
}
26 changes: 26 additions & 0 deletions pkg/sst/platform_unsupported.go
Comment thread
TonyxSun marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build !amd64

/*
Copyright 2026 Intel Corporation

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.
*/

package sst

// SstSupported returns false because Intel Speed Select Technologies (SST)
// cannot be interfaced on non-amd64 architectures.
func SstSupported() bool {
sstlog.Debug("sst is not supported on non-amd64 architectures")
return false
}
Loading
Loading