Skip to content

Commit

Permalink
fix: handle zero based hdm range
Browse files Browse the repository at this point in the history
  • Loading branch information
HJ-Fan committed Aug 9, 2024
1 parent a4e86d9 commit 71627f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
25 changes: 16 additions & 9 deletions cmd/cxl-host/service/cxl_host_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1386,15 +1386,22 @@ func (s *CxlHostApiService) RedfishV1SystemsComputerSystemIdMemoryDomainsMemoryD

} else {
bdf := CxlDevNodeToBDF(memoryChunksId)
memAddr := GetCxlAddressInfoMiB(bdf)
resource.AddressRangeOffsetMiB = &memAddr.BaseAddress
resource.MemoryChunkSizeMiB = &memAddr.Size
resource.Links.Endpoints = append(resource.Links.Endpoints, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/Systems/%s/Memory/CXL%d", computerSystemId, CxlDevBDFtoIndex(CxlDevNodeToBDF(memoryChunksId)))})
resource.Links.EndpointsodataCount = 1

perfMetric := GetCXLMemPerf(bdf)
if perfMetric != nil {
resource.Oem = map[string]interface{}{"Seagate": map[string]interface{}{"Bandwidth": perfMetric.Bandwidth, "Latency": perfMetric.Latency}}
if bdf == "" { // node doesn't match to a CXL dev's base address
mem := GetNumaMemInfo(memoryChunksId)
memMiB := mem.MemTotal >> 10 // MemTotal is in KiB
resource.MemoryChunkSizeMiB = &memMiB
resource.Links.Endpoints = make([]redfishapi.OdataV4IdRef, 0)
} else {
memAddr := GetCxlAddressInfoMiB(bdf)
resource.AddressRangeOffsetMiB = &memAddr.BaseAddress
resource.MemoryChunkSizeMiB = &memAddr.Size
resource.Links.Endpoints = append(resource.Links.Endpoints, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/Systems/%s/Memory/CXL%d", computerSystemId, CxlDevBDFtoIndex(CxlDevNodeToBDF(memoryChunksId)))})
resource.Links.EndpointsodataCount = 1

perfMetric := GetCXLMemPerf(bdf)
if perfMetric != nil {
resource.Oem = map[string]interface{}{"Seagate": map[string]interface{}{"Bandwidth": perfMetric.Bandwidth, "Latency": perfMetric.Latency}}
}
}
}

Expand Down
17 changes: 11 additions & 6 deletions cmd/cxl-host/service/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,22 @@ func GetMemOnlyNumaNodes() []string {
// GetCXLNumaNodes: return a map of [node]BDF
func GetCXLNumaNodes() map[string]string {
nodeMap := make(map[string]string)
for _, node := range GetMemOnlyNumaNodes() { // Initialize Node Map
nodeMap[node] = ""
}
if blockSizeByte != -1 {
cxlDevList := GetCXLWithMemDevList()
for _, bdf := range cxlDevList {
dev := GetCXLDevInfo(bdf)
base_addr := dev.GetMemoryBaseAddr()
blockIndex := base_addr / blockSizeByte
entries, err := os.ReadDir(fmt.Sprintf("%smemory%d", PlatformPath.SysMem, blockIndex))
if err == nil {
for _, entry := range entries {
if strings.HasPrefix(entry.Name(), "node") {
nodeMap[entry.Name()] = bdf
if base_addr != 0 {
blockIndex := base_addr / blockSizeByte
entries, err := os.ReadDir(fmt.Sprintf("%smemory%d", PlatformPath.SysMem, blockIndex))
if err == nil {
for _, entry := range entries {
if strings.HasPrefix(entry.Name(), "node") {
nodeMap[entry.Name()] = bdf
}
}
}
}
Expand Down

0 comments on commit 71627f2

Please sign in to comment.