Skip to content

sst: add support for TPMI interface and SST-TF#181

Open
marquiz wants to merge 4 commits into
intel:mainfrom
marquiz:devel/sst-tpmi
Open

sst: add support for TPMI interface and SST-TF#181
marquiz wants to merge 4 commits into
intel:mainfrom
marquiz:devel/sst-tpmi

Conversation

@marquiz
Copy link
Copy Markdown
Contributor

@marquiz marquiz commented Apr 17, 2026

This big patch contains four main changes (split into two commits):

  1. Introduce new API, required to to cover the new TPMI kernel
    interface.
  2. Add support for the TPMI interface of the Linux kernel
  3. Add new sst client that uses the new SST API. The old cmd/sst-ctl is left untouched, as an example client to test the old deprecated API.
  4. Add support for SST-TF (Turbo Frequency) feature, both the lib and the new sst client

The first patch contains heavy refactoring, almost full rewrite of some parts. It splits part of the code into separate sub-packages (mbox/ tmpi/ isst/) to make the code more maintainable.

The old SST API is marked as deprecated but is still available for backwards compatibility. The old (deprecated) API functions are wrappers around the new API and thus also support platforms that require the new TPMI interface.

An outline of the new API:

Initialization:

  • SstSupported()
  • Init()
  • SetLogger()

Platform methods:

  • Platform.Packages() (get all packages)
  • Platform.Package() (get one package)
  • Platform.ClosCount()
  • Platform.ClosAssociate()
  • Platform.GetCPUClosID()

Package methods:

  • Package.ID()
  • Package.GetStatus()
  • Package.BFEnable()
  • Package.BFDisable() error
  • Package.CPEnable()
  • Package.CPDisable()
  • Package.CPReset()
  • Package.CPSetPriorityType()
  • Package.ClosConfigure()
  • Package.TFEnable()
  • Package.TFDisable()

Note

The PR enables package-level controls. Punit-level controls can be added later if needed (and we're sure that's safe and sound).

@marquiz marquiz requested review from kad and klihub April 17, 2026 12:50
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
@marquiz marquiz force-pushed the devel/sst-tpmi branch 5 times, most recently from 4f936e8 to 78de4c7 Compare April 17, 2026 14:09
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Comment thread pkg/sst/sst_tpmi.go Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for the newer SST TPMI (API v2+) interface and refactors the existing Mbox/MMIO (API v1) implementation into separate backend-specific files with a small dispatcher that selects the correct interface at runtime.

Changes:

  • Introduce TPMI implementation (sst_tpmi.go) and a runtime backend dispatcher in sst.go (TPMI for API v2+, Mbox for v1).
  • Split existing Mbox/MMIO code into sst_mbox.go and move shared helpers into sst_common.go.
  • Extend generated SST ioctl constants/types for TPMI and add sysfs helpers for socket/die lookup.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/sst/sysfs.go Adds sysfs helpers to read socket/die IDs for a CPU.
pkg/sst/sst_types_amd64.go Updates generated ioctl constants/types to include TPMI definitions.
pkg/sst/sst_tpmi.go New TPMI backend implementation (platform info, perf levels, CP/CLOS/BF interactions).
pkg/sst/sst_mbox.go New file containing the refactored Mbox/MMIO backend logic previously in sst.go.
pkg/sst/sst_common.go Adds shared helper(s) used by both backends (e.g., punit core id derivation).
pkg/sst/sst.go Adds backend dispatcher + routes core operations through backend; adjusts CP reset/configure flows accordingly.
pkg/sst/fuzz_test.go Updates system fuzz test to call backend-specific package-info retrieval.
pkg/sst/_sst_types_amd64.go Extends cgo source types/constants used to generate sst_types_amd64.go with TPMI items.
Comments suppressed due to low confidence (1)

