现在的位置: 首页 > 综合 > 正文

cpumask_of_cpu()

2013年09月14日 ⁄ 综合 ⁄ 共 1720字 ⁄ 字号 评论关闭
根据处理器编号cpu,将处理器位图的相应位置置为1(其它位为0)
#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;                                          /
})

注:
(1)
---------------------------------
1UL<<(cpu)        将1左移(cpu)位

(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

如果系统中的CPU数目小于等于32则形成unsigned long bits[1]
如果系统中的CPU数目大于32(比如33)则形成unsigned long bits[2]
-----------------------------------------------------
#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
注:PC机上的Linux系统long (unsigned long)是32位(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);
}  

 

抱歉!评论已关闭.