Skip to content

Replace mmap-based IPC with score_baselibs SharedMemoryFactory in ts_client#54

Open
gordon9901 wants to merge 2 commits into
eclipse-score:mainfrom
gordon9901:ecarx_pr2_shm_impl
Open

Replace mmap-based IPC with score_baselibs SharedMemoryFactory in ts_client#54
gordon9901 wants to merge 2 commits into
eclipse-score:mainfrom
gordon9901:ecarx_pr2_shm_impl

Conversation

@gordon9901

@gordon9901 gordon9901 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the hand-rolled POSIX shm_open/mmap implementation in ts_client
with score::memory::shared::SharedMemoryFactory from score_baselibs, and
wires up a new SvtHandlerShm timebase handler in TimeDaemon.

ts_client (score/ts_client/)

  • GptpIpcPublisher / GptpIpcReceiver: remove direct shm_open, mmap,
    ftruncate, close calls; use SharedMemoryFactory::Create /
    SharedMemoryFactory::Open instead. Memory region is now constructed via
    ISharedMemoryResource::construct<GptpIpcRegion>().
  • SharedMemoryFactory::Remove + RemoveStaleArtefacts replace the raw
    shm_unlink in publisher init.
  • Header guards updated to drop the redundant _SRC_ segment.

TimeDaemon (score/time_daemon/src/application/svt/)

  • New SvtHandlerShm (factory_shm.h/.cpp, svt_handler_shm.h/.cpp):
    a TimebaseHandler implementation that reads live gPTP data from shared
    memory via GPTPShmMachine and drives the same verification + IPC-publish
    pipeline as the existing SvtHandler.

fixes (#41)

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.3.0) and connecting to it...
INFO: Invocation ID: ada07605-17ef-4e4b-8455-da9cc4cbfde0
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
WARNING: For repository 'aspect_rules_lint', the root module requires module version aspect_rules_lint@1.5.3, but got aspect_rules_lint@2.0.0 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
Computing main repo mapping: 
Loading: 
Loading: 2 packages loaded
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Analyzing: target //:license-check (3 packages loaded)
Analyzing: target //:license-check (3 packages loaded, 0 targets configured)
Analyzing: target //:license-check (3 packages loaded, 0 targets configured)

Analyzing: target //:license-check (75 packages loaded, 9 targets configured)

Analyzing: target //:license-check (91 packages loaded, 9 targets configured)

Analyzing: target //:license-check (148 packages loaded, 2654 targets configured)

Analyzing: target //:license-check (157 packages loaded, 7827 targets configured)

Analyzing: target //:license-check (169 packages loaded, 8049 targets configured)

Analyzing: target //:license-check (169 packages loaded, 8049 targets configured)

Analyzing: target //:license-check (169 packages loaded, 8049 targets configured)

Analyzing: target //:license-check (169 packages loaded, 8049 targets configured)

Analyzing: target //:license-check (172 packages loaded, 9937 targets configured)

INFO: Analyzed target //:license-check (174 packages loaded, 10184 targets configured).
[9 / 16] [Prepa] Expanding template external/score_tooling+/dash/tool/formatters/_dash_format_converter.venv/lib/python3.12/site-packages/_bazel_site_init.py [for tool]
[13 / 16] Generating Dash formatted dependency file ...; 0s disk-cache, processwrapper-sandbox
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 2 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
[14 / 16] checking cached actions
[14 / 16] [Prepa] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar
[15 / 16] Building license.check.license_check.jar (); 0s disk-cache, multiplex-worker
INFO: Found 1 target...
Target //:license.check.license_check up-to-date:
  bazel-bin/license.check.license_check
  bazel-bin/license.check.license_check.jar
INFO: Elapsed time: 32.782s, Critical Path: 2.25s
INFO: 16 processes: 12 internal, 3 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 16 total actions
INFO: Running command line: bazel-bin/license.check.license_check ./formatted.txt <args omitted>
usage: org.eclipse.dash.licenses.cli.Main [-batch <int>] [-cd <url>]
       [-confidence <int>] [-ef <url>] [-excludeSources <sources>] [-help] [-lic
       <url>] [-project <shortname>] [-repo <url>] [-review] [-summary <file>]
       [-timeout <seconds>] [-token <token>]

@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should not add these code duplications here. But instead replace the stub_ptp_machine by the shm_ptp_machine (see PR #25 how to achieve this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stub variant was kept to avoid breaking existing code during development. Now that the shm path is confirmed working, I've removed svt_handler_shm.cpp/.h and factory_shm.cpp/.h, and updated SvtHandler directly to use CreateGPTPShmMachine instead of CreateGPTPStubMachine.

********************************************************************************/
#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H
#define SCORE_TS_CLIENT_SRC_GPTP_IPC_H
#ifndef SCORE_TS_CLIENT_GPTP_IPC_H

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and everywhere: Why doing this include guard renaming?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SRC segment encodes the physical directory path (ts_client/src/), which is an internal layout detail. Include guards should reflect the logical module name, not the filesystem structure — hence SCORE_TS_CLIENT_* rather than SCORE_TS_CLIENT_SRC_*. All 6 headers under ts_client/src/ were updated consistently.

@BjoernAtBosch BjoernAtBosch Jun 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also see this. But I'm struggeling with the point, that the "physical" structure is also visible in the includes, e.g.

#include "score/ts_client/src/gptp_ipc_channel.h"

which then should also be

#include "score/ts_client/gptp_ipc_channel.h"

instead. But that's how it is in Bazel.

If we change it here, we would be inconsistent in the overall module and should change it everywhere. (Maybe not now)

Maybe there is some S-CORE convention. Lets check ...

Comment thread score/ts_client/src/gptp_ipc_data.h Outdated
* @brief IPC data snapshot written by TimeSlave and read by TimeDaemon.
*
* This type is internal to ts_client/src and intentionally decoupled from
* This type is internal to libTSClient and intentionally decoupled from

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This type is internal to libTSClient and intentionally decoupled from
* This type is internal to ts_client and intentionally decoupled from

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This was an oversight — the comment should say ts_client, not libTSClient. Fixed.

{

/// Default POSIX shared memory name for the gPTP IPC channel.
constexpr char kGptpIpcName[] = "/gptp_ptp_info";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constexpr char kGptpIpcName[] = "/gptp_ptp_info";
/// Default shared memory name for the gPTP IPC channel.
constexpr char kGptpIpcName[] = "/gptp_ptp_info";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The comment was removed because "POSIX" is no longer accurate after switching to SharedMemoryFactory. Restored as /// Default shared memory name for the gPTP IPC channel.

Comment thread score/ts_client/src/gptp_ipc_receiver.h Outdated

/// Open and map the shared memory segment (read-only).
/// @return true on success.
bool Init(const std::string& ipc_name = kGptpIpcName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool Init(const std::string& ipc_name = kGptpIpcName);
bool Open(const std::string& ipc_name = kGptpIpcName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.


/// Create and map the shared memory segment.
/// @return true on success.
bool Init(const std::string& ipc_name = kGptpIpcName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool Init(const std::string& ipc_name = kGptpIpcName);
bool Open(const std::string& ipc_name = kGptpIpcName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.

void Publish(const score::ts::GptpIpcData& data);

/// Unmap and unlink the shared memory segment.
void Destroy();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void Destroy();
void Close();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Open/Close is more semantically precise and forms a natural pair. Renamed in both GptpIpcPublisher and GptpIpcReceiver, including all call sites and test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants