All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	John Stultz <john.stultz@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Richard Cochran <richardcochran@gmail.com>,
	Prarit Bhargava <prarit@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, lttng-dev@lists.lttng.org
Subject: Re: [RFC PATCH] timekeeping: introduce timekeeping_is_busy()
Date: Thu, 12 Sep 2013 03:25:31 +0200	[thread overview]
Message-ID: <20130912012531.GS31370@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20130912004811.GA6096@Krystal>

On Wed, Sep 11, 2013 at 08:48:11PM -0400, Mathieu Desnoyers wrote:
> Thoughts ?


struct foo {
	...
};

spinlock_t foo_lock;
unsigned int foo_head = 0;
unsigned int foo_tail = 0;
struct foo foo_array[2];

void foo_assign(struct foo f)
{
	spin_lock(&foo_lock);
	foo_head++;
	smp_wmb();
	foo_array[foo_head & 1] = f;
	smp_wmb();
	foo_tail++;
	spin_unlock(&foo_lock);
}

struct foo foo_get(void)
{
	unsigned int tail, head;
	struct foo ret;

again:
	tail = ACCESS_ONCE(foo_tail);
	smp_rmb();
	ret = foo_array[tail & 1];
	smp_rmb();
	head = ACCESS_ONCE(foo_head);
	if (head - tail >= 2)
		goto again;

	return ret;
}

Should work and get you the most recent 'complete' foo even when
foo_get() is called nested inside foo_assign().

  reply	other threads:[~2013-09-12  1:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11 15:08 [RFC PATCH] timekeeping: introduce timekeeping_is_busy() Mathieu Desnoyers
2013-09-11 16:40 ` John Stultz
2013-09-11 17:07   ` Steven Rostedt
2013-09-11 17:49   ` Mathieu Desnoyers
2013-09-11 17:53     ` John Stultz
2013-09-11 18:54   ` Mathieu Desnoyers
2013-09-11 20:36     ` Paul E. McKenney
2013-09-12  0:48       ` Mathieu Desnoyers
2013-09-12  1:25         ` Peter Zijlstra [this message]
2013-09-12  3:22           ` Mathieu Desnoyers
2013-09-12 12:09             ` Peter Zijlstra
2013-09-12 13:48               ` Mathieu Desnoyers
2013-09-12 14:46                 ` Peter Zijlstra

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=20130912012531.GS31370@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lttng-dev@lists.lttng.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=prarit@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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.