15546be25SConrad Meyer.\" Copyright (c) 2015 Conrad Meyer <cem@FreeBSD.org> 25546be25SConrad Meyer.\" All rights reserved. 35546be25SConrad Meyer.\" 45546be25SConrad Meyer.\" Redistribution and use in source and binary forms, with or without 55546be25SConrad Meyer.\" modification, are permitted provided that the following conditions 65546be25SConrad Meyer.\" are met: 75546be25SConrad Meyer.\" 1. Redistributions of source code must retain the above copyright 85546be25SConrad Meyer.\" notice, this list of conditions and the following disclaimer. 95546be25SConrad Meyer.\" 2. Redistributions in binary form must reproduce the above copyright 105546be25SConrad Meyer.\" notice, this list of conditions and the following disclaimer in the 115546be25SConrad Meyer.\" documentation and/or other materials provided with the distribution. 125546be25SConrad Meyer.\" 135546be25SConrad Meyer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 145546be25SConrad Meyer.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 155546be25SConrad Meyer.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165546be25SConrad Meyer.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE 175546be25SConrad Meyer.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 185546be25SConrad Meyer.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 195546be25SConrad Meyer.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 205546be25SConrad Meyer.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 215546be25SConrad Meyer.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 225546be25SConrad Meyer.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 235546be25SConrad Meyer.\" POSSIBILITY OF SUCH DAMAGE. 245546be25SConrad Meyer.\" 258232a1edSBrooks Davis.Dd September 23, 2022 265546be25SConrad Meyer.Dt CPUSET 9 275546be25SConrad Meyer.Os 285546be25SConrad Meyer.Sh NAME 295546be25SConrad Meyer.Nm cpuset(9) 305546be25SConrad Meyer\(em 315546be25SConrad Meyer.Nm CPUSET_T_INITIALIZER , 325546be25SConrad Meyer.Nm CPUSET_FSET , 335546be25SConrad Meyer.Nm CPU_CLR , 345546be25SConrad Meyer.Nm CPU_COPY , 355546be25SConrad Meyer.Nm CPU_ISSET , 365546be25SConrad Meyer.Nm CPU_SET , 375546be25SConrad Meyer.Nm CPU_ZERO , 385546be25SConrad Meyer.Nm CPU_FILL , 395546be25SConrad Meyer.Nm CPU_SETOF , 405546be25SConrad Meyer.Nm CPU_EMPTY , 415546be25SConrad Meyer.Nm CPU_ISFULLSET , 425546be25SConrad Meyer.Nm CPU_FFS , 435546be25SConrad Meyer.Nm CPU_COUNT , 445546be25SConrad Meyer.Nm CPU_SUBSET , 455546be25SConrad Meyer.Nm CPU_OVERLAP , 465546be25SConrad Meyer.Nm CPU_CMP , 475546be25SConrad Meyer.Nm CPU_OR , 48*cd4bd975SJake Freeland.Nm CPU_ORNOT , 495546be25SConrad Meyer.Nm CPU_AND , 509825eadfSRyan Libby.Nm CPU_ANDNOT , 51e2650af1SStefan Eßer.Nm CPU_XOR , 525546be25SConrad Meyer.Nm CPU_CLR_ATOMIC , 535546be25SConrad Meyer.Nm CPU_SET_ATOMIC , 545546be25SConrad Meyer.Nm CPU_SET_ATOMIC_ACQ , 555546be25SConrad Meyer.Nm CPU_AND_ATOMIC , 565546be25SConrad Meyer.Nm CPU_OR_ATOMIC , 575546be25SConrad Meyer.Nm CPU_COPY_STORE_REL 585546be25SConrad Meyer.Nd cpuset manipulation macros 595546be25SConrad Meyer.Sh SYNOPSIS 605546be25SConrad Meyer.In sys/_cpuset.h 615546be25SConrad Meyer.In sys/cpuset.h 625546be25SConrad Meyer.\" 635546be25SConrad Meyer.Fn CPUSET_T_INITIALIZER "ARRAY_CONTENTS" 645546be25SConrad Meyer.Vt CPUSET_FSET 655546be25SConrad Meyer.\" 665546be25SConrad Meyer.Fn CPU_CLR "size_t cpu_idx" "cpuset_t *cpuset" 675546be25SConrad Meyer.Fn CPU_COPY "cpuset_t *from" "cpuset_t *to" 685546be25SConrad Meyer.Ft bool 695546be25SConrad Meyer.Fn CPU_ISSET "size_t cpu_idx" "cpuset_t *cpuset" 705546be25SConrad Meyer.Fn CPU_SET "size_t cpu_idx" "cpuset_t *cpuset" 715546be25SConrad Meyer.Fn CPU_ZERO "cpuset_t *cpuset" 725546be25SConrad Meyer.Fn CPU_FILL "cpuset_t *cpuset" 735546be25SConrad Meyer.Fn CPU_SETOF "size_t cpu_idx" "cpuset_t *cpuset" 745546be25SConrad Meyer.Ft bool 755546be25SConrad Meyer.Fn CPU_EMPTY "cpuset_t *cpuset" 765546be25SConrad Meyer.Ft bool 775546be25SConrad Meyer.Fn CPU_ISFULLSET "cpuset_t *cpuset" 7871aa6fbfSEric van Gyzen.Ft int 795546be25SConrad Meyer.Fn CPU_FFS "cpuset_t *cpuset" 8071aa6fbfSEric van Gyzen.Ft int 815546be25SConrad Meyer.Fn CPU_COUNT "cpuset_t *cpuset" 825546be25SConrad Meyer.\" 835546be25SConrad Meyer.Ft bool 845546be25SConrad Meyer.Fn CPU_SUBSET "cpuset_t *haystack" "cpuset_t *needle" 855546be25SConrad Meyer.Ft bool 865546be25SConrad Meyer.Fn CPU_OVERLAP "cpuset_t *cpuset1" "cpuset_t *cpuset2" 875546be25SConrad Meyer.Ft bool 885546be25SConrad Meyer.Fn CPU_CMP "cpuset_t *cpuset1" "cpuset_t *cpuset2" 89e2650af1SStefan Eßer.Fn CPU_OR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2" 90*cd4bd975SJake Freeland.Fn CPU_ORNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2" 91e2650af1SStefan Eßer.Fn CPU_AND "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2" 92e2650af1SStefan Eßer.Fn CPU_ANDNOT "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2" 93e2650af1SStefan Eßer.Fn CPU_XOR "cpuset_t *dst" "cpuset_t *src1" "cpuset_t *src2" 945546be25SConrad Meyer.\" 955546be25SConrad Meyer.Fn CPU_CLR_ATOMIC "size_t cpu_idx" "cpuset_t *cpuset" 965546be25SConrad Meyer.Fn CPU_SET_ATOMIC "size_t cpu_idx" "cpuset_t *cpuset" 975546be25SConrad Meyer.Fn CPU_SET_ATOMIC_ACQ "size_t cpu_idx" "cpuset_t *cpuset" 985546be25SConrad Meyer.\" 995546be25SConrad Meyer.Fn CPU_AND_ATOMIC "cpuset_t *dst" "cpuset_t *src" 1005546be25SConrad Meyer.Fn CPU_OR_ATOMIC "cpuset_t *dst" "cpuset_t *src" 1015546be25SConrad Meyer.Fn CPU_COPY_STORE_REL "cpuset_t *from" "cpuset_t *to" 1025546be25SConrad Meyer.Sh DESCRIPTION 1035546be25SConrad MeyerThe 1045546be25SConrad Meyer.Nm 1055546be25SConrad Meyerfamily of macros provide a flexible and efficient CPU set implementation, 1065546be25SConrad Meyerbacked by the 1075546be25SConrad Meyer.Xr bitset 9 1085546be25SConrad Meyermacros. 1095546be25SConrad MeyerEach CPU is represented by a single bit. 1105546be25SConrad MeyerThe maximum number of CPUs representable by 1115546be25SConrad Meyer.Vt cpuset_t 1125546be25SConrad Meyeris 1138232a1edSBrooks Davis.Va CPU_SETSIZE . 1145546be25SConrad MeyerIndividual CPUs in cpusets are referenced with indices zero through 1158232a1edSBrooks Davis.Fa CPU_SETSIZE - 1 . 1165546be25SConrad Meyer.Pp 1175546be25SConrad MeyerThe 1185546be25SConrad Meyer.Fn CPUSET_T_INITIALIZER 1195546be25SConrad Meyermacro allows one to initialize a 1205546be25SConrad Meyer.Vt cpuset_t 1215546be25SConrad Meyerwith a compile time literal value. 1225546be25SConrad Meyer.Pp 1235546be25SConrad MeyerThe 1245546be25SConrad Meyer.Fn CPUSET_FSET 1255546be25SConrad Meyermacro defines a compile time literal, usable by 1265546be25SConrad Meyer.Fn CPUSET_T_INITIALIZER , 1275546be25SConrad Meyerrepresenting a full cpuset (all CPUs present). 1285546be25SConrad MeyerFor examples of 1295546be25SConrad Meyer.Fn CPUSET_T_INITIALIZER 1305546be25SConrad Meyerand 1315546be25SConrad Meyer.Fn CPUSET_FSET 1325546be25SConrad Meyerusage, see the 1335546be25SConrad Meyer.Sx CPUSET_T_INITIALIZER EXAMPLE 1345546be25SConrad Meyersection. 1355546be25SConrad Meyer.Pp 1365546be25SConrad MeyerThe 1375546be25SConrad Meyer.Fn CPU_CLR 1385546be25SConrad Meyermacro removes CPU 1395546be25SConrad Meyer.Fa cpu_idx 1405546be25SConrad Meyerfrom the cpuset pointed to by 1415546be25SConrad Meyer.Fa cpuset . 1425546be25SConrad MeyerThe 1435546be25SConrad Meyer.Fn CPU_CLR_ATOMIC 1445546be25SConrad Meyermacro is identical, but the bit representing the CPU is cleared with atomic 1455546be25SConrad Meyermachine instructions. 1465546be25SConrad Meyer.Pp 1475546be25SConrad MeyerThe 1485546be25SConrad Meyer.Fn CPU_COPY 1495546be25SConrad Meyermacro copies the contents of the cpuset 1505546be25SConrad Meyer.Fa from 1515546be25SConrad Meyerto the cpuset 1525546be25SConrad Meyer.Fa to . 1535546be25SConrad Meyer.Fn CPU_COPY_STORE_REL 1545546be25SConrad Meyeris similar, but copies component machine words from 1555546be25SConrad Meyer.Fa from 1565546be25SConrad Meyerand writes them to 1575546be25SConrad Meyer.Fa to 1585546be25SConrad Meyerwith atomic store with release semantics. 1595546be25SConrad Meyer(That is, if 1605546be25SConrad Meyer.Fa to 1615546be25SConrad Meyeris composed of multiple machine words, 1625546be25SConrad Meyer.Fn CPU_COPY_STORE_REL 1635546be25SConrad Meyerperforms multiple individually atomic operations.) 1645546be25SConrad Meyer.Pp 1655546be25SConrad MeyerThe 1665546be25SConrad Meyer.Fn CPU_SET 1675546be25SConrad Meyermacro adds CPU 1685546be25SConrad Meyer.Fa cpu_idx 1695546be25SConrad Meyerto the cpuset pointed to by 1705546be25SConrad Meyer.Fa cpuset , 1715546be25SConrad Meyerif it is not already present. 1725546be25SConrad MeyerThe 1735546be25SConrad Meyer.Fn CPU_SET_ATOMIC 1745546be25SConrad Meyermacro is identical, but the bit representing the CPU is set with atomic 1755546be25SConrad Meyermachine instructions. 1765546be25SConrad MeyerThe 1775546be25SConrad Meyer.Fn CPU_SET_ATOMIC_ACQ 1785546be25SConrad Meyermacro sets the bit representing the CPU with atomic acquire semantics. 1795546be25SConrad Meyer.Pp 1805546be25SConrad MeyerThe 181eaf3c3afSStefan Eßer.Fn CPU_ISSET 182eaf3c3afSStefan Eßermacro returns 183eaf3c3afSStefan Eßer.Dv true 184eaf3c3afSStefan Eßerif CPU 185eaf3c3afSStefan Eßer.Fa cpu_idx 186eaf3c3afSStefan Eßeris a member of the cpuset pointed to by 187eaf3c3afSStefan Eßer.Fa cpuset . 188eaf3c3afSStefan Eßer.Pp 189eaf3c3afSStefan EßerThe 1905546be25SConrad Meyer.Fn CPU_ZERO 1915546be25SConrad Meyermacro removes all CPUs from 1925546be25SConrad Meyer.Fa cpuset . 1935546be25SConrad Meyer.Pp 1945546be25SConrad MeyerThe 1955546be25SConrad Meyer.Fn CPU_FILL 1965546be25SConrad Meyermacro adds all CPUs to 1975546be25SConrad Meyer.Fa cpuset . 1985546be25SConrad Meyer.Pp 1995546be25SConrad MeyerThe 2005546be25SConrad Meyer.Fn CPU_SETOF 2015546be25SConrad Meyermacro removes all CPUs in 2025546be25SConrad Meyer.Fa cpuset 2035546be25SConrad Meyerbefore adding only CPU 2045546be25SConrad Meyer.Fa cpu_idx . 2055546be25SConrad Meyer.Pp 2065546be25SConrad MeyerThe 2075546be25SConrad Meyer.Fn CPU_EMPTY 2085546be25SConrad Meyermacro returns 2095546be25SConrad Meyer.Dv true 2105546be25SConrad Meyerif 2115546be25SConrad Meyer.Fa cpuset 2125546be25SConrad Meyeris empty. 2135546be25SConrad Meyer.Pp 2145546be25SConrad MeyerThe 2155546be25SConrad Meyer.Fn CPU_ISFULLSET 2165546be25SConrad Meyermacro returns 2175546be25SConrad Meyer.Dv true 2185546be25SConrad Meyerif 2195546be25SConrad Meyer.Fa cpuset 2205546be25SConrad Meyeris full (the set of all CPUs). 2215546be25SConrad Meyer.Pp 2225546be25SConrad MeyerThe 2235546be25SConrad Meyer.Fn CPU_FFS 2245546be25SConrad Meyermacro returns the 1-index of the first (lowest) CPU in 2255546be25SConrad Meyer.Fa cpuset , 2265546be25SConrad Meyeror zero if 2275546be25SConrad Meyer.Fa cpuset 2285546be25SConrad Meyeris empty. 2295546be25SConrad MeyerLike with 2305546be25SConrad Meyer.Xr ffs 3 , 2315546be25SConrad Meyerto use the non-zero result of 2325546be25SConrad Meyer.Fn CPU_FFS 2335546be25SConrad Meyeras a 2345546be25SConrad Meyer.Fa cpu_idx 2355546be25SConrad Meyerindex parameter to any other 2365546be25SConrad Meyer.Nm 2375546be25SConrad Meyermacro, you must subtract one from the result. 2385546be25SConrad Meyer.Pp 2395546be25SConrad MeyerThe 2405546be25SConrad Meyer.Fn CPU_COUNT 2415546be25SConrad Meyermacro returns the total number of CPUs in 2425546be25SConrad Meyer.Fa cpuset . 2435546be25SConrad Meyer.Pp 2445546be25SConrad MeyerThe 2455546be25SConrad Meyer.Fn CPU_SUBSET 2465546be25SConrad Meyermacro returns 2475546be25SConrad Meyer.Dv true 2485546be25SConrad Meyerif 2495546be25SConrad Meyer.Fa needle 2505546be25SConrad Meyeris a subset of 2515546be25SConrad Meyer.Fa haystack . 2525546be25SConrad Meyer.Pp 2535546be25SConrad MeyerThe 2545546be25SConrad Meyer.Fn CPU_OVERLAP 2555546be25SConrad Meyermacro returns 2565546be25SConrad Meyer.Dv true 2575546be25SConrad Meyerif 2585546be25SConrad Meyer.Fa cpuset1 2595546be25SConrad Meyerand 2605546be25SConrad Meyer.Fa cpuset2 2615546be25SConrad Meyerhave any common CPUs. 2625546be25SConrad Meyer(That is, if 2635546be25SConrad Meyer.Fa cpuset1 2645546be25SConrad MeyerAND 2655546be25SConrad Meyer.Fa cpuset2 2665546be25SConrad Meyeris not the empty set.) 2675546be25SConrad Meyer.Pp 2685546be25SConrad MeyerThe 2695546be25SConrad Meyer.Fn CPU_CMP 2705546be25SConrad Meyermacro returns 2715546be25SConrad Meyer.Dv true 2725546be25SConrad Meyerif 2735546be25SConrad Meyer.Fa cpuset1 2745546be25SConrad Meyeris NOT equal to 2755546be25SConrad Meyer.Fa cpuset2 . 2765546be25SConrad Meyer.Pp 2775546be25SConrad MeyerThe 2785546be25SConrad Meyer.Fn CPU_OR 2795546be25SConrad Meyermacro adds CPUs present in 2805546be25SConrad Meyer.Fa src 2815546be25SConrad Meyerto 2825546be25SConrad Meyer.Fa dst . 2835546be25SConrad Meyer(It is the 2845546be25SConrad Meyer.Nm 2855546be25SConrad Meyerequivalent of the scalar: 2865546be25SConrad Meyer.Fa dst 2875546be25SConrad Meyer|= 2885546be25SConrad Meyer.Fa src . ) 2895546be25SConrad Meyer.Fn CPU_OR_ATOMIC 2905546be25SConrad Meyeris similar, but sets the bits representing CPUs in the component machine words 2915546be25SConrad Meyerin 2925546be25SConrad Meyer.Fa dst 2935546be25SConrad Meyerwith atomic machine instructions. 2945546be25SConrad Meyer(That is, if 2955546be25SConrad Meyer.Fa dst 2965546be25SConrad Meyeris composed of multiple machine words, 2975546be25SConrad Meyer.Fn CPU_OR_ATOMIC 2985546be25SConrad Meyerperforms multiple individually atomic operations.) 2995546be25SConrad Meyer.Pp 3005546be25SConrad MeyerThe 301*cd4bd975SJake Freeland.Fn CPU_ORNOT 302*cd4bd975SJake Freelandmacro add CPUs not in 303*cd4bd975SJake Freeland.Fa src 304*cd4bd975SJake Freelandto 305*cd4bd975SJake Freeland.Fa dst . 306*cd4bd975SJake Freeland(It is the 307*cd4bd975SJake Freeland.Nm 308*cd4bd975SJake Freelandequivalent of the scalar: 309*cd4bd975SJake Freeland.Fa dst 310*cd4bd975SJake Freeland|= 311*cd4bd975SJake Freeland.Fa ~ src . ) 312*cd4bd975SJake Freeland.Pp 313*cd4bd975SJake FreelandThe 3145546be25SConrad Meyer.Fn CPU_AND 3155546be25SConrad Meyermacro removes CPUs absent from 3165546be25SConrad Meyer.Fa src 3175546be25SConrad Meyerfrom 3185546be25SConrad Meyer.Fa dst . 3195546be25SConrad Meyer(It is the 3205546be25SConrad Meyer.Nm 3215546be25SConrad Meyerequivalent of the scalar: 3225546be25SConrad Meyer.Fa dst 3235546be25SConrad Meyer&= 3245546be25SConrad Meyer.Fa src . ) 3255546be25SConrad Meyer.Fn CPU_AND_ATOMIC 3265546be25SConrad Meyeris similar, with the same atomic semantics as 3275546be25SConrad Meyer.Fn CPU_OR_ATOMIC . 3285546be25SConrad Meyer.Pp 3295546be25SConrad MeyerThe 3309825eadfSRyan Libby.Fn CPU_ANDNOT 3315546be25SConrad Meyermacro removes CPUs in 3325546be25SConrad Meyer.Fa src 3335546be25SConrad Meyerfrom 3345546be25SConrad Meyer.Fa dst . 3355546be25SConrad Meyer(It is the 3365546be25SConrad Meyer.Nm 3375546be25SConrad Meyerequivalent of the scalar: 3385546be25SConrad Meyer.Fa dst 3395546be25SConrad Meyer&= 3405546be25SConrad Meyer.Fa ~ src . ) 3415546be25SConrad Meyer.Sh CPUSET_T_INITIALIZER EXAMPLE 3425546be25SConrad Meyer.Bd -literal 3435546be25SConrad Meyercpuset_t myset; 3445546be25SConrad Meyer 3455546be25SConrad Meyer/* Initialize myset to filled (all CPUs) */ 3465546be25SConrad Meyermyset = CPUSET_T_INITIALIZER(CPUSET_FSET); 3475546be25SConrad Meyer 3485546be25SConrad Meyer/* Initialize myset to only the lowest CPU */ 3495546be25SConrad Meyermyset = CPUSET_T_INITIALIZER(0x1); 3505546be25SConrad Meyer.Ed 3515546be25SConrad Meyer.Sh SEE ALSO 3528b584e9dSConrad Meyer.Xr cpuset 1 , 3538b584e9dSConrad Meyer.Xr cpuset 2 , 3545546be25SConrad Meyer.Xr bitset 9 3555546be25SConrad Meyer.Sh HISTORY 3565546be25SConrad Meyer.In sys/cpuset.h 3575546be25SConrad Meyerfirst appeared in 3585546be25SConrad Meyer.Fx 7.1 , 3595546be25SConrad Meyerreleased in January 2009, and in 3605546be25SConrad Meyer.Fx 8.0 , 3615546be25SConrad Meyerreleased in November 2009. 3625546be25SConrad Meyer.Pp 3635546be25SConrad MeyerThis manual page first appeared in 3645546be25SConrad Meyer.Fx 11.0 . 3655546be25SConrad Meyer.Sh AUTHORS 3665546be25SConrad Meyer.An -nosplit 3675546be25SConrad MeyerThe 3685546be25SConrad Meyer.Nm 3695546be25SConrad Meyermacros were written by 3705546be25SConrad Meyer.An Jeff Roberson Aq Mt jeff@FreeBSD.org . 3715546be25SConrad MeyerThis manual page was written by 3725546be25SConrad Meyer.An Conrad Meyer Aq Mt cem@FreeBSD.org . 3735546be25SConrad Meyer.Sh CAVEATS 3745546be25SConrad MeyerUnlike every other reference to individual set members, which are zero-indexed, 3755546be25SConrad Meyer.Fn CPU_FFS 3765546be25SConrad Meyerreturns a one-indexed result (or zero if the cpuset is empty). 377