Skip to content

Commit 0378c93

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Support IIO free-running counters on Sapphire Rapids server
Several free-running counters for IIO uncore blocks are supported on Sapphire Rapids server. They are not enumerated in the discovery tables. Extend generic_init_uncores() to support extra uncore types. The uncore types for the free-running counters is inserted right after the uncore types retrieved from the discovery table. The number of the free-running counter boxes is calculated from the max number of the corresponding standard boxes. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1583971 commit 0378c93

File tree

3 files changed

+136
-11
lines changed

3 files changed

+136
-11
lines changed

arch/x86/events/intel/uncore_discovery.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,15 @@ static bool uncore_update_uncore_type(enum uncore_access_type type_id,
569569
}
570570

571571
struct intel_uncore_type **
572-
intel_uncore_generic_init_uncores(enum uncore_access_type type_id)
572+
intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extra)
573573
{
574574
struct intel_uncore_discovery_type *type;
575575
struct intel_uncore_type **uncores;
576576
struct intel_uncore_type *uncore;
577577
struct rb_node *node;
578578
int i = 0;
579579

580-
uncores = kcalloc(num_discovered_types[type_id] + 1,
580+
uncores = kcalloc(num_discovered_types[type_id] + num_extra + 1,
581581
sizeof(struct intel_uncore_type *), GFP_KERNEL);
582582
if (!uncores)
583583
return empty_uncore;
@@ -606,17 +606,17 @@ intel_uncore_generic_init_uncores(enum uncore_access_type type_id)
606606

607607
void intel_uncore_generic_uncore_cpu_init(void)
608608
{
609-
uncore_msr_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_MSR);
609+
uncore_msr_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_MSR, 0);
610610
}
611611

612612
int intel_uncore_generic_uncore_pci_init(void)
613613
{
614-
uncore_pci_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_PCI);
614+
uncore_pci_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_PCI, 0);
615615

616616
return 0;
617617
}
618618

619619
void intel_uncore_generic_uncore_mmio_init(void)
620620
{
621-
uncore_mmio_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_MMIO);
621+
uncore_mmio_uncores = intel_uncore_generic_init_uncores(UNCORE_ACCESS_MMIO, 0);
622622
}

arch/x86/events/intel/uncore_discovery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ u64 intel_generic_uncore_pci_read_counter(struct intel_uncore_box *box,
149149
struct perf_event *event);
150150

151151
struct intel_uncore_type **
152-
intel_uncore_generic_init_uncores(enum uncore_access_type type_id);
152+
intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extra);

arch/x86/events/intel/uncore_snbep.c

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5752,6 +5752,7 @@ static struct intel_uncore_type spr_uncore_mdf = {
57525752
};
57535753

57545754
#define UNCORE_SPR_NUM_UNCORE_TYPES 12
5755+
#define UNCORE_SPR_IIO 1
57555756

