gdb, btrace: fix family and model computation

Message ID 20221021121308.294059-1-markus.t.metzger@intel.com
State Committed
Commit d9757bcd43534875d2003962944d3d130289f82c
Headers
Series gdb, btrace: fix family and model computation |

Commit Message

Metzger, Markus T Oct. 21, 2022, 12:13 p.m. UTC
  In gdb/nat/linux-btrace.c:btrace_this_cpu() we initialize the cpu
structure given to the libipt btrace decoder.

We only consider the extended model field for family 0x6 and forget about
family 0xf and we don't consider the extended family field.  Fix it.
---
 gdb/nat/linux-btrace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Tom Tromey Oct. 21, 2022, 3:30 p.m. UTC | #1
>>>>> "Markus" == Markus Metzger via Gdb-patches <gdb-patches@sourceware.org> writes:

Markus> In gdb/nat/linux-btrace.c:btrace_this_cpu() we initialize the cpu
Markus> structure given to the libipt btrace decoder.

Markus> We only consider the extended model field for family 0x6 and forget about
Markus> family 0xf and we don't consider the extended family field.  Fix it.

You should probably just self-approve this.

Markus>  	      cpu.family = (cpuid >> 8) & 0xf;
Markus> -	      cpu.model = (cpuid >> 4) & 0xf;
Markus> +	      if (cpu.family == 0xf)
Markus> +		cpu.family += (cpuid >> 20) & 0xff;
 
Markus> -	      if (cpu.family == 0x6)
Markus> +	      cpu.model = (cpuid >> 4) & 0xf;
Markus> +	      if ((cpu.family == 0x6) || ((cpu.family & 0xf) == 0xf))
Markus>  		cpu.model += (cpuid >> 12) & 0xf0;

I wonder if these magic numbers have #defines anywhere we could use.

Tom
  
Terekhov, Mikhail via Gdb-patches Oct. 24, 2022, 8:19 a.m. UTC | #2
Hello Tom,

>Markus>  	      cpu.family = (cpuid >> 8) & 0xf;
>Markus> -	      cpu.model = (cpuid >> 4) & 0xf;
>Markus> +	      if (cpu.family == 0xf)
>Markus> +		cpu.family += (cpuid >> 20) & 0xff;
>
>Markus> -	      if (cpu.family == 0x6)
>Markus> +	      cpu.model = (cpuid >> 4) & 0xf;
>Markus> +	      if ((cpu.family == 0x6) || ((cpu.family & 0xf) == 0xf))
>Markus>  		cpu.model += (cpuid >> 12) & 0xf0;
>
>I wonder if these magic numbers have #defines anywhere we could use.

In fact,

    bb368aad297 gprofng: a new GNU profiler

added the same functionality, so now we have two versions of it.  I tried
to unify them (attached) but wasn't able to pass gprofng tests on my box.
They already fail without my changes.

I could replace this patch with the attached two.  What do you think?

regards,
markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Tom Tromey Oct. 25, 2022, 4:55 p.m. UTC | #3
> In fact,
>     bb368aad297 gprofng: a new GNU profiler
> added the same functionality, so now we have two versions of it.  I tried
> to unify them (attached) but wasn't able to pass gprofng tests on my box.
> They already fail without my changes.

> I could replace this patch with the attached two.  What do you think?

I wouldn't hold up your patch for this, but if you wanted to coordinate
with the gprofng folks and get this new patch in, it does seem better to
consolidate the code.

Tom
  
Terekhov, Mikhail via Gdb-patches Oct. 28, 2022, 6:46 a.m. UTC | #4
Thanks, Tom,

>> In fact,
>>     bb368aad297 gprofng: a new GNU profiler
>> added the same functionality, so now we have two versions of it.  I tried
>> to unify them (attached) but wasn't able to pass gprofng tests on my box.
>> They already fail without my changes.
>
>> I could replace this patch with the attached two.  What do you think?
>
>I wouldn't hold up your patch for this, but if you wanted to coordinate
>with the gprofng folks and get this new patch in, it does seem better to
>consolidate the code.

I'll push this patch, then, so we get the fix.  Then, I'll send out the other
two to consolidate if there is interest from gprofng.

regards,
markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 4911630ba5c..a951f3b56aa 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -84,9 +84,11 @@  btrace_this_cpu (void)
 	      cpu.vendor = CV_INTEL;
 
 	      cpu.family = (cpuid >> 8) & 0xf;
-	      cpu.model = (cpuid >> 4) & 0xf;
+	      if (cpu.family == 0xf)
+		cpu.family += (cpuid >> 20) & 0xff;
 
-	      if (cpu.family == 0x6)
+	      cpu.model = (cpuid >> 4) & 0xf;
+	      if ((cpu.family == 0x6) || ((cpu.family & 0xf) == 0xf))
 		cpu.model += (cpuid >> 12) & 0xf0;
 	    }
 	}