Skip to content

Commit

Permalink
Merge pull request #242 from lf-lang/enclaves2
Browse files Browse the repository at this point in the history
Scheduling enclaves
  • Loading branch information
erlingrj authored Nov 13, 2023
2 parents d26e285 + 390667b commit f68e56a
Show file tree
Hide file tree
Showing 33 changed files with 1,340 additions and 989 deletions.
8 changes: 8 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ tracing=${LF_TRACE}.")
include(threaded/CMakeLists.txt)
endif()

# Add sources for the local RTI if we are using scheduling enclaves
if(DEFINED LF_ENCLAVES)
include(federated/RTI/local_rti.cmake)
endif()

# Include sources from subdirectories
include(utils/CMakeLists.txt)
Expand All @@ -50,6 +54,7 @@ target_include_directories(core PUBLIC ../include/core/platform)
target_include_directories(core PUBLIC ../include/core/modal_models)
target_include_directories(core PUBLIC ../include/core/threaded)
target_include_directories(core PUBLIC ../include/core/utils)
target_include_directories(core PUBLIC federated/RTI/)

if (APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
Expand Down Expand Up @@ -123,3 +128,6 @@ define(SCHEDULER)
define(LF_SOURCE_DIRECTORY)
define(LF_PACKAGE_DIRECTORY)
define(LF_FILE_SEPARATOR)
define(WORKERS_NEEDED_FOR_FEDERATE)
define(LF_ENCLAVES)
define(LF_NOASSERT)
28 changes: 17 additions & 11 deletions core/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void environment_init_threaded(environment_t* env, int num_workers) {
#if !defined(LF_SINGLE_THREADED)
env->num_workers = num_workers;
env->thread_ids = (lf_thread_t*)calloc(num_workers, sizeof(lf_thread_t));
lf_assert(env->thread_ids != NULL, "Out of memory");
LF_ASSERT(env->thread_ids, "Out of memory");
env->barrier.requestors = 0;
env->barrier.horizon = FOREVER_TAG;

Expand Down Expand Up @@ -84,14 +84,14 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
#ifdef MODAL_REACTORS
if (num_modes > 0) {
mode_environment_t* modes = (mode_environment_t *) calloc(1, sizeof(mode_environment_t));
lf_assert(modes != NULL, "Out of memory");
LF_ASSERT(modes, "Out of memory");
modes->modal_reactor_states = (reactor_mode_state_t**) calloc(num_modes, sizeof(reactor_mode_state_t*));
lf_assert(modes->modal_reactor_states != NULL, "Out of memory");
LF_ASSERT(modes->modal_reactor_states, "Out of memory");
modes->modal_reactor_states_size = num_modes;
modes->triggered_reactions_request = 0;

modes->state_resets = (mode_state_variable_reset_data_t *) calloc(num_state_resets, sizeof(mode_state_variable_reset_data_t));
lf_assert(modes->state_resets != NULL, "Out of memory");
LF_ASSERT(modes->state_resets, "Out of memory");
modes->state_resets_size = num_state_resets;

env->modes = modes;
Expand All @@ -108,7 +108,7 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
static void environment_init_federated(environment_t* env, int num_is_present_fields) {
#ifdef FEDERATED_DECENTRALIZED
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
lf_assert(env->_lf_intended_tag_fields != NULL, "Out of memory");
LF_ASSERT(env->_lf_intended_tag_fields, "Out of memory");
env->_lf_intended_tag_fields_size = num_is_present_fields;
#endif
}
Expand Down Expand Up @@ -155,6 +155,7 @@ static void environment_free_federated(environment_t* env) {
}

void environment_free(environment_t* env) {
free(env->name);
free(env->timer_triggers);
free(env->startup_reactions);
free(env->shutdown_reactions);
Expand All @@ -175,6 +176,7 @@ void environment_free(environment_t* env) {

int environment_init(
environment_t* env,
const char *name,
int id,
int num_workers,
int num_timers,
Expand All @@ -187,33 +189,37 @@ int environment_init(
const char * trace_file_name
) {

env->name = malloc(strlen(name) + 1); // +1 for the null terminator
LF_ASSERT(env->name, "Out of memory");
strcpy(env->name, name);

env->id = id;
env->stop_tag = FOREVER_TAG;

env->timer_triggers_size=num_timers;
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
lf_assert(env->timer_triggers != NULL, "Out of memory");
LF_ASSERT(env->timer_triggers, "Out of memory");

env->startup_reactions_size=num_startup_reactions;
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
lf_assert(env->startup_reactions != NULL, "Out of memory");
LF_ASSERT(env->startup_reactions, "Out of memory");

env->shutdown_reactions_size=num_shutdown_reactions;
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
lf_assert(env->shutdown_reactions != NULL, "Out of memory");
LF_ASSERT(env->shutdown_reactions, "Out of memory");

env->reset_reactions_size=num_reset_reactions;
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
lf_assert(env->reset_reactions != NULL, "Out of memory");
LF_ASSERT(env->reset_reactions, "Out of memory");

env->is_present_fields_size = num_is_present_fields;
env->is_present_fields_abbreviated_size = 0;

env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
lf_assert(env->is_present_fields != NULL, "Out of memory");
LF_ASSERT(env->is_present_fields, "Out of memory");

env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
lf_assert(env->is_present_fields_abbreviated != NULL, "Out of memory");
LF_ASSERT(env->is_present_fields_abbreviated, "Out of memory");

env->_lf_handle=1;

Expand Down
10 changes: 7 additions & 3 deletions core/federated/RTI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ include_directories(${IncludeDir}/utils)
# Declare a new executable target and list all its sources
add_executable(
RTI
enclave.c
rti.c
rti_lib.c
main.c
rti_common.c
rti_remote.c
${CoreLib}/trace.c
${LF_PLATFORM_FILE}
${CoreLib}/platform/lf_unix_clock_support.c
Expand All @@ -79,8 +79,12 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
target_compile_definitions(RTI PUBLIC LOG_LEVEL=4)
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)

# Set the STANDALONE_RTI flag to include the rti_remote and rti_common.
target_compile_definitions(RTI PUBLIC STANDALONE_RTI=1)

# Set FEDERATED to get federated compilation support
target_compile_definitions(RTI PUBLIC FEDERATED=1)

target_compile_definitions(RTI PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})

# Set RTI Tracing
Expand Down
Loading

0 comments on commit f68e56a

Please sign in to comment.