All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Tejun Heo <tj@kernel.org>, Suren Baghdasaryan <surenb@google.com>,
	Daniel Drake <drake@endlessm.com>,
	Vinayak Menon <vinmenon@codeaurora.org>,
	Christopher Lameter <cl@linux.com>,
	Peter Enderborg <peter.enderborg@sony.com>,
	Shakeel Butt <shakeelb@google.com>,
	Mike Galbraith <efault@gmx.de>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO
Date: Fri, 7 Sep 2018 12:16:34 +0200	[thread overview]
Message-ID: <20180907101634.GO24106@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180828172258.3185-9-hannes@cmpxchg.org>

On Tue, Aug 28, 2018 at 01:22:57PM -0400, Johannes Weiner wrote:
> +enum psi_states {
> +	PSI_IO_SOME,
> +	PSI_IO_FULL,
> +	PSI_MEM_SOME,
> +	PSI_MEM_FULL,
> +	PSI_CPU_SOME,
> +	/* Only per-CPU, to weigh the CPU in the global average: */
> +	PSI_NONIDLE,
> +	NR_PSI_STATES,
> +};

> +static u32 get_recent_time(struct psi_group *group, int cpu,
> +			   enum psi_states state)
> +{
> +	struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu);
> +	unsigned int seq;
> +	u32 time, delta;
> +
> +	do {
> +		seq = read_seqcount_begin(&groupc->seq);
> +
> +		time = groupc->times[state];
> +		/*
> +		 * In addition to already concluded states, we also
> +		 * incorporate currently active states on the CPU,
> +		 * since states may last for many sampling periods.
> +		 *
> +		 * This way we keep our delta sampling buckets small
> +		 * (u32) and our reported pressure close to what's
> +		 * actually happening.
> +		 */
> +		if (test_state(groupc->tasks, state))
> +			time += cpu_clock(cpu) - groupc->state_start;
> +	} while (read_seqcount_retry(&groupc->seq, seq));
> +
> +	delta = time - groupc->times_prev[state];
> +	groupc->times_prev[state] = time;
> +
> +	return delta;
> +}

