---
name: "CPU_ZERO"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/CPUSET_FSET"
---

# CPU\_ZERO(9)

cpuset manipulation macros

Part of [CPUSET\_FSET(9)](/CPUSET_FSET/9.md).

## NAME

**cpuset**, **CPUSET\_T\_INITIALIZER**, **CPUSET\_FSET**, **CPU\_CLR**, **CPU\_COPY**, **CPU\_ISSET**, **CPU\_SET**, **CPU\_ZERO**, **CPU\_FILL**, **CPU\_SETOF**, **CPU\_EMPTY**, **CPU\_ISFULLSET**, **CPU\_FFS**, **CPU\_COUNT**, **CPU\_SUBSET**, **CPU\_OVERLAP**, **CPU\_CMP**, **CPU\_OR**, **CPU\_ORNOT**, **CPU\_AND**, **CPU\_ANDNOT**, **CPU\_XOR**, **CPU\_CLR\_ATOMIC**, **CPU\_TEST\_CLR\_ATOMIC**, **CPU\_SET\_ATOMIC**, **CPU\_SET\_ATOMIC\_ACQ**, **CPU\_TEST\_SET\_ATOMIC**, **CPU\_AND\_ATOMIC**, **CPU\_OR\_ATOMIC**, **CPU\_COPY\_STORE\_REL** – cpuset manipulation macros

## SYNOPSIS

**#include \<sys/\_cpuset.h\>**

**#include \<sys/cpuset.h\>**

**CPUSET\_T\_INITIALIZER**(*ARRAY\_CONTENTS*); *CPUSET\_FSET*

**CPU\_CLR**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_COPY**(*cpuset\_t \*from*, *cpuset\_t \*to*);

*bool*\

**CPU\_ISSET**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_SET**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_ZERO**(*cpuset\_t \*cpuset*);

**CPU\_FILL**(*cpuset\_t \*cpuset*);

**CPU\_SETOF**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

*bool*\

**CPU\_EMPTY**(*cpuset\_t \*cpuset*);

*bool*\

**CPU\_ISFULLSET**(*cpuset\_t \*cpuset*);

*int*\

**CPU\_FFS**(*cpuset\_t \*cpuset*);

*int*\

**CPU\_COUNT**(*cpuset\_t \*cpuset*);

*bool*\

**CPU\_SUBSET**(*cpuset\_t \*haystack*, *cpuset\_t \*needle*);

*bool*\

**CPU\_OVERLAP**(*cpuset\_t \*cpuset1*, *cpuset\_t \*cpuset2*);

*bool*\

**CPU\_CMP**(*cpuset\_t \*cpuset1*, *cpuset\_t \*cpuset2*);

**CPU\_OR**(*cpuset\_t \*dst*, *cpuset\_t \*src1*, *cpuset\_t \*src2*);

**CPU\_ORNOT**(*cpuset\_t \*dst*, *cpuset\_t \*src1*, *cpuset\_t \*src2*);

**CPU\_AND**(*cpuset\_t \*dst*, *cpuset\_t \*src1*, *cpuset\_t \*src2*);

**CPU\_ANDNOT**(*cpuset\_t \*dst*, *cpuset\_t \*src1*, *cpuset\_t \*src2*);

**CPU\_XOR**(*cpuset\_t \*dst*, *cpuset\_t \*src1*, *cpuset\_t \*src2*);

**CPU\_CLR\_ATOMIC**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_TEST\_CLR\_ATOMIC**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_SET\_ATOMIC**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_SET\_ATOMIC\_ACQ**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_TEST\_SET\_ATOMIC**(*size\_t cpu\_idx*, *cpuset\_t \*cpuset*);

**CPU\_AND\_ATOMIC**(*cpuset\_t \*dst*, *cpuset\_t \*src*);

**CPU\_OR\_ATOMIC**(*cpuset\_t \*dst*, *cpuset\_t \*src*);

**CPU\_COPY\_STORE\_REL**(*cpuset\_t \*from*, *cpuset\_t \*to*);

## DESCRIPTION

The **cpuset** family of macros provide a flexible and efficient CPU set implementation, backed by the [bitset(9)](/bitset/9.md) macros. Each CPU is represented by a single bit. The maximum number of CPUs representable by *cpuset\_t* is *CPU\_SETSIZE*. Individual CPUs in cpusets are referenced with indices zero through *CPU\_SETSIZE*, *-*, *1*.

The **CPUSET\_T\_INITIALIZER**() macro allows one to initialize a *cpuset\_t* with a compile time literal value.

The **CPUSET\_FSET**() macro defines a compile time literal, usable by **CPUSET\_T\_INITIALIZER**(), representing a full cpuset (all CPUs present). For examples of **CPUSET\_T\_INITIALIZER**() and **CPUSET\_FSET**() usage, see the CPUSET\_T\_INITIALIZER EXAMPLE section.

