Files
libreoffice/opencl/source/OpenCLZone.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.7 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <opencl/openclwrapper.hxx>
#include <opencl/OpenCLZone.hxx>
#include <opencl_device.hxx>
#include <memory>
#include <officecfg/Office/Common.hxx>
#include <com/sun/star/util/XFlushable.hpp>
#include <com/sun/star/configuration/theDefaultProvider.hpp>
// FIXME: templatize me vs. OpenGLZone.
-Werror=volatile in OpenCLZone Recent GCC 10 trunk in C++20 mode reports issues like > include/opencl/OpenCLZone.hxx:27:9: error: ‘++’ expression of ‘volatile’-qualified type is deprecated [-Werror=volatile] > 27 | gnEnterCount++; > | ^~~~~~~~~~~~ But unlike in the case of ec17c8ec5256386b0197a8ffe5d7cad3e7d70f8f "-Werror=volatile in OpenGLZone", * it looks like there are no multi-threading issues here, and the counters are just accessed (via OpenCLZone::isInZone) from the VCLExceptionSignal_impl signal handler in addition to being modified (via OpenCLZone RAII objects) from mainline code; and * from the usage pattern of gnEnterCount and gnLeaveCount it appears that they can be combined into a single counter. (f41eb66302208f384a475fb20c98b6d1b0676cb6 "opencl: OpenCLZone, detect CL device change and disable CL on crash" presumably modelled OpenCLZone naively after OpenGLZone, without simplifying it where possible.) One minor advantage of having two monotonically increasing counters is that when they overflow, the implementation of isInZone (comparing them for equality) still gives ~useful results (assuming that a false "match" of non-overflown gnEnterCount against overflown gnLeaveCount is highly unlikely). But instances of OpenCLZone RAII objects are presumably never nested very deeply (if at all), so that the newly added "TODO: overflow" comment (which would even cause UB if std::sig_atomic_t is signed) is probably of no practical concern. Change-Id: I92e1f2c46ca996a0a86bacabcda2accba5eb6298 Reviewed-on: https://gerrit.libreoffice.org/79106 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-09-18 19:13:34 +02:00
std::sig_atomic_t volatile OpenCLZone::gnEnterCount = 0;
bool volatile OpenCLZone::gbInInitialTest = false;
/**
* Called from a signal handler if we get
* a crash or hang in some CL code.
*/
void OpenCLZone::hardDisable()
{
// protect ourselves from double calling etc.
static bool bDisabled = false;
if (!bDisabled)
{
bDisabled = true;
std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Misc::UseOpenCL::set(false, xChanges);
xChanges->commit();
// Force synchronous config write
auto xConfProvider = css::configuration::theDefaultProvider::get(comphelper::getProcessComponentContext());
css::uno::Reference<css::util::XFlushable> xFlushable(xConfProvider, css::uno::UNO_QUERY_THROW);
xFlushable->flush();
releaseOpenCLEnv(&openclwrapper::gpuEnv);
}
}
void OpenCLZone::enterInitialTest()
{
gbInInitialTest = true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */