Skip to content

Commit

Permalink
Add timeouts to the thunk generated by toolchain models.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadjad committed Sep 17, 2018
1 parent 9b87791 commit 5b0a4d8
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 21 deletions.
5 changes: 5 additions & 0 deletions examples/gtest/create-thunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <chrono>
#include <algorithm>
#include <cctype>
#include <getopt.h>
Expand All @@ -17,8 +18,11 @@
#include "util/path.hh"

using namespace std;
using namespace std::chrono;
using namespace gg::thunk;

static constexpr milliseconds TIMEOUT = 20s;

void usage( const char * argv0 )
{
cerr << "Usage: " << argv0 << endl
Expand Down Expand Up @@ -81,6 +85,7 @@ struct TestCase
executables,
outputs,
{},
TIMEOUT,
ThunkFactory::Options::collect_data
| ThunkFactory::Options::include_filenames
);
Expand Down
2 changes: 1 addition & 1 deletion src/models/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bin_PROGRAMS = model-gcc model-ar model-ranlib model-strip model-ld \
model-generic model-nm model-readelf generate-deps dir-watcher

COMMON_TOOLCHAIN_SOURCES = cli_description.hh cli_description.cc \
toolchain.hh toolchain.cc gcc.hh
toolchain.hh toolchain.cc gcc.hh timeouts.hh

model_gcc_SOURCES = gcc.cc gcc-base.cc preprocessor.cc \
linker.cc linker-base.cc gcc-args.cc \
Expand Down
5 changes: 4 additions & 1 deletion src/models/ar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstring>
#include <getopt.h>

#include "timeouts.hh"
#include "thunk/factory.hh"
#include "thunk/ggutils.hh"
#include "thunk/thunk.hh"
Expand All @@ -15,9 +16,10 @@
#include "toolchain.hh"

using namespace std;
using namespace std::chrono;
using namespace gg::thunk;

const int PLUGIN_FLAG = 1000;
static constexpr int PLUGIN_FLAG = 1000;

/* this function is based on ar source code */
void generate_thunk( int argc, char * argv[] )
Expand Down Expand Up @@ -131,6 +133,7 @@ void generate_thunk( int argc, char * argv[] )
{ program_data.at( AR ) },
{ { "output", outfile } },
{},
AR_TIMEOUT,
ThunkFactory::Options::create_placeholder
| ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
Expand Down
12 changes: 9 additions & 3 deletions src/models/gcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include <fstream>
#include <sstream>
#include <cmath>
#include <chrono>
#include <getopt.h>
#include <libgen.h>
#include <sys/ioctl.h>

#include "timeouts.hh"
#include "protobufs/util.hh"
#include "thunk/factory.hh"
#include "thunk/placeholder.hh"
Expand All @@ -33,6 +35,7 @@
#include "util/ipc_socket.hh"

using namespace std;
using namespace std::chrono;
using namespace gg::thunk;

class Blueprints
Expand Down Expand Up @@ -534,7 +537,8 @@ string GCCModelGenerator::generate_thunk( const GCCStage first_stage,
base_executables,
thunk_outputs,
dummy_dirs,
ThunkFactory::Options::collect_data
( defer_depgen_ ) ? DEPGEN_TIMEOUT : PREPROCESS_TIMEOUT,
ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
| ThunkFactory::Options::include_filenames
);
Expand Down Expand Up @@ -574,7 +578,8 @@ string GCCModelGenerator::generate_thunk( const GCCStage first_stage,
base_executables,
{ { "output", output } },
dummy_dirs,
ThunkFactory::Options::collect_data
COMPILE_TIMEOUT,
ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
| ThunkFactory::Options::include_filenames
);
Expand Down Expand Up @@ -607,7 +612,8 @@ string GCCModelGenerator::generate_thunk( const GCCStage first_stage,
base_executables,
{ { "output", output } },
dummy_dirs,
ThunkFactory::Options::collect_data
ASSEMBLE_TIMEOUT,
ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
| ThunkFactory::Options::include_filenames
);
Expand Down
1 change: 1 addition & 0 deletions src/models/gcc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <vector>
#include <chrono>
#include <unordered_map>

