diff options
author | Thomas Renninger <trenn@suse.de> | 2010-04-29 13:46:44 +0200 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2010-04-29 16:52:19 +0200 |
commit | a920f6d9adf3bf177f51f4a3e16f9fd028686cc7 (patch) | |
tree | 5513350f246f16beace2296a5e7623450a0970ca | |
parent | 6396da3821b552d4b7a5b36f772ca2801b4ca2e7 (diff) | |
download | cpufrequtils-a920f6d9adf3bf177f51f4a3e16f9fd028686cc7.tar.gz |
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>
-rw-r--r-- | utils/aperf.c | 37 |
1 files changed, 1 insertions, 36 deletions
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 @@ struct avg_perf_cpu_info 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 @@ static int do_measure_all_cpus(int sleep_time, int once) 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)); |