Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [patch] add trace capabilities to arm sim
       [not found] <200102240025.TAA28612@greed.delorie.com>
@ 2001-02-26 10:40 ` Richard Earnshaw
  2001-02-26 10:57   ` DJ Delorie
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Earnshaw @ 2001-02-26 10:40 UTC (permalink / raw)
  To: DJ Delorie; +Cc: gdb-patches, Richard.Earnshaw

I haven't seen anyone else comment on this, so I'll stick my nose in ;-)

I can't approve or reject this patch, but:


> 2001-02-23  DJ Delorie  <dj@redhat.com>
> 
> 	* armemu.c (ARMul_Emulate): Add hook for tracing.
> 	* wrapper.c (current_bfd): New, remembers which bfd we're
> 	simulating.
> 	(sim_dis_read): New, helper for tracing.
> 	(remove_useless_symbols): New, helper for tracing.  From objdump.
> 	(compare_symbols): Ditto.
> 	(sim_trace_one_arm_insn): New, trace one instruction using
> 	disassembler.
> 	(sim_trace): Make it do something useful now.
> 	(sim_create_inferior): Save current bfd.
> 	(sim_open): Ditto.
> 	(sim_load): Ditto.
> 	(sim_do_command): Handle the `trace' command.
> 
> 	* wrapper.c (ARMul_Debug): Return insn just in case we're called.
> 

> --- armemu.c	2001/02/24 00:24:39
> *************** ARMul_Emulate26 (register ARMul_State * 
> *** 377,382 ****
> --- 377,383 ----
>         if (instr == 0)
>   	abort ();
>   #endif
> +       sim_trace_one_arm_insn (pc, instr);

This will bump up the cost of simulating each instruction by the overhead 
of this call plus any code within that always gets executed.

Since tracing is going to slow the simulation to a crawl, I think it would 
be better to consider this an "exceptional condition"; that is, put the 
code inside the immediately following test:

>   
>         if (state->Exception)
>   	{			/* Any exceptions */

and then bump state->Exception (which behaves pretty much like a semaphore 
count on the number of extra things to go look at) when tracing needs to 
run.

> + void
> + sim_trace_one_arm_insn(pc, insn)
> + 	      int pc;
> + 	      unsigned int insn;
> + {
> +   static int initted = 0;
> +   static asymbol **symtab = 0;
> +   static int symcount = 0;
> +   static int last_sym = -1;
> +   static struct disassemble_info info;
> +   int storage, sym, bestsym, bestaddr;
> +   int min, max, i, pnl;
> +   static ARMword prevregs[16];
> + 
> +   if (insn == 0)
> +     {
> +       state->Emulate = STOP;

why should executing the (legal) instruction

	andeq	r0, r0, r0

cause the simulation to halt (OK, it's not very useful, but it is a valid 
NOP)?

> +       return;
> +     }
> +   if (current_bfd == 0)
> +     return;
> +   if (!do_tracing)
> +     return;

Shouldn't this be the first thing you check?

>   int
>   sim_trace (sd)
>        SIM_DESC sd ATTRIBUTE_UNUSED;

It is used now... (this is also where you might bump/unbump state->
Exception).

> ! {
> !   do_tracing = 1;
> !   sim_resume(sd, 0, 0);
> !   do_tracing = 0;
>     return 1;
>   }
>   

You'd also need to do it here (but a bit more subtly...

>   sim_do_command (sd, cmd)
>        SIM_DESC sd ATTRIBUTE_UNUSED;
>        char *cmd ATTRIBUTE_UNUSED;
> ! {
> !   if (strcmp(cmd, "trace") == 0)
> !     {
> !       do_tracing = !do_tracing;
> !       if (do_tracing)
> ! 	(*sim_callback->printf_filtered) (sim_callback,
> ! 					  "Tracing on.\n");
> !       else
> ! 	(*sim_callback->printf_filtered) (sim_callback,
> ! 					  "Tracing off.\n");
> !     }
> !   else
> ! 	(*sim_callback->printf_filtered) (sim_callback,
> ! 					  "Unknown command, only `trace' allowed.\n");
>   }
>   
>   

R.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
  2001-02-26 10:40 ` [patch] add trace capabilities to arm sim Richard Earnshaw
@ 2001-02-26 10:57   ` DJ Delorie
  2001-02-26 11:02     ` Richard Earnshaw
  0 siblings, 1 reply; 7+ messages in thread
From: DJ Delorie @ 2001-02-26 10:57 UTC (permalink / raw)
  To: Richard.Earnshaw; +Cc: gdb-patches

> > +       sim_trace_one_arm_insn (pc, instr);
> 
> This will bump up the cost of simulating each instruction by the overhead 
> of this call plus any code within that always gets executed.

OK, I hadn't looked at the state->Exception check as a generic "check things"
but that makes sense.


> > +   if (insn == 0)
> > +     {
> > +       state->Emulate = STOP;
> 
> why should executing the (legal) instruction
> 
> 	andeq	r0, r0, r0
> 
> cause the simulation to halt (OK, it's not very useful, but it is a valid 
> NOP)?

I took that from a commented out debug check in the emulator.  The
idea was to trap when the thread of execution left the code space and
either hit zeros in the data space, or left RAM completely.  I'll take
it out now that I know it's a valid opcode.

> > +   if (!do_tracing)
> > +     return;
> 
> Shouldn't this be the first thing you check?

Either way worked for me, but I can make it first.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
  2001-02-26 10:57   ` DJ Delorie
