Cpumask_of_cpu ()

Source: Internet
Author: User
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 );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.