The **CPU\_CLR**() macro removes CPU *cpu\_idx* from the cpuset pointed to by *cpuset*. The **CPU\_CLR\_ATOMIC**() macro is identical, but the bit representing the CPU is cleared with atomic machine instructions. The **CPU\_TEST\_CLR\_ATOMIC**() macro atomically clears the bit representing the CPU and returns whether it was set.

The **CPU\_COPY**() macro copies the contents of the cpuset *from* to the cpuset *to*. **CPU\_COPY\_STORE\_REL**() is similar, but copies component machine words from *from* and writes them to *to* with atomic store with release semantics. (That is, if *to* is composed of multiple machine words, **CPU\_COPY\_STORE\_REL**() performs multiple individually atomic operations.)

The **CPU\_SET**() macro adds CPU *cpu\_idx* to the cpuset pointed to by *cpuset*, if it is not already present. The **CPU\_SET\_ATOMIC**() macro is identical, but the bit representing the CPU is set with atomic machine instructions. The **CPU\_SET\_ATOMIC\_ACQ**() macro sets the bit representing the CPU with atomic acquire semantics. The **CPU\_TEST\_SET\_ATOMIC**() macro atomically sets the bit representing the CPU and returns whether it was set.

The **CPU\_ISSET**() macro returns true if CPU *cpu\_idx* is a member of the cpuset pointed to by *cpuset*.

The **CPU\_ZERO**() macro removes all CPUs from *cpuset*.

The **CPU\_FILL**() macro adds all CPUs to *cpuset*.

The **CPU\_SETOF**() macro removes all CPUs in *cpuset* before adding only CPU *cpu\_idx*.

The **CPU\_EMPTY**() macro returns true if *cpuset* is empty.

The **CPU\_ISFULLSET**() macro returns true if *cpuset* is full (the set of all CPUs).

The **CPU\_FFS**() macro returns the 1-index of the first (lowest) CPU in *cpuset*, or zero if *cpuset* is empty. Like with [ffs(3)](/ffs/3.md), to use the non-zero result of **CPU\_FFS**() as a *cpu\_idx* index parameter to any other **cpuset** macro, you must subtract one from the result.

The **CPU\_COUNT**() macro returns the total number of CPUs in *cpuset*.

The **CPU\_SUBSET**() macro returns true if *needle* is a subset of *haystack*.

The **CPU\_OVERLAP**() macro returns true if *cpuset1* and *cpuset2* have any common CPUs. (That is, if *cpuset1* AND *cpuset2* is not the empty set.)

The **CPU\_CMP**() macro returns true if *cpuset1* is NOT equal to *cpuset2*.

The **CPU\_OR**() macro adds CPUs present in *src* to *dst*. (It is the **cpuset** equivalent of the scalar: *dst* \|= *src*.) **CPU\_OR\_ATOMIC**() is similar, but sets the bits representing CPUs in the component machine words in *dst* with atomic machine instructions. (That is, if *dst* is composed of multiple machine words, **CPU\_OR\_ATOMIC**() performs multiple individually atomic operations.)

The **CPU\_ORNOT**() macro add CPUs not in *src* to *dst*. (It is the **cpuset** equivalent of the scalar: *dst* \|= *~*, *src*.)

The **CPU\_AND**() macro removes CPUs absent from *src* from *dst*. (It is the **cpuset** equivalent of the scalar: *dst* &= *src*.) **CPU\_AND\_ATOMIC**() is similar, with the same atomic semantics as **CPU\_OR\_ATOMIC**().

The **CPU\_ANDNOT**() macro removes CPUs in *src* from *dst*. (It is the **cpuset** equivalent of the scalar: *dst* &= *~*, *src*.)

## CPUSET\_T\_INITIALIZER EXAMPLE

```
cpuset_t myset;
/* Initialize myset to filled (all CPUs) */
myset = CPUSET_T_INITIALIZER(CPUSET_FSET);
/* Initialize myset to only the lowest CPU */
myset = CPUSET_T_INITIALIZER(0x1);
```

## SEE ALSO

[cpuset(1)](/cpuset/1.md), [cpuset(2)](/cpuset/2.md), [bitset(9)](/bitset/9.md)

## HISTORY

⟨sys/cpuset.h⟩ first appeared in FreeBSD 7.1, released in January 2009, and in FreeBSD 8.0, released in November 2009.

This manual page first appeared in FreeBSD 11.0.

## AUTHORS

The **cpuset** macros were written by Jeff Roberson ⟨*jeff@FreeBSD.org*⟩. This manual page was written by Conrad Meyer ⟨*cem@FreeBSD.org*⟩.

## CAVEATS

Unlike every other reference to individual set members, which are zero-indexed, **CPU\_FFS**() returns a one-indexed result (or zero if the cpuset is empty).
