From 4e030c9cd0d40946f1394964f7f7c09abf997320 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 31 Dec 2019 09:51:02 -0500 Subject: [PATCH] Fix CI hangs on win32 After much debugging, it turns out that OpenBlas is sometimes hanging on exit due to bad assumptions in its thread management. The upstream discussion is at https://github.com/xianyi/OpenBLAS/pull/2350, but this should fix our frequent win32 CI failures in the meantime. --- deps/blas.mk | 7 ++++++- deps/patches/openblas-winexit.patch | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 deps/patches/openblas-winexit.patch diff --git a/deps/blas.mk b/deps/blas.mk index cd6026319c5dc..89656c1844365 100644 --- a/deps/blas.mk +++ b/deps/blas.mk @@ -99,7 +99,12 @@ $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied: $(BUILDDIR patch -p1 -f < $(SRCDIR)/patches/openblas-skylakexdgemm.patch echo 1 > $@ -$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied +$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-winexit.patch-applied: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/source-extracted + cd $(BUILDDIR)/$(OPENBLAS_SRC_DIR) && \ + patch -p1 -f < $(SRCDIR)/patches/openblas-winexit.patch + echo 1 > $@ + +$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-winexit.patch-applied echo 1 > $@ $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-compiled: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured diff --git a/deps/patches/openblas-winexit.patch b/deps/patches/openblas-winexit.patch new file mode 100644 index 0000000000000..6e46a647932df --- /dev/null +++ b/deps/patches/openblas-winexit.patch @@ -0,0 +1,27 @@ +commit 7f4a96a353c06c2fdecb0b2464800bcf8fab6fd7 +Author: Keno Fischer +Date: Sun Dec 29 15:08:13 2019 -0500 + + win32: Don't run cleanup if we're about to exit anyway + + If the process is about to exit, there's no point trying to do + a bunch of work to clean up resources. The kernel will release + them much more efficiently when the process exits at the end + of this function. + +diff --git a/exports/dllinit.c b/exports/dllinit.c +index 02ff092e..56aafa95 100644 +--- a/exports/dllinit.c ++++ b/exports/dllinit.c +@@ -48,7 +48,10 @@ BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { + } + + if (reason == DLL_PROCESS_DETACH) { +- gotoblas_quit(); ++ // If the process is about to exit, don't bother releasing any resources ++ // The kernel is much better at bulk releasing then. ++ if (!reserved) ++ gotoblas_quit(); + } + + return TRUE;