函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\time\tick-broadcast-hrtimer.c Create Date:2022-07-27 11:51:03
首页 Copyright©Brick

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * This is called from the guts of the broadcast code when the cpu
 * which is about to enter idle has the earliest broadcast timer event.
 */
static int bc_set_next(ktime_t expires, struct clock_event_device *bc)
{
    /*
     * This is called either from enter/exit idle code or from the
     * broadcast handler. In all cases tick_broadcast_lock is held.
     *
     * hrtimer_cancel() cannot be called here neither from the
     * broadcast handler nor from the enter/exit idle code. The idle
     * code can run into the problem described in bc_shutdown() and the
     * broadcast handler cannot wait for itself to complete for obvious
     * reasons.
     *
     * Each caller tries to arm the hrtimer on its own CPU, but if the
     * hrtimer callbback function is currently running, then
     * hrtimer_start() cannot move it and the timer stays on the CPU on
     * which it is assigned at the moment.
     *
     * As this can be called from idle code, the hrtimer_start()
     * invocation has to be wrapped with RCU_NONIDLE() as
     * hrtimer_start() can call into tracing.
     */
    RCU_NONIDLE( {
        hrtimer_start(&bctimer, expires, HRTIMER_MODE_ABS_PINNED_HARD);
        /*
         * The core tick broadcast mode expects bc->bound_on to be set
         * correctly to prevent a CPU which has the broadcast hrtimer
         * armed from going deep idle.
         *
         * As tick_broadcast_lock is held, nothing can change the cpu
         * base which was just established in hrtimer_start() above. So
         * the below access is safe even without holding the hrtimer
         * base lock.
         */
        bc->bound_on = bctimer.base->cpu_base->cpu;
    } );
    return 0;
}