Support additional AMD EILVT registers
Subsystems (2)
v4 cover Support additional AMD EILVT registers
Add support for additional APIC EILVT registers being introduced in future AMD processors:
https://docs.amd.com/v/u/en-US/69205_1.00_AMD64_IBS_PUB)
Since v3 (http://lore.kernel.org/r/[email protected]):
- Move apic_eilvt_count into 'struct apic' (Thomas Gleixner)
- Rename apic_eilvt_count to eilvt_regs_count to more accurately reflect its purpose.
- Naveen
Naveen N Rao (AMD) (3):
perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10 x86/apic: Introduce a variable to track the number of EILVT registers x86/apic: Drop APIC_EILVT_NR_MAX
arch/x86/include/asm/apic.h | 2 ++ arch/x86/include/asm/apicdef.h | 2 +- arch/x86/events/amd/ibs.c | 4 ++-- arch/x86/kernel/apic/apic.c | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
base-commit: 385a91beefc86cb6b7f05b2c3a59b2b82c38c92e
Signature · 1 line
2.54.0
PATCH v4 2/3 x86/apic: Introduce a variable to track the number of EILVT registers
Future AMD processors will be increasing the number of EILVT registers. Rather than hardcoding the maximum EILVT register count and using that everywhere, introduce a variable in 'struct apic' to track the EILVT register count.
The number of EILVT registers is exposed through the extended APIC Feature Register (APIC_EFEAT) bits 23:16. Use this to initialize the count and fall back to the current default (APIC_EILVT_NR_AMD_10H) if the count is not available.
--- arch/x86/include/asm/apic.h | 2 ++ arch/x86/include/asm/apicdef.h | 1 + arch/x86/kernel/apic/apic.c | 10 ++++++++++ 3 files changed, 13 insertions(+)
arch/x86/include/asm/apic.h +2 -0
@@ -317,6 +317,8 @@ struct apic {void (*update_vector)(unsigned int cpu,unsigned int vector,bool set); +u32 eilvt_regs_count; +char *name; };
arch/x86/include/asm/apicdef.h +1 -0
@@ -134,6 +134,7 @@#define APIC_TDR_DIV_64 0x9#define APIC_TDR_DIV_128 0xA#define APIC_EFEAT 0x400 +#define APIC_EFEAT_XLC (x) (((x) >> 16) & 0xff)#define APIC_ECTRL 0x410#define APIC_SEOI 0x420#define APIC_IER 0x480
arch/x86/kernel/apic/apic.c +10 -0
@@ -410,6 +410,15 @@ int setup_APIC_eilvt(u8 offset, u8 vector, u8 msg_type, u8 mask) }EXPORT_SYMBOL_GPL (setup_APIC_eilvt); +static __init void init_eilvt (void ) +{ +if (cpu_feature_enabled (X86_FEATURE_EXTAPIC )) + apic->eilvt_regs_count =APIC_EFEAT_XLC (apic_read (APIC_EFEAT )); + +if (!apic->eilvt_regs_count && boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) + apic->eilvt_regs_count =APIC_EILVT_NR_AMD_10H ; +} +/* * Program the next event, relative to now */
@@ -2345,6 +2354,7 @@ static void __init apic_bsp_setup(bool upmode)if (upmode)apic_bsp_up_setup ();setup_local_APIC (); +init_eilvt ();enable_IO_APIC ();end_local_APIC_setup ();
Signature · 1 line
2.54.0
PATCH v4 3/3 x86/apic: Drop APIC_EILVT_NR_MAX
In reply to Naveen N Rao (AMD)Switch to using apic->eilvt_regs_count as the maximum EILVT register count. Since this value is no longer a compile-time constant, update eilvt_offsets to be dynamically allocated.
--- arch/x86/include/asm/apicdef.h | 1 - arch/x86/kernel/apic/apic.c | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/asm/apicdef.h +0 -1
@@ -140,7 +140,6 @@#define APIC_IER 0x480#define APIC_EILVTn (n) (0x500 + 0x10 * n)#define APIC_EILVT_NR_AMD_10H 4 -#define APIC_EILVT_NR_MAX APIC_EILVT_NR_AMD_10H#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))#define APIC_BASE_MSR 0x800
arch/x86/kernel/apic/apic.c +5 -2
@@ -341,7 +341,7 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)* necessarily a BIOS bug. */ -static atomic_t eilvt_offsets[APIC_EILVT_NR_MAX ]; +static atomic_t *eilvt_offsets;static inline int eilvt_entry_is_changeable (unsigned int old,unsigned int new) {
@@ -354,7 +354,7 @@ static unsigned int reserve_eilvt_offset(int offset, unsigned int new) {unsigned int rsvd, vector; -if (offset >=APIC_EILVT_NR_MAX ) +if (!eilvt_offsets || offset >= apic->eilvt_regs_count)return ~0 ; rsvd =atomic_read (&eilvt_offsets[offset]);
@@ -417,6 +417,9 @@ static __init void init_eilvt(void)if (!apic->eilvt_regs_count && boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) apic->eilvt_regs_count =APIC_EILVT_NR_AMD_10H ; + +if (apic->eilvt_regs_count) + eilvt_offsets =kzalloc_objs (atomic_t, apic->eilvt_regs_count); }/*
Signature · 1 line
2.54.0
PATCH v4 1/3 perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10
In reply to Naveen N Rao (AMD)For AMD family 0x10, EILVT offsets are not assigned by BIOS and is instead assigned by picking the next available EILVT offset. Use the maximum EILVT count for family 0x10 (APIC_EILVT_NR_AMD_10H) rather than an arbitrary maximum EILVT count when looking for the next available EILVT offset.
--- arch/x86/events/amd/ibs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/events/amd/ibs.c +2 -2
@@ -1839,13 +1839,13 @@ static void force_ibs_eilvt_setup(void)preempt_disable ();/* find the next free available EILVT entry, skip offset 0 */ -for (offset =1 ; offset <APIC_EILVT_NR_MAX ; offset++) { +for (offset =1 ; offset <APIC_EILVT_NR_AMD_10H ; offset++) {if (get_eilvt (offset))break ; }preempt_enable (); -if (offset ==APIC_EILVT_NR_MAX ) { +if (offset ==APIC_EILVT_NR_AMD_10H ) {pr_debug ("No EILVT entry available\n" );return ; }
Signature · 1 line
2.54.0
Re: [PATCH v4 1/3] perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10
Quoted 17 lines · Naveen N Rao (AMD)
For AMD family
0x10, EILVT offsets are not assigned by BIOS and is instead assigned by picking the next available EILVT offset. Use the maximum EILVT count for family0x10(APIC_EILVT_NR_AMD_10H) rather than an arbitrary maximum EILVT count when looking for the next available EILVT offset.Signed-off-by Naveen N Rao (AMD) <[email protected]>Tested-by Manali Shukla <[email protected]>--- arch/x86/events/amd/ibs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/events/amd/ibs.c +0
-0
arch/x86/events/amd/ibs.c static void force_ibs_eilvt_setup(void) · line 1842
Quoted 5 lines
arch/x86/events/amd/ibs.c +1
-1@@ -1839,13 +1839,13 @@ static void force_ibs_eilvt_setup(void)preempt_disable ();/* find the next free available EILVT entry, skip offset 0 */ -for (offset =1 ; offset <APIC_EILVT_NR_MAX ; offset++) { +for (offset =1 ; offset <APIC_EILVT_NR_AMD_10H ; offset++) {
Nit:
s/APIC_EILVT_NR_AMD_10H
/APIC_EILVT_NR_MAX_AMD_10H
to make it clear at first sight that this is a (family specific) maximum, not some default count or other random value.
Thanks,
Ingo
Re: [PATCH v4 1/3] perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10
Hi Ingo,
Quoted 28 lines · Ingo Molnar
Quoted 17 lines · Naveen N Rao (AMD)
For AMD family
0x10, EILVT offsets are not assigned by BIOS and is instead assigned by picking the next available EILVT offset. Use the maximum EILVT count for family0x10(APIC_EILVT_NR_AMD_10H) rather than an arbitrary maximum EILVT count when looking for the next available EILVT offset.Signed-off-by Naveen N Rao (AMD) <[email protected]>Tested-by Manali Shukla <[email protected]>--- arch/x86/events/amd/ibs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/events/amd/ibs.c +0
-0arch/x86/events/amd/ibs.c static void force_ibs_eilvt_setup(void) · line 1842
Quoted 5 lines
arch/x86/events/amd/ibs.c +1
-1@@ -1839,13 +1839,13 @@ static void force_ibs_eilvt_setup(void)preempt_disable ();/* find the next free available EILVT entry, skip offset 0 */ -for (offset =1 ; offset <APIC_EILVT_NR_MAX ; offset++) { +for (offset =1 ; offset <APIC_EILVT_NR_AMD_10H ; offset++) {Nit:
Quoted 5 lines
s/APIC_EILVT_NR_AMD_10H
/APIC_EILVT_NR_MAX_AMD_10Hto make it clear at first sight that this is a (family specific) maximum, not some default count or other random value.
Makes sense - I will send that as a separate cleanup on top of this series.
Thanks for the review!
- Naveen
Re: [PATCH v4 1/3] perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10
In reply to Ingo MolnarHi Ingo,
Quoted 28 lines · Ingo Molnar
Quoted 17 lines · Naveen N Rao (AMD)
For AMD family
0x10, EILVT offsets are not assigned by BIOS and is instead assigned by picking the next available EILVT offset. Use the maximum EILVT count for family0x10(APIC_EILVT_NR_AMD_10H) rather than an arbitrary maximum EILVT count when looking for the next available EILVT offset.Signed-off-by Naveen N Rao (AMD) <[email protected]>Tested-by Manali Shukla <[email protected]>--- arch/x86/events/amd/ibs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/events/amd/ibs.c +0
-0arch/x86/events/amd/ibs.c static void force_ibs_eilvt_setup(void) · line 1842
Quoted 5 lines
arch/x86/events/amd/ibs.c +1
-1@@ -1839,13 +1839,13 @@ static void force_ibs_eilvt_setup(void)preempt_disable ();/* find the next free available EILVT entry, skip offset 0 */ -for (offset =1 ; offset <APIC_EILVT_NR_MAX ; offset++) { +for (offset =1 ; offset <APIC_EILVT_NR_AMD_10H ; offset++) {Nit:
Quoted 5 lines
s/APIC_EILVT_NR_AMD_10H
/APIC_EILVT_NR_MAX_AMD_10Hto make it clear at first sight that this is a (family specific) maximum, not some default count or other random value.
While trying to make this change, I realized _NR_MAX_ may not be accurate either.
APIC_EILVT_NR_AMD_10H is actually representing the number of EILVT registers on AMD processor family 0x10 as a fixed entity (not a family specific maximum which would imply that the count can be less). This particular function (force_ibs_eilvt_setup()) is specific to AMD 0x10 family. So, the name does seem reasonable to me in hindsight.
I believe its use in the for loop above, and going from a macro that represents a generic maximum count to a family-specific count feels less intuitive.
I'm leaning towards retaining the current name or renaming it to APIC_EILVT_COUNT_AMD_10H to represent the EILVT register count.
Thoughts?
Thanks,
Naveen