Skip to content

Commit

Permalink
chore(qrm): support cpu/memory write-only state
Browse files Browse the repository at this point in the history
  • Loading branch information
luomingmeng committed Nov 22, 2024
1 parent 26b7de0 commit c741de5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
}

state.SetReadonlyState(stateImpl)
state.SetWriteOnlyState(stateImpl)

wrappedEmitter := agentCtx.EmitterPool.GetDefaultMetricsEmitter().WithTags(agentName, metrics.MetricTag{
Key: util.QRMPluginPolicyTagName,
Expand Down
31 changes: 31 additions & 0 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ type ReadonlyState interface {
reader
}

// WriteOnlyState interface only provides methods for update pod assignments
type WriteOnlyState interface {
writer
}

type GenerateMachineStateFromPodEntriesFunc func(topology *machine.CPUTopology, podEntries PodEntries) (NUMANodeMap, error)

var (
Expand Down Expand Up @@ -589,3 +594,29 @@ func SetReadonlyState(state ReadonlyState) {

readonlyState = state
}

var (
writeOnlyStateLock sync.RWMutex
writeOnlyState WriteOnlyState
)

// GetWriteOnlyState returns state.WriteOnlyState to provides a way
// to update the states of the plugin
func GetWriteOnlyState() (WriteOnlyState, error) {
writeOnlyStateLock.RLock()
defer writeOnlyStateLock.RUnlock()

if writeOnlyState == nil {
return nil, fmt.Errorf("readonlyState isn't set")
}
return writeOnlyState, nil
}

// SetWriteOnlyState sets state.WriteOnlyState to be used by the plugin
// this function should only be called once during initialization
func SetWriteOnlyState(state WriteOnlyState) {
readonlyStateLock.Lock()
defer readonlyStateLock.Unlock()

writeOnlyState = state
}
1 change: 1 addition & 0 deletions pkg/agent/qrm-plugins/cpu/nativepolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func NewNativePolicy(agentCtx *agent.GenericContext, conf *config.Configuration,
}

state.SetReadonlyState(stateImpl)
state.SetWriteOnlyState(stateImpl)

wrappedEmitter := agentCtx.EmitterPool.GetDefaultMetricsEmitter().WithTags(agentName, metrics.MetricTag{
Key: util.QRMPluginPolicyTagName,
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
}

state.SetReadonlyState(stateImpl)
state.SetWriteOnlyState(stateImpl)

wrappedEmitter := agentCtx.EmitterPool.GetDefaultMetricsEmitter().WithTags(agentName, metrics.MetricTag{
Key: util.QRMPluginPolicyTagName,
Expand Down
31 changes: 31 additions & 0 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ type ReadonlyState interface {
GetReservedMemory() map[v1.ResourceName]map[int]uint64
}

// WriteOnlyState interface only provides methods for update pod assignments
type WriteOnlyState interface {
writer
}

// State interface provides methods for tracking and setting pod assignments
type State interface {
writer
Expand Down Expand Up @@ -411,3 +416,29 @@ func SetReadonlyState(state ReadonlyState) {

readonlyState = state
}

var (
writeOnlyStateLock sync.RWMutex
writeOnlyState WriteOnlyState
)

// GetWriteOnlyState returns state.WriteOnlyState to provides a way
// to update the states of the plugin
func GetWriteOnlyState() (WriteOnlyState, error) {
writeOnlyStateLock.RLock()
defer writeOnlyStateLock.RUnlock()

if writeOnlyState == nil {
return nil, fmt.Errorf("readonlyState isn't set")
}
return writeOnlyState, nil
}

// SetWriteOnlyState sets state.WriteOnlyState to be used by the plugin
// this function should only be called once during initialization
func SetWriteOnlyState(state WriteOnlyState) {
readonlyStateLock.Lock()
defer readonlyStateLock.Unlock()

writeOnlyState = state
}

0 comments on commit c741de5

Please sign in to comment.