blandwidth
blandwidth copied to clipboard
Add linux port
I hope you find this helpful; if not, feel free to close this.
First of all, I did compile this with both MSVC and clang on Windows. I also got roughly the same numbers on both Linux and Windows (though I didn't take any statistics, measure whether there was a difference in the gate operation, etc.). So that's something.
There were two changes I had to make to the main code to get this to work on Linux (the format strings are a separate issue). There was one direct usage of wsprintf
in blandwidth.c, so I added a platform function Stringf
to do that. I also had to rename struct time
because it collides with the Linux definition.
I wrote a conversion function to go from wsprintf
format strings to Linux sprintf
strings (just the 64-bit int issue). The other alternative I could see is using macros like so:
// Win32
#define FMTu64 "%Iu"
// Linux
#define FMTu64 "%lu"
Statusf(Buffer, "Label: " FMTu64 "," FMTu64 "\n", ...);
That makes the format strings slightly harder to read though, so that wasn't really my first choice in this case.
There are also fixes for #11 and the clang CTAssert
TODO in here if you don't get to them first.
Lastly, I didn't try to emulate your braces/spacing yet. I can take a shot at cleaning that up if you want to merge this.
This is delightful - thank you very much! I am very busy at the moment so I may not be able to merge this in until the weekend (I'd like to go over it and make sure I understand all the changes). But this is great, and I'm very happy to have a Linux port.
- Casey
Dear @btolsch , great work on the Linux port. With just a few changes it also compiles and runs under MacOS.
In linux_build.sh
add -Wno-deprecated
to CFLAGS_C
. That is because sem_t
and the sem_*
functions are deprecrated in MacOS but they do still work.
CFLAGS_C="-Wall -Werror -Wno-unused-function -Wno-unused-variable -Wno-deprecated -march=native -pthread"
In linux_blandwidth.c
remove the include for sys/sysinfo.h
, which doesn't exist on MacOS, and add these instead:
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdarg.h>
#else
#include <sys/sysinfo.h>
#endif
In the same file, replace the call to get_nprocs()
with the following code:
- u32 MaxThreadCount = get_nprocs();
+ u32 MaxThreadCount;
+ size_t MaxThreadCountLen = sizeof(u32);
+ sysctlbyname("hw.logicalcpu", &MaxThreadCount, &MaxThreadCountLen, NULL, 0);
I tested with clang 9.0.0 under MacOS 10.14.