Fixes and improvements for Linux#25
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
06f0df5 to
b2de800
Compare
b2de800 to
a93e5aa
Compare
f201317 to
949c02a
Compare
| Close(); | ||
|
|
||
| const int fd = sys_->socket_call(AF_PACKET, SOCK_RAW, htons(ETH_P_1588)); | ||
| const int fd = sys_->socket_call(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
There was a problem hiding this comment.
The BPF filter only checks EtherType at offset 12 == 0x88F7, but VLAN-tagged frames have 0x8100 there — the inner 0x88F7 is at offset 16. Those frames are silently dropped before reaching frame_codec, which already handles them correctly. If VLAN-tagged PTP traffic is not expected in the target environment this is fine,
There was a problem hiding this comment.
With the previous configuration, I wasn't able to receive gPTP frames in the time_slave. That's the reason to change it. Any gPTP frame should not be VLAN tagged - see my reply to Valery's comment.
|
|
||
| for (++iter; iter != args.cend(); ++iter) | ||
| { | ||
| if (*iter == "-h" || *iter == "--help") |
There was a problem hiding this comment.
Returning kInitFailure for --help is problematic — in an automotive lifecycle framework this can trigger watchdog restarts or fault reports. --help is intentional, not an error. Consider exit(0) directly after printing usage, or a separate return code.
There was a problem hiding this comment.
I can change that, but not sure if returning a 0 (zero) is the right thing. Documentation of the Initialize function tells:
If non-zero returned, application will exit with exit
code returned from Initialize and Run method won't be called.
That's not an issue. That is what we want in case help was requested. But:
NOTE: In case non-zero is returned, the whole group where this
application belongs to will not leave the machine state Init and
thus, all the applications of such group will never be promoted to
the machine state Running. This could lead to the whole ECU not being
able to startup at all which will result in continuous general rejects.
Could it cause issues if we return a zero here from the terminated process (signalling success)? Normally, I'd expect that it should not because the process is expected to be running ...
I mean, this is a bit artificial because in a correctly configured system the time_slave shouldn't be called with -h or --help.
| { | ||
|
|
||
| constexpr int kRxTimeoutMs = 100; // poll timeout; keeps RxLoop responsive to shutdown | ||
| constexpr int kRxTimeoutMs = 500; // poll timeout; keeps RxLoop responsive to shutdown |
There was a problem hiding this comment.
kRxTimeoutMs raised from 100 → 500 ms with no explanation in the commit message. Worst-case shutdown latency for RxLoop is now 5× longer. Please document the reason (CPU load? NIC behaviour?) so the timing impact can be assessed.
There was a problem hiding this comment.
My intention was to reduce checking load and 0.5 sec isn't a long period. But we can switch back to the previous value if preferred.
There was a problem hiding this comment.
Understood. Worth noting though that gPTP Sync messages arrive every ~125 ms, so a 500 ms poll wait could span 4 Sync cycles. Not a bug, just something to keep in mind.
| << " [options]\n" | ||
| "Options:\n" | ||
| " -h, --help Print this message and exit.\n" | ||
| " -i, --interface <iface> Define the ethernet interface to be used (default is \"" |
There was a problem hiding this comment.
Do we have more options, which are needed for the slave? I would assume, yes
shall we specify then the config file and make it mandatory to be run?
There was a problem hiding this comment.
My intention was to solve the issue first that the interface name differs between QNX and Linux. Furthermore it is quite likely that the user wants to use another interface.
Further options could be added as needed.
| auto iter = args.cbegin(); | ||
| const auto& app_name = *iter; | ||
|
|
||
| for (++iter; iter != args.cend(); ++iter) |
There was a problem hiding this comment.
Do we have already and command parses solutions in the base libs already?
There was a problem hiding this comment.
Seems not: Neither lifecycle mgm has nor I found some in baselibs.
| // (outer EtherType is 0x8100, not 0x88F7). The BPF filter runs in-kernel before delivery | ||
| // to userspace, so non-PTP frames are dropped with zero overhead in the application. | ||
| static const ::sock_filter kPtpBpfCode[] = { | ||
| BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), // load EtherType |
There was a problem hiding this comment.
Can we change the "12" to some not -magic number?
| static const ::sock_filter kPtpBpfCode[] = { | ||
| BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), // load EtherType | ||
| BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETH_P_1588, 1, 0), // == 0x88F7 → PASS | ||
| BPF_STMT(BPF_RET | BPF_K, 0U), // FAIL: drop |
There was a problem hiding this comment.
the same here and on the line below
There was a problem hiding this comment.
Do you mean the 1 and the 0 in line 122? That's just the jump width to the filter instruction to be executed next ...
| { | ||
|
|
||
| constexpr int kRxTimeoutMs = 100; // poll timeout; keeps RxLoop responsive to shutdown | ||
| constexpr int kRxTimeoutMs = 500; // poll timeout; keeps RxLoop responsive to shutdown |
There was a problem hiding this comment.
why was it encreased? any justifications?
There was a problem hiding this comment.
See reply to gordon9901's comment.
| if (*iter == "-h" || *iter == "--help") | ||
| { | ||
| PrintUsage(app_name); | ||
| return false; |
There was a problem hiding this comment.
I would believe, it shall return true here
There was a problem hiding this comment.
But would it terminate then? Typical behavior if querying help of a cmd is to print usage and terminate.
| { | ||
| const auto& args = context.get_arguments(); | ||
| auto iter = args.cbegin(); | ||
| const auto& app_name = *iter; |
There was a problem hiding this comment.
shall we check if args. are empty before resolving the iterator?
ApplicationContxt might not be == to the classical C argv*
There was a problem hiding this comment.
Current impl is. It stores all C args in the vector. It has a separate private variable m_app_path to store the app path, but no public getter :-O
|
|
||
| void RawSocketImpl::Close() | ||
| { | ||
| const int fd = fd_.exchange(-1, std::memory_order_acq_rel); |
There was a problem hiding this comment.
Shall we drop here the PACKET_DROP_MEMBERSHIP for symmetry?
| } | ||
|
|
||
| // BPF filter: pass only frames with EtherType 0x88F7 (PTP/gPTP). | ||
| // ETH_P_ALL is used for socket/bind because ETH_P_1588 misses VLAN-tagged PTP frames |
There was a problem hiding this comment.
the filter above, if I'm correct, handles the non tagged frames only.
to address vlan youwould need additioanl instructions.
but in general, I would believe the ptp frames shall not be vlan tagged, so the fileter is correct.
jsut the comments shall be adjusted
There was a problem hiding this comment.
but in general, I would believe the ptp frames shall not be vlan tagged, so the fileter is correct.
Yes, gPTP specification (IEEE Std 802.1AS-2011) states in section 11.3.3: "A frame that carries an IEEE 802.1AS message shall not have a VLAN tag nor a priority tag."
Will adjust comment ...
| // ETH_P_ALL is used for socket/bind because ETH_P_1588 misses VLAN-tagged PTP frames | ||
| // (outer EtherType is 0x8100, not 0x88F7). The BPF filter runs in-kernel before delivery | ||
| // to userspace, so non-PTP frames are dropped with zero overhead in the application. | ||
| static const ::sock_filter kPtpBpfCode[] = { |
There was a problem hiding this comment.
kPtpBpfCode value (not type, qnx one is obviously qnx-specific) is identical to kPtp1588FilterInsns defined in gptp/platform/qnx/qnx_raw_shim.cpp - can we combine these somewhere common?
There was a problem hiding this comment.
Don't know if that makes sense as this raw_socket impl is Linux-specific
There was a problem hiding this comment.
The socket is, but the EtherType for PTP/gPTP is the same across platforms no?
There was a problem hiding this comment.
Ah - got it now. But no, they are not exactly the same. Furthermore, these setting are quite driver-specific, so I'd like to keep it as is for now.
There was a problem hiding this comment.
Ok - both filter instructions do the same. (Wasn't aware how the filter is exactly working - that part was fixed by AI). But still - I think this is quite OS specific, so I'd keep those separatly
This PR fixes some issues discovered in Linux (closes #36):