Skip to content

Commit

Permalink
Merge branch 'main' into stm32
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh authored Feb 2, 2024
2 parents cd0cbd2 + 9bbd509 commit dbcec8a
Show file tree
Hide file tree
Showing 75 changed files with 8,303 additions and 7,198 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@

# Generated trace files
*.lft
util/tracing/trace_to_chrome
util/tracing/trace_to_chrome.o
util/tracing/trace_to_csv
util/tracing/trace_to_csv.o
util/tracing/trace_to_influxdb
util/tracing/trace_to_influxdb.o
util/tracing/trace_util.o
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ endif()

set(Test test)
set(Lib lib)
set(CoreLib core)
set(CoreLibPath core)
set(CoreLib reactor-c)
set(PlatformLib platform)

include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/include/core)
include_directories(${CMAKE_SOURCE_DIR}/include/core/federated)
include_directories(${CMAKE_SOURCE_DIR}/include/core/federated/network)
include_directories(${CMAKE_SOURCE_DIR}/include/core/modal_models)
include_directories(${CMAKE_SOURCE_DIR}/include/core/platform)
include_directories(${CMAKE_SOURCE_DIR}/include/core/threaded)
Expand All @@ -39,6 +41,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/api)
enable_testing()
add_subdirectory(${Test})
add_subdirectory(${Lib})
add_subdirectory(${CoreLib})
add_subdirectory(${CoreLibPath})

include(test/Tests.cmake)
69 changes: 44 additions & 25 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,64 @@ if (DEFINED LF_TRACE)
list(APPEND GENERAL_SOURCES trace.c)
endif()

# Store all sources used to build the reactor-c lib in INFO_SOURCES
list(APPEND INFO_SOURCES ${GENERAL_SOURCES})

# Create the core library
add_library(core ${GENERAL_SOURCES})
# Add the general sources to the list of REACTORC_SOURCES
list(APPEND REACTORC_SOURCES ${GENERAL_SOURCES})

# Add sources for either threaded or single-threaded runtime
if (DEFINED FEDERATED)
include(federated/CMakeLists.txt)
include(federated/network/CMakeLists.txt)
endif()

# Add sources for either threaded or single-threaded runtime
if(DEFINED LF_SINGLE_THREADED)
message(STATUS "Including sources for single-threaded runtime.")
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
target_sources(core PRIVATE ${SINGLE_THREADED_SOURCES})
list(APPEND INFO_SOURCES ${SINGLE_THREADED_SOURCES})
list(APPEND REACTORC_SOURCES ${SINGLE_THREADED_SOURCES})
else()
message(STATUS "Including sources for threaded runtime with \
${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \
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)
include(modal_models/CMakeLists.txt)
include(platform/CMakeLists.txt)

# Print sources used for compilation
list(JOIN INFO_SOURCES ", " PRINTABLE_SOURCE_LIST)
list(JOIN REACTORC_SOURCES ", " PRINTABLE_SOURCE_LIST)
message(STATUS "Including the following sources: " ${PRINTABLE_SOURCE_LIST})

target_include_directories(core PUBLIC ../include)
target_include_directories(core PUBLIC ../include/core)
target_include_directories(core PUBLIC ../include/core/federated)
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)
# Create the reactor-c library. If we are targeting Zephyr we have to use the
# Zephyr Cmake extension to create the library and add the sources.
if(PLATFORM_ZEPHYR)
message("--- Building Zephyr library")
zephyr_library_named(reactor-c)
zephyr_library_sources(${REACTORC_SOURCES})
zephyr_library_link_libraries(kernel)
else()
add_library(reactor-c ${REACTORC_SOURCES})
endif()

# Apply compile definitions to the reactor-c library.
target_compile_definitions(reactor-c PUBLIC ${REACTORC_COMPILE_DEFS})

target_include_directories(reactor-c PUBLIC ../include)
target_include_directories(reactor-c PUBLIC ../include/core)
target_include_directories(reactor-c PUBLIC ../include/core/federated)
target_include_directories(reactor-c PUBLIC ../include/core/federated/network)
target_include_directories(reactor-c PUBLIC ../include/core/platform)
target_include_directories(reactor-c PUBLIC ../include/core/modal_models)
target_include_directories(reactor-c PUBLIC ../include/core/threaded)
target_include_directories(reactor-c PUBLIC ../include/core/utils)
target_include_directories(reactor-c PUBLIC federated/RTI/)

if (APPLE)
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
Expand All @@ -64,38 +81,38 @@ if(DEFINED FEDERATED_AUTHENTICATED)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
endif()
find_package(OpenSSL REQUIRED)
target_link_libraries(core PUBLIC OpenSSL::SSL)
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
endif()

if(DEFINED _LF_CLOCK_SYNC_ON)
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(core PUBLIC ${MATH_LIBRARY})
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
endif()
endif()

# Link with thread library, unless if we are targeting the Zephyr RTOS
# Link with thread library, unless we are on the Zephyr platform.
if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
if (NOT PLATFORM_ZEPHYR)
find_package(Threads REQUIRED)
target_link_libraries(core PUBLIC Threads::Threads)
target_link_libraries(reactor-c PUBLIC Threads::Threads)
endif()
endif()