@ 2001-02-26 11:02     ` Richard Earnshaw
  2001-02-26 11:12       ` DJ Delorie
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Earnshaw @ 2001-02-26 11:02 UTC (permalink / raw)
  To: DJ Delorie; +Cc: Richard.Earnshaw, gdb-patches

dj@redhat.com said:
> > +   if (!do_tracing)
> > +     return;
> 
> > Shouldn't this be the first thing you check?
> Either way worked for me, but I can make it first.

I'd go one step further.  Move the check to the caller side.

R.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
  2001-02-26 11:02     ` Richard Earnshaw
@ 2001-02-26 11:12       ` DJ Delorie
  2001-02-27  1:47         ` Richard Earnshaw
  0 siblings, 1 reply; 7+ messages in thread
From: DJ Delorie @ 2001-02-26 11:12 UTC (permalink / raw)
  To: Richard.Earnshaw; +Cc: gdb-patches

> I'd go one step further.  Move the check to the caller side.

(1) wouldn't the state->Exceptions check effectively do that?

(2) I'd have to make do_tracing global if I did that.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
  2001-02-26 11:12       ` DJ Delorie
@ 2001-02-27  1:47         ` Richard Earnshaw
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Earnshaw @ 2001-02-27  1:47 UTC (permalink / raw)
  To: DJ Delorie; +Cc: Richard.Earnshaw, gdb-patches

> 
> > I'd go one step further.  Move the check to the caller side.
> 
> (1) wouldn't the state->Exceptions check effectively do that?

Well, it would help, but it is also enabled for other things.

> 
> (2) I'd have to make do_tracing global if I did that.

That brings up another issue.  What if there is more than one ARM model in 
a simulation?  Shouldn't the variable be made part of the "State" anyway?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
  2001-02-27  6:26 ` Richard Earnshaw
@ 2001-02-27  7:08   ` Andrew Cagney
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Cagney @ 2001-02-27  7:08 UTC (permalink / raw)
  To: Richard.Earnshaw; +Cc: Frank Ch. Eigler, DJ Delorie, gdb-patches

The ARM simulator doesn't use sim/common so this is strictly a BTW.

sim/common simulators address performance concerns such as function call
overhead using two techniques:

	o	inline

	o	compile time
		enabling of features

code would we written as:

	do_trace_stuff (....)

and then, when the compiler supported it, ``do_trace_stuff'' might or
might not be inlined.


The second bit of trivia relates to Frank's comment.  Performance
analysis of simulators has shown that some stuff, like tracing, should
be left as separate functions.  The likely reason was that inlining the
code blew out the host CPU cache.

For what it is worth.

	Andrew


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] add trace capabilities to arm sim
       [not found] <o53dd1w76u.fsf@toenail.toronto.redhat.com>
@ 2001-02-27  6:26 ` Richard Earnshaw
  2001-02-27  7:08   ` Andrew Cagney
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Earnshaw @ 2001-02-27  6:26 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: Richard.Earnshaw, DJ Delorie, gdb-patches

> 
> Richard Earnshaw <rearnsha@arm.com> writes:
> 
> : I haven't seen anyone else comment on this, so I'll stick my nose in ;-)
> : I can't approve or reject this patch, but:
> 
> Thanks - your input is always appreciated.
> 
> 
> : [...]
> : >         if (state->Exception)
> : >   	{			/* Any exceptions */
> : 
> : and then bump state->Exception (which behaves pretty much like a semaphore 
> : count on the number of extra things to go look at) when tracing needs to 
> : run.
> 
> An interesting technique!  Have you tried using gcc's __builtin_expect
> function to provide branch (un)likelihood hints to the compiler,
> instead of this method?

Well, it would have a marginal benefit on those hosts that support branch 
prediction, but you would still need to do each check.  As long as we 
don't get to the point where state->Exception is more often true than 
false, it is still a benefit to wrap them all up into a single pre-check.

R.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-02-27  7:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200102240025.TAA28612@greed.delorie.com>
2001-02-26 10:40 ` [patch] add trace capabilities to arm sim Richard Earnshaw
2001-02-26 10:57   ` DJ Delorie
2001-02-26 11:02     ` Richard Earnshaw
2001-02-26 11:12       ` DJ Delorie
2001-02-27  1:47         ` Richard Earnshaw
     [not found] <o53dd1w76u.fsf@toenail.toronto.redhat.com>
2001-02-27  6:26 ` Richard Earnshaw
2001-02-27  7:08   ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox