Skip to content

Commit c458b1d

Browse files
anna-marialxIngo Molnar
authored andcommitted
hrtimer: Prepare handling of hard and softirq based hrtimers
The softirq based hrtimer can utilize most of the existing hrtimers functions, but need to operate on a different data set. Add an 'active_mask' parameter to various functions so the hard and soft bases can be selected. Fixup the existing callers and hand in the ACTIVE_HARD mask. Signed-off-by: Anna-Maria Gleixner <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: John Stultz <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 98ecadd commit c458b1d

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

kernel/time/hrtimer.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959

6060
#include "tick-internal.h"
6161

62+
/*
63+
* Masks for selecting the soft and hard context timers from
64+
* cpu_base->active
65+
*/
66+
#define MASK_SHIFT (HRTIMER_BASE_MONOTONIC_SOFT)
67+
#define HRTIMER_ACTIVE_HARD ((1U << MASK_SHIFT) - 1)
68+
#define HRTIMER_ACTIVE_SOFT (HRTIMER_ACTIVE_HARD << MASK_SHIFT)
69+
#define HRTIMER_ACTIVE_ALL (HRTIMER_ACTIVE_SOFT | HRTIMER_ACTIVE_HARD)
70+
6271
/*
6372
* The timer bases:
6473
*
@@ -507,13 +516,24 @@ static ktime_t __hrtimer_next_event_base(struct hrtimer_cpu_base *cpu_base,
507516
return expires_next;
508517
}
509518

510-
static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base)
519+
/*
520+
* Recomputes cpu_base::*next_timer and returns the earliest expires_next but
521+
* does not set cpu_base::*expires_next, that is done by hrtimer_reprogram.
522+
*
523+
* @active_mask must be one of:
524+
* - HRTIMER_ACTIVE,
525+
* - HRTIMER_ACTIVE_SOFT, or
526+
* - HRTIMER_ACTIVE_HARD.
527+
*/
528+
static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base,
529+
unsigned int active_mask)
511530
{
512-
unsigned int active = cpu_base->active_bases;
531+
unsigned int active;
513532
ktime_t expires_next = KTIME_MAX;
514533

515534
cpu_base->next_timer = NULL;
516535

536+
active = cpu_base->active_bases & active_mask;
517537
expires_next = __hrtimer_next_event_base(cpu_base, active, expires_next);
518538

519539
return expires_next;
@@ -553,7 +573,7 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
553573
{
554574
ktime_t expires_next;
555575

556-
expires_next = __hrtimer_get_next_event(cpu_base);
576+
expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_HARD);
557577

558578
if (skip_equal && expires_next == cpu_base->expires_next)
559579
return;
@@ -1074,7 +1094,7 @@ u64 hrtimer_get_next_event(void)
10741094
raw_spin_lock_irqsave(&cpu_base->lock, flags);
10751095

10761096
if (!__hrtimer_hres_active(cpu_base))
1077-
expires = __hrtimer_get_next_event(cpu_base);
1097+
expires = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_HARD);
10781098

10791099
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
10801100

@@ -1248,10 +1268,10 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
12481268
}
12491269

12501270
static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now,
1251-
unsigned long flags)
1271+
unsigned long flags, unsigned int active_mask)
12521272
{
12531273
struct hrtimer_clock_base *base;
1254-
unsigned int active = cpu_base->active_bases;
1274+
unsigned int active = cpu_base->active_bases & active_mask;
12551275

12561276
for_each_active_base(base, cpu_base, active) {
12571277
struct timerqueue_node *node;
@@ -1314,10 +1334,10 @@ void hrtimer_interrupt(struct clock_event_device *dev)
13141334
*/
13151335
cpu_base->expires_next = KTIME_MAX;
13161336

1317-
__hrtimer_run_queues(cpu_base, now, flags);
1337+
__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);
13181338

13191339
/* Reevaluate the clock bases for the next expiry */
1320-
expires_next = __hrtimer_get_next_event(cpu_base);
1340+
expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_HARD);
13211341
/*
13221342
* Store the new expiry value so the migration code can verify
13231343
* against it.
@@ -1421,7 +1441,7 @@ void hrtimer_run_queues(void)
14211441

14221442
raw_spin_lock_irqsave(&cpu_base->lock, flags);
14231443
now = hrtimer_update_base(cpu_base);
1424-
__hrtimer_run_queues(cpu_base, now, flags);
1444+
__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);
14251445
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
14261446
}
14271447

0 commit comments

Comments
 (0)