> +static bool update_stats(struct psi_group *group)
> +{
> +	u64 deltas[NR_PSI_STATES - 1] = { 0, };
> +	unsigned long missed_periods = 0;
> +	unsigned long nonidle_total = 0;
> +	u64 now, expires, period;
> +	int cpu;
> +	int s;
> +
> +	mutex_lock(&group->stat_lock);
> +
> +	/*
> +	 * Collect the per-cpu time buckets and average them into a
> +	 * single time sample that is normalized to wallclock time.
> +	 *
> +	 * For averaging, each CPU is weighted by its non-idle time in
> +	 * the sampling period. This eliminates artifacts from uneven
> +	 * loading, or even entirely idle CPUs.
> +	 */
> +	for_each_possible_cpu(cpu) {
> +		u32 nonidle;
> +
> +		nonidle = get_recent_time(group, cpu, PSI_NONIDLE);
> +		nonidle = nsecs_to_jiffies(nonidle);
> +		nonidle_total += nonidle;
> +
> +		for (s = 0; s < PSI_NONIDLE; s++) {
> +			u32 delta;
> +
> +			delta = get_recent_time(group, cpu, s);
> +			deltas[s] += (u64)delta * nonidle;
> +		}
> +	}

This does the whole seqcount thing 6x, which is a bit of a waste.

struct snapshot {
	u32 times[NR_PSI_STATES];
};

static inline struct snapshot get_times_snapshot(struct psi_group *pg, int cpu)
{
	struct pci_group_cpu *pgc = per_cpu_ptr(pg->pcpu, cpu);
	struct snapshot s;
	unsigned int seq;
	u32 delta;
	int i;

	do {
		seq = read_seqcount_begin(&pgc->seq);

		delta = cpu_clock(cpu) - pgc->state_start;
		for (i = 0; i < NR_PSI_STATES; i++) {
			s.times[i] = gpc->times[i];
			if (test_state(pgc->tasks, i))
				s.times[i] += delta;
		}

	} while (read_seqcount_retry(&pgc->seq, seq);

	return s;
}


	for_each_possible_cpu(cpu) {
		struct snapshot s = get_times_snapshot(pg, cpu);

		nonidle = nsecs_to_jiffies(s.times[PSI_NONIDLE]);
		nonidle_total += nonidle;

		for (i = 0; i < PSI_NONIDLE; i++)
			deltas[s] += (u64)s.times[i] * nonidle;

		/* ... */

	}


It's a bit cumbersome, but that's because of C.

  parent reply	other threads:[~2018-09-07 10:17 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 17:22 [PATCH 0/9] psi: pressure stall information for CPU, memory, and IO v4 Johannes Weiner
2018-08-28 17:22 ` [PATCH 1/9] mm: workingset: don't drop refault information prematurely Johannes Weiner
2018-08-28 17:22 ` [PATCH 2/9] mm: workingset: tell cache transitions from workingset thrashing Johannes Weiner
2018-08-28 17:22 ` [PATCH 3/9] delayacct: track delays from thrashing cache pages Johannes Weiner
2018-08-28 17:22 ` [PATCH 4/9] sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD Johannes Weiner
2018-09-12 23:28   ` Andrew Morton
2018-09-13  1:49     ` Johannes Weiner
2018-08-28 17:22 ` [PATCH 5/9] sched: loadavg: make calc_load_n() public Johannes Weiner
2018-08-28 17:22 ` [PATCH 6/9] sched: sched.h: make rq locking and clock functions available in stats.h Johannes Weiner
2018-08-28 17:22 ` [PATCH 7/9] sched: introduce this_rq_lock_irq() Johannes Weiner
2018-08-28 17:22 ` [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO Johannes Weiner
2018-08-28 20:11   ` Randy Dunlap
2018-08-28 20:56     ` Johannes Weiner
2018-08-28 21:30       ` Randy Dunlap
2018-09-07 10:16   ` Peter Zijlstra [this message]
2018-09-07 10:21     ` Peter Zijlstra
2018-09-07 14:44     ` Johannes Weiner
2018-09-07 14:58       ` Peter Zijlstra
2018-09-07 17:50         ` Johannes Weiner
2018-09-07 10:24   ` Peter Zijlstra
2018-09-07 14:54     ` Johannes Weiner
2018-08-28 17:22 ` [PATCH 9/9] psi: cgroup support Johannes Weiner
2018-09-05 21:43 ` [PATCH 0/9] psi: pressure stall information for CPU, memory, and IO v4 Johannes Weiner
2018-09-07  7:36   ` Daniel Drake
2018-09-07  7:46   ` Peter Zijlstra
2018-09-07 11:04   ` Peter Zijlstra
2018-09-07 15:09     ` Johannes Weiner
2018-09-07 15:58       ` Suren Baghdasaryan
2018-09-17  5:22         ` Daniel Drake
2018-09-18 15:53           ` Suren Baghdasaryan
2018-09-25 22:05             ` Suren Baghdasaryan
2018-09-17 13:29         ` peter enderborg
2018-09-17 13:29           ` peter enderborg
2018-09-17 13:40           ` Peter Zijlstra
2018-09-18 16:03           ` Suren Baghdasaryan
2018-10-19  2:07 ` Andrew Morton
2018-10-23 17:29   ` Johannes Weiner
2018-10-23 17:41     ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2018-08-01 15:19 [PATCH 0/9] psi: pressure stall information for CPU, memory, and IO v3 Johannes Weiner
2018-08-01 15:19 ` [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO Johannes Weiner
2018-08-03 16:56   ` Peter Zijlstra
2018-08-06 15:05     ` Johannes Weiner
2018-08-06 15:25       ` Peter Zijlstra
2018-08-06 15:40         ` Johannes Weiner
2018-08-06 15:19     ` Johannes Weiner
2018-08-06 16:03       ` Peter Zijlstra
2018-08-21 19:44     ` Johannes Weiner
2018-08-22  9:16       ` Peter Zijlstra
2018-08-03 17:07   ` Peter Zijlstra
2018-08-06 15:23     ` Johannes Weiner
2018-08-03 17:15   ` Peter Zijlstra
2018-08-03 17:21   ` Peter Zijlstra
2018-08-21 20:11     ` Johannes Weiner
2018-08-22  9:10       ` Peter Zijlstra
2018-08-22 17:28         ` Johannes Weiner
2018-08-01 15:12 Johannes Weiner
2018-08-01 15:13 ` [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO Johannes Weiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180907101634.GO24106@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=cl@linux.com \
    --cc=drake@endlessm.com \
    --cc=efault@gmx.de \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=peter.enderborg@sony.com \
    --cc=shakeelb@google.com \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vinmenon@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.