Skip to content

Commit

Permalink
feat(swagger): agent, add definitions for cpu pinning endpoints (#4072)
Browse files Browse the repository at this point in the history
* feat(swagger): agent, add cpu pinning endpoints

Those endpoints will be used during restore
to optionally unpin agent from cpus for
its duration.

* feat(cpuset): add function for checking pinned cpus

This function will in the agent's endpoint
getting cpus to which agent is pinned.
  • Loading branch information
Michal-Leszczynski authored Oct 17, 2024
1 parent 8af93cf commit d044b17
Show file tree
Hide file tree
Showing 10 changed files with 999 additions and 0 deletions.
25 changes: 25 additions & 0 deletions v3/pkg/util/cpuset/cpuset_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ func schedSetAffinityToMany(pids []int, set *unix.CPUSet) (err error) {
return
}

// SchedGetAffinity gets a union of CPUs used by this process threads.
func SchedGetAffinity() ([]int, error) {
pids, err := osTasks(os.Getpid())
if err != nil {
return nil, errors.Wrap(err, "get tasks")
}

union := make(map[int]struct{})
for _, pid := range pids {
var cpus unix.CPUSet
if err := unix.SchedGetaffinity(pid, &cpus); err != nil {
return nil, errors.Wrap(err, "get affinity")
}
for _, cpu := range cpulist(&cpus) {
union[cpu] = struct{}{}
}
}

var out []int
for cpu := range union {
out = append(out, cpu)
}
return out, nil
}

func cpuset(cpus []int) *unix.CPUSet {
set := &unix.CPUSet{}
set.Zero()
Expand Down
80 changes: 80 additions & 0 deletions v3/swagger/agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,74 @@
"security": []
}
},
"/pin_cpu": {
"get": {
"description": "Get CPUs to which agent is pinned",
"summary": "Get CPUs to which agent is pinned",
"operationId": "GetCpu",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "CPUs to which agent is pinned",
"schema": {
"$ref": "#/definitions/Cpus"
}
},
"default": {
"description": "Server error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
},
"post": {
"description": "Pin agent to CPUs according to start-up logic",
"summary": "Pin agent to CPUs according to start-up logic",
"operationId": "PinCpu",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Empty object",
"schema": {
"type": "object"
}
},
"default": {
"description": "Server error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
},
"delete": {
"description": "Unpin agent from CPUs",
"summary": "Unpin agent from CPUs",
"operationId": "UnpinCpu",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Empty object",
"schema": {
"type": "object"
}
},
"default": {
"description": "Server error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
},
"/terminate": {
"post": {
"description": "Reload agent config",
Expand Down Expand Up @@ -901,6 +969,18 @@
}
},
"definitions": {
"Cpus": {
"type": "object",
"properties": {
"cpu": {
"description": "List of cpus",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"Bandwidth": {
"title": "bandwidth rate",
"description": "Rate at witch to rate limit bandwidth",
Expand Down
113 changes: 113 additions & 0 deletions v3/swagger/gen/agent/client/operations/get_cpu_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions v3/swagger/gen/agent/client/operations/get_cpu_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d044b17

Please sign in to comment.