qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [patch] performance counters from inside of Qemu


From: Lluís
Subject: Re: [Qemu-devel] [patch] performance counters from inside of Qemu
Date: Tue, 09 Nov 2010 22:02:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Vince Weaver writes:
[...]
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 26ea1e5..f2aa2d7 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -31,6 +31,20 @@
 
>  //#define DEBUG_MMU
 
> +long long global_ins_count[3] = {0,0,0};
> +
> +void helper_insn_count(unsigned int cpl);
> +
> +void helper_insn_count(unsigned int cpl) {
> +   if (cpl==0) {
> +      global_ins_count[1]++;
> +   }
> +   else if (cpl==3) {
> +      global_ins_count[0]++;  
> +   }
> +   /* FIXME -- handle overflow interrupts */
> +}
> +
>  /* NOTE: must be called outside the CPU execute loop */
>  void cpu_reset(CPUX86State *env)
>  {
> diff --git a/target-i386/translate.c b/target-i386/translate.c
> index 7b6e3c2..1d8f95e 100644
> --- a/target-i386/translate.c
> +++ b/target-i386/translate.c
> @@ -4215,6 +4215,15 @@ static target_ulong disas_insn(DisasContext *s, 
> target_ulong pc_start)
>      if (prefixes & PREFIX_LOCK)
>          gen_helper_lock();
 
> +    {
> +        /* vmw */
> +     TCGv const1;
> +
> +     const1 = tcg_const_i32(s->cpl);
> +        gen_helper_insn_count(const1);
> +        tcg_temp_free(const1);     
> +   }
> +      
>      /* now check op code */
>   reswitch:
>      switch(b) {

Maybe you should use a per-vCPU "ins_count" array, so that these
counters would support CMP.

In addition, instead of using a helper, you could use the following to
speed up the execution (as this will be present on each instruction):

      tcg_gen_add_i64(cpu_T[0], cpu_env, offsetof(CPUState, ins_count[s->cpl]));
      tcg_gen_addi(cpu_T[0], cpu_T[0], 1);

Haven't checked if this TCG is correct, though (and still does not check
for overflows).

In any case, I think this kind of counting has some overlapping with the
"icount" infrastructure (cpu_get_icount), so maybe you could update the
per-vCPU "ins_count" lazily using the "icount" counters (e.g., add to
"ins_count" when "icount_decr" expires or a TB ends, plus fine-sync when
reading the MSRs). Of course, then you would need to force the usage of
icount.


Lluis

-- 
 "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



reply via email to

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