Lines Matching full:ts
174 static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) in tick_sched_do_timer() argument
205 if (ts->last_tick_jiffies != jiffies) { in tick_sched_do_timer()
206 ts->stalled_jiffies = 0; in tick_sched_do_timer()
207 ts->last_tick_jiffies = READ_ONCE(jiffies); in tick_sched_do_timer()
209 if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) { in tick_sched_do_timer()
211 ts->stalled_jiffies = 0; in tick_sched_do_timer()
212 ts->last_tick_jiffies = READ_ONCE(jiffies); in tick_sched_do_timer()
216 if (ts->inidle) in tick_sched_do_timer()
217 ts->got_idle_tick = 1; in tick_sched_do_timer()
220 static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) in tick_sched_handle() argument
231 if (ts->tick_stopped) { in tick_sched_handle()
234 ts->idle_jiffies++; in tick_sched_handle()
240 ts->next_tick = 0; in tick_sched_handle()
287 static bool can_stop_full_tick(int cpu, struct tick_sched *ts) in can_stop_full_tick() argument
297 if (check_tick_dependency(&ts->tick_dep_mask)) in can_stop_full_tick()
431 struct tick_sched *ts; in tick_nohz_dep_set_cpu() local
433 ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_set_cpu()
435 prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_set_cpu()
453 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_dep_clear_cpu() local
455 atomic_andnot(BIT(bit), &ts->tick_dep_mask); in tick_nohz_dep_clear_cpu()
508 struct tick_sched *ts; in __tick_nohz_task_switch() local
513 ts = this_cpu_ptr(&tick_cpu_sched); in __tick_nohz_task_switch()
515 if (ts->tick_stopped) { in __tick_nohz_task_switch()
605 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_tick_stopped() local
607 return ts->tick_stopped; in tick_nohz_tick_stopped()
612 struct tick_sched *ts = per_cpu_ptr(&tick_cpu_sched, cpu); in tick_nohz_tick_stopped_cpu() local
614 return ts->tick_stopped; in tick_nohz_tick_stopped_cpu()
644 update_ts_time_stats(int cpu, struct tick_sched *ts, ktime_t now, u64 *last_update_time) in update_ts_time_stats() argument
648 if (ts->idle_active) { in update_ts_time_stats()
649 delta = ktime_sub(now, ts->idle_entrytime); in update_ts_time_stats()
651 ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); in update_ts_time_stats()
653 ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); in update_ts_time_stats()
654 ts->idle_entrytime = now; in update_ts_time_stats()
662 static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) in tick_nohz_stop_idle() argument
664 update_ts_time_stats(smp_processor_id(), ts, now, NULL); in tick_nohz_stop_idle()
665 ts->idle_active = 0; in tick_nohz_stop_idle()
670 static void tick_nohz_start_idle(struct tick_sched *ts) in tick_nohz_start_idle() argument
672 ts->idle_entrytime = ktime_get(); in tick_nohz_start_idle()
673 ts->idle_active = 1; in tick_nohz_start_idle()
693 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_idle_time_us() local
701 update_ts_time_stats(cpu, ts, now, last_update_time); in get_cpu_idle_time_us()
702 idle = ts->idle_sleeptime; in get_cpu_idle_time_us()
704 if (ts->idle_active && !nr_iowait_cpu(cpu)) { in get_cpu_idle_time_us()
705 ktime_t delta = ktime_sub(now, ts->idle_entrytime); in get_cpu_idle_time_us()
707 idle = ktime_add(ts->idle_sleeptime, delta); in get_cpu_idle_time_us()
709 idle = ts->idle_sleeptime; in get_cpu_idle_time_us()
734 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in get_cpu_iowait_time_us() local
742 update_ts_time_stats(cpu, ts, now, last_update_time); in get_cpu_iowait_time_us()
743 iowait = ts->iowait_sleeptime; in get_cpu_iowait_time_us()
745 if (ts->idle_active && nr_iowait_cpu(cpu) > 0) { in get_cpu_iowait_time_us()
746 ktime_t delta = ktime_sub(now, ts->idle_entrytime); in get_cpu_iowait_time_us()
748 iowait = ktime_add(ts->iowait_sleeptime, delta); in get_cpu_iowait_time_us()
750 iowait = ts->iowait_sleeptime; in get_cpu_iowait_time_us()
758 static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) in tick_nohz_restart() argument
760 hrtimer_cancel(&ts->sched_timer); in tick_nohz_restart()
761 hrtimer_set_expires(&ts->sched_timer, ts->last_tick); in tick_nohz_restart()
764 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_restart()
766 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_restart()
767 hrtimer_start_expires(&ts->sched_timer, in tick_nohz_restart()
770 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_restart()
777 ts->next_tick = 0; in tick_nohz_restart()
785 static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) in tick_nohz_next_event() argument
797 ts->last_jiffies = basejiff; in tick_nohz_next_event()
798 ts->timer_expires_base = basemono; in tick_nohz_next_event()
822 ts->next_timer = next_tick; in tick_nohz_next_event()
840 if (!ts->tick_stopped) { in tick_nohz_next_event()
841 ts->timer_expires = 0; in tick_nohz_next_event()
853 (tick_do_timer_cpu != TICK_DO_TIMER_NONE || !ts->do_timer_last)) in tick_nohz_next_event()
862 ts->timer_expires = min_t(u64, expires, next_tick); in tick_nohz_next_event()
865 return ts->timer_expires; in tick_nohz_next_event()
868 static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_tick() argument
871 u64 basemono = ts->timer_expires_base; in tick_nohz_stop_tick()
872 u64 expires = ts->timer_expires; in tick_nohz_stop_tick()
876 ts->timer_expires_base = 0; in tick_nohz_stop_tick()
888 ts->do_timer_last = 1; in tick_nohz_stop_tick()
890 ts->do_timer_last = 0; in tick_nohz_stop_tick()
894 if (ts->tick_stopped && (expires == ts->next_tick)) { in tick_nohz_stop_tick()
896 if (tick == KTIME_MAX || ts->next_tick == hrtimer_get_expires(&ts->sched_timer)) in tick_nohz_stop_tick()
900 …printk_once("basemono: %llu ts->next_tick: %llu dev->next_event: %llu timer->active: %d timer->exp… in tick_nohz_stop_tick()
901 basemono, ts->next_tick, dev->next_event, in tick_nohz_stop_tick()
902 hrtimer_active(&ts->sched_timer), hrtimer_get_expires(&ts->sched_timer)); in tick_nohz_stop_tick()
912 if (!ts->tick_stopped) { in tick_nohz_stop_tick()
916 ts->last_tick = hrtimer_get_expires(&ts->sched_timer); in tick_nohz_stop_tick()
917 ts->tick_stopped = 1; in tick_nohz_stop_tick()
921 ts->next_tick = tick; in tick_nohz_stop_tick()
928 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) in tick_nohz_stop_tick()
929 hrtimer_cancel(&ts->sched_timer); in tick_nohz_stop_tick()
935 if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { in tick_nohz_stop_tick()
936 hrtimer_start(&ts->sched_timer, tick, in tick_nohz_stop_tick()
939 hrtimer_set_expires(&ts->sched_timer, tick); in tick_nohz_stop_tick()
944 static void tick_nohz_retain_tick(struct tick_sched *ts) in tick_nohz_retain_tick() argument
946 ts->timer_expires_base = 0; in tick_nohz_retain_tick()
950 static void tick_nohz_stop_sched_tick(struct tick_sched *ts, int cpu) in tick_nohz_stop_sched_tick() argument
952 if (tick_nohz_next_event(ts, cpu)) in tick_nohz_stop_sched_tick()
953 tick_nohz_stop_tick(ts, cpu); in tick_nohz_stop_sched_tick()
955 tick_nohz_retain_tick(ts); in tick_nohz_stop_sched_tick()
959 static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_restart_sched_tick() argument
975 ts->tick_stopped = 0; in tick_nohz_restart_sched_tick()
976 tick_nohz_restart(ts, now); in tick_nohz_restart_sched_tick()
979 static void __tick_nohz_full_update_tick(struct tick_sched *ts, in __tick_nohz_full_update_tick() argument
985 if (can_stop_full_tick(cpu, ts)) in __tick_nohz_full_update_tick()
986 tick_nohz_stop_sched_tick(ts, cpu); in __tick_nohz_full_update_tick()
987 else if (ts->tick_stopped) in __tick_nohz_full_update_tick()
988 tick_nohz_restart_sched_tick(ts, now); in __tick_nohz_full_update_tick()
992 static void tick_nohz_full_update_tick(struct tick_sched *ts) in tick_nohz_full_update_tick() argument
997 if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) in tick_nohz_full_update_tick()
1000 __tick_nohz_full_update_tick(ts, ktime_get()); in tick_nohz_full_update_tick()
1042 static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) in can_stop_idle_tick() argument
1058 ts->next_tick = 0; in can_stop_idle_tick()
1062 if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) in can_stop_idle_tick()
1087 static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) in __tick_nohz_idle_stop_tick() argument
1096 if (ts->timer_expires_base) in __tick_nohz_idle_stop_tick()
1097 expires = ts->timer_expires; in __tick_nohz_idle_stop_tick()
1098 else if (can_stop_idle_tick(cpu, ts)) in __tick_nohz_idle_stop_tick()
1099 expires = tick_nohz_next_event(ts, cpu); in __tick_nohz_idle_stop_tick()
1103 ts->idle_calls++; in __tick_nohz_idle_stop_tick()
1106 int was_stopped = ts->tick_stopped; in __tick_nohz_idle_stop_tick()
1108 tick_nohz_stop_tick(ts, cpu); in __tick_nohz_idle_stop_tick()
1110 ts->idle_sleeps++; in __tick_nohz_idle_stop_tick()
1111 ts->idle_expires = expires; in __tick_nohz_idle_stop_tick()
1113 if (!was_stopped && ts->tick_stopped) { in __tick_nohz_idle_stop_tick()
1114 ts->idle_jiffies = ts->last_jiffies; in __tick_nohz_idle_stop_tick()
1118 tick_nohz_retain_tick(ts); in __tick_nohz_idle_stop_tick()
1149 struct tick_sched *ts; in tick_nohz_idle_enter() local
1155 ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_enter()
1157 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_enter()
1159 ts->inidle = 1; in tick_nohz_idle_enter()
1160 tick_nohz_start_idle(ts); in tick_nohz_idle_enter()
1175 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_exit() local
1177 if (ts->inidle) in tick_nohz_irq_exit()
1178 tick_nohz_start_idle(ts); in tick_nohz_irq_exit()
1180 tick_nohz_full_update_tick(ts); in tick_nohz_irq_exit()
1188 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_got_tick() local
1190 if (ts->got_idle_tick) { in tick_nohz_idle_got_tick()
1191 ts->got_idle_tick = 0; in tick_nohz_idle_got_tick()
1222 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_sleep_length() local
1228 ktime_t now = ts->idle_entrytime; in tick_nohz_get_sleep_length()
1231 WARN_ON_ONCE(!ts->inidle); in tick_nohz_get_sleep_length()
1235 if (!can_stop_idle_tick(cpu, ts)) in tick_nohz_get_sleep_length()
1238 next_event = tick_nohz_next_event(ts, cpu); in tick_nohz_get_sleep_length()
1247 hrtimer_next_event_without(&ts->sched_timer)); in tick_nohz_get_sleep_length()
1260 struct tick_sched *ts = tick_get_tick_sched(cpu); in tick_nohz_get_idle_calls_cpu() local
1262 return ts->idle_calls; in tick_nohz_get_idle_calls_cpu()
1272 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_get_idle_calls() local
1274 return ts->idle_calls; in tick_nohz_get_idle_calls()
1277 static void tick_nohz_account_idle_time(struct tick_sched *ts, in tick_nohz_account_idle_time() argument
1282 ts->idle_exittime = now; in tick_nohz_account_idle_time()
1291 ticks = jiffies - ts->idle_jiffies; in tick_nohz_account_idle_time()
1301 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_restart_tick() local
1303 if (ts->tick_stopped) { in tick_nohz_idle_restart_tick()
1305 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_restart_tick()
1306 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_restart_tick()
1310 static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now) in tick_nohz_idle_update_tick() argument
1313 __tick_nohz_full_update_tick(ts, now); in tick_nohz_idle_update_tick()
1315 tick_nohz_restart_sched_tick(ts, now); in tick_nohz_idle_update_tick()
1317 tick_nohz_account_idle_time(ts, now); in tick_nohz_idle_update_tick()
1329 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_idle_exit() local
1335 WARN_ON_ONCE(!ts->inidle); in tick_nohz_idle_exit()
1336 WARN_ON_ONCE(ts->timer_expires_base); in tick_nohz_idle_exit()
1338 ts->inidle = 0; in tick_nohz_idle_exit()
1339 idle_active = ts->idle_active; in tick_nohz_idle_exit()
1340 tick_stopped = ts->tick_stopped; in tick_nohz_idle_exit()
1346 tick_nohz_stop_idle(ts, now); in tick_nohz_idle_exit()
1349 tick_nohz_idle_update_tick(ts, now); in tick_nohz_idle_exit()
1359 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_handler() local
1365 tick_sched_do_timer(ts, now); in tick_nohz_handler()
1366 tick_sched_handle(ts, regs); in tick_nohz_handler()
1368 if (unlikely(ts->tick_stopped)) { in tick_nohz_handler()
1378 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_nohz_handler()
1379 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_handler()
1382 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) in tick_nohz_activate() argument
1386 ts->nohz_mode = mode; in tick_nohz_activate()
1397 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_switch_to_nohz() local
1407 * Recycle the hrtimer in ts, so we can share the in tick_nohz_switch_to_nohz()
1410 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_nohz_switch_to_nohz()
1414 hrtimer_set_expires(&ts->sched_timer, next); in tick_nohz_switch_to_nohz()
1415 hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); in tick_nohz_switch_to_nohz()
1416 tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); in tick_nohz_switch_to_nohz()
1417 tick_nohz_activate(ts, NOHZ_MODE_LOWRES); in tick_nohz_switch_to_nohz()
1422 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_nohz_irq_enter() local
1425 if (!ts->idle_active && !ts->tick_stopped) in tick_nohz_irq_enter()
1428 if (ts->idle_active) in tick_nohz_irq_enter()
1429 tick_nohz_stop_idle(ts, now); in tick_nohz_irq_enter()
1437 if (ts->tick_stopped) in tick_nohz_irq_enter()
1445 static inline void tick_nohz_activate(struct tick_sched *ts, int mode) { } in tick_nohz_activate() argument
1468 struct tick_sched *ts = in tick_sched_timer() local
1473 tick_sched_do_timer(ts, now); in tick_sched_timer()
1480 tick_sched_handle(ts, regs); in tick_sched_timer()
1482 ts->next_tick = 0; in tick_sched_timer()
1485 if (unlikely(ts->tick_stopped)) in tick_sched_timer()
1508 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_setup_sched_timer() local
1514 hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); in tick_setup_sched_timer()
1515 ts->sched_timer.function = tick_sched_timer; in tick_setup_sched_timer()
1518 hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); in tick_setup_sched_timer()
1525 hrtimer_add_expires_ns(&ts->sched_timer, offset); in tick_setup_sched_timer()
1528 hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); in tick_setup_sched_timer()
1529 hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); in tick_setup_sched_timer()
1530 tick_nohz_activate(ts, NOHZ_MODE_HIGHRES); in tick_setup_sched_timer()
1537 struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); in tick_cancel_sched_timer() local
1540 if (ts->sched_timer.base) in tick_cancel_sched_timer()
1541 hrtimer_cancel(&ts->sched_timer); in tick_cancel_sched_timer()
1544 memset(ts, 0, sizeof(*ts)); in tick_cancel_sched_timer()
1564 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_oneshot_notify() local
1566 set_bit(0, &ts->check_clocks); in tick_oneshot_notify()
1579 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); in tick_check_oneshot_change() local
1581 if (!test_and_clear_bit(0, &ts->check_clocks)) in tick_check_oneshot_change()
1584 if (ts->nohz_mode != NOHZ_MODE_INACTIVE) in tick_check_oneshot_change()