Skip to content
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

replace signal-based Timer with a ticking thread #577

Merged
merged 13 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions CASC/PortfolioMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ bool PortfolioMode::perform(Problem* problem)
if (outputAllowed()) {
if (resValue) {
addCommentSignForSZS(cout);
cout<<"Success in time "<<Timer::msToSecondsString(env.timer->elapsedMilliseconds())<<endl;
cout<<"Success in time "<<Timer::msToSecondsString(Timer::elapsedMilliseconds())<<endl;
}
else {
addCommentSignForSZS(cout);
cout<<"Proof not found in time "<<Timer::msToSecondsString(env.timer->elapsedMilliseconds())<<endl;
cout<<"Proof not found in time "<<Timer::msToSecondsString(Timer::elapsedMilliseconds())<<endl;
if (env.remainingTime()/100>0) {
addCommentSignForSZS(cout);
cout<<"SZS status GaveUp for "<<env.options->problemName()<<endl;
Expand Down Expand Up @@ -439,7 +439,7 @@ bool PortfolioMode::runSchedule(Schedule schedule) {
Set<pid_t> processes;
bool success = false;
int remainingTime;
while(Timer::syncClock(), remainingTime = env.remainingTime() / 100, remainingTime > 0)
while(remainingTime = env.remainingTime() / 100, remainingTime > 0)
{
// running under capacity, wake up more tasks
while(processes.size() < _numWorkers)
Expand Down Expand Up @@ -632,12 +632,7 @@ void PortfolioMode::runSlice(Options& strategyOpt)
{
System::registerForSIGHUPOnParentDeath();
UIHelper::portfolioParent=false;

env.timer->reset();
env.timer->start();

Timer::resetInstructionMeasuring();
Timer::setLimitEnforcement(true);
MichaelRawson marked this conversation as resolved.
Show resolved Hide resolved
Timer::reinitialise();
quickbeam123 marked this conversation as resolved.
Show resolved Hide resolved

Options opt = strategyOpt;
//we have already performed the normalization (or don't care about it)
Expand Down
3 changes: 0 additions & 3 deletions FMB/FiniteModelBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,9 +1601,6 @@ MainLoopResult FiniteModelBuilder::runImpl()
}
cout << "]" << endl;
}
Timer::syncClock();
if(env.timeLimitReached()){ return MainLoopResult(Statistics::TIME_LIMIT); }

quickbeam123 marked this conversation as resolved.
Show resolved Hide resolved
{
TIME_TRACE("fmb constraint creation");

Expand Down
4 changes: 0 additions & 4 deletions Forwards.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
namespace Lib
{
struct EmptyStruct {};
typedef void (*VoidFunc)();

template<typename T> class VirtualIterator;

Expand All @@ -37,7 +36,6 @@ template<typename T> class SharedSet;

typedef List<int> IntList;
typedef Stack<vstring> StringStack;
typedef List<VoidFunc> VoidFuncList;

class DefaultHash;
class DefaultHash2;
Expand All @@ -47,8 +45,6 @@ template <typename Key, typename Val, class Hash1=DefaultHash, class Hash2=Defau
template <typename Val, class Hash1=DefaultHash, class Hash2=DefaultHash2> class DHSet;
template <typename Val, class Hash1=DefaultHash, class Hash2=DefaultHash2> class DHMultiset;
template <typename Val, class Hash=DefaultHash> class Set;

class Timer;
};

namespace Kernel
Expand Down
11 changes: 0 additions & 11 deletions Kernel/MLMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ class MLMatcher::Impl final
// For backtracking support
DArray<unsigned> s_matchRecord;
unsigned s_currBLit;
int s_counter;
bool s_multiset;
};

Expand Down Expand Up @@ -557,7 +556,6 @@ void MLMatcher::Impl::init(Literal** baseLits, unsigned baseLen, Clause* instanc

s_matchingData.nextAlts[0] = 0;
s_currBLit = 0;
s_counter = 0;
s_multiset = multiset;
}

Expand Down Expand Up @@ -621,15 +619,6 @@ bool MLMatcher::Impl::nextMatch()
if(s_currBLit==0) { return false; }
s_currBLit--;
}

s_counter++;
if(s_counter==50000) {
s_counter=0;
if(env.timeLimitReached()) {
throw TimeLimitExceededException();
}
}

} // while (true)

ASSERTION_VIOLATION; // unreachable
Expand Down
14 changes: 0 additions & 14 deletions Kernel/MLMatcherSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,6 @@ class MLMatcherSD::Impl final
DArray<pair<int,int> > s_intersectionData;

MatchingData s_matchingData;

int s_counter;
};


Expand Down Expand Up @@ -889,8 +887,6 @@ void MLMatcherSD::Impl::init(Literal** baseLits, unsigned baseLen, Clause* insta
std::cerr << "\tinstance: " << instance->toString() << std::endl;
#endif
initMatchingData(baseLits, baseLen, instance, alts);

s_counter = 0;
}


Expand Down Expand Up @@ -1060,16 +1056,6 @@ bool MLMatcherSD::Impl::nextMatch()
return false;
}
}

