cpuset

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

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"

Documentation

Index

Constants

View Source
const Version = "0.2.3"

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUSet

type CPUSet struct {
	// contains filtered or unexported fields
}

A CPUSet defines a list of CPUs to restrict processes to. The zero value of a CPUSet is ready to use.

func Difference

func Difference(s1, s2 CPUSet) CPUSet

Difference returns a new CPUSet containing the CPUs of s1 that are not in s2.

func Intersection

func Intersection(s1, s2 CPUSet) CPUSet

Intersection returns a new CPUSet containing the CPUs of s1 that are in s2.

func Of

func Of(cpus ...uint) CPUSet

Of returns a new CPUSet containing the CPUs listed.

func ParseList

func ParseList(s string) (cset CPUSet, _ error)

ParseList decodes s into a CPUSet. It returns an error if s is not a valid list string, as specified in the Linux cpuset(7) man page (see "List Format").

func ParseMask

func ParseMask(s string) (cset CPUSet, _ error)

ParseMask decodes s into a CPUSet. It returns an error if s is not a valid mask string, as specified in the Linux cpuset(7) man page (see "Mask Format").

func Union

func Union(s1, s2 CPUSet) CPUSet

Union returns a new CPUSet containing the CPUs of s1 and s2.

func (*CPUSet) Add

func (s *CPUSet) Add(cpu uint) bool

Add adds a CPU to s. It reports whether the CPU was not present before.

func (*CPUSet) Clear

func (s *CPUSet) Clear()

Clear removes all CPUs from s, leaving it empty.

func (*CPUSet) Clone

func (s *CPUSet) Clone() CPUSet

Clone returns a copy of s.

func (*CPUSet) Contains

func (s *CPUSet) Contains(cpu uint) bool

Contains reports whether a CPU is present in s.

func (*CPUSet) Delete

func (s *CPUSet) Delete(cpu uint) bool

Delete removes a CPU from s. It reports whether the CPU was present.

func (*CPUSet) Equal

func (s *CPUSet) Equal(s2 CPUSet) bool

Equal reports whether s and s2 contain exactly the same CPUs.

func (*CPUSet) Len

func (s *CPUSet) Len() int

Len returns the number of CPUs in s.

func (*CPUSet) ListString

func (s *CPUSet) ListString() string

ListString encodes s into a list string.

func (*CPUSet) MaskString

func (s *CPUSet) MaskString() string

MaskString encodes s into a mask string.

func (*CPUSet) String

func (s *CPUSet) String() string

String is an alias for CPUSet.ListString.

func (*CPUSet) UnsortedList

func (s *CPUSet) UnsortedList() []uint

UnsortedList returns a slice of all the CPUs in s, in an unpredictable order.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL