Received: from eggs.gnu.org ([140.186.70.92]:53571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R7wxM-00011R-Vz for qemu-devel@nongnu.org; Sun, 25 Sep 2011 18:13:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R7wxL-0007rC-L9 for qemu-devel@nongnu.org; Sun, 25 Sep 2011 18:13:52 -0400 Received: from gw.ac.upc.es ([147.83.30.3]:52219 helo=gw.ac.upc.edu) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R7wxL-0007r6-Ar for qemu-devel@nongnu.org; Sun, 25 Sep 2011 18:13:51 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= In-Reply-To: (Blue Swirl's message of "Sun, 25 Sep 2011 20:03:57 +0000") References: <20110921183838.9431.70792.stgit@ginnungagap.bsc.es> <87wrcwr06z.fsf@ginnungagap.bsc.es> Date: Mon, 26 Sep 2011 00:10:45 +0200 Message-ID: <87aa9stgre.fsf@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] trace: Provide a per-event status define for conditional compilation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org, Richard Henderson Blue Swirl writes: > 2011/9/25 Llu=C3=ADs Vilanova : >> Blue Swirl writes: >>=20 >>> 2011/9/21 Llu=C3=ADs Vilanova : >> [...] >>>> +=3D=3D Trace event properties =3D=3D >>>> + >>>> +Each event in the "trace-events" file can be prefixed with a space-se= parated >>>> +list of zero or more of the following event properties. >>>> + >>>> +=3D=3D=3D "disable" =3D=3D=3D >>>> + >>>> +If a specific trace event is going to be invoked a huge number of tim= es, this >>>> +might have a noticeable performance impact even when the event is >>>> +programmatically disabled. >>>> + >>>> +In this case you should declare such event with the "disable" propert= y. This >>>> +will effectively disable the event at compile time (by using the "nop= " backend), >>>> +thus having no performance impact at all on regular builds (i.e., unl= ess you >>>> +edit the "trace-events" file). >>=20 >>> Nack, by default events should have no performance impact. >>=20 >> Sure, but some events can have an impact. Then it is advisable to ship Q= EMU with >> the "disable" property on these events, and (if necesary) use the >> trace_*_enabled (or TRACE_*_ENABLED) define to eliminate all possible so= urces of >> performance degradation from that event. > Maybe it was not so good idea to remove the 'disable' property from > all trace-events. Well, all the events I've seen use values from the caller, so there's no performance impact there. But of course the developer must have that in mind when adding an event (that's why I wrote the original comment about perform= ance in tracing.txt). >> For example, the patches I sent long ago for instrumenting guest code us= ing TCG >> now use QEMU's tracing infrastructure. These events are disabled by defa= ult, but >> some of them perform some computations to produce their arguments. E.g.,= one of >> the events has code for computing the set of used/defined registers for = each >> instruction, which is not for free. >>=20 >>=20 >> [...] >>>> diff --git a/scripts/tracetool b/scripts/tracetool >>>> index 4c9951d..97f9f1b 100755 >>>> --- a/scripts/tracetool >>>> +++ b/scripts/tracetool >>>> @@ -519,7 +519,7 @@ linetostap_end_dtrace() >>>> =C2=A0# Process stdin by calling begin, line, and end functions for th= e backend >>>> =C2=A0convert() >>>> =C2=A0{ >>>> - =C2=A0 =C2=A0local begin process_line end str disable >>>> + =C2=A0 =C2=A0local begin process_line end str name enabled >>>> =C2=A0 =C2=A0 begin=3D"lineto$1_begin_$backend" >>>> =C2=A0 =C2=A0 process_line=3D"lineto$1_$backend" >>>> =C2=A0 =C2=A0 end=3D"lineto$1_end_$backend" >>>> @@ -534,8 +534,14 @@ convert() >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Process the line. =C2=A0The nop backend = handles disabled lines. >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if has_property "$str" "disable"; then >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "lineto$1_nop" "$str" >>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0enabled=3D0 >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 else >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "$process_line" "$str" >>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0enabled=3D1 >>=20 >>> Instead of '1', couldn't this be a function that checks if the trace >>> point is enabled during run time (from monitor etc.)? >>=20 >> What you're proposing is the counterpart of 'trace_event_set_state' (in >> "trace/control.h"). This would miss the whole point of this patch, which= is to >> be able to ship QEMU with relatively costly tracing events whose perform= ance >> impact can be completely eliminated at compile time. > Not exactly, for '0' case, the code would be disabled. > For the trace_event_get_state() case, there would be a call to check > if the event is currently enabled. Then it would be possible to > control the additional code using monitor commands. > Case '1' (like you propose) could also make sense in some cases, then > the code would be always enabled. > Even more complex way could be that the distinction between '1' and > dynamical check could be determined by the caller (if that is the > right place). TRACE_*_ENABLED could be #defined as 0 or 1. > TRACE_*_CHECK_ENABLED() could perform a dynamical check or still > return 1 or 0 if configured to do so. Sounds a little bit over-engineered to me, but having the TRACE_*_ENABLED define and a new 'trace_event_get_state' would make for the most complete solution. Note that this and 'trace_event_get_state' should be changed to work with an enum/define instead of the current string (e.g., adding a 'trace_event_t trace_event_num(char* name)'). Unfortunately, the implementation of 'trace_event_get_state' would be backend-specific, and from what I recall it is not possible on some backend= s to easily get the state of an event with just a couple of lines of code. Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth