Lines Matching refs:ts

172 static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)  in tick_sched_do_timer()  argument
199 if (ts->inidle) in tick_sched_do_timer()
200 ts->got_idle_tick = 1; in tick_sched_do_timer()
203 static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) in tick_sched_handle() argument
214 if (ts->tick_stopped) { in tick_sched_handle()
217 ts->idle_jiffies++; in tick_sched_handle()
223 ts->next_tick = 0; in tick_sched_handle()
270 static bool can_stop_full_tick(int cpu, struct tick_sched *ts) in can_stop_full_tick() argument
280 if (check_tick_dependency(&ts->tick_dep_mask)) in can_stop_full_tick()
414 struct tick_sched *ts; in tick_nohz_dep_set_cpu() local
416 ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_set_cpu()
418 prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_set_cpu()
436 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_clear_cpu() local
438 atomic_andnot(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_clear_cpu()
491 struct tick_sched *ts; in __tick_nohz_task_switch() local
496 ts = this_cpu_ptr(&tick_cpu_sched); in __tick_nohz_task_switch()
498 if (ts->tick_stopped) { in __tick_nohz_task_switch()
589 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_tick_stopped() local
591 return ts->tick_stopped; in tick_nohz_tick_stopped()
596 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_tick_stopped_cpu() local
598 return ts->tick_stopped; in tick_nohz_tick_stopped_cpu()
628 update_ts_time_stats(int cpu, struct tick_sched *ts, ktime_t now, u64 *last_update_time) in update_ts_time_stats() argument
632 if (ts->idle_active) { in update_ts_time_stats()
633 delta = ktime_sub(now, ts->idle_entrytime); in update_ts_time_stats()
635 ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); in update_ts_time_stats()
637 ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); in update_ts_time_stats()
638 ts->idle_entrytime = now; in update_ts_time_stats()
646 static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) in tick_nohz_stop_idle() argument
648 update_ts_time_stats(smp_processor_id(), ts, now, NULL); in tick_nohz_stop_idle()
649 ts->idle_active = 0; in tick_nohz_stop_idle()
654 static void tick_nohz_start_idle(struct tick_sched *ts) in tick_nohz_start_idle() argument
656 ts->idle_entrytime = ktime_get(); in tick_nohz_start_idle()
657 ts->idle_active = 1; in tick_nohz_start_idle()
677 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_idle_time_us() local
685 update_ts_time_stats(cpu, ts, now, last_update_time); in get_cpu_idle_time_us()
686 idle = ts->idle_sleeptime; in get_cpu_idle_time_us()
688 if (ts->idle_active && !nr_iowait_cpu(cpu)) { in get_cpu_idle_time_us()
689 ktime_t delta = ktime_sub(now, ts->idle_entrytime); in get_cpu_idle_time_us()
691 idle = ktime_add(ts->idle_sleeptime, delta); in get_cpu_idle_time_us()
693 idle = ts->idle_sleeptime; in get_cpu_idle_time_us()
718 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_iowait_time_us() local
726 update_ts_time_stats(cpu, ts, now, last_update_time); in get_cpu_iowait_time_us()
727 iowait = ts->iowait_sleeptime; in get_cpu_iowait_time_us()
729 if (ts->idle_active && nr_iowait_cpu(cpu) > 0) { in get_cpu_iowait_time_us()
730 ktime_t delta = ktime_sub(now, ts->idle_entrytime); in get_cpu_iowait_time_us()
732 iowait = ktime_add(ts->iowait_sleeptime, delta); in get_cpu_iowait_time_us()
734 iowait = ts->iowait_sleeptime; in get_cpu_iowait_time_us()
742 static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) in tick_nohz_restart() argument
744 hrtimer_cancel(&ts->sched_timer); in tick_nohz_restart()
745 hrtimer_set_expires(&ts->sched_timer, ts->last_tick); in tick_nohz_restart()
748 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_restart()
750 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_restart()
751 hrtimer_start_expires(&ts->sched_timer, in tick_nohz_restart()
754 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_restart()
761 ts->next_tick = 0; in tick_nohz_restart()
769 static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) in tick_nohz_next_event() argument
781 ts->last_jiffies = basejiff; in tick_nohz_next_event()
782 ts->timer_expires_base = basemono; in tick_nohz_next_event()
806 ts->next_timer = next_tmr; in tick_nohz_next_event()
826 if (!ts->tick_stopped) { in tick_nohz_next_event()
827 ts->timer_expires = 0; in tick_nohz_next_event()
839 (tick_do_timer_cpu != TICK_DO_TIMER_NONE || !ts->do_timer_last)) in tick_nohz_next_event()
848 ts->timer_expires = min_t(u64, expires, next_tick); in tick_nohz_next_event()
851 return ts->timer_expires; in tick_nohz_next_event()
854 static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_tick() argument
857 u64 basemono = ts->timer_expires_base; in tick_nohz_stop_tick()
858 u64 expires = ts->timer_expires; in tick_nohz_stop_tick()
862 ts->timer_expires_base = 0; in tick_nohz_stop_tick()
874 ts->do_timer_last = 1; in tick_nohz_stop_tick()
876 ts->do_timer_last = 0; in tick_nohz_stop_tick()
880 if (ts->tick_stopped && (expires == ts->next_tick)) { in tick_nohz_stop_tick()
882 if (tick == KTIME_MAX || ts->next_tick == hrtimer_get_expires(&ts->sched_timer)) in tick_nohz_stop_tick()
887 basemono, ts->next_tick, dev->next_event, in tick_nohz_stop_tick()
888 hrtimer_active(&ts->sched_timer), hrtimer_get_expires(&ts->sched_timer)); in tick_nohz_stop_tick()
898 if (!ts->tick_stopped) { in tick_nohz_stop_tick()
902 ts->last_tick = hrtimer_get_expires(&ts->sched_timer); in tick_nohz_stop_tick()
903 ts->tick_stopped = 1; in tick_nohz_stop_tick()
907 ts->next_tick = tick; in tick_nohz_stop_tick()
914 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) in tick_nohz_stop_tick()
915 hrtimer_cancel(&ts->sched_timer); in tick_nohz_stop_tick()
919 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_stop_tick()
920 hrtimer_start(&ts->sched_timer, tick, in tick_nohz_stop_tick()
923 hrtimer_set_expires(&ts->sched_timer, tick); in tick_nohz_stop_tick()
928 static void tick_nohz_retain_tick(struct tick_sched *ts) in tick_nohz_retain_tick() argument
930 ts->timer_expires_base = 0; in tick_nohz_retain_tick()
934 static void tick_nohz_stop_sched_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_sched_tick() argument
936 if (tick_nohz_next_event(ts, cpu)) in tick_nohz_stop_sched_tick()
937 tick_nohz_stop_tick(ts, cpu); in tick_nohz_stop_sched_tick()
939 tick_nohz_retain_tick(ts); in tick_nohz_stop_sched_tick()
943 static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_restart_sched_tick() argument
959 ts->tick_stopped = 0; in tick_nohz_restart_sched_tick()
960 tick_nohz_restart(ts, now); in tick_nohz_restart_sched_tick()
963 static void __tick_nohz_full_update_tick(struct tick_sched *ts, in __tick_nohz_full_update_tick() argument
969 if (can_stop_full_tick(cpu, ts)) in __tick_nohz_full_update_tick()
970 tick_nohz_stop_sched_tick(ts, cpu); in __tick_nohz_full_update_tick()
971 else if (ts->tick_stopped) in __tick_nohz_full_update_tick()
972 tick_nohz_restart_sched_tick(ts, now); in __tick_nohz_full_update_tick()
976 static void tick_nohz_full_update_tick(struct tick_sched *ts) in tick_nohz_full_update_tick() argument
981 if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) in tick_nohz_full_update_tick()
984 __tick_nohz_full_update_tick(ts, ktime_get()); in tick_nohz_full_update_tick()
987 static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) in can_stop_idle_tick() argument
1003 ts->next_tick = 0; in can_stop_idle_tick()
1007 if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) in can_stop_idle_tick()
1041 static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) in __tick_nohz_idle_stop_tick() argument
1050 if (ts->timer_expires_base) in __tick_nohz_idle_stop_tick()
1051 expires = ts->timer_expires; in __tick_nohz_idle_stop_tick()
1052 else if (can_stop_idle_tick(cpu, ts)) in __tick_nohz_idle_stop_tick()
1053 expires = tick_nohz_next_event(ts, cpu); in __tick_nohz_idle_stop_tick()
1057 ts->idle_calls++; in __tick_nohz_idle_stop_tick()
1060 int was_stopped = ts->tick_stopped; in __tick_nohz_idle_stop_tick()
1062 tick_nohz_stop_tick(ts, cpu); in __tick_nohz_idle_stop_tick()
1064 ts->idle_sleeps++; in __tick_nohz_idle_stop_tick()
1065 ts->idle_expires = expires; in __tick_nohz_idle_stop_tick()
1067 if (!was_stopped && ts->tick_stopped) { in __tick_nohz_idle_stop_tick()
1068 ts->idle_jiffies = ts->last_jiffies; in __tick_nohz_idle_stop_tick()
1072 tick_nohz_retain_tick(ts); in __tick_nohz_idle_stop_tick()
1103 struct tick_sched *ts; in tick_nohz_idle_enter() local
1109 ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_enter()
1111 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_enter()
1113 ts->inidle = 1; in tick_nohz_idle_enter()
1114 tick_nohz_start_idle(ts); in tick_nohz_idle_enter()
1129 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_exit() local
1131 if (ts->inidle) in tick_nohz_irq_exit()
1132 tick_nohz_start_idle(ts); in tick_nohz_irq_exit()
1134 tick_nohz_full_update_tick(ts); in tick_nohz_irq_exit()
1142 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_got_tick() local
1144 if (ts->got_idle_tick) { in tick_nohz_idle_got_tick()
1145 ts->got_idle_tick = 0; in tick_nohz_idle_got_tick()
1176 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_sleep_length() local
1182 ktime_t now = ts->idle_entrytime; in tick_nohz_get_sleep_length()
1185 WARN_ON_ONCE(!ts->inidle); in tick_nohz_get_sleep_length()
1189 if (!can_stop_idle_tick(cpu, ts)) in tick_nohz_get_sleep_length()
1192 next_event = tick_nohz_next_event(ts, cpu); in tick_nohz_get_sleep_length()
1201 hrtimer_next_event_without(&ts->sched_timer)); in tick_nohz_get_sleep_length()
1214 struct tick_sched *ts = tick_get_tick_sched(cpu); in tick_nohz_get_idle_calls_cpu() local
1216 return ts->idle_calls; in tick_nohz_get_idle_calls_cpu()
1226 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_idle_calls() local
1228 return ts->idle_calls; in tick_nohz_get_idle_calls()
1231 static void tick_nohz_account_idle_time(struct tick_sched *ts, in tick_nohz_account_idle_time() argument
1236 ts->idle_exittime = now; in tick_nohz_account_idle_time()
1245 ticks = jiffies - ts->idle_jiffies; in tick_nohz_account_idle_time()
1255 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_restart_tick() local
1257 if (ts->tick_stopped) { in tick_nohz_idle_restart_tick()
1259 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_restart_tick()
1260 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_restart_tick()
1264 static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_idle_update_tick() argument
1267 __tick_nohz_full_update_tick(ts, now); in tick_nohz_idle_update_tick()
1269 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_update_tick()
1271 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_update_tick()
1283 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_exit() local
1289 WARN_ON_ONCE(!ts->inidle); in tick_nohz_idle_exit()
1290 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_exit()
1292 ts->inidle = 0; in tick_nohz_idle_exit()
1293 idle_active = ts->idle_active; in tick_nohz_idle_exit()
1294 tick_stopped = ts->tick_stopped; in tick_nohz_idle_exit()
1300 tick_nohz_stop_idle(ts, now); in tick_nohz_idle_exit()
1303 tick_nohz_idle_update_tick(ts, now); in tick_nohz_idle_exit()
1313 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_handler() local
1319 tick_sched_do_timer(ts, now); in tick_nohz_handler()
1320 tick_sched_handle(ts, regs); in tick_nohz_handler()
1323 if (unlikely(ts->tick_stopped)) in tick_nohz_handler()
1326 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_handler()
1327 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_handler()
1330 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) in tick_nohz_activate() argument
1334 ts->nohz_mode = mode; in tick_nohz_activate()
1345 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_switch_to_nohz() local
1358 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_nohz_switch_to_nohz()
1362 hrtimer_set_expires(&ts->sched_timer, next); in tick_nohz_switch_to_nohz()
1363 hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); in tick_nohz_switch_to_nohz()
1364 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_switch_to_nohz()
1365 tick_nohz_activate(ts, NOHZ_MODE_LOWRES); in tick_nohz_switch_to_nohz()
1370 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_enter() local
1373 if (!ts->idle_active && !ts->tick_stopped) in tick_nohz_irq_enter()
1376 if (ts->idle_active) in tick_nohz_irq_enter()
1377 tick_nohz_stop_idle(ts, now); in tick_nohz_irq_enter()
1385 if (ts->tick_stopped) in tick_nohz_irq_enter()
1393 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) { } in tick_nohz_activate() argument
1416 struct tick_sched *ts = in tick_sched_timer() local
1421 tick_sched_do_timer(ts, now); in tick_sched_timer()
1428 tick_sched_handle(ts, regs); in tick_sched_timer()
1430 ts->next_tick = 0; in tick_sched_timer()
1433 if (unlikely(ts->tick_stopped)) in tick_sched_timer()
1456 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_setup_sched_timer() local
1462 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_setup_sched_timer()
1463 ts->sched_timer.function = tick_sched_timer; in tick_setup_sched_timer()
1466 hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); in tick_setup_sched_timer()
1473 hrtimer_add_expires_ns(&ts->sched_timer, offset); in tick_setup_sched_timer()
1476 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_setup_sched_timer()
1477 hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); in tick_setup_sched_timer()
1478 tick_nohz_activate(ts, NOHZ_MODE_HIGHRES); in tick_setup_sched_timer()
1485 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in tick_cancel_sched_timer() local
1488 if (ts->sched_timer.base) in tick_cancel_sched_timer()
1489 hrtimer_cancel(&ts->sched_timer); in tick_cancel_sched_timer()
1492 memset(ts, 0, sizeof(*ts)); in tick_cancel_sched_timer()
1512 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_oneshot_notify() local
1514 set_bit(0, &ts->check_clocks); in tick_oneshot_notify()
1527 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_check_oneshot_change() local
1529 if (!test_and_clear_bit(0, &ts->check_clocks)) in tick_check_oneshot_change()
1532 if (ts->nohz_mode != NOHZ_MODE_INACTIVE) in tick_check_oneshot_change()