mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Add helper macros to iterate over available CPUs in the system.
CPU_FOREACH(i) iterates over the CPU IDs of all available CPUs. The CPU_FIRST() and CPU_NEXT(i) macros can also be used to iterate over available CPU IDs. CPU_NEXT(i) wraps around to CPU_FIRST() rather than returning some sort of terminator. Requested by: rwatson Reviewed by: attilio
This commit is contained in:
parent
9124d0d6a3
commit
e762f66672
1 changed files with 38 additions and 0 deletions
|
|
@ -91,6 +91,44 @@ extern cpumask_t all_cpus;
|
|||
*/
|
||||
#define CPU_ABSENT(x_cpu) ((all_cpus & (1 << (x_cpu))) == 0)
|
||||
|
||||
/*
|
||||
* Macros to iterate over non-absent CPUs. CPU_FOREACH() takes an
|
||||
* integer iterator and iterates over the available set of CPUs.
|
||||
* CPU_FIRST() returns the id of the first non-absent CPU. CPU_NEXT()
|
||||
* returns the id of the next non-absent CPU. It will wrap back to
|
||||
* CPU_FIRST() once the end of the list is reached. The iterators are
|
||||
* currently implemented via inline functions.
|
||||
*/
|
||||
#define CPU_FOREACH(i) \
|
||||
for ((i) = 0; (i) <= mp_maxid; (i)++) \
|
||||
if (!CPU_ABSENT((i)))
|
||||
|
||||
static __inline int
|
||||
cpu_first(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0;; i++)
|
||||
if (!CPU_ABSENT(i))
|
||||
return (i);
|
||||
}
|
||||
|
||||
static __inline int
|
||||
cpu_next(int i)
|
||||
{
|
||||
|
||||
for (;;) {
|
||||
i++;
|
||||
if (i > mp_maxid)
|
||||
i = 0;
|
||||
if (!CPU_ABSENT(i))
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
|
||||
#define CPU_FIRST() cpu_first()
|
||||
#define CPU_NEXT(i) cpu_next((i))
|
||||
|
||||
#ifdef SMP
|
||||
/*
|
||||
* Machine dependent functions used to initialize MP support.
|
||||
|
|
|
|||
Loading…
Reference in a new issue