Commit 4e5904b5 authored by Kan Liang's avatar Kan Liang Committed by Yunying Sun
Browse files

perf/x86/intel/uncore: Generic uncore_get_uncores and MMIO format of SPR

mainline inclusion
from mainline-v6.8-rc1
commit cf35791476fcb3230b98a42241a56242d60ebdd3
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I8YW2E
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cf35791476fcb3230b98a42241a56242d60ebdd3



-------------------------------------

Factor out SPR_UNCORE_MMIO_COMMON_FORMAT which can be reused by
Granite Rapids in the following patch.

Granite Rapids have more uncore units than Sapphire Rapids. Add new
parameters to support adjustable uncore units.

No functional change.

Intel-SIG: commit cf35791476fc perf/x86/intel/uncore: Generic uncore_get_uncores and MMIO format of SPR
Backport GNR/SRF PMU uncore support to kernel 5.10.

Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: default avatarAmmy Yi <ammy.yi@intel.com>
Link: https://lore.kernel.org/r/20231117163939.2468007-1-kan.liang@linux.intel.com


Signed-off-by: default avatarYunying Sun <yunying.sun@intel.com>
parent 263f00bd
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -5586,13 +5586,16 @@ static struct intel_uncore_ops spr_uncore_mmio_ops = {
	.read_counter		= uncore_mmio_read_counter,
};

#define SPR_UNCORE_MMIO_COMMON_FORMAT()				\
	SPR_UNCORE_COMMON_FORMAT(),				\
	.ops			= &spr_uncore_mmio_ops

static struct intel_uncore_type spr_uncore_imc = {
	SPR_UNCORE_COMMON_FORMAT(),
	SPR_UNCORE_MMIO_COMMON_FORMAT(),
	.name			= "imc",
	.fixed_ctr_bits		= 48,
	.fixed_ctr		= SNR_IMC_MMIO_PMON_FIXED_CTR,
	.fixed_ctl		= SNR_IMC_MMIO_PMON_FIXED_CTL,
	.ops			= &spr_uncore_mmio_ops,
};

static void spr_uncore_pci_enable_event(struct intel_uncore_box *box,
@@ -5878,7 +5881,8 @@ static void uncore_type_customized_copy(struct intel_uncore_type *to_type,

static struct intel_uncore_type **
uncore_get_uncores(enum uncore_access_type type_id, int num_extra,
		    struct intel_uncore_type **extra)
		   struct intel_uncore_type **extra, int max_num_types,
		   struct intel_uncore_type **uncores)
{
	struct intel_uncore_type **types, **start_types;
	int i;
@@ -5887,9 +5891,9 @@ uncore_get_uncores(enum uncore_access_type type_id, int num_extra,

	/* Only copy the customized features */
	for (; *types; types++) {
		if ((*types)->type_id >= UNCORE_SPR_NUM_UNCORE_TYPES)
		if ((*types)->type_id >= max_num_types)
			continue;
		uncore_type_customized_copy(*types, spr_uncores[(*types)->type_id]);
		uncore_type_customized_copy(*types, uncores[(*types)->type_id]);
	}

	for (i = 0; i < num_extra; i++, types++)
@@ -5936,7 +5940,9 @@ void spr_uncore_cpu_init(void)

	uncore_msr_uncores = uncore_get_uncores(UNCORE_ACCESS_MSR,
						UNCORE_SPR_MSR_EXTRA_UNCORES,
						spr_msr_uncores);
						spr_msr_uncores,
						UNCORE_SPR_NUM_UNCORE_TYPES,
						spr_uncores);

	type = uncore_find_type_by_id(uncore_msr_uncores, UNCORE_SPR_CHA);
	if (type) {
@@ -6018,7 +6024,9 @@ int spr_uncore_pci_init(void)
	spr_update_device_location(UNCORE_SPR_M3UPI);
	uncore_pci_uncores = uncore_get_uncores(UNCORE_ACCESS_PCI,
						UNCORE_SPR_PCI_EXTRA_UNCORES,
						spr_pci_uncores);
						spr_pci_uncores,
						UNCORE_SPR_NUM_UNCORE_TYPES,
						spr_uncores);
	return 0;
}

@@ -6026,12 +6034,16 @@ void spr_uncore_mmio_init(void)
{
	int ret = snbep_pci2phy_map_init(0x3250, SKX_CPUNODEID, SKX_GIDNIDMAP, true);

	if (ret)
		uncore_mmio_uncores = uncore_get_uncores(UNCORE_ACCESS_MMIO, 0, NULL);
	else {
	if (ret) {
		uncore_mmio_uncores = uncore_get_uncores(UNCORE_ACCESS_MMIO, 0, NULL,
							 UNCORE_SPR_NUM_UNCORE_TYPES,
							 spr_uncores);
	} else {
		uncore_mmio_uncores = uncore_get_uncores(UNCORE_ACCESS_MMIO,
							 UNCORE_SPR_MMIO_EXTRA_UNCORES,
							 spr_mmio_uncores);
							 spr_mmio_uncores,
							 UNCORE_SPR_NUM_UNCORE_TYPES,
							 spr_uncores);

		spr_uncore_imc_free_running.num_boxes = uncore_type_max_boxes(uncore_mmio_uncores, UNCORE_SPR_IMC) / 2;
	}