Set the corresponding location of the processor bitmap to 1 (the other bit is 0) based on the processor number CPU)
# Define cpumask_of_cpu (CPU )/
({/
Typeof (_ unused_cpumask_arg _) m ;/
If (sizeof (m) = sizeof (unsigned long )){/
M. Bits [0] = 1ul <(CPU );/
} Else {/
Cpus_clear (m );/
Cpu_set (CPU), m );/
}/
M ;/
})
Note:
(1)
---------------------------------
1ul <(CPU) shifts 1 left (CPU) Bit
(2) _ unused_cpumask_arg _
---------------------------------
Extern cpumask_t _ unused_cpumask_arg _;
Typedef struct {declare_bitmap (bits, nr_cpus);} cpumask_t;
# Ifdef config_smp
# Define nr_cpus config_nr_cpus
# Else
# Define nr_cpus 1
# Endif
If the number of CPUs in the system is less than or equal to 32, the unsigned long bits [1] is formed.
If the number of CPUs in the system is greater than 32 (for example, 33), the unsigned long bits [2] is formed.
-----------------------------------------------------
# Define declare_bitmap (name, BITs )/
Unsigned long name [bits_to_longs (BITs)]
# Define bits_to_longs (BITs )/
(BITs) + BITS_PER_LONG-1)/bits_per_long)
# Define bits_per_long 32
Note: The Linux system long (unsigned long) on PC is 32-bit (BITs)
(3) cpus_clear (DST)
-----------------------------------------------------
# Define cpus_clear (DST) _ cpus_clear (& (DST), nr_cpus)
Static inline void _ cpus_clear (cpumask_t * dstp, int nbits)
{
Bitmap_zero (dstp-> bits, nbits );
}
Static inline void bitmap_zero (unsigned long * DST, int nbits)
{
If (nbits <= bits_per_long)
* DST = 0ul;
Else {
Int Len = bits_to_longs (nbits) * sizeof (unsigned long );
Memset (DST, 0, Len );
}
}
(4) cpu_set (CPU, DST)
-----------------------------------------------------
# Define cpu_set (CPU, DST) _ cpu_set (CPU), & (DST ))
Static inline void _ cpu_set (int cpu, volatile cpumask_t * dstp)
{
Set_bit (CPU, dstp-> bits );
}