perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array
authorKan Liang <kan.liang@linux.intel.com>
Fri, 17 Nov 2023 16:39:36 +0000 (08:39 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 24 Nov 2023 19:25:01 +0000 (20:25 +0100)
The current perf doesn't save the complete address of an uncore unit.
The complete address of each unit is calculated by the base address +
offset. The type of the base address is u64, while the type of offset is
unsigned.
In the old platforms (without the discovery table method), the base
address and offset are hard coded in the driver. Perf can always use the
lowest address as the base address. Everything works well.

In the new platforms (starting from SPR), the discovery table provides
a complete address for all uncore units. To follow the current
framework/codes, when parsing the discovery table, the complete address
of the first box is stored as a base address. The offset of the
following units is calculated by the complete address of the unit minus
the base address (the address of the first unit). On GNR, the latter
units may have a lower address compared to the first unit. So the offset
is a negative value. The upper 32 bits are lost when casting a negative
u64 to an unsigned type.

Use u64 to replace unsigned for the uncore offsets array to correct the
above case. There is no functional change.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Ammy Yi <ammy.yi@intel.com>
Link: https://lore.kernel.org/r/20231117163939.2468007-2-kan.liang@linux.intel.com
arch/x86/events/intel/uncore.h
arch/x86/events/intel/uncore_discovery.c
arch/x86/events/intel/uncore_discovery.h
arch/x86/events/intel/uncore_nhmex.c
arch/x86/events/intel/uncore_snbep.c

index c30fb5bb1222b39ed54e4eabc28e1fd826b03455..7428ecaddf72d99b1160dca1a894b20d7fdfdc8b 100644 (file)
@@ -72,9 +72,9 @@ struct intel_uncore_type {
        unsigned single_fixed:1;
        unsigned pair_ctr_ctl:1;
        union {
-               unsigned *msr_offsets;
-               unsigned *pci_offsets;
-               unsigned *mmio_offsets;
+               u64 *msr_offsets;
+               u64 *pci_offsets;
+               u64 *mmio_offsets;
        };
        unsigned *box_ids;
        struct event_constraint unconstrainted;
index cb488e41807c76cbf7c200c88be9ceff97ff04d2..9a698a92962a10a3c10e70c1ca393603b2f551db 100644 (file)
@@ -125,7 +125,8 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit,
                       int die, bool parsed)
 {
        struct intel_uncore_discovery_type *type;
-       unsigned int *box_offset, *ids;
+       unsigned int *ids;
+       u64 *box_offset;
        int i;
 
        if (!unit->ctl || !unit->ctl_offset || !unit->ctr_offset) {
@@ -153,7 +154,7 @@ uncore_insert_box_info(struct uncore_unit_discovery *unit,
        if (!type)
                return;
 
-       box_offset = kcalloc(type->num_boxes + 1, sizeof(unsigned int), GFP_KERNEL);
+       box_offset = kcalloc(type->num_boxes + 1, sizeof(u64), GFP_KERNEL);
        if (!box_offset)
                return;
 
index 6ee80ad3423e4e71d68d6da9fd7214cf3a0f33e0..22e769a81103935d52e9e92c086d022a96864007 100644 (file)
@@ -125,7 +125,7 @@ struct intel_uncore_discovery_type {
        u8              ctr_offset;     /* Counter 0 offset */
        u16             num_boxes;      /* number of boxes for the uncore block */
        unsigned int    *ids;           /* Box IDs */
-       unsigned int    *box_offset;    /* Box offset */
+       u64             *box_offset;    /* Box offset */
 };
 
 bool intel_uncore_has_discovery_tables(int *ignore);
index 173e2674be6ef24293c5113b43d738af3d3f1981..56eea2c66cfb8cc7d9cc395e58c24a7319afc944 100644 (file)
@@ -306,7 +306,7 @@ static const struct attribute_group nhmex_uncore_cbox_format_group = {
 };
 
 /* msr offset for each instance of cbox */
-static unsigned nhmex_cbox_msr_offsets[] = {
+static u64 nhmex_cbox_msr_offsets[] = {
        0x0, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x240, 0x2c0,
 };
 
index fc6587016af7c60c08cabc83c6cea89b8681ae66..344319ab6dd52dfc6778a8fda978771b3805c13d 100644 (file)
@@ -5278,7 +5278,7 @@ void snr_uncore_mmio_init(void)
 
 /* ICX uncore support */
 
-static unsigned icx_cha_msr_offsets[] = {
+static u64 icx_cha_msr_offsets[] = {
        0x2a0, 0x2ae, 0x2bc, 0x2ca, 0x2d8, 0x2e6, 0x2f4, 0x302, 0x310,
        0x31e, 0x32c, 0x33a, 0x348, 0x356, 0x364, 0x372, 0x380, 0x38e,
        0x3aa, 0x3b8, 0x3c6, 0x3d4, 0x3e2, 0x3f0, 0x3fe, 0x40c, 0x41a,
@@ -5326,7 +5326,7 @@ static struct intel_uncore_type icx_uncore_chabox = {
        .format_group           = &snr_uncore_chabox_format_group,
 };
 
-static unsigned icx_msr_offsets[] = {
+static u64 icx_msr_offsets[] = {
        0x0, 0x20, 0x40, 0x90, 0xb0, 0xd0,
 };
 
@@ -6184,7 +6184,7 @@ static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = {
  */
 #define SPR_UNCORE_UPI_NUM_BOXES       4
 
-static unsigned int spr_upi_pci_offsets[SPR_UNCORE_UPI_NUM_BOXES] = {
+static u64 spr_upi_pci_offsets[SPR_UNCORE_UPI_NUM_BOXES] = {
        0, 0x8000, 0x10000, 0x18000
 };