Lines Matching refs:group
179 static void group_init(struct psi_group *group) in group_init() argument
183 group->enabled = true; in group_init()
185 seqcount_init(&per_cpu_ptr(group->pcpu, cpu)->seq); in group_init()
186 group->avg_last_update = sched_clock(); in group_init()
187 group->avg_next_update = group->avg_last_update + psi_period; in group_init()
188 mutex_init(&group->avgs_lock); in group_init()
191 INIT_LIST_HEAD(&group->avg_triggers); in group_init()
192 memset(group->avg_nr_triggers, 0, sizeof(group->avg_nr_triggers)); in group_init()
193 INIT_DELAYED_WORK(&group->avgs_work, psi_avgs_work); in group_init()
196 atomic_set(&group->rtpoll_scheduled, 0); in group_init()
197 mutex_init(&group->rtpoll_trigger_lock); in group_init()
198 INIT_LIST_HEAD(&group->rtpoll_triggers); in group_init()
199 group->rtpoll_min_period = U32_MAX; in group_init()
200 group->rtpoll_next_update = ULLONG_MAX; in group_init()
201 init_waitqueue_head(&group->rtpoll_wait); in group_init()
202 timer_setup(&group->rtpoll_timer, poll_timer_fn, 0); in group_init()
203 rcu_assign_pointer(group->rtpoll_task, NULL); in group_init()
249 static void get_recent_times(struct psi_group *group, int cpu, in get_recent_times() argument
253 struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu); in get_recent_times()
305 if (current_work() == &group->avgs_work.work) { in get_recent_times()
340 static void collect_percpu_times(struct psi_group *group, in collect_percpu_times() argument
363 get_recent_times(group, cpu, aggregator, times, in collect_percpu_times()
388 group->total[aggregator][s] += in collect_percpu_times()
441 static void update_triggers(struct psi_group *group, u64 now, in update_triggers() argument
445 u64 *total = group->total[aggregator]; in update_triggers()
450 triggers = &group->avg_triggers; in update_triggers()
451 aggregator_total = group->avg_total; in update_triggers()
453 triggers = &group->rtpoll_triggers; in update_triggers()
454 aggregator_total = group->rtpoll_total; in update_triggers()
503 static u64 update_averages(struct psi_group *group, u64 now) in update_averages() argument
511 expires = group->avg_next_update; in update_averages()
523 period = now - (group->avg_last_update + (missed_periods * psi_period)); in update_averages()
524 group->avg_last_update = now; in update_averages()
529 sample = group->total[PSI_AVGS][s] - group->avg_total[s]; in update_averages()
549 group->avg_total[s] += sample; in update_averages()
550 calc_avgs(group->avg[s], missed_periods, sample, period); in update_averages()
559 struct psi_group *group; in psi_avgs_work() local
564 group = container_of(dwork, struct psi_group, avgs_work); in psi_avgs_work()
566 mutex_lock(&group->avgs_lock); in psi_avgs_work()
570 collect_percpu_times(group, PSI_AVGS, &changed_states); in psi_avgs_work()
578 if (now >= group->avg_next_update) { in psi_avgs_work()
579 update_triggers(group, now, PSI_AVGS); in psi_avgs_work()
580 group->avg_next_update = update_averages(group, now); in psi_avgs_work()
585 group->avg_next_update - now) + 1); in psi_avgs_work()
588 mutex_unlock(&group->avgs_lock); in psi_avgs_work()
591 static void init_rtpoll_triggers(struct psi_group *group, u64 now) in init_rtpoll_triggers() argument
595 list_for_each_entry(t, &group->rtpoll_triggers, node) in init_rtpoll_triggers()
597 group->total[PSI_POLL][t->state], 0); in init_rtpoll_triggers()
598 memcpy(group->rtpoll_total, group->total[PSI_POLL], in init_rtpoll_triggers()
599 sizeof(group->rtpoll_total)); in init_rtpoll_triggers()
600 group->rtpoll_next_update = now + group->rtpoll_min_period; in init_rtpoll_triggers()
604 static void psi_schedule_rtpoll_work(struct psi_group *group, unsigned long delay, in psi_schedule_rtpoll_work() argument
613 if (atomic_xchg(&group->rtpoll_scheduled, 1) && !force) in psi_schedule_rtpoll_work()
618 task = rcu_dereference(group->rtpoll_task); in psi_schedule_rtpoll_work()
624 mod_timer(&group->rtpoll_timer, jiffies + delay); in psi_schedule_rtpoll_work()
626 atomic_set(&group->rtpoll_scheduled, 0); in psi_schedule_rtpoll_work()
631 static void psi_rtpoll_work(struct psi_group *group) in psi_rtpoll_work() argument
637 mutex_lock(&group->rtpoll_trigger_lock); in psi_rtpoll_work()
641 if (now > group->rtpoll_until) { in psi_rtpoll_work()
651 atomic_set(&group->rtpoll_scheduled, 0); in psi_rtpoll_work()
678 collect_percpu_times(group, PSI_POLL, &changed_states); in psi_rtpoll_work()
680 if (changed_states & group->rtpoll_states) { in psi_rtpoll_work()
682 if (now > group->rtpoll_until) in psi_rtpoll_work()
683 init_rtpoll_triggers(group, now); in psi_rtpoll_work()
690 group->rtpoll_until = now + in psi_rtpoll_work()
691 group->rtpoll_min_period * UPDATES_PER_WINDOW; in psi_rtpoll_work()
694 if (now > group->rtpoll_until) { in psi_rtpoll_work()
695 group->rtpoll_next_update = ULLONG_MAX; in psi_rtpoll_work()
699 if (now >= group->rtpoll_next_update) { in psi_rtpoll_work()
700 if (changed_states & group->rtpoll_states) { in psi_rtpoll_work()
701 update_triggers(group, now, PSI_POLL); in psi_rtpoll_work()
702 memcpy(group->rtpoll_total, group->total[PSI_POLL], in psi_rtpoll_work()
703 sizeof(group->rtpoll_total)); in psi_rtpoll_work()
705 group->rtpoll_next_update = now + group->rtpoll_min_period; in psi_rtpoll_work()
708 psi_schedule_rtpoll_work(group, in psi_rtpoll_work()
709 nsecs_to_jiffies(group->rtpoll_next_update - now) + 1, in psi_rtpoll_work()
713 mutex_unlock(&group->rtpoll_trigger_lock); in psi_rtpoll_work()
718 struct psi_group *group = (struct psi_group *)data; in psi_rtpoll_worker() local
723 wait_event_interruptible(group->rtpoll_wait, in psi_rtpoll_worker()
724 atomic_cmpxchg(&group->rtpoll_wakeup, 1, 0) || in psi_rtpoll_worker()
729 psi_rtpoll_work(group); in psi_rtpoll_worker()
736 struct psi_group *group = from_timer(group, t, rtpoll_timer); in poll_timer_fn() local
738 atomic_set(&group->rtpoll_wakeup, 1); in poll_timer_fn()
739 wake_up_interruptible(&group->rtpoll_wait); in poll_timer_fn()
771 static void psi_group_change(struct psi_group *group, int cpu, in psi_group_change() argument
781 groupc = per_cpu_ptr(group->pcpu, cpu); in psi_group_change()
833 if (!group->enabled) { in psi_group_change()
869 if (state_mask & group->rtpoll_states) in psi_group_change()
870 psi_schedule_rtpoll_work(group, 1, false); in psi_group_change()
872 if (wake_clock && !delayed_work_pending(&group->avgs_work)) in psi_group_change()
873 schedule_delayed_work(&group->avgs_work, PSI_FREQ); in psi_group_change()
903 struct psi_group *group; in psi_task_change() local
910 group = task_psi_group(task); in psi_task_change()
912 psi_group_change(group, cpu, clear, set, true); in psi_task_change()
913 } while ((group = group->parent)); in psi_task_change()
919 struct psi_group *group, *common = NULL; in psi_task_switch() local
929 group = task_psi_group(next); in psi_task_switch()
931 if (per_cpu_ptr(group->pcpu, cpu)->state_mask & in psi_task_switch()
933 common = group; in psi_task_switch()
937 psi_group_change(group, cpu, 0, TSK_ONCPU, true); in psi_task_switch()
938 } while ((group = group->parent)); in psi_task_switch()
971 group = task_psi_group(prev); in psi_task_switch()
973 if (group == common) in psi_task_switch()
975 psi_group_change(group, cpu, clear, set, wake_clock); in psi_task_switch()
976 } while ((group = group->parent)); in psi_task_switch()
986 for (; group; group = group->parent) in psi_task_switch()
987 psi_group_change(group, cpu, clear, set, wake_clock); in psi_task_switch()
996 struct psi_group *group; in psi_account_irqtime() local
1008 group = task_psi_group(curr); in psi_account_irqtime()
1009 if (prev && task_psi_group(prev) == group) in psi_account_irqtime()
1021 if (!group->enabled) in psi_account_irqtime()
1024 groupc = per_cpu_ptr(group->pcpu, cpu); in psi_account_irqtime()
1034 if (group->rtpoll_states & (1 << PSI_IRQ_FULL)) in psi_account_irqtime()
1035 psi_schedule_rtpoll_work(group, 1, false); in psi_account_irqtime()
1036 } while ((group = group->parent)); in psi_account_irqtime()
1201 void psi_cgroup_restart(struct psi_group *group) in psi_cgroup_restart() argument
1220 if (!group->enabled) in psi_cgroup_restart()
1228 psi_group_change(group, cpu, 0, 0, true); in psi_cgroup_restart()
1234 int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res) in psi_show() argument
1244 mutex_lock(&group->avgs_lock); in psi_show()
1246 collect_percpu_times(group, PSI_AVGS, NULL); in psi_show()
1247 if (now >= group->avg_next_update) in psi_show()
1248 group->avg_next_update = update_averages(group, now); in psi_show()
1249 mutex_unlock(&group->avgs_lock); in psi_show()
1261 if (!(group == &psi_system && res == PSI_CPU && full)) { in psi_show()
1263 avg[w] = group->avg[res * 2 + full][w]; in psi_show()
1264 total = div_u64(group->total[PSI_AVGS][res * 2 + full], in psi_show()
1279 struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, in psi_trigger_create() argument
1331 t->group = group; in psi_trigger_create()
1336 group->total[PSI_POLL][t->state], 0); in psi_trigger_create()
1347 mutex_lock(&group->rtpoll_trigger_lock); in psi_trigger_create()
1349 if (!rcu_access_pointer(group->rtpoll_task)) { in psi_trigger_create()
1352 task = kthread_create(psi_rtpoll_worker, group, "psimon"); in psi_trigger_create()
1355 mutex_unlock(&group->rtpoll_trigger_lock); in psi_trigger_create()
1358 atomic_set(&group->rtpoll_wakeup, 0); in psi_trigger_create()
1360 rcu_assign_pointer(group->rtpoll_task, task); in psi_trigger_create()
1363 list_add(&t->node, &group->rtpoll_triggers); in psi_trigger_create()
1364 group->rtpoll_min_period = min(group->rtpoll_min_period, in psi_trigger_create()
1366 group->rtpoll_nr_triggers[t->state]++; in psi_trigger_create()
1367 group->rtpoll_states |= (1 << t->state); in psi_trigger_create()
1369 mutex_unlock(&group->rtpoll_trigger_lock); in psi_trigger_create()
1371 mutex_lock(&group->avgs_lock); in psi_trigger_create()
1373 list_add(&t->node, &group->avg_triggers); in psi_trigger_create()
1374 group->avg_nr_triggers[t->state]++; in psi_trigger_create()
1376 mutex_unlock(&group->avgs_lock); in psi_trigger_create()
1383 struct psi_group *group; in psi_trigger_destroy() local
1393 group = t->group; in psi_trigger_destroy()
1405 mutex_lock(&group->avgs_lock); in psi_trigger_destroy()
1408 group->avg_nr_triggers[t->state]--; in psi_trigger_destroy()
1410 mutex_unlock(&group->avgs_lock); in psi_trigger_destroy()
1412 mutex_lock(&group->rtpoll_trigger_lock); in psi_trigger_destroy()
1418 group->rtpoll_nr_triggers[t->state]--; in psi_trigger_destroy()
1419 if (!group->rtpoll_nr_triggers[t->state]) in psi_trigger_destroy()
1420 group->rtpoll_states &= ~(1 << t->state); in psi_trigger_destroy()
1425 if (group->rtpoll_min_period == div_u64(t->win.size, UPDATES_PER_WINDOW)) { in psi_trigger_destroy()
1426 list_for_each_entry(tmp, &group->rtpoll_triggers, node) in psi_trigger_destroy()
1429 group->rtpoll_min_period = period; in psi_trigger_destroy()
1432 if (group->rtpoll_states == 0) { in psi_trigger_destroy()
1433 group->rtpoll_until = 0; in psi_trigger_destroy()
1435 group->rtpoll_task, in psi_trigger_destroy()
1436 lockdep_is_held(&group->rtpoll_trigger_lock)); in psi_trigger_destroy()
1437 rcu_assign_pointer(group->rtpoll_task, NULL); in psi_trigger_destroy()
1438 del_timer(&group->rtpoll_timer); in psi_trigger_destroy()
1441 mutex_unlock(&group->rtpoll_trigger_lock); in psi_trigger_destroy()
1461 atomic_set(&group->rtpoll_scheduled, 0); in psi_trigger_destroy()