Skip to content

Commit

Permalink
fix nil ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jul 3, 2024
1 parent bca3cd0 commit f318f38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions internal/coreinfo/coreinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GetNumaNodeToProcessorInfo() ([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, error)
uintptr(unsafe.Pointer(&returnLength)),
)
if r1 != 0 && err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
return nil, fmt.Errorf("Call to GetLogicalProcessorInformationEx failed: %v", err)
return nil, fmt.Errorf("call to GetLogicalProcessorInformationEx failed: %v", err)
}

// Allocate the buffer with the length it should be
Expand All @@ -80,10 +80,10 @@ func GetNumaNodeToProcessorInfo() ([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, error)
uintptr(unsafe.Pointer(&returnLength)),
)
if r1 == 0 {
return nil, fmt.Errorf("Call to GetLogicalProcessorInformationEx failed: %v", err)
return nil, fmt.Errorf("call to GetLogicalProcessorInformationEx failed: %v", err)
}

var groupMasks []winapi.JOBOBJECT_CPU_GROUP_AFFINITY
var allGroupMasks []winapi.JOBOBJECT_CPU_GROUP_AFFINITY
for offset := 0; offset < len(buffer); {
info := (*_SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)(unsafe.Pointer(&buffer[offset]))
numaNodeRelationship := (*_NUMA_NODE_RELATIONSHIP)(unsafe.Pointer(&info.data))
Expand All @@ -93,9 +93,9 @@ func GetNumaNodeToProcessorInfo() ([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, error)
for i := 0; i < int(numaNodeRelationship.GroupCount); i++ {
groupMasks[i] = *(*winapi.JOBOBJECT_CPU_GROUP_AFFINITY)(unsafe.Pointer(uintptr(unsafe.Pointer(&numaNodeRelationship.GroupMasks)) + uintptr(i)*unsafe.Sizeof(winapi.JOBOBJECT_CPU_GROUP_AFFINITY{})))
}

allGroupMasks = append(allGroupMasks, groupMasks...)
offset += int(info.Size)
}

return groupMasks, nil
return allGroupMasks, nil
}
14 changes: 8 additions & 6 deletions internal/hcsoci/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C

// if container is process isolated, check if affinityCPUs has been set in createOptions.
// If yes, set information on the job object created for this container

if coi.HostingSystem == nil && coi.Spec.Windows != nil {
err = setCPUAffinityOnJobObject(ctx, coi.Spec, system.ID())
if err != nil {
Expand All @@ -300,7 +301,8 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C

func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSystemId string) error {
//
if spec.Windows.Resources == nil || spec.Windows.Resources.CPU == nil {
if spec == nil || spec.Windows == nil || spec.Windows.Resources == nil ||
spec.Windows.Resources.CPU == nil || spec.Windows.Resources.CPU.AffinityCPUs == nil {
return nil
}

Expand Down Expand Up @@ -357,10 +359,10 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
}
}
*/
numaNodeInfo := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
// numaNodeInfo := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
info := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
if spec.Windows.Resources.CPU.AffinityCPUs != nil {
info := make([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, len(spec.Windows.Resources.CPU.AffinityCPUs))
info = make([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, len(spec.Windows.Resources.CPU.AffinityCPUs))
for i, cpu := range spec.Windows.Resources.CPU.AffinityCPUs {
info[i].CpuMask = (uintptr)(cpu.CPUMask)
info[i].CpuGroup = (uint16)(cpu.CPUGroup)
Expand All @@ -369,12 +371,12 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
}

if spec.Windows.Resources.CPU.AffinityPreferredNumaNodes != nil {
numaNodeInfo, err = coreinfo.GetNumaNodeToProcessorInfo()
numaNodeInfo, err := coreinfo.GetNumaNodeToProcessorInfo()
if err != nil {
return fmt.Errorf("error getting numa node info: %v", err)
}
// check if cpu affinities are also set and consolidate the masks
if len(info) != 0 {
if len(info) > 0 {
for _, numaNode := range numaNodeInfo {
doesCpuAffinityExist := false
for ind, _ := range info {
Expand All @@ -385,7 +387,7 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
break
}
}
if doesCpuAffinityExist == false {
if !doesCpuAffinityExist {
info = append(info, numaNode)
}
}
Expand Down

0 comments on commit f318f38

Please sign in to comment.