Skip to content

Commit

Permalink
Temp:not working
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jun 12, 2024
1 parent 8f20ab6 commit a952a6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
6 changes: 4 additions & 2 deletions internal/hcsoci/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strconv"
"unsafe"

"github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/internal/cow"
Expand Down Expand Up @@ -330,12 +331,13 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
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 = cpu.CPUMask
info[i].CpuGroup = cpu.CPUGroup
info[i].CpuMask = (uintptr)(unsafe.Pointer(&cpu.CPUMask))
info[i].CpuGroup = (uint16)(cpu.CPUGroup)
//info[i].Reserved = [3]uint32{0, 0, 0}
}

return job.SetInformationJobObject(info)
//return job.GetInformationJobObject()
}

// isV2Xenon returns true if the create options are for a HCS schema V2 xenon container
Expand Down
29 changes: 26 additions & 3 deletions internal/jobobject/jobobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,15 @@ func isJobSilo(h windows.Handle) bool {
}

func (job *JobObject) SetInformationJobObject(affinityCPUs []winapi.JOBOBJECT_CPU_GROUP_AFFINITY) error {
len := len(affinityCPUs)
sizeOfGroupAffinity := unsafe.Sizeof(winapi.JOBOBJECT_CPU_GROUP_AFFINITY{})
//len := len(affinityCPUs)
//sizeOfGroupAffinity := unsafe.Sizeof(winapi.JOBOBJECT_CPU_GROUP_AFFINITY{})
_, err := windows.SetInformationJobObject(
job.handle,
winapi.JobObjectGroupInformationEx,
//uintptr(unsafe.Pointer(affinityCPUs)),
uintptr(unsafe.Pointer(&affinityCPUs[0])),
uint32(uintptr(len)*sizeOfGroupAffinity),
//uint32(unsafe.Sizeof(affinityCPUs)),
uint32(unsafe.Sizeof(affinityCPUs)*2),
)

if err != nil {
Expand All @@ -558,6 +560,27 @@ func (job *JobObject) SetInformationJobObject(affinityCPUs []winapi.JOBOBJECT_CP
return nil
}

func (job *JobObject) GetInformationJobObject() error {
info := make([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, 10)
var len uint32
//sizeOfGroupAffinity := unsafe.Sizeof(winapi.JOBOBJECT_CPU_GROUP_AFFINITY{})
err := windows.QueryInformationJobObject(
job.handle,
(int32)(winapi.JobObjectGroupInformationEx),
//uintptr(unsafe.Pointer(affinityCPUs)),
uintptr(unsafe.Pointer(&info)),
uint32(unsafe.Sizeof(info)*10),
&len,
)

fmt.Printf("length returned %v", len)
fmt.Printf("data returned %v", info)
if err != nil {
return fmt.Errorf("failed to set CPU affinities: %w", err)
}
return nil
}

// PromoteToSilo promotes a job object to a silo. There must be no running processess
// in the job for this to succeed. If the job is already a silo this is a no-op.
func (job *JobObject) PromoteToSilo() error {
Expand Down
6 changes: 3 additions & 3 deletions internal/winapi/jobobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct {

// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-group_affinity
type JOBOBJECT_CPU_GROUP_AFFINITY struct {
CpuMask uint64
CpuGroup uint32
//Reserved [3]uint32
CpuMask uintptr
CpuGroup uint16
Reserved [3]uint16
}

// BOOL IsProcessInJob(
Expand Down

0 comments on commit a952a6a

Please sign in to comment.