Skip to content

Commit 333f301

Browse files
surenbaghdasaryantorvalds
authored andcommitted
psi: track changed states
Introduce changed_states parameter into collect_percpu_times to track the states changed since the last update. This will be needed to detect whether polled states activated in the monitor patch. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Suren Baghdasaryan <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Li Zefan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7fc70a3 commit 333f301

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

kernel/sched/psi.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,17 @@ static bool test_state(unsigned int *tasks, enum psi_states state)
210210
}
211211
}
212212

213-
static void get_recent_times(struct psi_group *group, int cpu, u32 *times)
213+
static void get_recent_times(struct psi_group *group, int cpu, u32 *times,
214+
u32 *pchanged_states)
214215
{
215216
struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu);
216217
u64 now, state_start;
217218
enum psi_states s;
218219
unsigned int seq;
219220
u32 state_mask;
220221

222+
*pchanged_states = 0;
223+
221224
/* Snapshot a coherent view of the CPU state */
222225
do {
223226
seq = read_seqcount_begin(&groupc->seq);
@@ -246,6 +249,8 @@ static void get_recent_times(struct psi_group *group, int cpu, u32 *times)
246249
groupc->times_prev[s] = times[s];
247250

248251
times[s] = delta;
252+
if (delta)
253+
*pchanged_states |= (1 << s);
249254
}
250255
}
251256

@@ -269,10 +274,11 @@ static void calc_avgs(unsigned long avg[3], int missed_periods,
269274
avg[2] = calc_load(avg[2], EXP_300s, pct);
270275
}
271276

272-
static bool collect_percpu_times(struct psi_group *group)
277+
static void collect_percpu_times(struct psi_group *group, u32 *pchanged_states)
273278
{
274279
u64 deltas[NR_PSI_STATES - 1] = { 0, };
275280
unsigned long nonidle_total = 0;
281+
u32 changed_states = 0;
276282
int cpu;
277283
int s;
278284

@@ -287,8 +293,11 @@ static bool collect_percpu_times(struct psi_group *group)
287293
for_each_possible_cpu(cpu) {
288294
u32 times[NR_PSI_STATES];
289295
u32 nonidle;
296+
u32 cpu_changed_states;
290297

291-
get_recent_times(group, cpu, times);
298+
get_recent_times(group, cpu, times,
299+
&cpu_changed_states);
300+
changed_states |= cpu_changed_states;
292301

293302
nonidle = nsecs_to_jiffies(times[PSI_NONIDLE]);
294303
nonidle_total += nonidle;
@@ -313,7 +322,8 @@ static bool collect_percpu_times(struct psi_group *group)
313322
for (s = 0; s < NR_PSI_STATES - 1; s++)
314323
group->total[s] += div_u64(deltas[s], max(nonidle_total, 1UL));
315324

316-
return nonidle_total;
325+
if (pchanged_states)
326+
*pchanged_states = changed_states;
317327
}
318328

319329
static u64 update_averages(struct psi_group *group, u64 now)
@@ -373,6 +383,7 @@ static void psi_avgs_work(struct work_struct *work)
373383
{
374384
struct delayed_work *dwork;
375385
struct psi_group *group;
386+
u32 changed_states;
376387
bool nonidle;
377388
u64 now;
378389

@@ -383,7 +394,8 @@ static void psi_avgs_work(struct work_struct *work)
383394

384395
now = sched_clock();
385396

386-
nonidle = collect_percpu_times(group);
397+
collect_percpu_times(group, &changed_states);
398+
nonidle = changed_states & (1 << PSI_NONIDLE);
387399
/*
388400
* If there is task activity, periodically fold the per-cpu
389401
* times and feed samples into the running averages. If things
@@ -719,7 +731,7 @@ int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
719731
/* Update averages before reporting them */
720732
mutex_lock(&group->avgs_lock);
721733
now = sched_clock();
722-
collect_percpu_times(group);
734+
collect_percpu_times(group, NULL);
723735
if (now >= group->avg_next_update)
724736
group->avg_next_update = update_averages(group, now);
725737
mutex_unlock(&group->avgs_lock);

0 commit comments

Comments
 (0)