Skip to content

Add linux port#12

Open
btolsch wants to merge 2 commits into
cmuratori:masterfrom
btolsch:linux
Open

Add linux port#12
btolsch wants to merge 2 commits into
cmuratori:masterfrom
btolsch:linux

Conversation

@btolsch

@btolsch btolsch commented Jul 13, 2021

Copy link
Copy Markdown

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 commit adds a linux platform layer.  The two necessary non-platform
changes are:
- Adding a sprintf-style platform function (Statusf) for the main code
  to call instead of wsprintf.
- Changing `struct time` to `struct timestamp` because it conflicts with
  a type already defined on linux.

The format specifier differences between wsprintf and the linux sprintf
are handled by manually converting the format strings in the platform
layer instead of changing any other existing code.
@cmuratori

Copy link
Copy Markdown
Owner

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

@alexkelbo

alexkelbo commented Oct 17, 2021

Copy link
Copy Markdown

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.

@dijit

dijit commented Jun 17, 2024

Copy link
Copy Markdown

Is there anything holding back this merge now? Or was it just forgotten to time?

@cmuratori

Copy link
Copy Markdown
Owner

Nothing is holding it back other than me having time to test it.

- Casey

@Error323

Copy link
Copy Markdown

For the Linux version in this PR, I wrote a small fix that makes it compile on my machine using clang and extract the relevant information for avx512. I also did a comparison test between Windows and Linux on the same machine.

CPU: AMD Ryzen 7 7800X3D 8-Core Processor
Logical Cores: 16
Expected frequency: 4200mhz
Support: X64Read128 X64Write128 X64ReadWrite128 X64Read256 X64Write256 X64ReadWrite256 X64Read512 X64Write512 X64ReadWrite512

The histograms show that the Linux version is outperforming the Win32 version.
image

Time series shows that there are some spikes occurring periodically. Not sure what to make of that yet.
image

Perhaps more people should do measurements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants