cpumask_of_cpu()

根据处理器编号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);
}  











 
以下是Linux内核4.19版本中timer_interrupt()函数的源码实现: ``` asmlinkage __visible void __weak timer_interrupt(struct pt_regs *regs) { struct cpu_data *cpu = get_cpu_ptr(smp_processor_id()); struct clock_event_device *evt = cpu->evtdev; unsigned long next_jiffies = jiffies + 1; if (unlikely(time_after_eq(next_jiffies, cpu->last_jiffies + TICK_NSEC))) { /* * Some of this is really subtle. If we're in the middle of a tick * already, we don't want to update the tick count - that could * confuse the heck out of anyone trying to do timing. So make sure * we don't update the tick until after the tick period has * expired. */ if (time_after(next_jiffies, cpu->last_jiffies + TICK_NSEC)) { int clock_was_set = 0; while (time_after_eq(next_jiffies, cpu->last_jiffies + TICK_NSEC)) { cpu->last_jiffies += TICK_NSEC; update_wall_time(); clock_was_set = tick_nohz_update_jiffies(&cpu->tick_dep_mask); if (cpu_is_offline(smp_processor_id())) return; } if (clock_was_set) tick_program_event(evt, cpu->next_timer_interrupt); } /* * We must make sure that the jiffies update is visible * before we test time_after_eq(). */ smp_wmb(); if (time_after_eq(next_jiffies, READ_ONCE(jiffies))) __generic_touch_nmi_watchdog(); if (unlikely(in_nmi())) return; /* * If we missed any timer interrupts, correct this now * by advancing the local timer and updating wall time * again. */ while (time_after_eq(next_jiffies, READ_ONCE(jiffies))) { cpu->last_jiffies += TICK_NSEC; update_wall_time(); tick_nohz_idle_enter(); } } evt->event_handler(evt); } ``` timer_interrupt()函数是中断处理程序,用于处理定时器中断。该函数首先获取当前CPU的事件设备指针,然后计算出下一次中断的时间,如果下一次中断的时间已经到了,则更新 jiffies 值并调用事件处理函数。如果下一次中断的时间还没有到,则继续等待下一次中断。函数中还包含了一些调用其他函数的代码块,用于更新时间值、设置时钟事件等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值