Mellanox / sockperf

Network Benchmarking Utility
Other
597 stars 119 forks source link

Ported to macOS #210

Closed Pusnow closed 1 year ago

Pusnow commented 1 year ago

Hi,

I ported sockperf to macOS. To do so, I changed the followings.

Resolves #83

1. Change the version file to sockperf-version.

In my machine (macOS 13.1, Apple M1 (arm64), AppleClang 14.0.0), when I tried to build sockperf, the version file conflicted with C++20's version header (https://en.cppreference.com/w/cpp/header/version). The version header is used in the macOS's C++ std library, and an error occurs when the library tries to include the version header. So I changed the version's filename to sockperf-version.

2. Change struct sockaddr_store_t's ss_family to addr.

struct sockaddr_store_t {
    union {
        sockaddr addr; // was  sa_family_t ss_family;
        sockaddr_in addr4;
        sockaddr_in6 addr6;
        sockaddr_un addr_un;
    };
};

In macOS, the first member of sockaddr_* structures is not sa_family_t (https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in.h#L397-L403). So to access ss_family correctly in a portable way, I changed the member ss_family to sockaddr addr and all codes accessing it.

3. Add macOS-specific a thread affinity implementation

Unlike other parts of os_abstract, the thread affinity codes are not compatible with macOS, so I implement macOS-specific thread affinity functions. However, macOS's thread affinity API has a different behavior from the other OSes. In macOS, it is impossible to "pin" threads to specific cores, and rather application gives a tag (or hint) to the OS scheduler, and threads with the same affinity tag will be scheduled to share an L2 cache if possible. In this implementation, if a user gives thread affinity information, sockperf only gives a tag (only the last core id) to threads.

See https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/thread_policy.h#L186-L202 for more detail.

4. Some misc changes

I also changed argument parsing and vma_xlio parts to port sockperf to macOS.

swx-jenkins4 commented 1 year ago

Can one of the admins verify this patch?

igor-ivanov commented 1 year ago

bot:retest

Pusnow commented 1 year ago

Hi,I've updated the codes.

Pusnow commented 1 year ago

Done!

igor-ivanov commented 1 year ago

@Pusnow There is compilation failure when enabling extra api.

Compilation error: src/sockperf.cpp: In function ‘bool is_unspec_addr(const sockaddr_store_t&)’: src/sockperf.cpp:3068:18: error: ‘const struct sockaddr_store_t’ has no member named ‘ss_family’ switch (addr.ss_family) { ^~~~~ make[2]: [Makefile:688: src/sockperf.o] Error 1 make[2]: Waiting for unfinished jobs....

Note: configure --prefix=$PWD/install --enable-extra-api CPPFLAGS=-I libvma: https://github.com/Mellanox/libvma/

Pusnow commented 1 year ago

I fixed the compilation error. Would you verify the patch?

igor-ivanov commented 1 year ago

Thanks, could you combine commit 5 with 2 and commit 4 with 3 to have following list of changes as [Change version file's name to sockperf-version] [Ported to macOS] [Ported to macOS (misc parts)]

Pusnow commented 1 year ago

Sure, I've merged the commits.