# Macro for translating a command-line argument into compile definition for
# core lib
# reactor-c lib
macro(define X)
if(DEFINED ${X})
message(STATUS ${X}=${${X}})
target_compile_definitions(core PUBLIC ${X}=${${X}})
target_compile_definitions(reactor-c PUBLIC ${X}=${${X}})
endif(DEFINED ${X})
endmacro()

# FIXME: May want these to be application dependent, hence passed as
# parameters to Cmake.
target_compile_definitions(core PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
target_compile_definitions(core PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
target_compile_definitions(core PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
target_compile_definitions(reactor-c PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
target_compile_definitions(reactor-c PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
target_compile_definitions(reactor-c PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})

# Search and apply all possible compile definitions
message(STATUS "Applying preprocessor definitions...")
Expand Down Expand Up @@ -123,3 +140,5 @@ define(SCHEDULER)
define(LF_SOURCE_DIRECTORY)
define(LF_PACKAGE_DIRECTORY)
define(LF_FILE_SEPARATOR)
define(WORKERS_NEEDED_FOR_FEDERATE)
define(LF_ENCLAVES)
76 changes: 55 additions & 21 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,15 +84,19 @@ 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");
modes->state_resets_size = num_state_resets;
if (modes->state_resets_size > 0) {
modes->state_resets = (mode_state_variable_reset_data_t *) calloc(modes->state_resets_size, sizeof(mode_state_variable_reset_data_t));
LF_ASSERT(modes->state_resets, "Out of memory");
} else {
modes->state_resets = NULL;
}

env->modes = modes;

Expand All @@ -107,9 +111,13 @@ 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");
env->_lf_intended_tag_fields_size = num_is_present_fields;
if (num_is_present_fields > 0) {
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
LF_ASSERT(env->_lf_intended_tag_fields, "Out of memory");
env->_lf_intended_tag_fields_size = num_is_present_fields;
} else {
env->_lf_intended_tag_fields_size = NULL;
}
#endif
}

Expand Down Expand Up @@ -155,6 +163,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 +184,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 +197,57 @@ 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");
if(env->timer_triggers_size > 0) {
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
LF_ASSERT(env->timer_triggers, "Out of memory");
} else {
env->timer_triggers = NULL;
}

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");
if (env->startup_reactions_size > 0) {
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
LF_ASSERT(env->startup_reactions, "Out of memory");
} else {
env->startup_reactions = NULL;
}

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");
if(env->shutdown_reactions_size > 0) {
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
LF_ASSERT(env->shutdown_reactions, "Out of memory");
} else {
env->shutdown_reactions = NULL;
}

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");
if (env->reset_reactions_size > 0) {
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
LF_ASSERT(env->reset_reactions, "Out of memory");
} else {
env->reset_reactions = NULL;
}

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");

env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
lf_assert(env->is_present_fields_abbreviated != NULL, "Out of memory");
if (env->is_present_fields_size > 0) {
env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
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, "Out of memory");
} else {
env->is_present_fields = NULL;
env->is_present_fields_abbreviated = NULL;
}

env->_lf_handle=1;

Expand Down
5 changes: 2 additions & 3 deletions core/federated/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(FEDERATED_SOURCES clock-sync.c federate.c net_util.c)
list(APPEND INFO_SOURCES ${FEDERATED_SOURCES})
set(FEDERATED_SOURCES clock-sync.c federate.c)

list(TRANSFORM FEDERATED_SOURCES PREPEND federated/)
target_sources(core PRIVATE ${FEDERATED_SOURCES})
list(APPEND REACTORC_SOURCES ${FEDERATED_SOURCES})
16 changes: 11 additions & 5 deletions core/federated/RTI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ endif()
set(IncludeDir ../../../include/core)
include_directories(${IncludeDir})
include_directories(${IncludeDir}/federated)
include_directories(${IncludeDir}/federated/network)
include_directories(${IncludeDir}/modal_models)
include_directories(${IncludeDir}/platform)
include_directories(${IncludeDir}/utils)
Expand All @@ -60,17 +61,18 @@ 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
${CoreLib}/utils/util.c
${CoreLib}/tag.c
${CoreLib}/federated/net_util.c
${CoreLib}/federated/network/net_util.c
${CoreLib}/utils/pqueue_base.c
${CoreLib}/utils/pqueue_tag.c
${CoreLib}/utils/pqueue.c
message_record/message_record.c
)

IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
Expand All @@ -79,8 +81,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
16 changes: 14 additions & 2 deletions core/federated/RTI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,17 @@ If you would like to go back to non-AUTH mode, you would have to remove all cont

To build a docker image for the RTI, do
```bash
docker build -t rti:rti -f rti.Dockerfile ../../../core/
```
docker build -t lflang/rti:latest -f rti.Dockerfile ../../../
```

To push it to DockerHub, run:
```bash
docker push lflang/rti:latest
```

You may need to login first:
```bash
docker login -u [username]
```

To authenticate, request a PAT on [DockerHub](https://hub.docker.com/settings/security).
Loading

0 comments on commit dbcec8a

Please sign in to comment.