Skip to content

Commit

Permalink
Some improvements for get_freq again.
Browse files Browse the repository at this point in the history
Fix frequency not printing correctly (I wasn't using the divisor)
Add more guards.
  • Loading branch information
npyl committed Jul 29, 2018
1 parent bca32ef commit aa69475
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/darwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,15 +973,20 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) {
/* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size,
const char *p_format, int divisor, unsigned int cpu) {

if ((p_client_buffer == nullptr) || client_buffer_size <= 0 ||
(p_format == nullptr) || divisor <= 0) {
return 0;
}

#ifdef BUILD_IPGFREQ
/*
* Our data is always the same for every core, so ignore |cpu| argument.
*/

static bool initialised = false;

if (!initialised)
{
if (!initialised) {
IntelEnergyLibInitialize();
initialised = true;
}
Expand All @@ -990,7 +995,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
GetIAFrequency(cpu, &freq);

snprintf(p_client_buffer, client_buffer_size, p_format,
static_cast<float>(freq));
static_cast<float>(freq) / divisor);
#else
/*
* We get the factory cpu frequency, not **current** cpu frequency
Expand All @@ -1002,11 +1007,6 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
unsigned int freq;
size_t len;

if ((p_client_buffer == nullptr) || client_buffer_size <= 0 ||
(p_format == nullptr) || divisor <= 0) {
return 0;
}

mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
len = sizeof(freq);
Expand All @@ -1024,7 +1024,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
return 0;
}
#endif

return 1;
}

Expand Down

0 comments on commit aa69475

Please sign in to comment.