Skip to content

revive the Windows port #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2018
Merged

revive the Windows port #344

merged 3 commits into from
Mar 19, 2018

Conversation

compnerd
Copy link
Member

The DISPATCH_EXPORT macro added an extraneous extern on the
declaration. This was pointed out by a newer clang. Adjust the
declaration accordingly.

Add build rules to improve Windows builds. These additions help
cross-compile to Windows with both clang-cl as well as the GNU clang
driver.

Use the newer Windows APIs to detect the windows CPU state. This allows
us to collect all of the CPU configuration information to properly
affinitise work to the preferred CPU.

Use the FLS API to create thread local data storage for libdispatch's
queues.

@compnerd
Copy link
Member Author

CC: @das @MadCoder @jrose-apple @parkera

@compnerd
Copy link
Member Author

This is a partial patch, it still needs more work. But, it sets up a lot of the work that is needed. It also fixes cross-compilation on Linux to Windows. The assumption here is that you are using clang-cl or clang to build libdispatch. I figure that putting this up here earlier is better as it allows others to take a look as well as possibly solve some of the remaining issues.

src/shims/tsd.h Outdated
void *dispatch_deferred_items_key;
};

extern __declspec(thread) struct dispatch_tsd __dispatch_tsd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you try to reuse DISPATCH_USE_THREAD_LOCAL_STORAGE it's supposed to be the same trick, no? instead of duplicating the whole struct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, its actually the same exact structure too ... just didn't move things around to make it easier. I can do that.

@MadCoder
Copy link
Contributor

I have to look at the patch more, and it's more than I can do in a timely fashion, but I've seen nothing shocking in there overall.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm an expert in neither Windows nor GCD, so I can't really comment. Nothing jumped out at me as wrong, but I also didn't understand a lot of it, like which things need to be marked stdcall and which don't.

#define MAX(a,b) (((a)>(b))?(a):(b))
// Unicies provide `MIN` via sys/param.h
#define MIN(a,b) (((a)<(b))?(a):(b))
// Unicies provide `howmany` via sys/param.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: inconsistent between Unices and Unicies.

src/block.cpp Outdated
@@ -69,7 +69,8 @@ struct dispatch_block_private_data_s {
{
// copy constructor, create copy with retained references
if (dbpd_voucher) voucher_retain(dbpd_voucher);
if (o.dbpd_block) dbpd_block = _dispatch_Block_copy(o.dbpd_block);
if (o.dbpd_block) dbpd_block =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use braces

@@ -32,7 +32,9 @@
#include <os/availability.h>
#include <TargetConditionals.h>
#include <os/base.h>
#elif defined(__linux__) || defined(__FreeBSD__)
#elif defined(_WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use TARGET_OS_WIN32 to be consistent with the rest of the tests I think

@@ -137,7 +137,7 @@ _dispatch_introspection_thread_add(void)
_dispatch_unfair_lock_unlock(&_dispatch_introspection.threads_lock);
}

static void
static __stdcall void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is __stdcall defined by clang on darwin or linux?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get

<stdin>:1:6: warning: calling convention '__stdcall' ignored for this target
      [-Wignored-attributes]
void __stdcall test();
     ^

So yeah, it might be something you want to guard.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can control this by a macro

@compnerd
Copy link
Member Author

compnerd commented Mar 2, 2018

Updated to address the comments. This is further along now, with a lot more of the port formalized.

Copy link
Contributor

@MadCoder MadCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the review makes perfect sense to me, however I see a problem, where do you get TARGET_OS_WIN32 from? is there someone that defines it that I missed? os/object uses _WIN32 as a guard but not the rest.

src/internal.h Outdated

#if __GNUC__
#if __GNUC__ || defined(__clang__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if defined(__GNUC__) || defined(__clang__) would look better ;)

@compnerd
Copy link
Member Author

Oh, TARGET_OS_WIN32 comes from the build system. If there is a better way, Id love to know about that. https://github.com/apple/swift-corelibs-libdispatch/blob/master/CMakeLists.txt#L266

Good call on the style in src/internal.h.

@compnerd
Copy link
Member Author

There is a small amount of porting left: src/io.c (this previously was completely disabled).

@MadCoder
Copy link
Contributor

if TARGET_OS_WIN32 comes from the build system you can't have it in private.h or any header, you should use _WIN32 there, and then it is a question whether we need TARGET_OS_WIN32 at all, it seems confusing. TARGET_OS* comes from <TargetConditionals.h> which is a thing that Apple has when we build things on Windows platforms that's why it's this way. I don't think it should stay this way.

have you ported all of event/event.c too? ;) because that part is the one that needs basically full reimplementation, unless windows supports kevent :P (not that it should block anything, but between having dispatch sources working and io.c I know what should be done first :P)

@MadCoder
Copy link
Contributor

so please get rid of TARGET_OS_WIN32 consistently, we use __linux__ and __freebsd__ and such for other platforms, there's no reason for windows to be in between IMO. Once you've done that I'll merge.

@compnerd
Copy link
Member Author

Hah, kevent.c is huge (and as you pointed out, will require a full re-implementaiton), and I think that doing that as a separate change is best -- this is a pretty big change as is. While I agree that kevent.c is crucial, having this part means that we can at least ensure that build regressions don't occur while that is ported over. Replacing TARGET_OS_WIN32 with defined(_WIN32) sounds completely fine to me.

@MadCoder
Copy link
Contributor

as far as kevent.c is, it's huge, but you should instead model it after event_epoll.c which is way smaller, I have abstracted platform specific code this way way more than it used to be.

@compnerd
Copy link
Member Author

So, the build should be complete at this point, the top patch is the only thing which I don't know how to formalize. But, the entire build now completes successfully :-)

@@ -340,7 +340,7 @@ DISPATCH_ENUM(dispatch_invoke_flags, uint32_t,
#define _DISPATCH_INVOKE_AUTORELEASE_MASK 0x00300000u
);

enum {
enum : unsigned long {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this syntax is not supported by C mode on clang I think, can you use DISPATCH_ENUM() instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Silence the enum assignment warning from clang.  It is triggered by use
of constants in macros that are not part of an enumeration when the
parameter is of an enumerated type.  This shows up when building for
Windows.  Rather than clutter the codebase with compiler specific macros
to silence the warning, disable it.
The `DISPATCH_EXPORT` macro added an extraneous `extern` on the
declaration.  This was pointed out by a newer clang.  Adjust the
declaration accordingly.

Add build rules to improve Windows builds.  These additions help
cross-compile to Windows with both clang-cl as well as the GNU clang
driver.

Use the newer Windows APIs to detect the windows CPU state.  This allows
us to collect all of the CPU configuration information to properly
affinitise work to the preferred CPU.

Use the FLS API to create thread local data storage for libdispatch's
queues.
Windows uses signed enumerations by default rather than unsigned.  This
results in the values triggering warnings on Windows.
@MadCoder
Copy link
Contributor

@swift-ci please test

@MadCoder MadCoder merged commit 8d3aa22 into swiftlang:master Mar 19, 2018
@compnerd compnerd deleted the windows branch March 19, 2018 21:39
ktopley-apple pushed a commit that referenced this pull request Dec 6, 2018
revive the Windows port

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
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.

4 participants