-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathpartition.go
63 lines (56 loc) · 1.63 KB
/
partition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package cgroupslib
import (
"github.com/hashicorp/nomad/client/lib/idset"
"github.com/hashicorp/nomad/client/lib/numalib/hw"
)
// A Partition is used to track reserved vs. shared cpu cores.
type Partition interface {
Restore(*idset.Set[hw.CoreID])
Reserve(*idset.Set[hw.CoreID]) error
Release(*idset.Set[hw.CoreID]) error
}
// SharePartition is the name of the cgroup containing cgroups for tasks
// making use of the 'cpu' resource, which pools and shares cpu cores.
func SharePartition() string {
switch GetMode() {
case CG1:
return "share"
case CG2:
return "share.slice"
default:
return ""
}
}
// ReservePartition is the name of the cgroup containing cgroups for tasks
// making use of the 'cores' resource, which reserves specific cpu cores.
func ReservePartition() string {
switch GetMode() {
case CG1:
return "reserve"
case CG2:
return "reserve.slice"
default:
return ""
}
}
// GetPartitionFromCores returns the name of the cgroup that should contain
// the cgroup of the task, which is determined by inspecting the cores
// parameter, which is a non-empty string if the task is using reserved
// cores.
func GetPartitionFromCores(cores string) string {
if cores == "" {
return SharePartition()
}
return ReservePartition()
}
// GetPartitionFromBool returns the name of the cgroup that should contain
// the cgroup of the task, which is determined from the cores parameter,
// which indicates whether the task is making use of reserved cores.
func GetPartitionFromBool(cores bool) string {
if cores {
return ReservePartition()
}
return SharePartition()
}