[PATCH 03/12] perf/x86/intel/uncore: Replace CTL_OFFS8 box flag with type flag
From: Zide Chen
Date: Fri Dec 04 2026 - 22:34:49 EST
Setting UNCORE_BOX_FLAG_CTL_OFFS8 during runtime box initialization
requires custom init_box callbacks, leading to unnecessary custom ops.
Counter control register stride is a static architectural property of
the PMU type, not dynamic runtime state of a box instance. Replacing
UNCORE_BOX_FLAG_CTL_OFFS8 with a 1-bit ctl_offs8 field in struct
intel_uncore_type is not only more accurate, but also allows the stride
to be handled in a more generic way.
Since all discovered PCI types have an 8-byte stride, set ctl_offs8 = 1
in uncore_update_uncore_type(), and set it in all other types whose
boxes currently carry the UNCORE_BOX_FLAG_CTL_OFFS8 flag.
This allows spr_uncore_mmio_offs8_init_box() and the associated ops
to be dropped, paving the way for more generic handling of 8-byte
stride MMIO boxes in DMR and other future platforms.
No functional change intended.
Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
---
arch/x86/events/intel/uncore.h | 7 +++---
arch/x86/events/intel/uncore_discovery.c | 2 +-
arch/x86/events/intel/uncore_snbep.c | 31 +++++++++---------------
3 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index c8dfa2d21bfd..c88949387b7c 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -91,6 +91,7 @@ struct intel_uncore_type {
unsigned num_shared_regs:8;
unsigned single_fixed:1;
unsigned pair_ctr_ctl:1;
+ unsigned ctl_offs8:1; /* counter control registers are 8 bytes apart */
union {
u64 *msr_offsets;
u64 *pci_offsets;
@@ -197,10 +198,8 @@ struct intel_uncore_box {
#define CFL_UNC_CBO_7_PER_CTR0 0xf76
#define UNCORE_BOX_FLAG_INITIALIZED 0
-/* event config registers are 8-byte apart */
-#define UNCORE_BOX_FLAG_CTL_OFFS8 1
/* CFL 8th CBOX has different MSR space */
-#define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2
+#define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 1
struct uncore_event_desc {
struct device_attribute attr;
@@ -327,7 +326,7 @@ static inline unsigned uncore_pci_fixed_ctr(struct intel_uncore_box *box)
static inline
unsigned uncore_pci_event_ctl(struct intel_uncore_box *box, int idx)
{
- if (test_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags))
+ if (box->pmu->type->ctl_offs8)
return idx * 8 + box->pmu->type->event_ctl;
return idx * 4 + box->pmu->type->event_ctl;
diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/intel/uncore_discovery.c
index 99a1b974b14f..75fd3e52c540 100644
--- a/arch/x86/events/intel/uncore_discovery.c
+++ b/arch/x86/events/intel/uncore_discovery.c
@@ -585,7 +585,6 @@ int intel_generic_uncore_pci_init_box(struct intel_uncore_box *box)
if (!box_ctl)
return -ENODEV;
- __set_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags);
return pci_write_config_dword(box->pci_dev, box_ctl,
GENERIC_PMON_BOX_CTL_INT);
}
@@ -746,6 +745,7 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id,
break;
case UNCORE_ACCESS_PCI:
uncore->ops = &generic_uncore_pci_ops;
+ uncore->ctl_offs8 = 1;
break;
case UNCORE_ACCESS_MMIO:
uncore->ops = &generic_uncore_mmio_ops;
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 35212195b379..e0be7a35baec 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -4176,7 +4176,6 @@ static int skx_upi_uncore_pci_init_box(struct intel_uncore_box *box)
{
struct pci_dev *pdev = box->pci_dev;
- __set_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags);
return pci_write_config_dword(pdev, uncore_pci_box_ctl(box),
IVBEP_PMON_BOX_CTL_INT);
}
@@ -4326,6 +4325,7 @@ static struct intel_uncore_type skx_uncore_upi = {
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.event_mask_ext = SKX_UPI_CTL_UMASK_EXT,
.box_ctl = SKX_UPI_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &skx_upi_uncore_pci_ops,
.format_group = &skx_upi_uncore_format_group,
.attr_update = skx_upi_attr_update,
@@ -4338,7 +4338,6 @@ static int skx_m2m_uncore_pci_init_box(struct intel_uncore_box *box)
{
struct pci_dev *pdev = box->pci_dev;
- __set_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags);
return pci_write_config_dword(pdev, SKX_M2M_PCI_PMON_BOX_CTL,
IVBEP_PMON_BOX_CTL_INT);
}
@@ -4361,6 +4360,7 @@ static struct intel_uncore_type skx_uncore_m2m = {
.event_ctl = SKX_M2M_PCI_PMON_CTL0,
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.box_ctl = SKX_M2M_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &skx_m2m_uncore_pci_ops,
.format_group = &skx_uncore_format_group,
};
@@ -4848,7 +4848,6 @@ static int snr_m2m_uncore_pci_init_box(struct intel_uncore_box *box)
struct pci_dev *pdev = box->pci_dev;
int box_ctl = uncore_pci_box_ctl(box);
- __set_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags);
return pci_write_config_dword(pdev, box_ctl, IVBEP_PMON_BOX_CTL_INT);
}
@@ -4885,6 +4884,7 @@ static struct intel_uncore_type snr_uncore_m2m = {
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.event_mask_ext = SNR_M2M_PCI_PMON_UMASK_EXT,
.box_ctl = SNR_M2M_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &snr_m2m_uncore_pci_ops,
.format_group = &snr_m2m_uncore_format_group,
};
@@ -4917,6 +4917,7 @@ static struct intel_uncore_type snr_uncore_pcie3 = {
.event_mask = SKX_IIO_PMON_RAW_EVENT_MASK,
.event_mask_ext = SKX_IIO_PMON_RAW_EVENT_MASK_EXT,
.box_ctl = SNR_PCIE3_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &snr_pcie3_uncore_pci_ops,
.format_group = &skx_uncore_iio_format_group,
};
@@ -5450,6 +5451,7 @@ static struct intel_uncore_type icx_uncore_m2m = {
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.event_mask_ext = SNR_M2M_PCI_PMON_UMASK_EXT,
.box_ctl = SNR_M2M_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &snr_m2m_uncore_pci_ops,
.format_group = &snr_m2m_uncore_format_group,
};
@@ -5549,6 +5551,7 @@ static struct intel_uncore_type icx_uncore_upi = {
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.event_mask_ext = ICX_UPI_CTL_UMASK_EXT,
.box_ctl = ICX_UPI_PCI_PMON_BOX_CTL,
+ .ctl_offs8 = 1,
.ops = &skx_upi_uncore_pci_ops,
.format_group = &icx_upi_uncore_format_group,
.attr_update = icx_upi_attr_update,
@@ -5981,6 +5984,7 @@ static struct intel_uncore_ops spr_uncore_pci_ops = {
#define SPR_UNCORE_PCI_COMMON_FORMAT() \
SPR_UNCORE_COMMON_FORMAT(), \
+ .ctl_offs8 = 1, \
.ops = &spr_uncore_pci_ops
static struct intel_uncore_type spr_uncore_m2m = {
@@ -6020,25 +6024,9 @@ static struct intel_uncore_type spr_uncore_mdf = {
.name = "mdf",
};
-static int spr_uncore_mmio_offs8_init_box(struct intel_uncore_box *box)
-{
- __set_bit(UNCORE_BOX_FLAG_CTL_OFFS8, &box->flags);
- return intel_generic_uncore_mmio_init_box(box);
-}
-
-static struct intel_uncore_ops spr_uncore_mmio_offs8_ops = {
- .init_box = spr_uncore_mmio_offs8_init_box,
- .exit_box = uncore_mmio_exit_box,
- .disable_box = intel_generic_uncore_mmio_disable_box,
- .enable_box = intel_generic_uncore_mmio_enable_box,
- .disable_event = intel_generic_uncore_mmio_disable_event,
- .enable_event = spr_uncore_mmio_enable_event,
- .read_counter = uncore_mmio_read_counter,
-};
-
#define SPR_UNCORE_MMIO_OFFS8_COMMON_FORMAT() \
SPR_UNCORE_COMMON_FORMAT(), \
- .ops = &spr_uncore_mmio_offs8_ops
+ .ctl_offs8 = 1
static struct event_constraint spr_uncore_cxlcm_constraints[] = {
UNCORE_EVENT_CONSTRAINT(0x02, 0x0f),
@@ -6126,6 +6114,7 @@ static struct intel_uncore_type spr_uncore_upi = {
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
.event_mask_ext = SPR_RAW_EVENT_MASK_EXT,
.format_group = &spr_uncore_raw_format_group,
+ .ctl_offs8 = 1,
.ops = &spr_uncore_pci_ops,
.name = "upi",
.attr_update = spr_upi_attr_update,
@@ -6276,6 +6265,8 @@ static void uncore_type_customized_copy(struct intel_uncore_type *to_type,
to_type->num_shared_regs = from_type->num_shared_regs;
if (from_type->constraints)
to_type->constraints = from_type->constraints;
+ if (from_type->ctl_offs8)
+ to_type->ctl_offs8 = from_type->ctl_offs8;
if (from_type->ops)
to_type->ops = from_type->ops;
if (from_type->event_descs)
--
2.56.1