All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Hollis Blanchard <hollis_blanchard@mentor.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] trace: only create simple backend trace files when an event is emitted.
Date: Mon, 15 Feb 2016 15:52:55 +0000	[thread overview]
Message-ID: <20160215155255.GG10217@stefanha-x1.localdomain> (raw)
In-Reply-To: <1454957515-29258-1-git-send-email-hollis_blanchard@mentor.com>

[-- Attachment #1: Type: text/plain, Size: 1858 bytes --]

On Mon, Feb 08, 2016 at 10:51:55AM -0800, Hollis Blanchard wrote:
> Previously, trace record files (created by st_set_trace_file_enabled(true))
> were created by the simple backend at initialization time, even if no events
> were actually enabled.
> 
> As a consequence, the working directory would become littered with trace-PID
> files just by enabling the simple backend at configure time, even when no
> -trace options were used.
> 
> ---
> I've been using this to avoid creation of empty trace record files. I haven't
> done any scientific performance studies, but an extra function
> call/conditional/return when recording every trace event doesn't seem to have
> any noticeable effect.
> 
> Signed-off-by: Hollis Blanchard <hollis_blanchard@mentor.com>
> ---
>  trace/simple.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/trace/simple.c b/trace/simple.c
> index 3fdcc82..67ccc3c 100644
> --- a/trace/simple.c
> +++ b/trace/simple.c
> @@ -209,6 +209,8 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
>      uint64_t event_u64 = event;
>      uint64_t timestamp_ns = get_clock();
>  
> +    st_set_trace_file_enabled(true);

trace_record_start() can be called from multiple threads.
st_set_trace_file_enabled() is not thread-safe.

One way to solve this is to use a read memory barrier to fetch trace_fp.
If it's NULL then acquire trace_lock and recheck (in case another thread
has modified it since).  Now continue with the rest of
st_set_trace_file_enabled() to open the file.

If multiple threads pile up they will just wait for trace_lock until the
first thread has completed opening the file.  Or you could use try_lock
instead and return -EBUSY to drop those events similar to the -ENOSPC
error case in trace_record_start().

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2016-02-15 15:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 23:13 [Qemu-devel] trace: timestamps, core IDs, and file creation Hollis Blanchard
2016-02-08 15:30 ` Stefan Hajnoczi
2016-02-08 16:29   ` Lluís Vilanova
2016-02-08 18:51   ` [Qemu-devel] [PATCH] trace: only create simple backend trace files when an event is emitted Hollis Blanchard
2016-02-08 20:02     ` Alex Bennée
2016-02-15 15:52     ` Stefan Hajnoczi [this message]
2016-02-15 15:54     ` Stefan Hajnoczi
2016-02-08 19:59   ` [Qemu-devel] trace: timestamps, core IDs, and file creation Hollis Blanchard
2016-02-15 15:29     ` Stefan Hajnoczi
2016-02-08 18:01 ` Alex Bennée
2016-02-08 18:34   ` Alex Bennée

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=20160215155255.GG10217@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=hollis_blanchard@mentor.com \
    --cc=qemu-devel@nongnu.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.