Skip to content

Commit

Permalink
Fix compiler errors/warnings for NetBSD/arm. (#102)
Browse files Browse the repository at this point in the history
* Fix compilation error for NetBSD/arm.

The prototype for `get_cpu_speed()` had an incompatible return type as
defined in `c/netbsd.c`. This makes it compatible.

* Fix compilation warnings for NetBSD/arm.

The scope of local variables was moved into the conditional sections
to eliminate compilation warnings.

* Add ARM section for NetBSD.

`get_cpu_speed()` now has a section specific to NetBSD/arm targets.
Previously it would default to 1 Ghz.
  • Loading branch information
rneswold authored Oct 21, 2021
1 parent c53fc07 commit b9d8a5e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions c/netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,27 @@ const char *get_os_release(void) {
return (os_release);
}

uint64_t get_cpu_speed(void) {
unsigned long get_cpu_speed(void) {
#if defined(__i386__) || defined(__amd64__)
uint64_t tsc_freq;
size_t len;
int error;

#if defined(__i386__) || defined(__amd64__)
len = sizeof(tsc_freq);
error = sysctlbyname("machdep.tsc_freq", &tsc_freq, &len, NULL, 0);
if (error == -1)
return (0);
return (unsigned long) (tsc_freq / ONE_DECIMAL_K / ONE_DECIMAL_K);
#elif defined(__arm__) || defined(__aarch64__)
uint32_t tsc_freq;
size_t len = sizeof(tsc_freq);
int const result = sysctlbyname("machdep.cpu.frequency.current",
&tsc_freq, &len, NULL, 0);

return result == -1 ? ONE_DECIMAL_K : tsc_freq;
#else
tsc_freq = ONE_DECIMAL_K * ONE_DECIMAL_K * ONE_DECIMAL_K;
return ONE_DECIMAL_K;
#endif
return (tsc_freq / ONE_DECIMAL_K / ONE_DECIMAL_K);
}

unsigned long get_proc_total(void) {
Expand Down

0 comments on commit b9d8a5e

Please sign in to comment.