qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] trace: only create simple backend trace files w


From: Stefan Hajnoczi
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
User-agent: Mutt/1.5.24 (2015-08-30)

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 <address@hidden>
> ---
>  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: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]