Skip to contentSkip to conversation

events/amd/uncore: Minor cleanups

PATCH New Borislav Petkov 2 participants 7 messages Apr 10, 2017 – Apr 11, 2017

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

cover events/amd/uncore: Minor cleanups

From: Borislav Petkov <[email protected]>

Hi,

just a couple of minor cleanups which I came across while staring at code.

Borislav Petkov (3):
events/amd/uncore: Do feature check first, before assignments events/amd/uncore: Cleanup per-family setup events/amd/uncore: Fix pr_fmt prefix

 arch/x86/events/amd/uncore.c | 77 ++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 46 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/3 events/amd/uncore: Do feature check first, before assignments

From: Borislav Petkov <[email protected]>

... and save some unnecessary work. Remove now unused label while at it.

---
 arch/x86/events/amd/uncore.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/x86/events/amd/uncore.c +4 -5
index 4d1f7f2d9aff..abd4b9064fba 100644
@@ -509,7 +509,10 @@ static int __init amd_uncore_init(void)
 	int ret = -ENODEV;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
-		goto fail_nodev;
+		return -ENODEV;
+
+	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
+		return -ENODEV;
 
 	switch(boot_cpu_data.x86) {
 		case 23:
@@ -552,9 +555,6 @@ static int __init amd_uncore_init(void)
 	amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df;
 	amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3;
 
-	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
-		goto fail_nodev;
-
 	if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) {
 		amd_uncore_nb = alloc_percpu(struct amd_uncore *);
 		if (!amd_uncore_nb) {
@@ -615,7 +615,6 @@ static int __init amd_uncore_init(void)
 	if (amd_uncore_nb)
 		free_percpu(amd_uncore_nb);
 
-fail_nodev:
 	return ret;
 }
 device_initcall(amd_uncore_init);
Signature · 1 line
2.11.0
#2 lore raw

[tip:perf/core] perf/amd/uncore: Do feature check first, before assignments

perf/amd/uncore: Do feature check first, before assignments
Commit-ID:  c2628f90c9964881a62dd8e9f7372ca05cb6fe32
Gitweb:     http://git.kernel.org/tip/c2628f90c9964881a62dd8e9f7372ca05cb6fe32
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 10 Apr 2017 14:20:45 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 11 Apr 2017 08:44:59 +0200

perf/amd/uncore: Do feature check first, before assignments

... and save some unnecessary work. Remove now unused label while at it.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Suravee Suthikulpanit <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 arch/x86/events/amd/uncore.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/x86/events/amd/uncore.c +4 -5
index 4d1f7f2d..abd4b90 100644
@@ -509,7 +509,10 @@ static int __init amd_uncore_init(void)
 	int ret = -ENODEV;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
-		goto fail_nodev;
+		return -ENODEV;
+
+	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
+		return -ENODEV;
 
 	switch(boot_cpu_data.x86) {
 		case 23:
@@ -552,9 +555,6 @@ static int __init amd_uncore_init(void)
 	amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df;
 	amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3;
 
-	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
-		goto fail_nodev;
-
 	if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) {
 		amd_uncore_nb = alloc_percpu(struct amd_uncore *);
 		if (!amd_uncore_nb) {
@@ -615,7 +615,6 @@ fail_nb:
 	if (amd_uncore_nb)
 		free_percpu(amd_uncore_nb);
 
-fail_nodev:
 	return ret;
 }
 device_initcall(amd_uncore_init);
author maintainer
#3 lore raw

PATCH 2/3 events/amd/uncore: Cleanup per-family setup

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Fam16h is the same as the default one, remove it. Turn the switch-case into a simple if-else.

No functionality change.

---
 arch/x86/events/amd/uncore.c | 59 ++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 38 deletions(-)
arch/x86/events/amd/uncore.c +21 -38
index abd4b9064fba..975f24f6e238 100644
@@ -514,45 +514,28 @@ static int __init amd_uncore_init(void)
 	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
 		return -ENODEV;
 
-	switch(boot_cpu_data.x86) {
-		case 23:
-			/* Family 17h: */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L3;
-			/*
-			 * For Family17h, the NorthBridge counters are
-			 * re-purposed as Data Fabric counters. Also, support is
-			 * added for L3 counters. The pmus are exported based on
-			 * family as either L2 or L3 and NB or DF.
-			 */
-			amd_nb_pmu.name = "amd_df";
-			amd_llc_pmu.name = "amd_l3";
-			format_attr_event_df.show = &event_show_df;
-			format_attr_event_l3.show = &event_show_l3;
-			break;
-		case 22:
-			/* Family 16h - may change: */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L2;
-			amd_nb_pmu.name = "amd_nb";
-			amd_llc_pmu.name = "amd_l2";
-			format_attr_event_df = format_attr_event;
-			format_attr_event_l3 = format_attr_event;
-			break;
-		default:
-			/*
-			 * All prior families have the same number of
-			 * NorthBridge and Last Level Cache counters
-			 */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L2;
-			amd_nb_pmu.name = "amd_nb";
-			amd_llc_pmu.name = "amd_l2";
-			format_attr_event_df = format_attr_event;
-			format_attr_event_l3 = format_attr_event;
-			break;
+	if (boot_cpu_data.x86 == 0x17) {
+		/*
+		 * For F17h, the Northbridge counters are repurposed as Data
+		 * Fabric counters. Also, L3 counters are supported too. The PMUs
+		 * are exported based on  family as either L2 or L3 and NB or DF.
+		 */
+		num_counters_nb		  = NUM_COUNTERS_NB;
+		num_counters_llc	  = NUM_COUNTERS_L3;
+		amd_nb_pmu.name		  = "amd_df";
+		amd_llc_pmu.name	  = "amd_l3";
+		format_attr_event_df.show = &event_show_df;
+		format_attr_event_l3.show = &event_show_l3;
+	} else {
+		num_counters_nb		  = NUM_COUNTERS_NB;
+		num_counters_llc	  = NUM_COUNTERS_L2;
+		amd_nb_pmu.name		  = "amd_nb";
+		amd_llc_pmu.name	  = "amd_l2";
+		format_attr_event_df	  = format_attr_event;
+		format_attr_event_l3	  = format_attr_event;
 	}
-	amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df;
+
+	amd_nb_pmu.attr_groups	= amd_uncore_attr_groups_df;
 	amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3;
 
 	if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) {
Signature · 1 line
2.11.0
#4 lore raw

[tip:perf/core] perf/amd/uncore: Clean up per-family setup

perf/amd/uncore: Clean up per-family setup
Commit-ID:  68e8038048f44e7782079e79338506246393a876
Gitweb:     http://git.kernel.org/tip/68e8038048f44e7782079e79338506246393a876
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 10 Apr 2017 14:20:46 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 11 Apr 2017 08:44:59 +0200

perf/amd/uncore: Clean up per-family setup

Fam16h is the same as the default one, remove it. Turn the switch-case into a simple if-else.

No functionality change.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Suravee Suthikulpanit <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 arch/x86/events/amd/uncore.c | 59 ++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 38 deletions(-)
arch/x86/events/amd/uncore.c +21 -38
index abd4b90..975f24f 100644
@@ -514,45 +514,28 @@ static int __init amd_uncore_init(void)
 	if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
 		return -ENODEV;
 
-	switch(boot_cpu_data.x86) {
-		case 23:
-			/* Family 17h: */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L3;
-			/*
-			 * For Family17h, the NorthBridge counters are
-			 * re-purposed as Data Fabric counters. Also, support is
-			 * added for L3 counters. The pmus are exported based on
-			 * family as either L2 or L3 and NB or DF.
-			 */
-			amd_nb_pmu.name = "amd_df";
-			amd_llc_pmu.name = "amd_l3";
-			format_attr_event_df.show = &event_show_df;
-			format_attr_event_l3.show = &event_show_l3;
-			break;
-		case 22:
-			/* Family 16h - may change: */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L2;
-			amd_nb_pmu.name = "amd_nb";
-			amd_llc_pmu.name = "amd_l2";
-			format_attr_event_df = format_attr_event;
-			format_attr_event_l3 = format_attr_event;
-			break;
-		default:
-			/*
-			 * All prior families have the same number of
-			 * NorthBridge and Last Level Cache counters
-			 */
-			num_counters_nb = NUM_COUNTERS_NB;
-			num_counters_llc = NUM_COUNTERS_L2;
-			amd_nb_pmu.name = "amd_nb";
-			amd_llc_pmu.name = "amd_l2";
-			format_attr_event_df = format_attr_event;
-			format_attr_event_l3 = format_attr_event;
-			break;
+	if (boot_cpu_data.x86 == 0x17) {
+		/*
+		 * For F17h, the Northbridge counters are repurposed as Data
+		 * Fabric counters. Also, L3 counters are supported too. The PMUs
+		 * are exported based on  family as either L2 or L3 and NB or DF.
+		 */
+		num_counters_nb		  = NUM_COUNTERS_NB;
+		num_counters_llc	  = NUM_COUNTERS_L3;
+		amd_nb_pmu.name		  = "amd_df";
+		amd_llc_pmu.name	  = "amd_l3";
+		format_attr_event_df.show = &event_show_df;
+		format_attr_event_l3.show = &event_show_l3;
+	} else {
+		num_counters_nb		  = NUM_COUNTERS_NB;
+		num_counters_llc	  = NUM_COUNTERS_L2;
+		amd_nb_pmu.name		  = "amd_nb";
+		amd_llc_pmu.name	  = "amd_l2";
+		format_attr_event_df	  = format_attr_event;
+		format_attr_event_l3	  = format_attr_event;
 	}
-	amd_nb_pmu.attr_groups = amd_uncore_attr_groups_df;
+
+	amd_nb_pmu.attr_groups	= amd_uncore_attr_groups_df;
 	amd_llc_pmu.attr_groups = amd_uncore_attr_groups_l3;
 
 	if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) {
author maintainer
#5 lore raw

PATCH 3/3 events/amd/uncore: Fix pr_fmt prefix

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Make it "amd_uncore: ", i.e., something more specific than "perf: ".

---
 arch/x86/events/amd/uncore.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/events/amd/uncore.c +5 -2
index 975f24f6e238..ad44af0dd667 100644
@@ -30,6 +30,9 @@
 
 #define COUNTER_SHIFT		16
 
+#undef pr_fmt
+#define pr_fmt(fmt)	"amd_uncore: " fmt
+
 static int num_counters_llc;
 static int num_counters_nb;
 
@@ -548,7 +551,7 @@ static int __init amd_uncore_init(void)
 		if (ret)
 			goto fail_nb;
 
-		pr_info("perf: AMD NB counters detected\n");
+		pr_info("AMD NB counters detected\n");
 		ret = 0;
 	}
 
@@ -562,7 +565,7 @@ static int __init amd_uncore_init(void)
 		if (ret)
 			goto fail_llc;
 
-		pr_info("perf: AMD LLC counters detected\n");
+		pr_info("AMD LLC counters detected\n");
 		ret = 0;
 	}
 
Signature · 1 line
2.11.0
#6 lore raw

[tip:perf/core] perf/amd/uncore: Fix pr_fmt() prefix

perf/amd/uncore: Fix pr_fmt() prefix
Commit-ID:  9df9078ef2086652647248ee6e82ca8f661cb3f5
Gitweb:     http://git.kernel.org/tip/9df9078ef2086652647248ee6e82ca8f661cb3f5
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 10 Apr 2017 14:20:47 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 11 Apr 2017 08:44:59 +0200

perf/amd/uncore: Fix pr_fmt() prefix

Make it "perf/amd/uncore: ", i.e., something more specific than "perf: ".

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Suravee Suthikulpanit <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
[ Changed it to perf/amd/uncore/ ]
---
 arch/x86/events/amd/uncore.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/events/amd/uncore.c +5 -2
index 975f24f..ad44af0 100644
@@ -30,6 +30,9 @@
 
 #define COUNTER_SHIFT		16
 
+#undef pr_fmt
+#define pr_fmt(fmt)	"amd_uncore: " fmt
+
 static int num_counters_llc;
 static int num_counters_nb;
 
@@ -548,7 +551,7 @@ static int __init amd_uncore_init(void)
 		if (ret)
 			goto fail_nb;
 
-		pr_info("perf: AMD NB counters detected\n");
+		pr_info("AMD NB counters detected\n");
 		ret = 0;
 	}
 
@@ -562,7 +565,7 @@ static int __init amd_uncore_init(void)
 		if (ret)
 			goto fail_llc;
 
-		pr_info("perf: AMD LLC counters detected\n");
+		pr_info("AMD LLC counters detected\n");
 		ret = 0;
 	}