cpuset.h revision 250395
1176730Sjeff/*- 2176730Sjeff * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org> 3176730Sjeff * All rights reserved. 4176730Sjeff * 5177904Sjeff * Copyright (c) 2008 Nokia Corporation 6177904Sjeff * All rights reserved. 7177904Sjeff * 8176730Sjeff * Redistribution and use in source and binary forms, with or without 9176730Sjeff * modification, are permitted provided that the following conditions 10176730Sjeff * are met: 11176730Sjeff * 1. Redistributions of source code must retain the above copyright 12176730Sjeff * notice unmodified, this list of conditions, and the following 13176730Sjeff * disclaimer. 14176730Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15176730Sjeff * notice, this list of conditions and the following disclaimer in the 16176730Sjeff * documentation and/or other materials provided with the distribution. 17176730Sjeff * 18176730Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19176730Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20176730Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21176730Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22176730Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23176730Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24176730Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25176730Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26176730Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27176730Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28176730Sjeff * 29176730Sjeff * $FreeBSD: head/sys/sys/cpuset.h 250395 2013-05-09 00:04:59Z attilio $ 30176730Sjeff */ 31176730Sjeff 32176730Sjeff#ifndef _SYS_CPUSET_H_ 33176730Sjeff#define _SYS_CPUSET_H_ 34176730Sjeff 35222813Sattilio#include <sys/_cpuset.h> 36176730Sjeff 37250395Sattilio#include <sys/bitset.h> 38250395Sattilio 39222813Sattilio#define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) 40176730Sjeff 41250395Sattilio#define CPU_CLR(n, p) BIT_CLR(CPU_SETSIZE, n, p) 42250395Sattilio#define CPU_COPY(f, t) BIT_COPY(CPU_SETSIZE, f, t) 43250395Sattilio#define CPU_ISSET(n, p) BIT_ISSET(CPU_SETSIZE, n, p) 44250395Sattilio#define CPU_SET(n, p) BIT_SET(CPU_SETSIZE, n, p) 45250395Sattilio#define CPU_ZERO(p) BIT_ZERO(CPU_SETSIZE, p) 46250395Sattilio#define CPU_FILL(p) BIT_FILL(CPU_SETSIZE, p) 47250395Sattilio#define CPU_SETOF(n, p) BIT_SETOF(CPU_SETSIZE, n, p) 48250395Sattilio#define CPU_EMPTY(p) BIT_EMPTY(CPU_SETSIZE, p) 49250395Sattilio#define CPU_ISFULLSET(p) BIT_ISFULLSET(CPU_SETSIZE, p) 50250395Sattilio#define CPU_SUBSET(p, c) BIT_SUBSET(CPU_SETSIZE, p, c) 51250395Sattilio#define CPU_OVERLAP(p, c) BIT_OVERLAP(CPU_SETSIZE, p, c) 52250395Sattilio#define CPU_CMP(p, c) BIT_CMP(CPU_SETSIZE, p, c) 53250395Sattilio#define CPU_OR(d, s) BIT_OR(CPU_SETSIZE, d, s) 54250395Sattilio#define CPU_AND(d, s) BIT_AND(CPU_SETSIZE, d, s) 55250395Sattilio#define CPU_NAND(d, s) BIT_NAND(CPU_SETSIZE, d, s) 56250395Sattilio#define CPU_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(CPU_SETSIZE, n, p) 57250395Sattilio#define CPU_SET_ATOMIC(n, p) BIT_SET_ATOMIC(CPU_SETSIZE, n, p) 58250395Sattilio#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(CPU_SETSIZE, d, s) 59250395Sattilio#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(CPU_SETSIZE, f, t) 60232852Smav 61176730Sjeff/* 62176730Sjeff * Valid cpulevel_t values. 63176730Sjeff */ 64176730Sjeff#define CPU_LEVEL_ROOT 1 /* All system cpus. */ 65176730Sjeff#define CPU_LEVEL_CPUSET 2 /* Available cpus for which. */ 66176730Sjeff#define CPU_LEVEL_WHICH 3 /* Actual mask/id for which. */ 67176730Sjeff 68176730Sjeff/* 69176730Sjeff * Valid cpuwhich_t values. 70176730Sjeff */ 71176730Sjeff#define CPU_WHICH_TID 1 /* Specifies a thread id. */ 72176730Sjeff#define CPU_WHICH_PID 2 /* Specifies a process id. */ 73176730Sjeff#define CPU_WHICH_CPUSET 3 /* Specifies a set id. */ 74178092Sjeff#define CPU_WHICH_IRQ 4 /* Specifies an irq #. */ 75185435Sbz#define CPU_WHICH_JAIL 5 /* Specifies a jail id. */ 76176730Sjeff 77176730Sjeff/* 78176730Sjeff * Reserved cpuset identifiers. 79176730Sjeff */ 80176730Sjeff#define CPUSET_INVALID -1 81176730Sjeff#define CPUSET_DEFAULT 0 82176730Sjeff 83176730Sjeff#ifdef _KERNEL 84176730SjeffLIST_HEAD(setlist, cpuset); 85176730Sjeff 86176730Sjeff/* 87176730Sjeff * cpusets encapsulate cpu binding information for one or more threads. 88176730Sjeff * 89176730Sjeff * a - Accessed with atomics. 90176730Sjeff * s - Set at creation, never modified. Only a ref required to read. 91176730Sjeff * c - Locked internally by a cpuset lock. 92176730Sjeff * 93176730Sjeff * The bitmask is only modified while holding the cpuset lock. It may be 94176730Sjeff * read while only a reference is held but the consumer must be prepared 95176730Sjeff * to deal with inconsistent results. 96176730Sjeff */ 97176730Sjeffstruct cpuset { 98176730Sjeff cpuset_t cs_mask; /* bitmask of valid cpus. */ 99176730Sjeff volatile u_int cs_ref; /* (a) Reference count. */ 100176730Sjeff int cs_flags; /* (s) Flags from below. */ 101176730Sjeff cpusetid_t cs_id; /* (s) Id or INVALID. */ 102176730Sjeff struct cpuset *cs_parent; /* (s) Pointer to our parent. */ 103176730Sjeff LIST_ENTRY(cpuset) cs_link; /* (c) All identified sets. */ 104176730Sjeff LIST_ENTRY(cpuset) cs_siblings; /* (c) Sibling set link. */ 105176730Sjeff struct setlist cs_children; /* (c) List of children. */ 106176730Sjeff}; 107176730Sjeff 108176730Sjeff#define CPU_SET_ROOT 0x0001 /* Set is a root set. */ 109176730Sjeff#define CPU_SET_RDONLY 0x0002 /* No modification allowed. */ 110176730Sjeff 111177738Sjeffextern cpuset_t *cpuset_root; 112192895Sjamiestruct prison; 113185435Sbzstruct proc; 114177738Sjeff 115176730Sjeffstruct cpuset *cpuset_thread0(void); 116176730Sjeffstruct cpuset *cpuset_ref(struct cpuset *); 117177738Sjeffvoid cpuset_rel(struct cpuset *); 118177738Sjeffint cpuset_setthread(lwpid_t id, cpuset_t *); 119192895Sjamieint cpuset_create_root(struct prison *, struct cpuset **); 120185435Sbzint cpuset_setproc_update_set(struct proc *, struct cpuset *); 121222813Sattilioint cpusetobj_ffs(const cpuset_t *); 122222813Sattiliochar *cpusetobj_strprint(char *, const cpuset_t *); 123222813Sattilioint cpusetobj_strscan(cpuset_t *, const char *); 124177738Sjeff 125176730Sjeff#else 126176730Sjeff__BEGIN_DECLS 127176730Sjeffint cpuset(cpusetid_t *); 128176730Sjeffint cpuset_setid(cpuwhich_t, id_t, cpusetid_t); 129176730Sjeffint cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *); 130177597Sruint cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t *); 131177597Sruint cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const cpuset_t *); 132176730Sjeff__END_DECLS 133176730Sjeff#endif 134176730Sjeff#endif /* !_SYS_CPUSET_H_ */ 135