cpufrequtils aperf: Use sysconf() glibc func to detect possible cpus

Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
diff --git a/utils/aperf.c b/utils/aperf.c
index 17e1cb6..bbe0d9b 100644
--- a/utils/aperf.c
+++ b/utils/aperf.c
@@ -59,8 +59,6 @@
 #define MSR_IA32_APERF 0x000000E8
 #define MSR_IA32_MPERF 0x000000E7
 
-#define LINE_LEN 10
-
 struct avg_perf_cpu_info
 {
 	unsigned long max_freq;
@@ -69,39 +67,6 @@
 	uint32_t is_valid:1;
 };
 
-static unsigned int count_cpus(void)
-{
-	FILE *fp;
-	char value[LINE_LEN];
-	unsigned int ret = 0;
-	unsigned int cpunr = 0;
-
-	fp = fopen("/proc/stat", "r");
-	if(!fp) {
-		printf("Couldn't count the number of CPUs (%s: %s), "
-			"assuming 1\n", "/proc/stat", strerror(errno));
-		return 1;
-	}
-
-	while (!feof(fp)) {
-		if (!fgets(value, LINE_LEN, fp))
-			continue;
-		value[LINE_LEN - 1] = '\0';
-		if (strlen(value) < (LINE_LEN - 2))
-			continue;
-		if (strstr(value, "cpu "))
-			continue;
-		if (sscanf(value, "cpu%d ", &cpunr) != 1)
-			continue;
-		if (cpunr > ret)
-			ret = cpunr;
-	}
-	fclose(fp);
-
-	/* cpu count starts from 0, on error return 1 (UP) */
-	return (ret+1);
-}
-
 static int cpu_has_effective_freq()
 {
 	/* largest base level */
@@ -343,7 +308,7 @@
 	uint64_t current_aperf, current_mperf, mperf_diff, aperf_diff;
 	struct avg_perf_cpu_info *cpu_list;
 
-	cpus = count_cpus();
+	cpus = sysconf(_SC_NPROCESSORS_CONF);
 
 	cpu_list = (struct avg_perf_cpu_info*)
 		malloc(cpus * sizeof (struct avg_perf_cpu_info));