#include "thunk/thunk.hh"
Expand Down
3 changes: 3 additions & 0 deletions src/models/generate-deps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>

#include "gcc.hh"
#include "timeouts.hh"
#include "thunk/thunk.hh"
#include "thunk/thunk_reader.hh"
#include "thunk/thunk_writer.hh"
Expand Down Expand Up @@ -209,6 +210,8 @@ int main( int argc, char * argv[] )
Thunk new_thunk { move( new_function ), move( values ), {},
move( executables ), { "output" } };

new_thunk.set_timeout( PREPROCESS_TIMEOUT );

/* (4) clean up and write output ###############################*/
roost::remove_directory( sysroot );
ThunkWriter::write( new_thunk, execution_root / "output" );
Expand Down
2 changes: 2 additions & 0 deletions src/models/generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <getopt.h>

#include "timeouts.hh"
#include "cli_description.hh"
#include "thunk/factory.hh"
#include "thunk/ggutils.hh"
Expand Down Expand Up @@ -103,6 +104,7 @@ void generate_thunk( const CLIDescription & cli_description,
{ executable },
outfiles,
{},
NO_TIMEOUT,
ThunkFactory::Options::create_placeholder
| ThunkFactory::Options::collect_data
);
Expand Down
2 changes: 2 additions & 0 deletions src/models/ld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <list>

#include "gcc.hh"
#include "timeouts.hh"
#include "thunk/factory.hh"
#include "thunk/ggutils.hh"
#include "thunk/thunk.hh"
Expand Down Expand Up @@ -169,6 +170,7 @@ void generate_thunk( size_t argc, char * argv[] )
{ program_data.at( LD ) },
{ { "output", outfile } },
dummy_dirs,
LINK_TIMEOUT,
ThunkFactory::Options::create_placeholder
| ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
Expand Down
4 changes: 3 additions & 1 deletion src/models/linker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <unordered_set>

#include "timeouts.hh"
#include "thunk/placeholder.hh"
#include "thunk/factory.hh"
#include "util/system_runner.hh"
Expand Down Expand Up @@ -162,7 +163,8 @@ string GCCModelGenerator::generate_link_thunk( const vector<InputFile> & link_in
executables,
{ { "output", output } },
dummy_dirs,
ThunkFactory::Options::collect_data
LINK_TIMEOUT,
ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
| ThunkFactory::Options::include_filenames
);
Expand Down
2 changes: 2 additions & 0 deletions src/models/ranlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <getopt.h>

#include "timeouts.hh"
#include "thunk/factory.hh"
#include "thunk/ggutils.hh"
#include "thunk/thunk.hh"
Expand Down Expand Up @@ -39,6 +40,7 @@ void generate_thunk( int argc, char * argv[] )
{ program_data.at( RANLIB ) },
{ { "output", archive } },
{},
RANLIB_TIMEOUT,
ThunkFactory::Options::create_placeholder
| ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
Expand Down
2 changes: 2 additions & 0 deletions src/models/strip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <getopt.h>

#include "timeouts.hh"
#include "thunk/factory.hh"
#include "thunk/ggutils.hh"
#include "thunk/thunk.hh"
Expand Down Expand Up @@ -51,6 +52,7 @@ void generate_thunk( int argc, char * argv[] )
{ program_data.at( STRIP ) },
{ { "output", strip_output } },
{},
STRIP_TIMEOUT,
ThunkFactory::Options::create_placeholder
| ThunkFactory::Options::collect_data
| ThunkFactory::Options::generate_manifest
Expand Down
23 changes: 23 additions & 0 deletions src/models/timeouts.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* -*-mode:c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

#ifndef MODELS_TIMEOUTS_HH
#define MODELS_TIMEOUTS_HH

#include <chrono>

