Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: try to reduce escapes to heap #1886

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
4 changes: 2 additions & 2 deletions pkg/collector/stats/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}

func NewUInt64Stat(aggr, delta uint64) *UInt64Stat {
stat := &UInt64Stat{}
stat := UInt64Stat{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

stat.aggr.Store(aggr)
stat.delta.Store(delta)
return stat
return &stat
}

func (s *UInt64Stat) String() string {
return fmt.Sprintf("%d (%d)", s.delta.Load(), s.aggr.Load())

Check failure on line 24 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

(*atomic.Uint64).Load(s.delta) escapes to heap

Check failure on line 24 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

(*atomic.Uint64).Load(s.aggr) escapes to heap
}

// ResetDelta resets current value
Expand Down Expand Up @@ -91,7 +91,7 @@
}

func NewUInt64StatCollection() UInt64StatCollection {
return make(map[string]*UInt64Stat)

Check failure on line 94 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

make(map[string]*UInt64Stat) escapes to heap
}

type UInt64StatCollection map[string]*UInt64Stat
Expand All @@ -101,7 +101,7 @@
s[key] = NewUInt64Stat(newAggr, 0)
} else {
if err := instance.SetNewAggr(newAggr); err != nil {
klog.V(3).Infoln(err)

Check failure on line 104 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

... argument escapes to heap
}
}
}
Expand All @@ -111,7 +111,7 @@
s[key] = NewUInt64Stat(newDelta, newDelta)
} else {
if err := instance.AddNewDelta(newDelta); err != nil {
klog.V(3).Infoln(err)

Check failure on line 114 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

... argument escapes to heap
}
}
}
Expand All @@ -120,7 +120,7 @@
s[key] = NewUInt64Stat(newDelta, newDelta)
} else {
if err := instance.SetNewDelta(newDelta); err != nil {
klog.V(3).Infoln(err)

Check failure on line 123 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

... argument escapes to heap
}
}
}
Expand Down Expand Up @@ -150,5 +150,5 @@
}

func (s UInt64StatCollection) String() string {
return fmt.Sprintf("%d (%d)", s.SumAllDeltaValues(), s.SumAllAggrValues())

Check failure on line 153 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

UInt64StatCollection.SumAllDeltaValues(s) escapes to heap

Check failure on line 153 in pkg/collector/stats/types/types.go

View workflow job for this annotation

GitHub Actions / golang / escapes_detect

UInt64StatCollection.SumAllAggrValues(s) escapes to heap
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func getBoolConfig(configKey string, defaultBool bool) bool {
}

func getIntConfig(configKey string, defaultInt int) int {
defaultValue := fmt.Sprintf("%d", defaultInt)
defaultValue := strconv.Itoa(defaultInt)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

value, err := strconv.Atoi(getConfig(configKey, defaultValue))
if err == nil {
return value
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubelet/kubelet_pod_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (

var (
podURL string
client http.Client
)

func init() {
Expand All @@ -50,6 +51,8 @@ func init() {
port = "10250"
}
podURL = "https://" + nodeName + ":" + port + "/pods"
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client = http.Client{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Error: pkg/kubelet/kubelet_pod_lister.go:69:12: &http.Client{} escapes to heap
make http client reuse

}

func httpGet(url string) (*http.Response, error) {
Expand All @@ -65,8 +68,6 @@ func httpGet(url string) (*http.Response, error) {
return nil, err
}
req.Header.Add("Authorization", bearer)
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to get response from %q: %v", url, err)
Expand Down
10 changes: 4 additions & 6 deletions pkg/model/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ var (
LogisticTrainer,
ExponentialTrainer,
}
ModelOutputTypeConverter = []string{"AbsPower", "DynPower"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Error: pkg/model/types/types.go:63:17: []string{...} escapes to heap
Error: pkg/model/types/types.go:69:1[7](https://github.com/sustainable-computing-io/kepler/actions/runs/12177539929/job/33966954289#step:4:8): []string{...} escapes to heap

fixed

ModelTypeConverter = []string{"Ratio", "Regressor", "EstimatorSidecar"}
)

func getModelOutputTypeConverter() []string {
return []string{
"AbsPower", "DynPower",
}
return ModelOutputTypeConverter
}

func getModelTypeConverter() []string {
return []string{
"Ratio", "Regressor", "EstimatorSidecar",
}
return ModelTypeConverter
}

func (s ModelOutputType) String() string {
Expand Down
1 change: 0 additions & 1 deletion pkg/sensors/components/source/rapl_msr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func ReadMSR(packageID int, msr int64) (uint64, error) {
}

msrVal := byteOrder.Uint64(buf)

return msrVal, nil
}

Expand Down
16 changes: 12 additions & 4 deletions pkg/sensors/components/source/rapl_sysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"strconv"
"strings"
"sync"

"k8s.io/klog/v2"
)
Expand All @@ -43,7 +44,9 @@ const (
)

var (
eventPaths map[string]map[string]string
eventPaths map[string]map[string]string
once sync.Once
systemCollectionSupported bool
)

func init() {
Expand Down Expand Up @@ -125,9 +128,14 @@ func (PowerSysfs) GetName() string {
}

func (r *PowerSysfs) IsSystemCollectionSupported() bool {
path := fmt.Sprintf(packageNamePathTemplate, 0)
_, err := os.ReadFile(path + energyFile)
return err == nil
// use a hard code to reduce escapes to heap
// there are parts of code invokes this function
// use once to reduce IO
once.Do(func() {
_, err := os.ReadFile("/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj")
systemCollectionSupported = (err == nil)
})
return systemCollectionSupported
}

func (r *PowerSysfs) GetAbsEnergyFromDram() (uint64, error) {
Expand Down
Loading