Skip to content

Commit

Permalink
Merge pull request #1740 from sunya-ch/model-server
Browse files Browse the repository at this point in the history
fix: limit max core ratio to 1
  • Loading branch information
sunya-ch authored Aug 28, 2024
2 parents aa5a912 + b2926d1 commit 9ec3c95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
"github.com/sustainable-computing-io/kepler/pkg/collector/stats"
"github.com/sustainable-computing-io/kepler/pkg/config"
"github.com/sustainable-computing-io/kepler/pkg/model/utils"
"github.com/sustainable-computing-io/kepler/pkg/sensors/components"
"github.com/sustainable-computing-io/kepler/pkg/sensors/components/source"
"github.com/sustainable-computing-io/kepler/pkg/sensors/platform"
Expand Down Expand Up @@ -53,4 +54,19 @@ var _ = Describe("Test Model Unit", func() {
initModelURL := configValues[getModelConfigKey(modelItem, config.InitModelURLKey)]
Expect(initModelURL).NotTo(Equal(""))
})

Context("utils", func() {
DescribeTable("Test GetCoreRatio()", func(isIdlePower bool, inCoreRatio float64, expectedCoreRatio float64) {
coreRatio := utils.GetCoreRatio(isIdlePower, inCoreRatio)
Expect(coreRatio).To(Equal(expectedCoreRatio))
},
Entry("DynPower with valid coreRatio < 1", false, 0.5, 1.0),
Entry("IdlePower with valid coreRatio < 1", true, 0.5, 0.5),
Entry("IdlePower with valid coreRatio = 1", true, 1.0, 1.0),
Entry("IdlePower with invalid coreRatio = 0", true, 0.0, 1.0),
Entry("IdlePower with invalid coreRatio = -1", true, -1.0, 1.0),
Entry("IdlePower with invalid coreRatio > 1", true, 1.2, 1.0),
)
})

})
4 changes: 3 additions & 1 deletion pkg/model/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package utils

import (
"math"

"github.com/sustainable-computing-io/kepler/pkg/sensors/components/source"
)

Expand Down Expand Up @@ -63,7 +65,7 @@ func FillNodeComponentsPower(pkgPower, corePower, uncorePower, dramPower uint64)
func GetCoreRatio(isIdlePower bool, inCoreRatio float64) float64 {
var coreRatio float64 = 1
if isIdlePower && inCoreRatio > 0 {
coreRatio = inCoreRatio
coreRatio = math.Min(inCoreRatio, 1)
}
return coreRatio
}

0 comments on commit 9ec3c95

Please sign in to comment.