Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tick/nohz: Update comments some more

Inspired by recent enhancements to comments in kernel/time/tick-sched.c,
go through the entire file and fix/unify its comments:

- Fix over a dozen typos, spelling mistakes & cases of bad grammar.

- Re-phrase sentences that I needed to read three times to understand.

[ I used the following arbitrary rule-of-thumb:
- if I had to read a comment twice, it was usually my fault,
- if I had to read it a third time, it was the comment's fault. ]

- Comma updates:

- Add commas where needed

- Remove commas where not needed

- In cases where a comma is optional, choose one variant and try to
standardize it over similar sentences in the file.

- Standardize on standalone 'NOHZ' spelling in free-flowing comments:

s/nohz/NOHZ
s/no idle tick/NOHZ

Still keep 'dynticks' as a popular synonym.

- Standardize on referring to variable names within free-flowing
comments with the "'var'" nomenclature, and function names as
"function_name()".

- Standardize on '64-bit' and '32-bit':
s/32bit/32-bit
s/64bit/64-bit

- Standardize on 'IRQ work':
s/irq work/IRQ work

- A few other tidyups I probably missed to list.

No change in functionality intended - other than one small change to
a syslog output string.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/ZRVCNeMcSQcXS36N@gmail.com

+74 -76
+74 -76
kernel/time/tick-sched.c
··· 4 4 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar 5 5 * Copyright(C) 2006-2007 Timesys Corp., Thomas Gleixner 6 6 * 7 - * No idle tick implementation for low and high resolution timers 7 + * NOHZ implementation for low and high resolution timers 8 8 * 9 9 * Started by: Thomas Gleixner and Ingo Molnar 10 10 */ ··· 45 45 46 46 #if defined(CONFIG_NO_HZ_COMMON) || defined(CONFIG_HIGH_RES_TIMERS) 47 47 /* 48 - * The time, when the last jiffy update happened. Write access must hold 48 + * The time when the last jiffy update happened. Write access must hold 49 49 * jiffies_lock and jiffies_seq. tick_nohz_next_event() needs to get a 50 50 * consistent view of jiffies and last_jiffies_update. 51 51 */ ··· 60 60 ktime_t delta, nextp; 61 61 62 62 /* 63 - * 64bit can do a quick check without holding jiffies lock and 63 + * 64-bit can do a quick check without holding the jiffies lock and 64 64 * without looking at the sequence count. The smp_load_acquire() 65 65 * pairs with the update done later in this function. 66 66 * 67 - * 32bit cannot do that because the store of tick_next_period 68 - * consists of two 32bit stores and the first store could move it 69 - * to a random point in the future. 67 + * 32-bit cannot do that because the store of 'tick_next_period' 68 + * consists of two 32-bit stores, and the first store could be 69 + * moved by the CPU to a random point in the future. 70 70 */ 71 71 if (IS_ENABLED(CONFIG_64BIT)) { 72 72 if (ktime_before(now, smp_load_acquire(&tick_next_period))) ··· 75 75 unsigned int seq; 76 76 77 77 /* 78 - * Avoid contention on jiffies_lock and protect the quick 78 + * Avoid contention on 'jiffies_lock' and protect the quick 79 79 * check with the sequence count. 80 80 */ 81 81 do { ··· 90 90 /* Quick check failed, i.e. update is required. */ 91 91 raw_spin_lock(&jiffies_lock); 92 92 /* 93 - * Reevaluate with the lock held. Another CPU might have done the 93 + * Re-evaluate with the lock held. Another CPU might have done the 94 94 * update already. 95 95 */ 96 96 if (ktime_before(now, tick_next_period)) { ··· 114 114 TICK_NSEC); 115 115 } 116 116 117 - /* Advance jiffies to complete the jiffies_seq protected job */ 117 + /* Advance jiffies to complete the 'jiffies_seq' protected job */ 118 118 jiffies_64 += ticks; 119 119 120 - /* 121 - * Keep the tick_next_period variable up to date. 122 - */ 120 + /* Keep the tick_next_period variable up to date */ 123 121 nextp = ktime_add_ns(last_jiffies_update, TICK_NSEC); 124 122 125 123 if (IS_ENABLED(CONFIG_64BIT)) { 126 124 /* 127 125 * Pairs with smp_load_acquire() in the lockless quick 128 - * check above and ensures that the update to jiffies_64 is 129 - * not reordered vs. the store to tick_next_period, neither 126 + * check above, and ensures that the update to 'jiffies_64' is 127 + * not reordered vs. the store to 'tick_next_period', neither 130 128 * by the compiler nor by the CPU. 131 129 */ 132 130 smp_store_release(&tick_next_period, nextp); 133 131 } else { 134 132 /* 135 - * A plain store is good enough on 32bit as the quick check 133 + * A plain store is good enough on 32-bit, as the quick check 136 134 * above is protected by the sequence count. 137 135 */ 138 136 tick_next_period = nextp; ··· 138 140 139 141 /* 140 142 * Release the sequence count. calc_global_load() below is not 141 - * protected by it, but jiffies_lock needs to be held to prevent 143 + * protected by it, but 'jiffies_lock' needs to be held to prevent 142 144 * concurrent invocations. 143 145 */ 144 146 write_seqcount_end(&jiffies_seq); ··· 158 160 159 161 raw_spin_lock(&jiffies_lock); 160 162 write_seqcount_begin(&jiffies_seq); 161 - /* Did we start the jiffies update yet ? */ 163 + 164 + /* Have we started the jiffies update yet ? */ 162 165 if (last_jiffies_update == 0) { 163 166 u32 rem; 164 167 ··· 174 175 last_jiffies_update = tick_next_period; 175 176 } 176 177 period = last_jiffies_update; 178 + 177 179 write_seqcount_end(&jiffies_seq); 178 180 raw_spin_unlock(&jiffies_lock); 181 + 179 182 return period; 180 183 } 181 184 ··· 193 192 * concurrency: This happens only when the CPU in charge went 194 193 * into a long sleep. If two CPUs happen to assign themselves to 195 194 * this duty, then the jiffies update is still serialized by 196 - * jiffies_lock. 195 + * 'jiffies_lock'. 197 196 * 198 197 * If nohz_full is enabled, this should not happen because the 199 - * tick_do_timer_cpu never relinquishes. 198 + * 'tick_do_timer_cpu' CPU never relinquishes. 200 199 */ 201 200 if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) { 202 201 #ifdef CONFIG_NO_HZ_FULL ··· 206 205 } 207 206 #endif 208 207 209 - /* Check, if the jiffies need an update */ 208 + /* Check if jiffies need an update */ 210 209 if (tick_do_timer_cpu == cpu) 211 210 tick_do_update_jiffies64(now); 212 211 213 212 /* 214 - * If jiffies update stalled for too long (timekeeper in stop_machine() 213 + * If the jiffies update stalled for too long (timekeeper in stop_machine() 215 214 * or VMEXIT'ed for several msecs), force an update. 216 215 */ 217 216 if (ts->last_tick_jiffies != jiffies) { ··· 235 234 /* 236 235 * When we are idle and the tick is stopped, we have to touch 237 236 * the watchdog as we might not schedule for a really long 238 - * time. This happens on complete idle SMP systems while 237 + * time. This happens on completely idle SMP systems while 239 238 * waiting on the login prompt. We also increment the "start of 240 239 * idle" jiffy stamp so the idle accounting adjustment we do 241 - * when we go busy again does not account too much ticks. 240 + * when we go busy again does not account too many ticks. 242 241 */ 243 242 if (ts->tick_stopped) { 244 243 touch_softlockup_watchdog_sched(); ··· 363 362 364 363 /* 365 364 * If the task is not running, run_posix_cpu_timers() 366 - * has nothing to elapse, IPI can then be spared. 365 + * has nothing to elapse, and an IPI can then be optimized out. 367 366 * 368 367 * activate_task() STORE p->tick_dep_mask 369 368 * STORE p->on_rq ··· 426 425 427 426 /* 428 427 * Set a global tick dependency. Used by perf events that rely on freq and 429 - * by unstable clock. 428 + * unstable clocks. 430 429 */ 431 430 void tick_nohz_dep_set(enum tick_dep_bits bit) 432 431 { ··· 440 439 441 440 /* 442 441 * Set per-CPU tick dependency. Used by scheduler and perf events in order to 443 - * manage events throttling. 442 + * manage event-throttling. 444 443 */ 445 444 void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit) 446 445 { ··· 456 455 if (cpu == smp_processor_id()) { 457 456 tick_nohz_full_kick(); 458 457 } else { 459 - /* Remote irq work not NMI-safe */ 458 + /* Remote IRQ work not NMI-safe */ 460 459 if (!WARN_ON_ONCE(in_nmi())) 461 460 tick_nohz_full_kick_cpu(cpu); 462 461 } ··· 474 473 EXPORT_SYMBOL_GPL(tick_nohz_dep_clear_cpu); 475 474 476 475 /* 477 - * Set a per-task tick dependency. RCU need this. Also posix CPU timers 476 + * Set a per-task tick dependency. RCU needs this. Also posix CPU timers 478 477 * in order to elapse per task timers. 479 478 */ 480 479 void tick_nohz_dep_set_task(struct task_struct *tsk, enum tick_dep_bits bit) ··· 547 546 bool tick_nohz_cpu_hotpluggable(unsigned int cpu) 548 547 { 549 548 /* 550 - * The tick_do_timer_cpu CPU handles housekeeping duty (unbound 549 + * The 'tick_do_timer_cpu' CPU handles housekeeping duty (unbound 551 550 * timers, workqueues, timekeeping, ...) on behalf of full dynticks 552 551 * CPUs. It must remain online when nohz full is enabled. 553 552 */ ··· 569 568 return; 570 569 571 570 /* 572 - * Full dynticks uses irq work to drive the tick rescheduling on safe 573 - * locking contexts. But then we need irq work to raise its own 574 - * interrupts to avoid circular dependency on the tick 571 + * Full dynticks uses IRQ work to drive the tick rescheduling on safe 572 + * locking contexts. But then we need IRQ work to raise its own 573 + * interrupts to avoid circular dependency on the tick. 575 574 */ 576 575 if (!arch_irq_work_has_interrupt()) { 577 - pr_warn("NO_HZ: Can't run full dynticks because arch doesn't support irq work self-IPIs\n"); 576 + pr_warn("NO_HZ: Can't run full dynticks because arch doesn't support IRQ work self-IPIs\n"); 578 577 cpumask_clear(tick_nohz_full_mask); 579 578 tick_nohz_full_running = false; 580 579 return; ··· 644 643 * In case the sched_tick was stopped on this CPU, we have to check if jiffies 645 644 * must be updated. Otherwise an interrupt handler could use a stale jiffy 646 645 * value. We do this unconditionally on any CPU, as we don't know whether the 647 - * CPU, which has the update task assigned is in a long sleep. 646 + * CPU, which has the update task assigned, is in a long sleep. 648 647 */ 649 648 static void tick_nohz_update_jiffies(ktime_t now) 650 649 { ··· 727 726 * counters if NULL. 728 727 * 729 728 * Return the cumulative idle time (since boot) for a given 730 - * CPU, in microseconds. Note this is partially broken due to 729 + * CPU, in microseconds. Note that this is partially broken due to 731 730 * the counter of iowait tasks that can be remotely updated without 732 731 * any synchronization. Therefore it is possible to observe backward 733 732 * values within two consecutive reads. ··· 788 787 } 789 788 790 789 /* 791 - * Reset to make sure next tick stop doesn't get fooled by past 790 + * Reset to make sure the next tick stop doesn't get fooled by past 792 791 * cached clock deadline. 793 792 */ 794 793 ts->next_tick = 0; ··· 817 816 /* 818 817 * Keep the periodic tick, when RCU, architecture or irq_work 819 818 * requests it. 820 - * Aside of that check whether the local timer softirq is 821 - * pending. If so its a bad idea to call get_next_timer_interrupt() 819 + * Aside of that, check whether the local timer softirq is 820 + * pending. If so, its a bad idea to call get_next_timer_interrupt(), 822 821 * because there is an already expired timer, so it will request 823 822 * immediate expiry, which rearms the hardware timer with a 824 - * minimal delta which brings us back to this place 823 + * minimal delta, which brings us back to this place 825 824 * immediately. Lather, rinse and repeat... 826 825 */ 827 826 if (rcu_needs_cpu() || arch_needs_cpu() || ··· 862 861 863 862 /* 864 863 * If this CPU is the one which had the do_timer() duty last, we limit 865 - * the sleep time to the timekeeping max_deferment value. 864 + * the sleep time to the timekeeping 'max_deferment' value. 866 865 * Otherwise we can sleep as long as we want. 867 866 */ 868 867 delta = timekeeping_max_deferment(); ··· 896 895 * If this CPU is the one which updates jiffies, then give up 897 896 * the assignment and let it be taken by the CPU which runs 898 897 * the tick timer next, which might be this CPU as well. If we 899 - * don't drop this here the jiffies might be stale and 900 - * do_timer() never invoked. Keep track of the fact that it 898 + * don't drop this here, the jiffies might be stale and 899 + * do_timer() never gets invoked. Keep track of the fact that it 901 900 * was the one which had the do_timer() duty last. 902 901 */ 903 902 if (cpu == tick_do_timer_cpu) { ··· 907 906 ts->do_timer_last = 0; 908 907 } 909 908 910 - /* Skip reprogram of event if its not changed */ 909 + /* Skip reprogram of event if it's not changed */ 911 910 if (ts->tick_stopped && (expires == ts->next_tick)) { 912 911 /* Sanity check: make sure clockevent is actually programmed */ 913 912 if (tick == KTIME_MAX || ts->next_tick == hrtimer_get_expires(&ts->sched_timer)) ··· 920 919 } 921 920 922 921 /* 923 - * nohz_stop_sched_tick can be called several times before 924 - * the nohz_restart_sched_tick is called. This happens when 922 + * nohz_stop_sched_tick() can be called several times before 923 + * nohz_restart_sched_tick() is called. This happens when 925 924 * interrupts arrive which do not cause a reschedule. In the 926 925 * first call we save the current tick time, so we can restart 927 - * the scheduler tick in nohz_restart_sched_tick. 926 + * the scheduler tick in nohz_restart_sched_tick(). 928 927 */ 929 928 if (!ts->tick_stopped) { 930 929 calc_load_nohz_start(); ··· 986 985 987 986 calc_load_nohz_stop(); 988 987 touch_softlockup_watchdog_sched(); 989 - /* 990 - * Cancel the scheduled timer and restore the tick 991 - */ 988 + 989 + /* Cancel the scheduled timer and restore the tick: */ 992 990 ts->tick_stopped = 0; 993 991 tick_nohz_restart(ts, now); 994 992 } ··· 1019 1019 /* 1020 1020 * A pending softirq outside an IRQ (or softirq disabled section) context 1021 1021 * should be waiting for ksoftirqd to handle it. Therefore we shouldn't 1022 - * reach here due to the need_resched() early check in can_stop_idle_tick(). 1022 + * reach this code due to the need_resched() early check in can_stop_idle_tick(). 1023 1023 * 1024 1024 * However if we are between CPUHP_AP_SMPBOOT_THREADS and CPU_TEARDOWN_CPU on the 1025 1025 * cpu_down() process, softirqs can still be raised while ksoftirqd is parked, 1026 - * triggering the below since wakep_softirqd() is ignored. 1026 + * triggering the code below, since wakep_softirqd() is ignored. 1027 1027 * 1028 1028 */ 1029 1029 static bool report_idle_softirq(void) ··· 1044 1044 if (ratelimit >= 10) 1045 1045 return false; 1046 1046 1047 - /* On RT, softirqs handling may be waiting on some lock */ 1047 + /* On RT, softirq handling may be waiting on some lock */ 1048 1048 if (local_bh_blocked()) 1049 1049 return false; 1050 1050 ··· 1061 1061 * If this CPU is offline and it is the one which updates 1062 1062 * jiffies, then give up the assignment and let it be taken by 1063 1063 * the CPU which runs the tick timer next. If we don't drop 1064 - * this here the jiffies might be stale and do_timer() never 1065 - * invoked. 1064 + * this here, the jiffies might be stale and do_timer() never 1065 + * gets invoked. 1066 1066 */ 1067 1067 if (unlikely(!cpu_online(cpu))) { 1068 1068 if (cpu == tick_do_timer_cpu) ··· 1219 1219 1220 1220 /** 1221 1221 * tick_nohz_get_next_hrtimer - return the next expiration time for the hrtimer 1222 - * or the tick, whatever that expires first. Note that, if the tick has been 1222 + * or the tick, whichever expires first. Note that, if the tick has been 1223 1223 * stopped, it returns the next hrtimer. 1224 1224 * 1225 1225 * Called from power state control code with interrupts disabled ··· 1263 1263 return *delta_next; 1264 1264 1265 1265 /* 1266 - * If the next highres timer to expire is earlier than next_event, the 1266 + * If the next highres timer to expire is earlier than 'next_event', the 1267 1267 * idle governor needs to know that. 1268 1268 */ 1269 1269 next_event = min_t(u64, next_event, ··· 1307 1307 if (vtime_accounting_enabled_this_cpu()) 1308 1308 return; 1309 1309 /* 1310 - * We stopped the tick in idle. Update process times would miss the 1311 - * time we slept as update_process_times does only a 1 tick 1312 - * accounting. Enforce that this is accounted to idle ! 1310 + * We stopped the tick in idle. update_process_times() would miss the 1311 + * time we slept, as it does only a 1 tick accounting. 1312 + * Enforce that this is accounted to idle ! 1313 1313 */ 1314 1314 ticks = jiffies - ts->idle_jiffies; 1315 1315 /* ··· 1351 1351 * 1352 1352 * 2) If the CPU is in nohz_full mode (corner case): 1353 1353 * 2.1) If the tick can be kept stopped (no tick dependencies) 1354 - * then re-eavaluate the next tick and try to keep it stopped 1354 + * then re-evaluate the next tick and try to keep it stopped 1355 1355 * as long as possible. 1356 1356 * 2.2) If the tick has dependencies, restart the tick. 1357 1357 * ··· 1385 1385 1386 1386 /* 1387 1387 * In low-resolution mode, the tick handler must be implemented directly 1388 - * at the clockevent level. hrtimer can't be used instead because its 1388 + * at the clockevent level. hrtimer can't be used instead, because its 1389 1389 * infrastructure actually relies on the tick itself as a backend in 1390 1390 * low-resolution mode (see hrtimer_run_queues()). 1391 1391 * 1392 1392 * This low-resolution handler still makes use of some hrtimer APIs meanwhile 1393 - * for commodity with expiration calculation and forwarding. 1393 + * for convenience with expiration calculation and forwarding. 1394 1394 */ 1395 1395 static void tick_nohz_lowres_handler(struct clock_event_device *dev) 1396 1396 { ··· 1426 1426 } 1427 1427 1428 1428 /** 1429 - * tick_nohz_switch_to_nohz - switch to nohz mode 1429 + * tick_nohz_switch_to_nohz - switch to NOHZ mode 1430 1430 */ 1431 1431 static void tick_nohz_switch_to_nohz(void) 1432 1432 { ··· 1440 1440 return; 1441 1441 1442 1442 /* 1443 - * Recycle the hrtimer in ts, so we can share the 1444 - * hrtimer_forward with the highres code. 1443 + * Recycle the hrtimer in 'ts', so we can share the 1444 + * hrtimer_forward_now() function with the highres code. 1445 1445 */ 1446 1446 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); 1447 1447 /* Get the next period */ ··· 1464 1464 if (ts->idle_active) 1465 1465 tick_nohz_stop_idle(ts, now); 1466 1466 /* 1467 - * If all CPUs are idle. We may need to update a stale jiffies value. 1467 + * If all CPUs are idle we may need to update a stale jiffies value. 1468 1468 * Note nohz_full is a special case: a timekeeper is guaranteed to stay 1469 1469 * alive but it might be busy looping with interrupts disabled in some 1470 1470 * rare case (typically stop machine). So we must make sure we have a ··· 1483 1483 #endif /* CONFIG_NO_HZ_COMMON */ 1484 1484 1485 1485 /* 1486 - * Called from irq_enter to notify about the possible interruption of idle() 1486 + * Called from irq_enter() to notify about the possible interruption of idle() 1487 1487 */ 1488 1488 void tick_irq_enter(void) 1489 1489 { ··· 1509 1509 tick_sched_do_timer(ts, now); 1510 1510 1511 1511 /* 1512 - * Do not call, when we are not in irq context and have 1513 - * no valid regs pointer 1512 + * Do not call when we are not in IRQ context and have 1513 + * no valid 'regs' pointer 1514 1514 */ 1515 1515 if (regs) 1516 1516 tick_sched_handle(ts, regs); ··· 1548 1548 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); 1549 1549 ktime_t now = ktime_get(); 1550 1550 1551 - /* 1552 - * Emulate tick processing via per-CPU hrtimers: 1553 - */ 1551 + /* Emulate tick processing via per-CPU hrtimers: */ 1554 1552 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); 1555 1553 ts->sched_timer.function = tick_nohz_highres_handler; 1556 1554 1557 1555 /* Get the next period (per-CPU) */ 1558 1556 hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); 1559 1557 1560 - /* Offset the tick to avert jiffies_lock contention. */ 1558 + /* Offset the tick to avert 'jiffies_lock' contention. */ 1561 1559 if (sched_skew_tick) { 1562 1560 u64 offset = TICK_NSEC >> 1; 1563 1561 do_div(offset, num_possible_cpus()); ··· 1605 1607 } 1606 1608 1607 1609 /* 1608 - * Check, if a change happened, which makes oneshot possible. 1610 + * Check if a change happened, which makes oneshot possible. 1609 1611 * 1610 - * Called cyclic from the hrtimer softirq (driven by the timer 1611 - * softirq) allow_nohz signals, that we can switch into low-res nohz 1612 + * Called cyclically from the hrtimer softirq (driven by the timer 1613 + * softirq). 'allow_nohz' signals that we can switch into low-res NOHZ 1612 1614 * mode, because high resolution timers are disabled (either compile 1613 1615 * or runtime). Called with interrupts disabled. 1614 1616 */