Skip to content

Commit

Permalink
Merge pull request #1623 from yosefe/topic/fix-ppc-timebase-cpuinfo
Browse files Browse the repository at this point in the history
UCS/ARCH: Fix reading ppc timebase from /proc/cpuinfo.
  • Loading branch information
yosefe authored Jun 21, 2017
2 parents 022f9b1 + 8b21c3f commit 8a1596f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ucs/arch/ppc64/timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ double ucs_arch_get_clocks_per_sec()
#if HAVE_DECL___PPC_GET_TIMEBASE_FREQ
return __ppc_get_timebase_freq();
#else
return ucs_get_cpuinfo_clock_freq("timebase");
return ucs_get_cpuinfo_clock_freq("timebase", 1.0);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/ucs/arch/x86_64/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ double ucs_arch_get_clocks_per_sec()
}

/* Read clock speed from cpuinfo */
return ucs_get_cpuinfo_clock_freq("cpu MHz");
return ucs_get_cpuinfo_clock_freq("cpu MHz", 1e6);
}

ucs_cpu_model_t ucs_arch_get_cpu_model()
Expand Down
18 changes: 9 additions & 9 deletions src/ucs/sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,9 @@ int ucs_tgkill(int tgid, int tid, int sig)
return syscall(SYS_tgkill, tgid, tid, sig);
}

double ucs_get_cpuinfo_clock_freq(const char *mhz_header)
double ucs_get_cpuinfo_clock_freq(const char *header, double scale)
{
double mhz = 0.0;
double value = 0.0;
double m;
int rc;
FILE* f;
Expand All @@ -644,7 +644,7 @@ double ucs_get_cpuinfo_clock_freq(const char *mhz_header)
return 0.0;
}

snprintf(fmt, sizeof(fmt), "%s : %%lf", mhz_header);
snprintf(fmt, sizeof(fmt), "%s : %%lf ", header);

warn = 0;
while (fgets(buf, sizeof(buf), f)) {
Expand All @@ -654,22 +654,22 @@ double ucs_get_cpuinfo_clock_freq(const char *mhz_header)
continue;
}

if (mhz == 0.0) {
mhz = m;
if (value == 0.0) {
value = m;
continue;
}

if (mhz != m) {
mhz = ucs_max(mhz,m);
if (value != m) {
value = ucs_max(value,m);
warn = 1;
}
}
fclose(f);

if (warn) {
ucs_warn("Conflicting CPU frequencies detected, using: %.2f MHz", mhz);
ucs_warn("Conflicting CPU frequencies detected, using: %.2f", value);
}
return mhz * 1e6;
return value * scale;
}

void *ucs_sys_realloc(void *old_ptr, size_t old_length, size_t new_length)
Expand Down
5 changes: 3 additions & 2 deletions src/ucs/sys/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ int ucs_tgkill(int tgid, int tid, int sig);
/**
* Get CPU frequency from /proc/cpuinfo. Return value is clocks-per-second.
*
* @param mhz_header String in /proc/cpuinfo which precedes the clock speed number.
* @param header String in /proc/cpuinfo which precedes the clock speed number.
* @param scale Frequency value units.
*/
double ucs_get_cpuinfo_clock_freq(const char *mhz_header);
double ucs_get_cpuinfo_clock_freq(const char *mhz_header, double scale);


/**
Expand Down

0 comments on commit 8a1596f

Please sign in to comment.