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>,
	Mike Galbraith <efault@gmx.de>,
	Shakeel Butt <shakeelb@google.com>,
	Peter Enderborg <peter.enderborg@sony.com>,
	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, 3 Aug 2018 19:21:39 +0200	[thread overview]
Message-ID: <20180803172139.GE2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180801151958.32590-9-hannes@cmpxchg.org>

On Wed, Aug 01, 2018 at 11:19:57AM -0400, Johannes Weiner wrote:
> +			time = READ_ONCE(groupc->times[s]);
> +			/*
> +			 * 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, cpu, s)) {
> +				/*
> +				 * We can race with a state change and
> +				 * need to make sure the state_start
> +				 * update is ordered against the
> +				 * updates to the live state and the
> +				 * time buckets (groupc->times).
> +				 *
> +				 * 1. If we observe task state that
> +				 * needs to be recorded, make sure we
> +				 * see state_start from when that
> +				 * state went into effect or we'll
> +				 * count time from the previous state.
> +				 *
> +				 * 2. If the time delta has already
> +				 * been added to the bucket, make sure
> +				 * we don't see it in state_start or
> +				 * we'll count it twice.
> +				 *
> +				 * If the time delta is out of
> +				 * state_start but not in the time
> +				 * bucket yet, we'll miss it entirely
> +				 * and handle it in the next period.
> +				 */
> +				smp_rmb();
> +				time += cpu_clock(cpu) - groupc->state_start;
> +			}

As is, groupc->state_start needs a READ_ONCE() above and a WRITE_ONCE()
below. But like stated earlier, doing an update in scheduler_tick() is
probably easier.

> +static void psi_group_change(struct psi_group *group, int cpu, u64 now,
> +			     unsigned int clear, unsigned int set)
> +{
> +	struct psi_group_cpu *groupc;
> +	unsigned int t, m;
> +	u32 delta;
> +
> +	groupc = per_cpu_ptr(group->pcpu, cpu);
> +
> +	/*
> +	 * First we assess the aggregate resource states these CPU's
> +	 * tasks have been in since the last change, and account any
> +	 * SOME and FULL time that may have resulted in.
> +	 *
> +	 * Then we update the task counts according to the state
> +	 * change requested through the @clear and @set bits.
> +	 */
> +
> +	delta = now - groupc->state_start;
> +	groupc->state_start = now;
> +
> +	/*
> +	 * Update state_start before recording time in the sampling
> +	 * buckets and changing task counts, to prevent a racing
> +	 * aggregation from counting the delta twice or attributing it
> +	 * to an old state.
> +	 */
> +	smp_wmb();
> +
> +	if (test_state(groupc->tasks, cpu, PSI_IO_SOME)) {
> +		groupc->times[PSI_IO_SOME] += delta;
> +		if (test_state(groupc->tasks, cpu, PSI_IO_FULL))
> +			groupc->times[PSI_IO_FULL] += delta;
> +	}
> +	if (test_state(groupc->tasks, cpu, PSI_MEM_SOME)) {
> +		groupc->times[PSI_MEM_SOME] += delta;
> +		if (test_state(groupc->tasks, cpu, PSI_MEM_FULL))
> +			groupc->times[PSI_MEM_FULL] += delta;
> +	}

Might we worth checking the compiler does the right thing here and
optimizes this branch fest into something sensible.

> +	if (test_state(groupc->tasks, cpu, PSI_CPU_SOME))
> +		groupc->times[PSI_CPU_SOME] += delta;
> +	if (test_state(groupc->tasks, cpu, PSI_NONIDLE))
> +		groupc->times[PSI_NONIDLE] += delta;


  parent reply	other threads:[~2018-08-03 17:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 1/9] mm: workingset: don't drop refault information prematurely Johannes Weiner
2018-08-01 15:19 ` [PATCH 2/9] mm: workingset: tell cache transitions from workingset thrashing Johannes Weiner
2018-08-01 21:56   ` Suren Baghdasaryan
2018-08-02 12:28     ` Johannes Weiner
2018-08-01 15:19 ` [PATCH 3/9] delayacct: track delays from thrashing cache pages Johannes Weiner
2018-08-01 15:19 ` [PATCH 4/9] sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD Johannes Weiner
2018-08-01 15:19 ` [PATCH 5/9] sched: loadavg: make calc_load_n() public Johannes Weiner
2018-08-01 15:19 ` [PATCH 6/9] sched: sched.h: make rq locking and clock functions available in stats.h Johannes Weiner
2018-08-01 15:19 ` [PATCH 7/9] sched: introduce this_rq_lock_irq() 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 [this message]
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:19 ` [PATCH 9/9] psi: cgroup support Johannes Weiner
2018-08-07 11:50 ` [PATCH 0/9] psi: pressure stall information for CPU, memory, and IO v3 peter enderborg
2018-08-07 11:50   ` peter enderborg
2018-08-07 17:51   ` Johannes Weiner
  -- strict thread matches above, loose matches on Subject: below --
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 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
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-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=20180803172139.GE2494@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.