From 0db37afc551e7e7be04dfb3a7efe7a1e5e327f2f Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Fri, 12 Aug 2016 15:56:52 +0300 Subject: tdf#100965: Restart on initialisation-time OpenCL crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a flag to the OpenCLZone indicating whether we are performing the first-start OpenCL functionality verification, so that if we run into a crash that is caught by the VCL VCLExceptionSignal_impl() handler, we terminate the process with the EXITHELPER_NORMAL_RESTART status after first having disabled OpenCL use. The wrapper process will then restart soffice.bin. This is for Windows only so far. This matches what we do if OpenGL fails early during start of LibreOffice. Also, the enter() and leave() functions are not used anywhere (cherry picked from commit 32881f01833dbcefd5600e1135dd8743178bfd96) (cherry picked from commit b9898f03eb05411c508b1b02588812074d40417a) Change-Id: Ibb9bf3a86b7521bf16728de2a118ad4323be674b Reviewed-on: https://gerrit.libreoffice.org/28139 Reviewed-by: Eike Rathke Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- desktop/source/app/opencl.cxx | 1 + include/opencl/OpenCLZone.hxx | 17 +++++++++-------- opencl/source/OpenCLZone.cxx | 6 ++++++ vcl/source/app/svmain.cxx | 8 ++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/desktop/source/app/opencl.cxx b/desktop/source/app/opencl.cxx index 2b8d6d67e98e..13161f3a299f 100644 --- a/desktop/source/app/opencl.cxx +++ b/desktop/source/app/opencl.cxx @@ -123,6 +123,7 @@ void Desktop::CheckOpenCLCompute(const Reference< XDesktop2 > &xDesktop) SAL_INFO("opencl", "Initiating test of OpenCL device"); OpenCLZone aZone; + OpenCLZone::enterInitialTest(); OUString aDevice = officecfg::Office::Calc::Formula::Calculation::OpenCLDevice::get(); OUString aSelectedCLDeviceVersionID; diff --git a/include/opencl/OpenCLZone.hxx b/include/opencl/OpenCLZone.hxx index 1fbc666f4df0..0d2059dddc87 100644 --- a/include/opencl/OpenCLZone.hxx +++ b/include/opencl/OpenCLZone.hxx @@ -19,15 +19,8 @@ class OPENCL_DLLPUBLIC OpenCLZone static volatile sal_uInt64 gnEnterCount; /// how many times have we left a new CL zone static volatile sal_uInt64 gnLeaveCount; + static volatile bool gbInInitialTest; - static void enter() - { - gnEnterCount++; - } - static void leave() - { - gnLeaveCount--; - } public: OpenCLZone() { @@ -37,6 +30,8 @@ public: ~OpenCLZone() { gnLeaveCount++; + if (!isInZone()) + gbInInitialTest = false; } static bool isInZone() @@ -44,7 +39,13 @@ public: return gnEnterCount != gnLeaveCount; } + static bool isInInitialTest() + { + return gbInInitialTest; + } + static void hardDisable(); + static void enterInitialTest(); }; #endif // INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX diff --git a/opencl/source/OpenCLZone.cxx b/opencl/source/OpenCLZone.cxx index 03521a29c66f..52d6ada8518a 100644 --- a/opencl/source/OpenCLZone.cxx +++ b/opencl/source/OpenCLZone.cxx @@ -21,6 +21,7 @@ sal_uInt64 volatile OpenCLZone::gnEnterCount = 0; sal_uInt64 volatile OpenCLZone::gnLeaveCount = 0; +bool volatile OpenCLZone::gbInInitialTest = false; /** * Called from a signal handler if we get @@ -47,4 +48,9 @@ void OpenCLZone::hardDisable() } } +void OpenCLZone::enterInitialTest() +{ + gbInInitialTest = true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx index 54aecfdcddae..81bfb759a337 100644 --- a/vcl/source/app/svmain.cxx +++ b/vcl/source/app/svmain.cxx @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -123,7 +125,13 @@ oslSignalAction SAL_CALL VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo #endif #if HAVE_FEATURE_OPENCL if (OpenCLZone::isInZone()) + { OpenCLZone::hardDisable(); +#ifdef _WIN32 + if (OpenCLZone::isInInitialTest()) + TerminateProcess(GetCurrentProcess(), EXITHELPER_NORMAL_RESTART); +#endif + } #endif } -- cgit