Skip to content

Commit 05e827b

Browse files
authored
Bpf demo (#96)
* eBPF based process and syscall monitoring example * Build script improved for more control over what is build * Fixed DAQ event macros: Trigger DAQ event on first call * Removed hack for rust version which detects unused calibration segment management and then use the callbacks * Option to completely disable calibration segment management
1 parent 1e9d0ce commit 05e827b

File tree

24 files changed

+32509
-182
lines changed

24 files changed

+32509
-182
lines changed

.gitignore

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
/build
33
/build-*
44

5-
# vscode
6-
/DEBUGGING_SETUP.md
7-
/.vscode/c_cpp_properties.json
8-
9-
# doxygen
10-
/docs/html
11-
/Doxyfile.bak
12-
135

146
# CANape artefacts
157
*.hex
@@ -18,25 +10,16 @@
1810
*.tmp
1911

2012
# Examples A2L files
21-
/*.a2l
22-
/*.bin
23-
/c_demo.a2l
24-
/cpp_demo.a2l
25-
/hello_xcp.a2l
26-
/struct_demo.a2l
27-
/multi_thread_demo.a2l
13+
*.a2l
14+
*.bin
2815

2916
# Temporary files
30-
/conversions.a2l
31-
/groups.a2l
32-
/typedefs.a2l
17+
conversions.a2l
18+
groups.a2l
19+
typedefs.a2l
20+
*.bak
3321

3422

35-
/a2l_test.a2l
36-
/DOCUMENTATION.md
37-
/pi5
38-
/pi5.pub
39-
/setup_remote_pi.sh
40-
/sync.sh
41-
*.out
42-
/REMOTE_DEVELOPMENT.md
23+
/run_remote.sh
24+
/run.sh
25+
/examples/bpf_demo/CANape/CANapeTmpMea.ini

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"debuggerPath": "/usr/bin/gdb",
116116
"pipeProgram": "ssh",
117117
"pipeArgs": [
118-
118+
119119
],
120120
"pipeCwd": ""
121121
},
@@ -143,7 +143,7 @@
143143
"debuggerPath": "/usr/bin/gdb",
144144
"pipeProgram": "ssh",
145145
"pipeArgs": [
146-
146+
147147
],
148148
"pipeCwd": ""
149149
},

.vscode/tasks.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"--exclude=\"*.out\"",
1414
"--exclude=\"*.a\"",
1515
"./",
16-
"[email protected].205:~/XCPlite-RainerZ/"
16+
"[email protected].206:~/XCPlite-RainerZ/"
1717
],
1818
"options": {
1919
"cwd": "${workspaceFolder}"
@@ -28,7 +28,7 @@
2828
"focus": false,
2929
"panel": "shared"
3030
},
31-
"detail": "rsync to Raspberry Pi [email protected].205:~/XCPlite-RainerZ/"
31+
"detail": "rsync to Raspberry Pi [email protected].206:~/XCPlite-RainerZ/"
3232
},
3333
{
3434
"type": "shell",
@@ -47,7 +47,7 @@
4747
"focus": false,
4848
"panel": "shared"
4949
},
50-
"detail": "Call ./sync.sh - rsync to Raspberry Pi [email protected].205:~/XCPlite-RainerZ/"
50+
"detail": "Call ./sync.sh - rsync to Raspberry Pi [email protected].206:~/XCPlite-RainerZ/"
5151
},
5252
{
5353
"type": "cppbuild",
@@ -235,7 +235,7 @@
235235
"label": "XCPlite: Remote configure CMake on Pi",
236236
"command": "ssh",
237237
"args": [
238-
238+
239239
"cd ~/XCPlite-RainerZ && cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug"
240240
],
241241
"group": "build",
@@ -247,7 +247,7 @@
247247
"label": "XCPlite: Remote build hello_xcp on Pi",
248248
"command": "ssh",
249249
"args": [
250-
250+
251251
"cd ~/XCPlite-RainerZ && cmake --build build --target hello_xcp"
252252
],
253253
"group": {
@@ -265,7 +265,7 @@
265265
"label": "XCPlite: Remote build cpp_demo on Pi",
266266
"command": "ssh",
267267
"args": [
268-
268+
269269
"cd ~/XCPlite-RainerZ && cmake --build build --target cpp_demo"
270270
],
271271
"group": {
@@ -283,7 +283,7 @@
283283
"label": "XCPlite: Remote build all on Pi",
284284
"command": "ssh",
285285
"args": [
286-
286+
287287
"cd ~/XCPlite-RainerZ && cmake --build build"
288288
],
289289
"group": {
@@ -301,7 +301,7 @@
301301
"label": "XCPlite: Remote kill XCP processes on Pi",
302302
"command": "ssh",
303303
"args": [
304-
304+
305305
"pkill -f 'hello_xcp\\|cpp_demo\\|c_demo\\|multi_thread_demo' || true"
306306
],
307307
"group": "build",

CMakeLists.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ add_executable(c_demo ${c_demo_SOURCES})
146146
target_include_directories(c_demo PUBLIC "${PROJECT_ROOT}/inc")
147147
target_link_libraries(c_demo PRIVATE xcplib)
148148

149+
# Example cpp_demo
150+
add_executable(cpp_demo examples/cpp_demo/src/main.cpp examples/cpp_demo/src/sig_gen.cpp examples/cpp_demo/src/lookup.cpp)
151+
target_include_directories(cpp_demo PUBLIC "${PROJECT_ROOT}/inc")
152+
target_link_libraries(cpp_demo PRIVATE xcplib)
153+
149154
# Example struct_demo
150155
set(struct_demo_SOURCES examples/struct_demo/src/main.c)
151156
set_source_files_properties(${struct_demo_SOURCES} PROPERTIES LANGUAGE C)
@@ -160,11 +165,23 @@ add_executable(multi_thread_demo ${multi_thread_demo_SOURCES})
160165
target_include_directories(multi_thread_demo PUBLIC "${PROJECT_ROOT}/inc")
161166
target_link_libraries(multi_thread_demo PRIVATE xcplib)
162167

163-
# Example cpp_demo
164-
add_executable(cpp_demo examples/cpp_demo/src/main.cpp examples/cpp_demo/src/sig_gen.cpp examples/cpp_demo/src/lookup.cpp)
165-
target_include_directories(cpp_demo PUBLIC "${PROJECT_ROOT}/inc")
166-
target_link_libraries(cpp_demo PRIVATE xcplib)
167-
168+
# Example bpf_demo
169+
set(bpf_demo_SOURCES examples/bpf_demo/src/main.c)
170+
set_source_files_properties(${bpf_demo_SOURCES} PROPERTIES LANGUAGE C)
171+
add_executable(bpf_demo ${bpf_demo_SOURCES})
172+
target_include_directories(bpf_demo PUBLIC "${PROJECT_ROOT}/inc")
173+
target_link_libraries(bpf_demo PRIVATE xcplib)
174+
175+
# Add libbpf dependency for Linux builds
176+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
177+
find_library(LIBBPF_LIBRARY bpf)
178+
if(LIBBPF_LIBRARY)
179+
target_link_libraries(bpf_demo PRIVATE ${LIBBPF_LIBRARY})
180+
message(STATUS "Found libbpf: ${LIBBPF_LIBRARY}")
181+
else()
182+
message(WARNING "libbpf not found. BPF functionality will be disabled.")
183+
endif()
184+
endif()
168185

169186
# Tests
170187
if(BUILD_TEST)
@@ -201,12 +218,13 @@ else()
201218
target_link_libraries(hello_xcp_cpp PRIVATE m)
202219

203220
# Set .out suffix for executables on non-Windows platforms
204-
set_target_properties(c_demo PROPERTIES SUFFIX ".out")
205221
set_target_properties(hello_xcp PROPERTIES SUFFIX ".out")
222+
set_target_properties(hello_xcp_cpp PROPERTIES SUFFIX ".out")
223+
set_target_properties(c_demo PROPERTIES SUFFIX ".out")
224+
set_target_properties(cpp_demo PROPERTIES SUFFIX ".out")
206225
set_target_properties(struct_demo PROPERTIES SUFFIX ".out")
207226
set_target_properties(multi_thread_demo PROPERTIES SUFFIX ".out")
208-
set_target_properties(cpp_demo PROPERTIES SUFFIX ".out")
209-
set_target_properties(hello_xcp_cpp PROPERTIES SUFFIX ".out")
227+
set_target_properties(bpf_demo PROPERTIES SUFFIX ".out")
210228

211229
if(BUILD_TEST)
212230
set_target_properties(type_detection_test_c PROPERTIES SUFFIX ".out")

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ XCP is a measurement and calibration protocol commonly used in the automotive in
77
It provides real time signal oriented data acquisition (measurement, logging) and modification of parameter constants (calibration) in a target micro controller system (ECU), to help observing and optimizing cyber physical control algorithms in real time.
88

99
Timestamped events, measurement variables and parameter constants are described by an ASAM-A2L description file, another associated ASAM standard. A2L is a human readable ASCII format.
10-
Data objects are identified by address. In a micro controller system programmed in C or C++, these addresses are used to directly access the ECUs memory. This concept has minimum impact on the target system in terms of memory consumption, runtime and needs minimum code instrumentation. The A2l is a kind of annotated ELF Linker-Address-Map, with meta information on data instances and data types (MC specific types - lookup-tables, axis scaling, physical limits and units, conversion rules, ...).
11-
In a Microprocessor system developed in a system programming language like C, C++ or Rust, this concept is still usefull and efficient. Measurement signals and calibration parameters must have a static lifetime and a defined memory layout, but no predefined memory location and no static storage class. Data acquisition and modification is achieved by appropriate code instrumentation for measurement and wrapper types for groups of calibration parameters.
10+
In a micro controller system programmed in C or C++, measurement data items are directly accessed in their original memory locations. This concept has minimum impact on the target system in terms of memory consumption, runtime and needs minimum code instrumentation. The A2l is a kind of annotated ELF Linker-Address-Map, with meta information on data instances and data types (MC specific types - lookup-tables, axis scaling, physical limits and units, conversion rules, ...).
11+
12+
In a Microprocessor system developed in a system programming language like C, C++ or Rust, this concept is still useful and efficient. Measurement signals and calibration parameters usually have a static lifetime and a defined memory layout, but no predefined memory location and are not limited to static storage classes. Data acquisition and modification is achieved by appropriate code instrumentation for measurement and wrapper types for groups of calibration parameters.
13+
14+
From a software developer perspective, XCP may be considered to be a high-frequency application level tracing solution, using statically instrumented trace points with configurable associated data. Tracing can be started, stopped and reconfigured during runtime. What is not configured, does not consume bandwidth, memory and other resources. The acquired context data is always consistent and trace events are precisely time stamped. Data types and instances of available context data items are defined as code or obtained by a XCP tool from ELF/DWARF debug information. Data instances may be in global, local, thread local and heap storage locations. In addition to that, XCP provides the capability to modify application variables and state in a thread safe and consistent way.
1215

1316
The ASAM-XCP standard defines a protocol and a transport layer. There are transport layers for all common communication busses used in the automotive industry, such as CAN, CAN-FD, FLEXRAY, SPI and Ethernet.
1417

@@ -23,10 +26,10 @@ Visit the Virtual VectorAcademy for an E-Learning on XCP:
2326

2427
XCPlite is an implementation of XCP for Microprocessors in pure C, optimized for the XCP on Ethernet Transport Layer for TCP or UDP with jumbo frames.
2528
It is optimized for 64 Bit platforms with POSIX based Operating Systems, but also runs on 32 Bit platforms and on Windows with some restrictions.
26-
The A2L measurement and calibration object database can be generated during runtime and uploaded by the XCP client on connect.
29+
The A2L measurement and calibration object database can be generated during runtime and uploaded by the XCP client tool on connect.
2730

2831
XCPlite is provided to test and demonstrate calibration tools such as CANape or any other XCP client implementation.
29-
It may serve as a base for individually customized XCP implementations on Microprocessors.
32+
It may serve as a base for individually customized XCP on Ethernet implementations on Microprocessors.
3033
It implements and demonstrates some techniques how to deal with variables in dynamically allocated memory and how to do measurement and calibration in multi-threaded applications.
3134

3235
XCPlite is used as a C library by the implementation of XCP for Rust in:
@@ -82,13 +85,12 @@ There is a CANape project for each example in a directory folder "examples/<Exam
8285
To load a project into CANape, select load project and navigate to the CANape.ini file in this folder.
8386
All CANape project examples are configured to upload the A2L file via XCP. The IP address of the XCP server is stored in the A2L file uploaded last time. If CANape can not connect, check that the correct IP address is configured in "Device Configuration/Devices/<DeviceName>/Protocol/Transport Layer".
8487

85-
The examples should run with a CANape demo version, which can be downloaded from https://www.vector.com/de/de/support-downloads/download-center.
88+
The examples should run with a CANape demo version, which can be downloaded from <https://www.vector.com/de/de/support-downloads/download-center>.
8689
The demo installation must be explicitly enabled in the installer and has some limitations:
8790
It will store only the first seconds of measurement data and the number of measurement signals is limited.
8891

8992
Note: Some of the examples use display windows without title bars to make it look cleaner. This option can be turned of with "Options/Display/View/Display Headline".
9093

91-
9294
### Example Details
9395

9496
hello_xcp:
@@ -135,6 +137,13 @@ cpp_demo:
135137
Demonstrates measurement of member variables and stack variables in class instance member functions.
136138
Shows how to create a class with calibration parameters as member variables.
137139

140+
threadx_demo:
141+
Planned
142+
143+
bpf_demo:
144+
Experimental, work in progress.
145+
Demonstrates tracing of process creations and selected syscalls.
146+
138147
![CANape Screenshot](examples/cpp_demo/cpp_demo.png)
139148

140149
### Building a CANape project and configuration from scratch

0 commit comments

Comments
 (0)