-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Tomilla/feat_support_cpu_affinity_for_eat_…
…in_linux Feat support cpu affinity for eat in linux
- Loading branch information
Showing
13 changed files
with
424 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// contextKey is a value for use with context.WithValue. | ||
// It's used as a pointer. so it fits in an interface{} without allocation. | ||
type contextKey struct { | ||
name string | ||
valueType string | ||
} | ||
|
||
func (k *contextKey) String() string { | ||
return fmt.Sprintf("worker context value: name %s, type %s", k.name, k.valueType) | ||
} | ||
|
||
const ( | ||
intervalCpuWorkerCheckContextDone = 10000 | ||
durationMemoryWorkerDoRefresh = 5 * time.Minute | ||
durationEachSignCheck = 100 * time.Millisecond | ||
chunkSizeMemoryWorkerEachAllocate = 128 * 1024 * 1024 // 128MB | ||
) | ||
|
||
var ( | ||
cpuWorkerPartialCoreRatioContextKey = &contextKey{"partialCoreRatio", "float64"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package cpu_affinity | ||
|
||
import ( | ||
"runtime" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
type CpuAffinityDeputy struct{} | ||
|
||
func (CpuAffinityDeputy) GetProcessId() uint { | ||
return uint(syscall.Getpid()) | ||
} | ||
|
||
func (CpuAffinityDeputy) GetThreadId() uint { | ||
return uint(syscall.Gettid()) | ||
} | ||
|
||
func (CpuAffinityDeputy) SetCpuAffinities(pid uint, cpus ...uint) error { | ||
if len(cpus) == 0 { | ||
return nil | ||
} | ||
mask := new(unix.CPUSet) | ||
mask.Zero() | ||
for _, c := range cpus { | ||
mask.Set(int(c)) | ||
} | ||
return unix.SchedSetaffinity(int(pid), mask) | ||
} | ||
|
||
func (CpuAffinityDeputy) GetCpuAffinities(pid uint) (map[uint]bool, error) { | ||
mask := new(unix.CPUSet) | ||
mask.Zero() | ||
err := unix.SchedGetaffinity(int(pid), mask) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var res = make(map[uint]bool) | ||
for i := 0; i < runtime.NumCPU(); i++ { | ||
res[uint(i)] = mask.IsSet(i) | ||
} | ||
return res, nil | ||
} | ||
|
||
func (CpuAffinityDeputy) IsImplemented() bool { | ||
return true | ||
} |
Oops, something went wrong.