Skip to content

vallahaye/go-cpuset

Repository files navigation

Go cpuset

Go Reference Go Report Card

Go cpuset provides functions to parse strings according to the formats specified in the Linux cpuset(7) man page. The parsed representation can then be manipulated using well known set functions (difference, intersection, ...) and formatted back to string.

Goals

  • Handle all formats specified in the man page ("List" and "Mask")
  • Provide an API similar to Golang's upcoming standard set container implementation (golang/go#69230)
  • Make it accessible from the command-line
  • Well-tested and documented

Non-goals

  • Manage cpusets in the Linux kernel (similar to SUSE's cset command-line tool)

Installation

Install the cpuset command-line tool through GitHub Releases:

wget -q -O /usr/local/bin/cpuset "https://github.com/vallahaye/go-cpuset/releases/latest/download/cpuset-$(uname -s)-$(uname -m)" && \
chmod +x /usr/local/bin/cpuset

Or using the Go toolchain:

GOBIN=/usr/local/bin go install go.vallahaye.net/cpuset/cmd/cpuset@latest

To uninstall the cpuset command-line tool, run:

rm -f /usr/local/bin/cpuset

Example

Parse two cpusets, compute the intersection and format it back to string.

Golang

// Decode str1 into a CPUSet.
s1, err := cpuset.ParseList(str1)
if err != nil {
  // Do something with the error.
}

// Decode str2 into a CPUSet.
s2, err := cpuset.ParseList(str2)
if err != nil {
  // Do something with the error.
}

// Compute the intersection of the two cpusets.
s := cpuset.Intersection(s1, s2)

// Encode the intersection and print the result.
fmt.Println(s.String())

Command-line

cpuset intersection "$STR1" "$STR2"