Skip to content

Commit dbcec8a

Browse files
authored
Merge branch 'main' into stm32
2 parents cd0cbd2 + 9bbd509 commit dbcec8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+8303
-7198
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99

1010
# Generated trace files
1111
*.lft
12+
util/tracing/trace_to_chrome
13+
util/tracing/trace_to_chrome.o
14+
util/tracing/trace_to_csv
15+
util/tracing/trace_to_csv.o
16+
util/tracing/trace_to_influxdb
17+
util/tracing/trace_to_influxdb.o
18+
util/tracing/trace_util.o

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ endif()
2424

2525
set(Test test)
2626
set(Lib lib)
27-
set(CoreLib core)
27+
set(CoreLibPath core)
28+
set(CoreLib reactor-c)
2829
set(PlatformLib platform)
2930

3031
include_directories(${CMAKE_SOURCE_DIR}/include)
3132
include_directories(${CMAKE_SOURCE_DIR}/include/core)
3233
include_directories(${CMAKE_SOURCE_DIR}/include/core/federated)
34+
include_directories(${CMAKE_SOURCE_DIR}/include/core/federated/network)
3335
include_directories(${CMAKE_SOURCE_DIR}/include/core/modal_models)
3436
include_directories(${CMAKE_SOURCE_DIR}/include/core/platform)
3537
include_directories(${CMAKE_SOURCE_DIR}/include/core/threaded)
@@ -39,6 +41,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/api)
3941
enable_testing()
4042
add_subdirectory(${Test})
4143
add_subdirectory(${Lib})
42-
add_subdirectory(${CoreLib})
44+
add_subdirectory(${CoreLibPath})
4345

4446
include(test/Tests.cmake)

core/CMakeLists.txt

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,64 @@ if (DEFINED LF_TRACE)
99
list(APPEND GENERAL_SOURCES trace.c)
1010
endif()
1111

12-
# Store all sources used to build the reactor-c lib in INFO_SOURCES
13-
list(APPEND INFO_SOURCES ${GENERAL_SOURCES})
14-
15-
# Create the core library
16-
add_library(core ${GENERAL_SOURCES})
12+
# Add the general sources to the list of REACTORC_SOURCES
13+
list(APPEND REACTORC_SOURCES ${GENERAL_SOURCES})
1714

1815
# Add sources for either threaded or single-threaded runtime
1916
if (DEFINED FEDERATED)
2017
include(federated/CMakeLists.txt)
18+
include(federated/network/CMakeLists.txt)
2119
endif()
2220