static constexpr std::chrono::milliseconds NO_TIMEOUT { 0 };
static constexpr std::chrono::milliseconds VERY_SHORT_TIMEOUT { 5'000 };
static constexpr std::chrono::milliseconds SHORT_TIMEOUT { 7'500 };
static constexpr std::chrono::milliseconds LONG_TIMEOUT { 12'500 };
static constexpr std::chrono::milliseconds VERY_LONG_TIMEOUT { 17'500 };

static constexpr std::chrono::milliseconds DEPGEN_TIMEOUT = VERY_LONG_TIMEOUT;
static constexpr std::chrono::milliseconds PREPROCESS_TIMEOUT = LONG_TIMEOUT;
static constexpr std::chrono::milliseconds COMPILE_TIMEOUT = SHORT_TIMEOUT;
static constexpr std::chrono::milliseconds ASSEMBLE_TIMEOUT = SHORT_TIMEOUT;
static constexpr std::chrono::milliseconds LINK_TIMEOUT = LONG_TIMEOUT;
static constexpr std::chrono::milliseconds AR_TIMEOUT = SHORT_TIMEOUT;
static constexpr std::chrono::milliseconds STRIP_TIMEOUT = SHORT_TIMEOUT;
static constexpr std::chrono::milliseconds RANLIB_TIMEOUT = VERY_SHORT_TIMEOUT;

#endif /* MODELS_TIMEOUTS_HH */
33 changes: 19 additions & 14 deletions src/thunk/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "factory.hh"

#include <algorithm>
#include <chrono>
#include <sys/stat.h>
#include <fcntl.h>

Expand All @@ -18,6 +19,7 @@
#include "util/tokenize.hh"

using namespace std;
using namespace std::chrono;
using namespace gg;
using namespace gg::thunk;

Expand Down Expand Up @@ -49,6 +51,7 @@ Thunk ThunkFactory::create_thunk( const Function & function,
const vector<Data> & data,
const vector<Data> & executables,
const vector<Output> & outputs,
const milliseconds & timeout,
const bool include_filenames )
{
vector<Thunk::DataItem> thunk_data;
Expand All @@ -71,18 +74,19 @@ Thunk ThunkFactory::create_thunk( const Function & function,
thunk_outputs.push_back( output.tag() );
}

return { move( thunk_function ),
move( thunk_data ),
move( thunk_executables ),
move( thunk_outputs ) };
Thunk output_thunk { move( thunk_function ), move( thunk_data ),
move( thunk_executables ), move( thunk_outputs ) };

output_thunk.set_timeout( timeout );
return output_thunk;
}

std::string ThunkFactory::generate( const Function & function,
const std::vector<Data> & data,
const std::vector<Data> & executables,
const std::vector<Output> & outputs,
const std::vector<std::string> & dummy_dirs,
const int options )
string ThunkFactory::generate( const Function & function,
const vector<Data> & data,
const vector<Data> & executables,
const vector<Output> & outputs,
const vector<string> & dummy_dirs,
const milliseconds & timeout, const int options )
{
const bool generate_manifest = options & Options::generate_manifest;
const bool create_placeholder = options & Options::create_placeholder;
Expand Down Expand Up @@ -151,10 +155,11 @@ std::string ThunkFactory::generate( const Function & function,
for ( const Data & datum : executables ) { fn_collect( datum, true ); }
}

string hash = ThunkWriter::write( { move( thunk_function ),
move( thunk_data ),
move( thunk_executables ),
move( thunk_outputs ) } );
Thunk output_thunk { move( thunk_function ), move( thunk_data ),
move( thunk_executables ), move( thunk_outputs ) };

output_thunk.set_timeout( timeout );
const string hash = ThunkWriter::write( output_thunk );

if ( create_placeholder ) {
for ( size_t i = 0; i < outputs.size(); i++ ) {
Expand Down
6 changes: 5 additions & 1 deletion src/thunk/factory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <vector>
#include <chrono>
#include <sys/types.h>

#include "thunk/thunk.hh"
Expand Down Expand Up @@ -64,14 +65,17 @@ public:
const std::vector<Data> & data,
const std::vector<Data> & executables,
const std::vector<Output> & outputs,
const std::chrono::milliseconds & timeout,
const bool include_filenames = true );

static std::string generate( const Function & function,
const std::vector<Data> & data,
const std::vector<Data> & executables,
const std::vector<Output> & outputs,
const std::vector<std::string> & dummy_dirs,
const int options );
const std::chrono::milliseconds & timeout =
std::chrono::milliseconds { 0 },
const int options = 0 );
};

#endif /* FACTORY_HH */

0 comments on commit 5b0a4d8

Please sign in to comment.