57565757
static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = {
57575758
&spr_uncore_chabox,
@@ -5768,6 +5769,92 @@ static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = {
57685769
&spr_uncore_mdf,
57695770
};
57705771

5772+
enum perf_uncore_spr_iio_freerunning_type_id {
5773+
SPR_IIO_MSR_IOCLK,
5774+
SPR_IIO_MSR_BW_IN,
5775+
SPR_IIO_MSR_BW_OUT,
5776+
5777+
SPR_IIO_FREERUNNING_TYPE_MAX,
5778+
};
5779+
5780+
static struct freerunning_counters spr_iio_freerunning[] = {
5781+
[SPR_IIO_MSR_IOCLK] = { 0x340e, 0x1, 0x10, 1, 48 },
5782+
[SPR_IIO_MSR_BW_IN] = { 0x3800, 0x1, 0x10, 8, 48 },
5783+
[SPR_IIO_MSR_BW_OUT] = { 0x3808, 0x1, 0x10, 8, 48 },
5784+
};
5785+
5786+
static struct uncore_event_desc spr_uncore_iio_freerunning_events[] = {
5787+
/* Free-Running IIO CLOCKS Counter */
5788+
INTEL_UNCORE_EVENT_DESC(ioclk, "event=0xff,umask=0x10"),
5789+
/* Free-Running IIO BANDWIDTH IN Counters */
5790+
INTEL_UNCORE_EVENT_DESC(bw_in_port0, "event=0xff,umask=0x20"),
5791+
INTEL_UNCORE_EVENT_DESC(bw_in_port0.scale, "3.814697266e-6"),
5792+
INTEL_UNCORE_EVENT_DESC(bw_in_port0.unit, "MiB"),
5793+
INTEL_UNCORE_EVENT_DESC(bw_in_port1, "event=0xff,umask=0x21"),
5794+
INTEL_UNCORE_EVENT_DESC(bw_in_port1.scale, "3.814697266e-6"),
5795+
INTEL_UNCORE_EVENT_DESC(bw_in_port1.unit, "MiB"),
5796+
INTEL_UNCORE_EVENT_DESC(bw_in_port2, "event=0xff,umask=0x22"),
5797+
INTEL_UNCORE_EVENT_DESC(bw_in_port2.scale, "3.814697266e-6"),
5798+
INTEL_UNCORE_EVENT_DESC(bw_in_port2.unit, "MiB"),
5799+
INTEL_UNCORE_EVENT_DESC(bw_in_port3, "event=0xff,umask=0x23"),
5800+
INTEL_UNCORE_EVENT_DESC(bw_in_port3.scale, "3.814697266e-6"),
5801+
INTEL_UNCORE_EVENT_DESC(bw_in_port3.unit, "MiB"),
5802+
INTEL_UNCORE_EVENT_DESC(bw_in_port4, "event=0xff,umask=0x24"),
5803+
INTEL_UNCORE_EVENT_DESC(bw_in_port4.scale, "3.814697266e-6"),
5804+
INTEL_UNCORE_EVENT_DESC(bw_in_port4.unit, "MiB"),
5805+
INTEL_UNCORE_EVENT_DESC(bw_in_port5, "event=0xff,umask=0x25"),
5806+
INTEL_UNCORE_EVENT_DESC(bw_in_port5.scale, "3.814697266e-6"),
5807+
INTEL_UNCORE_EVENT_DESC(bw_in_port5.unit, "MiB"),
5808+
INTEL_UNCORE_EVENT_DESC(bw_in_port6, "event=0xff,umask=0x26"),
5809+
INTEL_UNCORE_EVENT_DESC(bw_in_port6.scale, "3.814697266e-6"),
5810+
INTEL_UNCORE_EVENT_DESC(bw_in_port6.unit, "MiB"),
5811+
INTEL_UNCORE_EVENT_DESC(bw_in_port7, "event=0xff,umask=0x27"),
5812+
INTEL_UNCORE_EVENT_DESC(bw_in_port7.scale, "3.814697266e-6"),
5813+
INTEL_UNCORE_EVENT_DESC(bw_in_port7.unit, "MiB"),
5814+
/* Free-Running IIO BANDWIDTH OUT Counters */
5815+
INTEL_UNCORE_EVENT_DESC(bw_out_port0, "event=0xff,umask=0x30"),
5816+
INTEL_UNCORE_EVENT_DESC(bw_out_port0.scale, "3.814697266e-6"),
5817+
INTEL_UNCORE_EVENT_DESC(bw_out_port0.unit, "MiB"),
5818+
INTEL_UNCORE_EVENT_DESC(bw_out_port1, "event=0xff,umask=0x31"),
5819+
INTEL_UNCORE_EVENT_DESC(bw_out_port1.scale, "3.814697266e-6"),
5820+
INTEL_UNCORE_EVENT_DESC(bw_out_port1.unit, "MiB"),
5821+
INTEL_UNCORE_EVENT_DESC(bw_out_port2, "event=0xff,umask=0x32"),
5822+
INTEL_UNCORE_EVENT_DESC(bw_out_port2.scale, "3.814697266e-6"),
5823+
INTEL_UNCORE_EVENT_DESC(bw_out_port2.unit, "MiB"),
5824+
INTEL_UNCORE_EVENT_DESC(bw_out_port3, "event=0xff,umask=0x33"),
5825+
INTEL_UNCORE_EVENT_DESC(bw_out_port3.scale, "3.814697266e-6"),
5826+
INTEL_UNCORE_EVENT_DESC(bw_out_port3.unit, "MiB"),
5827+
INTEL_UNCORE_EVENT_DESC(bw_out_port4, "event=0xff,umask=0x34"),
5828+
INTEL_UNCORE_EVENT_DESC(bw_out_port4.scale, "3.814697266e-6"),
5829+
INTEL_UNCORE_EVENT_DESC(bw_out_port4.unit, "MiB"),
5830+
INTEL_UNCORE_EVENT_DESC(bw_out_port5, "event=0xff,umask=0x35"),
5831+
INTEL_UNCORE_EVENT_DESC(bw_out_port5.scale, "3.814697266e-6"),
5832+
INTEL_UNCORE_EVENT_DESC(bw_out_port5.unit, "MiB"),
5833+
INTEL_UNCORE_EVENT_DESC(bw_out_port6, "event=0xff,umask=0x36"),
5834+
INTEL_UNCORE_EVENT_DESC(bw_out_port6.scale, "3.814697266e-6"),
5835+
INTEL_UNCORE_EVENT_DESC(bw_out_port6.unit, "MiB"),
5836+
INTEL_UNCORE_EVENT_DESC(bw_out_port7, "event=0xff,umask=0x37"),
5837+
INTEL_UNCORE_EVENT_DESC(bw_out_port7.scale, "3.814697266e-6"),
5838+
INTEL_UNCORE_EVENT_DESC(bw_out_port7.unit, "MiB"),
5839+
{ /* end: all zeroes */ },
5840+
};
5841+
5842+
static struct intel_uncore_type spr_uncore_iio_free_running = {
5843+
.name = "iio_free_running",
5844+
.num_counters = 17,
5845+
.num_freerunning_types = SPR_IIO_FREERUNNING_TYPE_MAX,
5846+
.freerunning = spr_iio_freerunning,
5847+
.ops = &skx_uncore_iio_freerunning_ops,
5848+
.event_descs = spr_uncore_iio_freerunning_events,
5849+
.format_group = &skx_uncore_iio_freerunning_format_group,
5850+
};
5851+
5852+
#define UNCORE_SPR_MSR_EXTRA_UNCORES 1
5853+
5854+
static struct intel_uncore_type *spr_msr_uncores[UNCORE_SPR_MSR_EXTRA_UNCORES] = {
5855+
&spr_uncore_iio_free_running,
5856+
};
5857+
57715858
static void uncore_type_customized_copy(struct intel_uncore_type *to_type,
57725859
struct intel_uncore_type *from_type)
57735860
{
@@ -5803,11 +5890,13 @@ static void uncore_type_customized_copy(struct intel_uncore_type *to_type,
58035890
}
58045891

58055892
static struct intel_uncore_type **
5806-
uncore_get_uncores(enum uncore_access_type type_id)
5893+
uncore_get_uncores(enum uncore_access_type type_id, int num_extra,
5894+
struct intel_uncore_type **extra)
58075895
{
58085896
struct intel_uncore_type **types, **start_types;
5897+
int i;
58095898

5810-
start_types = types = intel_uncore_generic_init_uncores(type_id);
5899+
start_types = types = intel_uncore_generic_init_uncores(type_id, num_extra);
58115900

58125901
/* Only copy the customized features */
58135902
for (; *types; types++) {
@@ -5816,23 +5905,59 @@ uncore_get_uncores(enum uncore_access_type type_id)
58165905
uncore_type_customized_copy(*types, spr_uncores[(*types)->type_id]);
58175906
}
58185907

5908+
for (i = 0; i < num_extra; i++, types++)
5909+
*types = extra[i];
5910+
58195911
return start_types;
58205912
}
58215913

5914+
static struct intel_uncore_type *
5915+
uncore_find_type_by_id(struct intel_uncore_type **types, int type_id)
5916+
{
5917+
for (; *types; types++) {
5918+
if (type_id == (*types)->type_id)
5919+
return *types;
5920+
}
5921+
5922+
return NULL;
5923+
}
5924+
5925+
static int uncore_type_max_boxes(struct intel_uncore_type **types,
5926+
int type_id)
5927+
{
5928+
struct intel_uncore_type *type;
5929+
int i, max = 0;
5930+
5931+
type = uncore_find_type_by_id(types, type_id);
5932+
if (!type)
5933+
return 0;
5934+
5935+
for (i = 0; i < type->num_boxes; i++) {
5936+
if (type->box_ids[i] > max)
5937+
max = type->box_ids[i];
5938+
}
5939+
5940+
return max + 1;
5941+
}
5942+
58225943
void spr_uncore_cpu_init(void)
58235944
{
5824-
uncore_msr_uncores = uncore_get_uncores(UNCORE_ACCESS_MSR);
5945+
uncore_msr_uncores = uncore_get_uncores(UNCORE_ACCESS_MSR,
5946+
UNCORE_SPR_MSR_EXTRA_UNCORES,
5947+
spr_msr_uncores);
5948+
5949+
spr_uncore_iio_free_running.num_boxes = uncore_type_max_boxes(uncore_msr_uncores, UNCORE_SPR_IIO);
58255950
}
58265951

58275952
int spr_uncore_pci_init(void)
58285953
{
5829-
uncore_pci_uncores = uncore_get_uncores(UNCORE_ACCESS_PCI);
5954+
uncore_pci_uncores = uncore_get_uncores(UNCORE_ACCESS_PCI, 0, NULL);
58305955
return 0;
58315956
}
58325957

58335958
void spr_uncore_mmio_init(void)
58345959
{
5835-
uncore_mmio_uncores = uncore_get_uncores(UNCORE_ACCESS_MMIO);
5960+
uncore_mmio_uncores = uncore_get_uncores(UNCORE_ACCESS_MMIO, 0, NULL);
58365961
}
58375962

58385963
/* end of SPR uncore support */

0 commit comments

Comments
 (0)