2321
# Add sources for either threaded or single-threaded runtime
2422
if(DEFINED LF_SINGLE_THREADED)
2523
message(STATUS "Including sources for single-threaded runtime.")
2624
list(APPEND SINGLE_THREADED_SOURCES reactor.c)
27-
target_sources(core PRIVATE ${SINGLE_THREADED_SOURCES})
28-
list(APPEND INFO_SOURCES ${SINGLE_THREADED_SOURCES})
25+
list(APPEND REACTORC_SOURCES ${SINGLE_THREADED_SOURCES})
2926
else()
3027
message(STATUS "Including sources for threaded runtime with \
3128
${NUMBER_OF_WORKERS} worker(s) with scheduler=${SCHEDULER} and \
3229
tracing=${LF_TRACE}.")
3330
include(threaded/CMakeLists.txt)
3431
endif()
3532

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

3738
# Include sources from subdirectories
3839
include(utils/CMakeLists.txt)
3940
include(modal_models/CMakeLists.txt)
4041
include(platform/CMakeLists.txt)
4142

4243
# Print sources used for compilation
43-
list(JOIN INFO_SOURCES ", " PRINTABLE_SOURCE_LIST)
44+
list(JOIN REACTORC_SOURCES ", " PRINTABLE_SOURCE_LIST)
4445
message(STATUS "Including the following sources: " ${PRINTABLE_SOURCE_LIST})
4546

46-
target_include_directories(core PUBLIC ../include)
47-
target_include_directories(core PUBLIC ../include/core)
48-
target_include_directories(core PUBLIC ../include/core/federated)
49-
target_include_directories(core PUBLIC ../include/core/platform)
50-
target_include_directories(core PUBLIC ../include/core/modal_models)
51-
target_include_directories(core PUBLIC ../include/core/threaded)
52-
target_include_directories(core PUBLIC ../include/core/utils)
47+
# Create the reactor-c library. If we are targeting Zephyr we have to use the
48+
# Zephyr Cmake extension to create the library and add the sources.
49+
if(PLATFORM_ZEPHYR)
50+
message("--- Building Zephyr library")
51+
zephyr_library_named(reactor-c)
52+
zephyr_library_sources(${REACTORC_SOURCES})
53+
zephyr_library_link_libraries(kernel)
54+
else()
55+
add_library(reactor-c ${REACTORC_SOURCES})
56+
endif()
57+
58+
# Apply compile definitions to the reactor-c library.
59+
target_compile_definitions(reactor-c PUBLIC ${REACTORC_COMPILE_DEFS})
60+
61+
target_include_directories(reactor-c PUBLIC ../include)
62+
target_include_directories(reactor-c PUBLIC ../include/core)
63+
target_include_directories(reactor-c PUBLIC ../include/core/federated)
64+
target_include_directories(reactor-c PUBLIC ../include/core/federated/network)
65+
target_include_directories(reactor-c PUBLIC ../include/core/platform)
66+
target_include_directories(reactor-c PUBLIC ../include/core/modal_models)
67+
target_include_directories(reactor-c PUBLIC ../include/core/threaded)
68+
target_include_directories(reactor-c PUBLIC ../include/core/utils)
69+
target_include_directories(reactor-c PUBLIC federated/RTI/)
5370

5471
if (APPLE)
5572
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
@@ -64,38 +81,38 @@ if(DEFINED FEDERATED_AUTHENTICATED)
6481
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
6582
endif()
6683
find_package(OpenSSL REQUIRED)
67-
target_link_libraries(core PUBLIC OpenSSL::SSL)
84+
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
6885
endif()
6986

7087
if(DEFINED _LF_CLOCK_SYNC_ON)
7188
find_library(MATH_LIBRARY m)
7289
if(MATH_LIBRARY)
73-
target_link_libraries(core PUBLIC ${MATH_LIBRARY})
90+
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
7491
endif()
7592
endif()
7693

77-
# Link with thread library, unless if we are targeting the Zephyr RTOS
94+
# Link with thread library, unless we are on the Zephyr platform.
7895
if(NOT DEFINED LF_SINGLE_THREADED OR DEFINED LF_TRACE)
79-
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Zephyr")
96+
if (NOT PLATFORM_ZEPHYR)
8097
find_package(Threads REQUIRED)
81-
target_link_libraries(core PUBLIC Threads::Threads)
98+
target_link_libraries(reactor-c PUBLIC Threads::Threads)
8299
endif()
83100
endif()
84101

85102
# Macro for translating a command-line argument into compile definition for
86-
# core lib
103+
# reactor-c lib
87104
macro(define X)
88105
if(DEFINED ${X})
89106
message(STATUS ${X}=${${X}})
90-
target_compile_definitions(core PUBLIC ${X}=${${X}})
107+
target_compile_definitions(reactor-c PUBLIC ${X}=${${X}})
91108
endif(DEFINED ${X})
92109
endmacro()
93110

94111
# FIXME: May want these to be application dependent, hence passed as
95112
# parameters to Cmake.
96-
target_compile_definitions(core PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
97-
target_compile_definitions(core PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
98-
target_compile_definitions(core PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
113+
target_compile_definitions(reactor-c PRIVATE INITIAL_EVENT_QUEUE_SIZE=10)
114+
target_compile_definitions(reactor-c PRIVATE INITIAL_REACT_QUEUE_SIZE=10)
115+
target_compile_definitions(reactor-c PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
99116

100117
# Search and apply all possible compile definitions
101118
message(STATUS "Applying preprocessor definitions...")
@@ -123,3 +140,5 @@ define(SCHEDULER)
123140
define(LF_SOURCE_DIRECTORY)
124141
define(LF_PACKAGE_DIRECTORY)
125142
define(LF_FILE_SEPARATOR)
143+
define(WORKERS_NEEDED_FOR_FEDERATE)
144+
define(LF_ENCLAVES)

core/environment.c

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void environment_init_threaded(environment_t* env, int num_workers) {
4545
#if !defined(LF_SINGLE_THREADED)
4646
env->num_workers = num_workers;
4747
env->thread_ids = (lf_thread_t*)calloc(num_workers, sizeof(lf_thread_t));
48-
lf_assert(env->thread_ids != NULL, "Out of memory");
48+
LF_ASSERT(env->thread_ids, "Out of memory");
4949
env->barrier.requestors = 0;
5050
env->barrier.horizon = FOREVER_TAG;
5151

@@ -84,15 +84,19 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
8484
#ifdef MODAL_REACTORS
8585
if (num_modes > 0) {
8686
mode_environment_t* modes = (mode_environment_t *) calloc(1, sizeof(mode_environment_t));
87-
lf_assert(modes != NULL, "Out of memory");
87+
LF_ASSERT(modes, "Out of memory");
8888
modes->modal_reactor_states = (reactor_mode_state_t**) calloc(num_modes, sizeof(reactor_mode_state_t*));
89-
lf_assert(modes->modal_reactor_states != NULL, "Out of memory");
89+
LF_ASSERT(modes->modal_reactor_states, "Out of memory");
9090
modes->modal_reactor_states_size = num_modes;
9191
modes->triggered_reactions_request = 0;
9292

93-
modes->state_resets = (mode_state_variable_reset_data_t *) calloc(num_state_resets, sizeof(mode_state_variable_reset_data_t));
94-
lf_assert(modes->state_resets != NULL, "Out of memory");
9593
modes->state_resets_size = num_state_resets;
94+
if (modes->state_resets_size > 0) {
95+
modes->state_resets = (mode_state_variable_reset_data_t *) calloc(modes->state_resets_size, sizeof(mode_state_variable_reset_data_t));
96+
LF_ASSERT(modes->state_resets, "Out of memory");
97+
} else {
98+
modes->state_resets = NULL;
99+
}
96100

97101
env->modes = modes;
98102

@@ -107,9 +111,13 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
107111
*/
108112
static void environment_init_federated(environment_t* env, int num_is_present_fields) {
109113
#ifdef FEDERATED_DECENTRALIZED
110-
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
111-
lf_assert(env->_lf_intended_tag_fields != NULL, "Out of memory");
112-
env->_lf_intended_tag_fields_size = num_is_present_fields;
114+
if (num_is_present_fields > 0) {
115+
env->_lf_intended_tag_fields = (tag_t**) calloc(num_is_present_fields, sizeof(tag_t*));
116+
LF_ASSERT(env->_lf_intended_tag_fields, "Out of memory");
117+
env->_lf_intended_tag_fields_size = num_is_present_fields;
118+
} else {
119+
env->_lf_intended_tag_fields_size = NULL;
120+
}
113121
#endif
114122
}
115123

@@ -155,6 +163,7 @@ static void environment_free_federated(environment_t* env) {
155163
}
156164

157165
void environment_free(environment_t* env) {
166+
free(env->name);
158167
free(env->timer_triggers);
159168
free(env->startup_reactions);
160169
free(env->shutdown_reactions);
@@ -175,6 +184,7 @@ void environment_free(environment_t* env) {
175184

176185
int environment_init(
177186
environment_t* env,
187+
const char *name,
178188
int id,
179189
int num_workers,
180190
int num_timers,
@@ -187,33 +197,57 @@ int environment_init(
187197
const char * trace_file_name
188198
) {
189199

200+
env->name = malloc(strlen(name) + 1); // +1 for the null terminator
201+
LF_ASSERT(env->name, "Out of memory");
202+
strcpy(env->name, name);
203+
190204
env->id = id;
191205
env->stop_tag = FOREVER_TAG;
192206

193207
env->timer_triggers_size=num_timers;
194-
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
195-
lf_assert(env->timer_triggers != NULL, "Out of memory");
208+
if(env->timer_triggers_size > 0) {
209+
env->timer_triggers = (trigger_t **) calloc(num_timers, sizeof(trigger_t));
210+
LF_ASSERT(env->timer_triggers, "Out of memory");
211+
} else {
212+
env->timer_triggers = NULL;
213+
}
196214

197215
env->startup_reactions_size=num_startup_reactions;
198-
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
199-
lf_assert(env->startup_reactions != NULL, "Out of memory");
216+
if (env->startup_reactions_size > 0) {
217+
env->startup_reactions = (reaction_t **) calloc(num_startup_reactions, sizeof(reaction_t));
218+
LF_ASSERT(env->startup_reactions, "Out of memory");
219+
} else {
220+
env->startup_reactions = NULL;
221+
}
200222

201223
env->shutdown_reactions_size=num_shutdown_reactions;
202-
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
203-
lf_assert(env->shutdown_reactions != NULL, "Out of memory");
224+
if(env->shutdown_reactions_size > 0) {
225+
env->shutdown_reactions = (reaction_t **) calloc(num_shutdown_reactions, sizeof(reaction_t));
226+
LF_ASSERT(env->shutdown_reactions, "Out of memory");
227+
} else {
228+
env->shutdown_reactions = NULL;
229+
}
204230

205231
env->reset_reactions_size=num_reset_reactions;
206-
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
207-
lf_assert(env->reset_reactions != NULL, "Out of memory");
232+
if (env->reset_reactions_size > 0) {
233+
env->reset_reactions = (reaction_t **) calloc(num_reset_reactions, sizeof(reaction_t));
234+
LF_ASSERT(env->reset_reactions, "Out of memory");
235+
} else {
236+
env->reset_reactions = NULL;
237+
}
208238

209239
env->is_present_fields_size = num_is_present_fields;
210240
env->is_present_fields_abbreviated_size = 0;
211241

212-
env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
213-
lf_assert(env->is_present_fields != NULL, "Out of memory");
214-
215-
env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
216-
lf_assert(env->is_present_fields_abbreviated != NULL, "Out of memory");
242+
if (env->is_present_fields_size > 0) {
243+
env->is_present_fields = (bool**)calloc(num_is_present_fields, sizeof(bool*));
244+
LF_ASSERT(env->is_present_fields, "Out of memory");
245+
env->is_present_fields_abbreviated = (bool**)calloc(num_is_present_fields, sizeof(bool*));
246+
LF_ASSERT(env->is_present_fields_abbreviated, "Out of memory");
247+
} else {
248+
env->is_present_fields = NULL;
249+
env->is_present_fields_abbreviated = NULL;
250+
}
217251

218252
env->_lf_handle=1;
219253

core/federated/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
set(FEDERATED_SOURCES clock-sync.c federate.c net_util.c)
2-
list(APPEND INFO_SOURCES ${FEDERATED_SOURCES})
1+
set(FEDERATED_SOURCES clock-sync.c federate.c)
32

43
list(TRANSFORM FEDERATED_SOURCES PREPEND federated/)
5-
target_sources(core PRIVATE ${FEDERATED_SOURCES})
4+
list(APPEND REACTORC_SOURCES ${FEDERATED_SOURCES})

core/federated/RTI/CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ endif()
5252
set(IncludeDir ../../../include/core)
5353
include_directories(${IncludeDir})
5454
include_directories(${IncludeDir}/federated)
55+
include_directories(${IncludeDir}/federated/network)
5556
include_directories(${IncludeDir}/modal_models)
5657
include_directories(${IncludeDir}/platform)
5758
include_directories(${IncludeDir}/utils)
@@ -60,17 +61,18 @@ include_directories(${IncludeDir}/utils)
6061
# Declare a new executable target and list all its sources
6162
add_executable(
6263
RTI
63-
enclave.c
64-
rti.c
65-
rti_lib.c
64+
main.c
65+
rti_common.c
66+
rti_remote.c
6667
${CoreLib}/trace.c
6768
${LF_PLATFORM_FILE}
6869
${CoreLib}/platform/lf_unix_clock_support.c
6970
${CoreLib}/utils/util.c
7071
${CoreLib}/tag.c
71-
${CoreLib}/federated/net_util.c
72+
${CoreLib}/federated/network/net_util.c
73+
${CoreLib}/utils/pqueue_base.c
74+
${CoreLib}/utils/pqueue_tag.c
7275
${CoreLib}/utils/pqueue.c
73-
message_record/message_record.c
7476
)
7577

7678
IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
@@ -79,8 +81,12 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
7981
target_compile_definitions(RTI PUBLIC LOG_LEVEL=4)
8082
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
8183

84+
# Set the STANDALONE_RTI flag to include the rti_remote and rti_common.
85+
target_compile_definitions(RTI PUBLIC STANDALONE_RTI=1)
86+
8287
# Set FEDERATED to get federated compilation support
8388
target_compile_definitions(RTI PUBLIC FEDERATED=1)
89+
8490
target_compile_definitions(RTI PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})
8591

8692
# Set RTI Tracing

core/federated/RTI/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,17 @@ If you would like to go back to non-AUTH mode, you would have to remove all cont
3333

3434
To build a docker image for the RTI, do
3535
```bash
36-
docker build -t rti:rti -f rti.Dockerfile ../../../core/
37-
```
36+
docker build -t lflang/rti:latest -f rti.Dockerfile ../../../
37+
```
38+
39+
To push it to DockerHub, run:
40+
```bash
41+
docker push lflang/rti:latest
42+
```
43+
44+
You may need to login first:
45+
```bash
46+
docker login -u [username]
47+
```
48+
49+
To authenticate, request a PAT on [DockerHub](https://hub.docker.com/settings/security).

0 commit comments

Comments
 (0)