// Ensure vampire exits timely in pathological cases instead of appearing to be stuck
s_counter++;
if(s_counter==50000) {
// std::cerr << "counter reached 50k" << std::endl;
s_counter=0;
if(env.timeLimitReached()) {
throw TimeLimitExceededException();
}
}
} // while (true)

// We found a complete match
Expand Down
10 changes: 0 additions & 10 deletions Kernel/MLVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ bool MLVariant::isVariant(Literal* const * cl1Lits, Clause* cl2, LiteralList** a
md->nextAlts[0]=0;
unsigned currBLit=0;

int counter=0;

while(true) {
MatchingData::InitResult ires=md->ensureInit(currBLit);
if(ires!=MatchingData::OK) {
Expand Down Expand Up @@ -448,14 +446,6 @@ bool MLVariant::isVariant(Literal* const * cl1Lits, Clause* cl2, LiteralList** a
if(currBLit==0) { return false; }
currBLit--;
}

counter++;
if(counter==50000) {
counter=0;
if(env.timeLimitReached()) {
throw TimeLimitExceededException();
}
}
}
return true;
}
Expand Down
8 changes: 3 additions & 5 deletions Lib/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
* @since 24/07/2023, mostly replaced by a small-object allocator
*/

#include <cstdlib>
#include <limits>

#include "Allocator.hpp"
#include "Lib/Timer.hpp"

#ifndef INDIVIDUAL_ALLOCATIONS
Lib::SmallObjectAllocator Lib::GLOBAL_SMALL_OBJECT_ALLOCATOR;
Expand All @@ -42,7 +44,6 @@ void *operator new(size_t size, std::align_val_t align_val) {
throw std::bad_alloc();
ALLOCATED += size;
{
Lib::TimeoutProtector tp;
quickbeam123 marked this conversation as resolved.
Show resolved Hide resolved
if(void *ptr = std::aligned_alloc(align, size))
return ptr;

Expand All @@ -62,7 +63,6 @@ void *operator new(size_t size) {
throw std::bad_alloc();
ALLOCATED += size;
{
Lib::TimeoutProtector tp;
if(void *ptr = std::malloc(size))
return ptr;
}
Expand All @@ -73,7 +73,6 @@ void *operator new(size_t size) {
void operator delete(void *ptr, size_t size) noexcept {
ASS_GE(ALLOCATED, size)
ALLOCATED -= size;
Lib::TimeoutProtector tp;
std::free(ptr);
}

Expand All @@ -88,6 +87,5 @@ void operator delete(void *ptr, size_t size, std::align_val_t align) noexcept {
// occurs very rarely and usually from deep in the bowels of the standard library
// TODO does cause us to slightly over-report allocated memory
void operator delete(void *ptr) noexcept {
Lib::TimeoutProtector tp;
std::free(ptr);
}
23 changes: 1 addition & 22 deletions Lib/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ Environment::Environment()
{
options = new Options;

// statistics calls the timer
timer = Timer::instance();

statistics = new Statistics;
signature = new Signature;
sharing = new TermSharing;
Expand All @@ -71,31 +68,13 @@ Environment::Environment()

Environment::~Environment()
{
Timer::setLimitEnforcement(false);

delete sharing;
delete signature;
delete statistics;
if (predicateSineLevels) delete predicateSineLevels;
delete options;
}

/**
* If the global time limit reached set Statistics::terminationReason
* to TIME_LIMIT and return true, otherwise return false.
* @since 25/03/2008 Torrevieja
*/
bool Environment::timeLimitReached() const
{
if (options->timeLimitInDeciseconds() &&
timer->elapsedDeciseconds() > options->timeLimitInDeciseconds()) {
statistics->terminationReason = Shell::Statistics::TIME_LIMIT;
Timer::setLimitEnforcement(false);
return true;
}
return false;
} // Environment::timeLimitReached

/**
* Return remaining time in miliseconds.
*/
Expand All @@ -105,7 +84,7 @@ int Environment::remainingTime() const
if(options->timeLimitInDeciseconds() == 0){
return 3600000;
}
return options->timeLimitInDeciseconds()*100 - timer->elapsedMilliseconds();
return options->timeLimitInDeciseconds()*100 - Timer::elapsedMilliseconds();
}

// global environment object, constructed before main() and used everywhere
Expand Down
16 changes: 0 additions & 16 deletions Lib/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,13 @@ class Environment
Indexing::TermSharing* sharing;
/** Currently used statistics */
Shell::Statistics* statistics;
/** Currently used timer, this is used by all timers as a global clock */
Timer* timer;

unsigned char maxSineLevel;

DHMap<unsigned, unsigned>* predicateSineLevels;

DHMap<const Kernel::Unit*,vstring>* proofExtra; // maps Unit* pointers to the associated proof extra string, if available

bool timeLimitReached() const;

template<int Period>
void checkTimeSometime() const
{
static int counter=0;
counter++;
if(counter==Period) {
counter=0;
if(timeLimitReached()) {
throw TimeLimitExceededException();
}
}
}
/** Time remaining until the end of the time-limit in miliseconds */
int remainingTime() const;
/** set to true when coloring is used for symbol elimination or interpolation */
Expand Down
8 changes: 8 additions & 0 deletions Lib/Portability.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ static_assert(
"Vampire assumes that there are 8 bits in a `char`"
);

#define VAMPIRE_PERF_EXISTS 0
quickbeam123 marked this conversation as resolved.
Show resolved Hide resolved
#ifdef __linux__
#if __has_include(<linux/perf_event.h>)
#undef VAMPIRE_PERF_EXISTS
#define VAMPIRE_PERF_EXISTS 1
#endif
#endif

#endif /*__Portability__*/
52 changes: 2 additions & 50 deletions Lib/Sys/Multiprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@
*/

#include <cerrno>

#include "Lib/Portability.hpp"

#include <csignal>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "Lib/Environment.hpp"
#include "Lib/List.hpp"
#include "Lib/Timer.hpp"
#include "Debug/TimeProfiling.hpp"
#include "Lib/Exception.hpp"

#include "Multiprocessing.hpp"
#include "Debug/TimeProfiling.hpp"

namespace Lib
{
Expand All @@ -39,56 +34,13 @@ Multiprocessing* Multiprocessing::instance()
return &inst;
}

Multiprocessing::Multiprocessing()
: _preFork(0), _postForkParent(0), _postForkChild(0)
{

}

Multiprocessing::~Multiprocessing()
{
VoidFuncList::destroy(_preFork);
VoidFuncList::destroy(_postForkParent);
VoidFuncList::destroy(_postForkChild);
}

void Multiprocessing::registerForkHandlers(VoidFunc before, VoidFunc afterParent, VoidFunc afterChild)
{
if(before) {
VoidFuncList::push(before, _preFork);
}
if(afterParent) {
VoidFuncList::push(afterParent, _postForkParent);
}
if(afterChild) {
VoidFuncList::push(afterChild, _postForkChild);
}
}

void Multiprocessing::executeFuncList(VoidFuncList* lst)
{
VoidFuncList::Iterator fit(lst);
while(fit.hasNext()) {
VoidFunc func=fit.next();
func();
}
}


pid_t Multiprocessing::fork()
{
executeFuncList(_preFork);
errno=0;
pid_t res=::fork();
if(res==-1) {
SYSTEM_FAIL("Call to fork() function failed.", errno);
}
if(res==0) {
executeFuncList(_postForkChild);
}
else {
executeFuncList(_postForkParent);
}
return res;
}

Expand Down
Loading