pkg/sst/fuzz_test.go:91

  • On TPMI platforms, backend.getSinglePackageInfo() populates only a subset of SstClosInfo fields (e.g., EPP/DesiredFreq aren’t read back), but this fuzz test compares the full struct. This will cause false failures on TPMI systems. Either compare only the fields supported by the active backend or gate/skip TPMI in this test until those fields are implemented for TPMI.
		info, err := backend.getSinglePackageInfo(pkgs[pkg].pkg)
		if err != nil {
			t.Errorf("failed to get package info: %v", err)
		}
		if !cmp.Equal(info.ClosInfo[clos], *expectedInfo) {
			t.Errorf("CLOS not configured correctly, expected %v, got %v", expectedInfo, info.ClosInfo[clos])

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/sst/sst_tpmi.go Outdated
Comment thread pkg/sst/sst.go Outdated
Comment thread pkg/sst/sst.go Outdated
Comment thread pkg/sst/sst_types_amd64.go Outdated
@marquiz marquiz force-pushed the devel/sst-tpmi branch 5 times, most recently from d508d44 to 8fea0f3 Compare April 21, 2026 17:29
@marquiz marquiz requested a review from Copilot April 21, 2026 17:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

pkg/sst/sst_if.go:42

  • cpuMap is a package-level map that is read and written from punitCPU without synchronization. If SST APIs are called concurrently (e.g., multiple goroutines calling GetPackageInfo / ClosSetup), this can trigger a "concurrent map read and map write" panic or a data race. Protect cpuMap with a mutex (or use sync.Map) around both the read and write paths.
// cpuMap holds the logical to punit cpu mapping table
var cpuMap = make(map[uint16]uint16)

// punitCPU returns the PUNIT CPU id corresponding a given Linux logical CPU
func punitCPU(cpu uint16) (uint16, error) {
	if id, ok := cpuMap[cpu]; ok {
		return id, nil
	}

	id, err := getCPUMapping(cpu)
	if err == nil {
		cpuMap[cpu] = id
	}
	return id, err

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/sst/sst_tpmi.go Outdated
Comment thread pkg/sst/sst_tpmi.go Outdated
Comment thread pkg/sst/sysfs.go Outdated
Comment thread pkg/sst/system.go
@marquiz marquiz force-pushed the devel/sst-tpmi branch 3 times, most recently from c47a370 to 7587acf Compare April 21, 2026 18:37
@marquiz marquiz requested a review from Copilot April 21, 2026 18:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

pkg/sst/sst_if.go:41

  • cpuMap is a package-level map that is read and written from getPunitCPUId without any synchronization. If SST APIs are called concurrently, this can trigger a data race or even a runtime panic (concurrent map writes). Protect the cache with a mutex (or use sync.Map), or build the mapping table once up-front and treat it as immutable thereafter.
// cpuMap holds the logical to punit cpu mapping table
var cpuMap = make(map[uint16]uint16)

// getPunitCPUId returns the PUNIT CPU id corresponding a given Linux logical CPU.
func getPunitCPUId(cpu uint16) (uint16, error) {
	if id, ok := cpuMap[cpu]; ok {
		return id, nil
	}

	id, err := getCPUMapping(cpu)
	if err == nil {
		cpuMap[cpu] = id
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/sst/sst_if.go Outdated
Comment thread pkg/sst/system.go
@marquiz marquiz force-pushed the devel/sst-tpmi branch 4 times, most recently from c702a59 to 8891806 Compare April 22, 2026 13:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pkg/sst/isst/types_amd64.go: Language not supported
Comments suppressed due to low confidence (1)

pkg/sst/isst/_types_priv.go:20

  • The regeneration instructions in this header are incorrect: types_priv.go is generated via //go:generate ./gen_types.sh in pkg/sst/isst/isst.go, so go generate ./pkg/sst/mbox/... will not regenerate this file. Update the comment to point at the correct go generate path (e.g. go generate ./pkg/sst/isst/... or go generate ./pkg/sst/...).

Comment thread pkg/sst/package.go
Comment thread cmd/sst/main.go
@marquiz marquiz force-pushed the devel/sst-tpmi branch 4 times, most recently from 8c23e00 to b6d90cf Compare May 21, 2026 09:41
@marquiz marquiz requested a review from Copilot May 21, 2026 09:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pkg/sst/isst/types_amd64.go: Language not supported
Comments suppressed due to low confidence (1)

pkg/sst/isst/_types_priv.go:19

  • The regeneration hint points to the wrong package path. This file is in pkg/sst/isst and the generator is //go:generate ./gen_types.sh in pkg/sst/isst/isst.go, so go generate ./pkg/sst/mbox/... will not update types_priv.go and is misleading. Update the comment to the correct go generate invocation (e.g. ./pkg/sst/isst/... or ./pkg/sst/...).

Comment thread pkg/sst/backend.go
Comment thread pkg/sst/tpmi/tpmi.go
Comment thread pkg/sst/tpmi/tpmi.go Outdated
@marquiz marquiz force-pushed the devel/sst-tpmi branch 2 times, most recently from c418351 to aeb7fa9 Compare May 21, 2026 10:58
@marquiz marquiz requested a review from Copilot May 21, 2026 10:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pkg/sst/isst/types_amd64.go: Language not supported
Comments suppressed due to low confidence (1)

pkg/sst/isst/_types_priv.go:20

  • The regeneration instructions in this file point to go generate ./pkg/sst/mbox/..., but the go:generate directive that produces types_priv.go lives in pkg/sst/isst/isst.go and runs ./gen_types.sh. Update the comment to reference the correct package/path so contributors can regenerate the file reliably.

Comment thread pkg/sst/package.go Outdated
Comment thread pkg/sst/tpmi/tpmi.go
marquiz added 2 commits May 21, 2026 14:24
This big patch contains two main changes:

1. Introduce new API, required to to cover the new TPMI kernel
   interface.
2. Add support for the TPMI interface of the Linux kernel

The patch contains heavy refactoring, almost full rewrite of some parts.
It splits part of the code into separate sub-packages (mbox/ tmpi/
isst/) to make the code more maintainable.

The old SST API is marked as deprecated but is still available for
backwards compatibility. The old (deprecated) API functions are wrappers
around the new API and thus also support platforms that require the new
TPMI interface.

An outline of the new API:

  Initialization:
    SstSupported()
    Init()
    SetLogger()

  Platform methods:
    Platform.Packages() (get all packages)
    Platform.Package() (get one package)
    Platform.ClosCount()
    Platform.ClosAssociate()
    Platform.GetCPUClosID()

  Package methods:
    Package.ID()
    Package.GetStatus()
    Package.BFEnable()
    Package.BFDisable() error
    Package.CPEnable()
    Package.CPDisable()
    Package.CPReset()
    Package.CPSetPriorityType()
    Package.ClosConfigure()

Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
Add new sst client that uses the new SST API. The old cmd/sst-ctl is
left untouched, as an example client to test the old deprecated API.

Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pkg/sst/isst/types_amd64.go: Language not supported
Comments suppressed due to low confidence (1)

pkg/sst/isst/_types_priv.go:19

  • The regeneration instructions are incorrect: this file belongs to the isst package and its go:generate entry point is pkg/sst/isst/isst.go (//go:generate ./gen_types.sh). go generate ./pkg/sst/mbox/... won’t regenerate types_priv.go and may mislead contributors. Update the comment to point at the correct package path (e.g. go generate ./pkg/sst/isst/... or go generate ./pkg/sst/...).

Comment thread cmd/sst/main.go
flag.Usage = usage

help := flag.Bool("help", false, "Display this help")
logLevel := log.NewLevelFlag(slog.LevelDebug)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could use LevelInfo as a default? (Ran sst status successfully out-of-the-box on a host, debug output was quite overwhelming.)

marquiz added 2 commits May 22, 2026 11:02
Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
@marquiz marquiz changed the title sst: add support for TPMI interface sst: add support for TPMI interface and SST-TF May 22, 2026
@marquiz
Copy link
Copy Markdown
Contributor Author

marquiz commented May 22, 2026

Updated: added SST-TF support to the PR.

I'd appreciate feedback on the API design 😊 Also on small things like XEnable()/XDisasable() vs. XSetStatus(enable bool)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants