Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCS/ARCH: Fix reading ppc timebase from /proc/cpuinfo. #1623

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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