]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/cpuset.h
Merge branch 'releng/11.3' into releng-CDN/11.3
[FreeBSD/FreeBSD.git] / sys / sys / cpuset.h
1 /*-
2  * Copyright (c) 2008,  Jeffrey Roberson <jeff@freebsd.org>
3  * All rights reserved.
4  *
5  * Copyright (c) 2008 Nokia Corporation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice unmodified, this list of conditions, and the following
13  *    disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _SYS_CPUSET_H_
33 #define _SYS_CPUSET_H_
34
35 #include <sys/_cpuset.h>
36
37 #include <sys/bitset.h>
38
39 #define _NCPUBITS       _BITSET_BITS
40 #define _NCPUWORDS      __bitset_words(CPU_SETSIZE)
41
42 #define CPUSETBUFSIZ    ((2 + sizeof(long) * 2) * _NCPUWORDS)
43
44 #define CPU_CLR(n, p)                   BIT_CLR(CPU_SETSIZE, n, p)
45 #define CPU_COPY(f, t)                  BIT_COPY(CPU_SETSIZE, f, t)
46 #define CPU_ISSET(n, p)                 BIT_ISSET(CPU_SETSIZE, n, p)
47 #define CPU_SET(n, p)                   BIT_SET(CPU_SETSIZE, n, p)
48 #define CPU_ZERO(p)                     BIT_ZERO(CPU_SETSIZE, p)
49 #define CPU_FILL(p)                     BIT_FILL(CPU_SETSIZE, p)
50 #define CPU_SETOF(n, p)                 BIT_SETOF(CPU_SETSIZE, n, p)
51 #define CPU_EMPTY(p)                    BIT_EMPTY(CPU_SETSIZE, p)
52 #define CPU_ISFULLSET(p)                BIT_ISFULLSET(CPU_SETSIZE, p)
53 #define CPU_SUBSET(p, c)                BIT_SUBSET(CPU_SETSIZE, p, c)
54 #define CPU_OVERLAP(p, c)               BIT_OVERLAP(CPU_SETSIZE, p, c)
55 #define CPU_CMP(p, c)                   BIT_CMP(CPU_SETSIZE, p, c)
56 #define CPU_OR(d, s)                    BIT_OR(CPU_SETSIZE, d, s)
57 #define CPU_AND(d, s)                   BIT_AND(CPU_SETSIZE, d, s)
58 #define CPU_NAND(d, s)                  BIT_NAND(CPU_SETSIZE, d, s)
59 #define CPU_CLR_ATOMIC(n, p)            BIT_CLR_ATOMIC(CPU_SETSIZE, n, p)
60 #define CPU_SET_ATOMIC(n, p)            BIT_SET_ATOMIC(CPU_SETSIZE, n, p)
61 #define CPU_SET_ATOMIC_ACQ(n, p)        BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p)
62 #define CPU_AND_ATOMIC(n, p)            BIT_AND_ATOMIC(CPU_SETSIZE, n, p)
63 #define CPU_OR_ATOMIC(d, s)             BIT_OR_ATOMIC(CPU_SETSIZE, d, s)
64 #define CPU_COPY_STORE_REL(f, t)        BIT_COPY_STORE_REL(CPU_SETSIZE, f, t)
65 #define CPU_FFS(p)                      BIT_FFS(CPU_SETSIZE, p)
66 #define CPU_COUNT(p)                    BIT_COUNT(CPU_SETSIZE, p)
67 #define CPUSET_FSET                     BITSET_FSET(_NCPUWORDS)
68 #define CPUSET_T_INITIALIZER            BITSET_T_INITIALIZER
69
70 /*
71  * Valid cpulevel_t values.
72  */
73 #define CPU_LEVEL_ROOT          1       /* All system cpus. */
74 #define CPU_LEVEL_CPUSET        2       /* Available cpus for which. */
75 #define CPU_LEVEL_WHICH         3       /* Actual mask/id for which. */
76
77 /*
78  * Valid cpuwhich_t values.
79  */
80 #define CPU_WHICH_TID           1       /* Specifies a thread id. */
81 #define CPU_WHICH_PID           2       /* Specifies a process id. */
82 #define CPU_WHICH_CPUSET        3       /* Specifies a set id. */
83 #define CPU_WHICH_IRQ           4       /* Specifies an irq #. */
84 #define CPU_WHICH_JAIL          5       /* Specifies a jail id. */
85 #define CPU_WHICH_DOMAIN        6       /* Specifies a NUMA domain id. */
86 #define CPU_WHICH_INTRHANDLER   7       /* Specifies an irq # (not ithread). */
87 #define CPU_WHICH_ITHREAD       8       /* Specifies an irq's ithread. */
88
89 /*
90  * Reserved cpuset identifiers.
91  */
92 #define CPUSET_INVALID  -1
93 #define CPUSET_DEFAULT  0
94
95 #ifdef _KERNEL
96 #include <sys/queue.h>
97
98 LIST_HEAD(setlist, cpuset);
99
100 /*
101  * cpusets encapsulate cpu binding information for one or more threads.
102  *
103  *      a - Accessed with atomics.
104  *      s - Set at creation, never modified.  Only a ref required to read.
105  *      c - Locked internally by a cpuset lock.
106  *
107  * The bitmask is only modified while holding the cpuset lock.  It may be
108  * read while only a reference is held but the consumer must be prepared
109  * to deal with inconsistent results.
110  */
111 struct cpuset {
112         cpuset_t                cs_mask;        /* bitmask of valid cpus. */
113         volatile u_int          cs_ref;         /* (a) Reference count. */
114         int                     cs_flags;       /* (s) Flags from below. */
115         cpusetid_t              cs_id;          /* (s) Id or INVALID. */
116         struct cpuset           *cs_parent;     /* (s) Pointer to our parent. */
117         LIST_ENTRY(cpuset)      cs_link;        /* (c) All identified sets. */
118         LIST_ENTRY(cpuset)      cs_siblings;    /* (c) Sibling set link. */
119         struct setlist          cs_children;    /* (c) List of children. */
120 };
121
122 #define CPU_SET_ROOT    0x0001  /* Set is a root set. */
123 #define CPU_SET_RDONLY  0x0002  /* No modification allowed. */
124
125 extern cpuset_t *cpuset_root;
126 struct prison;
127 struct proc;
128 struct thread;
129
130 struct cpuset *cpuset_thread0(void);
131 struct cpuset *cpuset_ref(struct cpuset *);
132 void    cpuset_rel(struct cpuset *);
133 int     cpuset_setthread(lwpid_t id, cpuset_t *);
134 int     cpuset_setithread(lwpid_t id, int cpu);
135 int     cpuset_create_root(struct prison *, struct cpuset **);
136 int     cpuset_setproc_update_set(struct proc *, struct cpuset *);
137 int     cpuset_which(cpuwhich_t, id_t, struct proc **,
138             struct thread **, struct cpuset **);
139
140 char    *cpusetobj_strprint(char *, const cpuset_t *);
141 int     cpusetobj_strscan(cpuset_t *, const char *);
142 #ifdef DDB
143 void    ddb_display_cpuset(const cpuset_t *);
144 #endif
145
146 #else
147 __BEGIN_DECLS
148 int     cpuset(cpusetid_t *);
149 int     cpuset_setid(cpuwhich_t, id_t, cpusetid_t);
150 int     cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *);
151 int     cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t *);
152 int     cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const cpuset_t *);
153 __END_DECLS
154 #endif
155 #endif /* !_SYS_CPUSET_H_ */