Lines Matching refs:ts
185 static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) in tick_sched_do_timer() argument
216 if (ts->last_tick_jiffies != jiffies) { in tick_sched_do_timer()
217 ts->stalled_jiffies = 0; in tick_sched_do_timer()
218 ts->last_tick_jiffies = READ_ONCE(jiffies); in tick_sched_do_timer()
220 if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) { in tick_sched_do_timer()
222 ts->stalled_jiffies = 0; in tick_sched_do_timer()
223 ts->last_tick_jiffies = READ_ONCE(jiffies); in tick_sched_do_timer()
227 if (ts->inidle) in tick_sched_do_timer()
228 ts->got_idle_tick = 1; in tick_sched_do_timer()
231 static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) in tick_sched_handle() argument
242 if (ts->tick_stopped) { in tick_sched_handle()
245 ts->idle_jiffies++; in tick_sched_handle()
251 ts->next_tick = 0; in tick_sched_handle()
303 static bool can_stop_full_tick(int cpu, struct tick_sched *ts) in can_stop_full_tick() argument
313 if (check_tick_dependency(&ts->tick_dep_mask)) in can_stop_full_tick()
447 struct tick_sched *ts; in tick_nohz_dep_set_cpu() local
449 ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_set_cpu()
451 prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_set_cpu()
469 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_clear_cpu() local
471 atomic_andnot(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_clear_cpu()
524 struct tick_sched *ts; in __tick_nohz_task_switch() local
529 ts = this_cpu_ptr(&tick_cpu_sched); in __tick_nohz_task_switch()
531 if (ts->tick_stopped) { in __tick_nohz_task_switch()
626 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_tick_stopped() local
628 return ts->tick_stopped; in tick_nohz_tick_stopped()
633 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_tick_stopped_cpu() local
635 return ts->tick_stopped; in tick_nohz_tick_stopped_cpu()
661 static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) in tick_nohz_stop_idle() argument
665 if (WARN_ON_ONCE(!ts->idle_active)) in tick_nohz_stop_idle()
668 delta = ktime_sub(now, ts->idle_entrytime); in tick_nohz_stop_idle()
670 write_seqcount_begin(&ts->idle_sleeptime_seq); in tick_nohz_stop_idle()
672 ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); in tick_nohz_stop_idle()
674 ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); in tick_nohz_stop_idle()
676 ts->idle_entrytime = now; in tick_nohz_stop_idle()
677 ts->idle_active = 0; in tick_nohz_stop_idle()
678 write_seqcount_end(&ts->idle_sleeptime_seq); in tick_nohz_stop_idle()
683 static void tick_nohz_start_idle(struct tick_sched *ts) in tick_nohz_start_idle() argument
685 write_seqcount_begin(&ts->idle_sleeptime_seq); in tick_nohz_start_idle()
686 ts->idle_entrytime = ktime_get(); in tick_nohz_start_idle()
687 ts->idle_active = 1; in tick_nohz_start_idle()
688 write_seqcount_end(&ts->idle_sleeptime_seq); in tick_nohz_start_idle()
693 static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, in get_cpu_sleep_time_us() argument
707 seq = read_seqcount_begin(&ts->idle_sleeptime_seq); in get_cpu_sleep_time_us()
709 if (ts->idle_active && compute_delta) { in get_cpu_sleep_time_us()
710 ktime_t delta = ktime_sub(now, ts->idle_entrytime); in get_cpu_sleep_time_us()
716 } while (read_seqcount_retry(&ts->idle_sleeptime_seq, seq)); in get_cpu_sleep_time_us()
741 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_idle_time_us() local
743 return get_cpu_sleep_time_us(ts, &ts->idle_sleeptime, in get_cpu_idle_time_us()
767 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_iowait_time_us() local
769 return get_cpu_sleep_time_us(ts, &ts->iowait_sleeptime, in get_cpu_iowait_time_us()
774 static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) in tick_nohz_restart() argument
776 hrtimer_cancel(&ts->sched_timer); in tick_nohz_restart()
777 hrtimer_set_expires(&ts->sched_timer, ts->last_tick); in tick_nohz_restart()
780 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_restart()
782 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_restart()
783 hrtimer_start_expires(&ts->sched_timer, in tick_nohz_restart()
786 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_restart()
793 ts->next_tick = 0; in tick_nohz_restart()
801 static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) in tick_nohz_next_event() argument
813 ts->last_jiffies = basejiff; in tick_nohz_next_event()
814 ts->timer_expires_base = basemono; in tick_nohz_next_event()
838 ts->next_timer = next_tick; in tick_nohz_next_event()
856 if (!ts->tick_stopped) { in tick_nohz_next_event()
857 ts->timer_expires = 0; in tick_nohz_next_event()
869 (tick_do_timer_cpu != TICK_DO_TIMER_NONE || !ts->do_timer_last)) in tick_nohz_next_event()
878 ts->timer_expires = min_t(u64, expires, next_tick); in tick_nohz_next_event()
881 return ts->timer_expires; in tick_nohz_next_event()
884 static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_tick() argument
887 u64 basemono = ts->timer_expires_base; in tick_nohz_stop_tick()
888 u64 expires = ts->timer_expires; in tick_nohz_stop_tick()
892 ts->timer_expires_base = 0; in tick_nohz_stop_tick()
904 ts->do_timer_last = 1; in tick_nohz_stop_tick()
906 ts->do_timer_last = 0; in tick_nohz_stop_tick()
910 if (ts->tick_stopped && (expires == ts->next_tick)) { in tick_nohz_stop_tick()
912 if (tick == KTIME_MAX || ts->next_tick == hrtimer_get_expires(&ts->sched_timer)) in tick_nohz_stop_tick()
917 basemono, ts->next_tick, dev->next_event, in tick_nohz_stop_tick()
918 hrtimer_active(&ts->sched_timer), hrtimer_get_expires(&ts->sched_timer)); in tick_nohz_stop_tick()
928 if (!ts->tick_stopped) { in tick_nohz_stop_tick()
932 ts->last_tick = hrtimer_get_expires(&ts->sched_timer); in tick_nohz_stop_tick()
933 ts->tick_stopped = 1; in tick_nohz_stop_tick()
937 ts->next_tick = tick; in tick_nohz_stop_tick()
944 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) in tick_nohz_stop_tick()
945 hrtimer_cancel(&ts->sched_timer); in tick_nohz_stop_tick()
951 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_stop_tick()
952 hrtimer_start(&ts->sched_timer, tick, in tick_nohz_stop_tick()
955 hrtimer_set_expires(&ts->sched_timer, tick); in tick_nohz_stop_tick()
960 static void tick_nohz_retain_tick(struct tick_sched *ts) in tick_nohz_retain_tick() argument
962 ts->timer_expires_base = 0; in tick_nohz_retain_tick()
966 static void tick_nohz_stop_sched_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_sched_tick() argument
968 if (tick_nohz_next_event(ts, cpu)) in tick_nohz_stop_sched_tick()
969 tick_nohz_stop_tick(ts, cpu); in tick_nohz_stop_sched_tick()
971 tick_nohz_retain_tick(ts); in tick_nohz_stop_sched_tick()
975 static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_restart_sched_tick() argument
991 ts->tick_stopped = 0; in tick_nohz_restart_sched_tick()
992 tick_nohz_restart(ts, now); in tick_nohz_restart_sched_tick()
995 static void __tick_nohz_full_update_tick(struct tick_sched *ts, in __tick_nohz_full_update_tick() argument
1001 if (can_stop_full_tick(cpu, ts)) in __tick_nohz_full_update_tick()
1002 tick_nohz_stop_sched_tick(ts, cpu); in __tick_nohz_full_update_tick()
1003 else if (ts->tick_stopped) in __tick_nohz_full_update_tick()
1004 tick_nohz_restart_sched_tick(ts, now); in __tick_nohz_full_update_tick()
1008 static void tick_nohz_full_update_tick(struct tick_sched *ts) in tick_nohz_full_update_tick() argument
1013 if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) in tick_nohz_full_update_tick()
1016 __tick_nohz_full_update_tick(ts, ktime_get()); in tick_nohz_full_update_tick()
1058 static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) in can_stop_idle_tick() argument
1074 ts->next_tick = 0; in can_stop_idle_tick()
1078 if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) in can_stop_idle_tick()
1110 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_stop_tick() local
1118 if (ts->timer_expires_base) in tick_nohz_idle_stop_tick()
1119 expires = ts->timer_expires; in tick_nohz_idle_stop_tick()
1120 else if (can_stop_idle_tick(cpu, ts)) in tick_nohz_idle_stop_tick()
1121 expires = tick_nohz_next_event(ts, cpu); in tick_nohz_idle_stop_tick()
1125 ts->idle_calls++; in tick_nohz_idle_stop_tick()
1128 int was_stopped = ts->tick_stopped; in tick_nohz_idle_stop_tick()
1130 tick_nohz_stop_tick(ts, cpu); in tick_nohz_idle_stop_tick()
1132 ts->idle_sleeps++; in tick_nohz_idle_stop_tick()
1133 ts->idle_expires = expires; in tick_nohz_idle_stop_tick()
1135 if (!was_stopped && ts->tick_stopped) { in tick_nohz_idle_stop_tick()
1136 ts->idle_jiffies = ts->last_jiffies; in tick_nohz_idle_stop_tick()
1140 tick_nohz_retain_tick(ts); in tick_nohz_idle_stop_tick()
1161 struct tick_sched *ts; in tick_nohz_idle_enter() local
1167 ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_enter()
1169 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_enter()
1171 ts->inidle = 1; in tick_nohz_idle_enter()
1172 tick_nohz_start_idle(ts); in tick_nohz_idle_enter()
1187 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_exit() local
1189 if (ts->inidle) in tick_nohz_irq_exit()
1190 tick_nohz_start_idle(ts); in tick_nohz_irq_exit()
1192 tick_nohz_full_update_tick(ts); in tick_nohz_irq_exit()
1200 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_got_tick() local
1202 if (ts->got_idle_tick) { in tick_nohz_idle_got_tick()
1203 ts->got_idle_tick = 0; in tick_nohz_idle_got_tick()
1234 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_sleep_length() local
1240 ktime_t now = ts->idle_entrytime; in tick_nohz_get_sleep_length()
1243 WARN_ON_ONCE(!ts->inidle); in tick_nohz_get_sleep_length()
1247 if (!can_stop_idle_tick(cpu, ts)) in tick_nohz_get_sleep_length()
1250 next_event = tick_nohz_next_event(ts, cpu); in tick_nohz_get_sleep_length()
1259 hrtimer_next_event_without(&ts->sched_timer)); in tick_nohz_get_sleep_length()
1272 struct tick_sched *ts = tick_get_tick_sched(cpu); in tick_nohz_get_idle_calls_cpu() local
1274 return ts->idle_calls; in tick_nohz_get_idle_calls_cpu()
1284 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_idle_calls() local
1286 return ts->idle_calls; in tick_nohz_get_idle_calls()
1289 static void tick_nohz_account_idle_time(struct tick_sched *ts, in tick_nohz_account_idle_time() argument
1294 ts->idle_exittime = now; in tick_nohz_account_idle_time()
1303 ticks = jiffies - ts->idle_jiffies; in tick_nohz_account_idle_time()
1313 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_restart_tick() local
1315 if (ts->tick_stopped) { in tick_nohz_idle_restart_tick()
1317 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_restart_tick()
1318 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_restart_tick()
1322 static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_idle_update_tick() argument
1325 __tick_nohz_full_update_tick(ts, now); in tick_nohz_idle_update_tick()
1327 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_update_tick()
1329 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_update_tick()
1341 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_exit() local
1347 WARN_ON_ONCE(!ts->inidle); in tick_nohz_idle_exit()
1348 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_exit()
1350 ts->inidle = 0; in tick_nohz_idle_exit()
1351 idle_active = ts->idle_active; in tick_nohz_idle_exit()
1352 tick_stopped = ts->tick_stopped; in tick_nohz_idle_exit()
1358 tick_nohz_stop_idle(ts, now); in tick_nohz_idle_exit()
1361 tick_nohz_idle_update_tick(ts, now); in tick_nohz_idle_exit()
1371 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_handler() local
1377 tick_sched_do_timer(ts, now); in tick_nohz_handler()
1378 tick_sched_handle(ts, regs); in tick_nohz_handler()
1380 if (unlikely(ts->tick_stopped)) { in tick_nohz_handler()
1390 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_handler()
1391 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_handler()
1394 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) in tick_nohz_activate() argument
1398 ts->nohz_mode = mode; in tick_nohz_activate()
1409 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_switch_to_nohz() local
1422 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_nohz_switch_to_nohz()
1426 hrtimer_set_expires(&ts->sched_timer, next); in tick_nohz_switch_to_nohz()
1427 hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); in tick_nohz_switch_to_nohz()
1428 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_switch_to_nohz()
1429 tick_nohz_activate(ts, NOHZ_MODE_LOWRES); in tick_nohz_switch_to_nohz()
1434 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_enter() local
1437 if (!ts->idle_active && !ts->tick_stopped) in tick_nohz_irq_enter()
1440 if (ts->idle_active) in tick_nohz_irq_enter()
1441 tick_nohz_stop_idle(ts, now); in tick_nohz_irq_enter()
1449 if (ts->tick_stopped) in tick_nohz_irq_enter()
1457 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) { } in tick_nohz_activate() argument
1480 struct tick_sched *ts = in tick_sched_timer() local
1485 tick_sched_do_timer(ts, now); in tick_sched_timer()
1492 tick_sched_handle(ts, regs); in tick_sched_timer()
1494 ts->next_tick = 0; in tick_sched_timer()
1497 if (unlikely(ts->tick_stopped)) in tick_sched_timer()
1520 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_setup_sched_timer() local
1526 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_setup_sched_timer()
1527 ts->sched_timer.function = tick_sched_timer; in tick_setup_sched_timer()
1530 hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); in tick_setup_sched_timer()
1537 hrtimer_add_expires_ns(&ts->sched_timer, offset); in tick_setup_sched_timer()
1540 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_setup_sched_timer()
1541 hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); in tick_setup_sched_timer()
1542 tick_nohz_activate(ts, NOHZ_MODE_HIGHRES); in tick_setup_sched_timer()
1549 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in tick_cancel_sched_timer() local
1554 if (ts->sched_timer.base) in tick_cancel_sched_timer()
1555 hrtimer_cancel(&ts->sched_timer); in tick_cancel_sched_timer()
1558 idle_sleeptime = ts->idle_sleeptime; in tick_cancel_sched_timer()
1559 iowait_sleeptime = ts->iowait_sleeptime; in tick_cancel_sched_timer()
1560 idle_calls = ts->idle_calls; in tick_cancel_sched_timer()
1561 idle_sleeps = ts->idle_sleeps; in tick_cancel_sched_timer()
1562 memset(ts, 0, sizeof(*ts)); in tick_cancel_sched_timer()
1563 ts->idle_sleeptime = idle_sleeptime; in tick_cancel_sched_timer()
1564 ts->iowait_sleeptime = iowait_sleeptime; in tick_cancel_sched_timer()
1565 ts->idle_calls = idle_calls; in tick_cancel_sched_timer()
1566 ts->idle_sleeps = idle_sleeps; in tick_cancel_sched_timer()
1586 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_oneshot_notify() local
1588 set_bit(0, &ts->check_clocks); in tick_oneshot_notify()
1601 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_check_oneshot_change() local
1603 if (!test_and_clear_bit(0, &ts->check_clocks)) in tick_check_oneshot_change()
1606 if (ts->nohz_mode != NOHZ_MODE_INACTIVE) in tick_check_oneshot_change()