mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Petr Mladek <pmladek@suse.cz>
Cc: Ingo Molnar <mingo@elte.hu>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Jiri Kosina <jkosina@suse.cz>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] ring-buffer: Race when writing and swapping cpu buffer in parallel
Date: Wed, 16 Jul 2014 12:43:56 -0400	[thread overview]
Message-ID: <20140716124356.398e21f4@gandalf.local.home> (raw)
In-Reply-To: <1405501084-16135-1-git-send-email-pmladek@suse.cz>

On Wed, 16 Jul 2014 10:58:04 +0200
Petr Mladek <pmladek@suse.cz> wrote:


> +/**
> + * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers
> + * @buffer_a: One buffer to swap with
> + * @buffer_b: The other buffer to swap with
> + *
> + * This function is useful for tracers that want to take a "snapshot"
> + * of a CPU buffer and has another back up buffer lying around.
> + * It is expected that the tracer handles the cpu buffer not being
> + * used at the moment.
> + */
> +int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
> +			 struct ring_buffer *buffer_b, int cpu)
> +{
> +	struct ring_buffer_swap_info rb_swap_info = {
> +		.buffer_a = buffer_a,
> +		.buffer_b = buffer_b,
> +	};
> +	int ret;
> +
> +	/*
> +	 * Swap the CPU buffer on the same CPU. Recording has to be fast
> +	 * and and this helps to avoid memory barriers.
> +	 */
> +	ret = smp_call_function_single(cpu, ring_buffer_swap_this_cpu,
> +				       (void *)&rb_swap_info, 1);
> +	if (ret)
> +		return ret;
> +
> +	return rb_swap_info.ret;

We need to check if the cpu is on the current CPU and if so, just call
the function directly. Otherwise this can't be done from interrupt
disabled context.

Enable IRQSOFF_TRACER and FTRACE_STARTUP_TEST to see why.

[    2.098008] Testing tracer irqsoff: 
[    2.351020] ------------[ cut here ]------------
[    2.352000] WARNING: CPU: 3 PID: 0 at /home/rostedt/work/git/linux-trace.git/kernel/smp.c:283 smp_call_function_single+0x66/0xad()
[    2.352000] Modules linked in:
[    2.352000] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 3.16.0-rc3-test+ #93
[    2.352000] Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To be filled by O.E.M., BIOS SDBLI944.86P 05/08/2007
[    2.352000]  0000000000000000 ffffffff810058cb ffffffff81503d20 0000000000000000
[    2.352000]  ffffffff81040ca1 0000000000000000 ffffffff8109712f 0000000000000001
[    2.352000]  0000000000000003 ffffffff810bf9db ffff88007a3c3e30 0000000000000001
[    2.352000] Call Trace:
[    2.352000]  [<ffffffff810058cb>] ? show_stack+0x5/0x3e
[    2.352000]  [<ffffffff81503d20>] ? dump_stack+0x4a/0x75
[    2.352000]  [<ffffffff81040ca1>] ? warn_slowpath_common+0x7e/0x97
[    2.352000]  [<ffffffff8109712f>] ? smp_call_function_single+0x66/0xad
[    2.352000]  [<ffffffff810bf9db>] ? ring_buffer_swap_cpu+0x45/0x45
[    2.352000]  [<ffffffff8109712f>] ? smp_call_function_single+0x66/0xad
[    2.352000]  [<ffffffff810970ce>] ? smp_call_function_single+0x5/0xad
[    2.352000]  [<ffffffff810bf9ce>] ? ring_buffer_swap_cpu+0x38/0x45
[    2.352000]  [<ffffffff810c6c64>] ? update_max_tr_single+0xb6/0x11f
[    2.352000]  [<ffffffff8100ae3e>] ? default_idle+0x1d/0x30
[    2.352000]  [<ffffffff810cd2ac>] ? stop_critical_timing+0x139/0x20d
[    2.352000]  [<ffffffff8100ae3e>] ? default_idle+0x1d/0x30
[    2.352000]  [<ffffffff81072d35>] ? cpu_startup_entry+0x115/0x220
[    2.352000]  [<ffffffff81027610>] ? start_secondary+0x21c/0x222
[    2.352000] ---[ end trace a712676a9f9a53a0 ]---


-- Steve

  reply	other threads:[~2014-07-16 16:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16  8:58 Petr Mladek
2014-07-16 16:43 ` Steven Rostedt [this message]
2014-07-18 15:34   ` Petr Mládek
2014-07-21 14:43     ` Petr Mládek
2014-07-21 15:43       ` Paul E. McKenney
2014-07-21 16:18         ` Petr Mládek
2014-07-21 16:30           ` Steven Rostedt
2014-07-29  9:02             ` Jiri Kosina
2014-07-23 16:28         ` Frederic Weisbecker
2014-07-23 16:34           ` Steven Rostedt
2014-07-23 16:47             ` Frederic Weisbecker
2014-07-23 16:49             ` Petr Mládek
2014-07-23 16:55               ` Steven Rostedt
2014-07-21 16:07       ` Steven Rostedt
2014-07-22  9:41         ` Petr Mládek

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=20140716124356.398e21f4@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=fweisbec@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pmladek@suse.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®