Skip to content

Conversation

@NelsonVides
Copy link
Contributor

I've tried to pretty much replicate existing code as much as possible.

This commit adds support for two additional timestamp-related socket options that provide enhanced timestamping capabilities:

  • SO_TIMESTAMPNS: Similar to SO_TIMESTAMP but provides nanosecond precision timestamps using timespec instead of timeval. This is useful for applications requiring higher precision timing information.

  • SO_TIMESTAMPING: An integer bitmask option that allows fine-grained control over which timestamp types are enabled (e.g., software timestamps, hardware timestamps, etc.). This is primarily used for advanced network monitoring and performance analysis.

Platform compatibility:

  • Linux: Full support for both options
  • BSD/macOS: Code compiles but options unavailable (guarded by #ifdef)
  • Windows: Code compiles but options unavailable

These options are particularly useful for network performance monitoring, packet capture tools, and applications requiring precise timing information.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

CT Test Results

    4 files    196 suites   1h 53m 48s ⏱️
3 229 tests 2 831 ✅ 397 💤 1 ❌
4 125 runs  3 649 ✅ 475 💤 1 ❌

For more details on these failures, see this check.

Results for commit 14d6eed.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@rickard-green rickard-green added team:VM Assigned to OTP team VM team:PS Assigned to OTP team PS and removed team:VM Assigned to OTP team VM labels Jan 7, 2026
@bmk bmk added testing currently being tested, tag is used by OTP internal CI team:PS Assigned to OTP team PS and removed team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI labels Jan 12, 2026
@bmk
Copy link
Contributor

bmk commented Jan 12, 2026

It (git) failed to merge into our test branch because of conflicts with other (unrelated) changes.
I have added the branch "manually" and resolved the conflicts, so it is now in testing (even though
there is no 'testing' label).

@NelsonVides NelsonVides force-pushed the feat/so_timestamp_ns_ing branch from 9749a86 to 310dfcc Compare January 13, 2026 10:36
@NelsonVides
Copy link
Contributor Author

@bmk the failures in CI, GHA is not giving me really explicit descriptions, do you have any hint about what is it that needs to be fixed or is it a false positive? :)

@bmk
Copy link
Contributor

bmk commented Jan 19, 2026

I have found a couple of issues.

  1. The new (test) groups (option_sock_timestampns and option_sock_timestamping) was not
    part of the function api_option_socket_cases (returns a list of cases and groups that should be used).
    The result was that the cases was not run.
  2. The test case for option_sock_timestampns had the problem that the value part was assumed
    to come in the 'data' field. It comes in the 'value' field.
    When this was corrected, the test case worked.
  3. I have yet to made (test case) option_sock_timestamping work.
    I have not yet figured out exactly what is wrong here.
  4. Option timestamping: Usually when we have a flag field, we translate that into a list: [flag()]

@NelsonVides
Copy link
Contributor Author

Goddamit, the tests were not enabled 🤦🏽 Just noticed where, adding them and fixing the tests! Thanks for the feedback!

I've tried to pretty much replicate existing code as much as possible.

This commit adds support for two additional timestamp-related socket
options that provide enhanced timestamping capabilities:

- SO_TIMESTAMPNS: Similar to SO_TIMESTAMP but provides nanosecond
  precision timestamps using timespec instead of timeval. This is
  useful for applications requiring higher precision timing
  information.

Platform compatibility:
- Linux: Full support for both options
- BSD/macOS: Code compiles but options unavailable (guarded by #ifdef)
- Windows: Code compiles but options unavailable

These options are particularly useful for network performance monitoring,
packet capture tools, and applications requiring precise timing
information.
I've tried to pretty much replicate existing code as much as possible.

- SO_TIMESTAMPING: An integer bitmask option that allows fine-grained
  control over which timestamp types are enabled (e.g., software
  timestamps, hardware timestamps, etc.). This is primarily used for
  advanced network monitoring and performance analysis.

Platform compatibility:
- Linux: Full support for both options
- BSD/macOS: Code compiles but options unavailable (guarded by #ifdef)
- Windows: Code compiles but options unavailable

These options are particularly useful for network performance monitoring,
packet capture tools, and applications requiring precise timing
information.
@NelsonVides NelsonVides force-pushed the feat/so_timestamp_ns_ing branch from 310dfcc to c20d68d Compare January 19, 2026 13:26
@NelsonVides
Copy link
Contributor Author

@bmk done now, made sure tests pass, tested using it on my machines, turned the flags into a list of atoms, added docs (forgot to do this last time!). Ready for review again :)

@NelsonVides
Copy link
Contributor Author

Ag, I've tested on Linux 6.12, SOF_TIMESTAMPING_TX_COMPLETION was introduced in 6.10, and Ubuntu 24.04 is running on 6.8 and therefore CI fails to compile. Fixing, I'll just not show any flag pre 3.0 in the erlang level and the user might just pass integers if he knows what he's doing.

@bmk
Copy link
Contributor

bmk commented Jan 19, 2026

Annoyingly these flags are not defines but enum values, making it non-trivial to ifdef for existence.

@bmk
Copy link
Contributor

bmk commented Jan 20, 2026

It now works fine when I test!
I would prefer if you skipped the 'timestamping_' prefix on the timestamping flags:
That is: Just 'rx_software' instead of 'timestamping_rx_software'

@NelsonVides
Copy link
Contributor Author

Sounds good to me, done 👌🏽

@bmk
Copy link
Contributor

bmk commented Jan 26, 2026

We have run into problems on a (Linux) cross build to PowerPC (sorry for the horrible format):

[00713](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#warnings): nifs/common/prim_socket_nif.c:3398:13: warning: initialization from incompatible pointer type [enabled by default] 00714: esock_setopt_timestamping, esock_getopt_timestamping, 00715: ^ [00716](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#warnings): nifs/common/prim_socket_nif.c:3398:13: warning: (near initialization for 'optLevelSocket[37].getopt') [enabled by default] 00717: nifs/common/prim_socket_nif.c: In function 'esock_cmsg_encode_scm_timestamping': [00718](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14116:26: error: dereferencing pointer to incomplete type 00719: if (dataLen < sizeof(*tsP)) 00720: ^ [00721](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14119:36: error: dereferencing pointer to incomplete type 00722: esock_encode_timespec(env, &tsP->ts[0], &tsList[0]); 00723: ^ [00724](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14120:36: error: dereferencing pointer to incomplete type 00725: esock_encode_timespec(env, &tsP->ts[1], &tsList[1]); 00726: ^ [00727](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14121:36: error: dereferencing pointer to incomplete type 00728: esock_encode_timespec(env, &tsP->ts[2], &tsList[2]); 00729: ^ 00730: nifs/common/prim_socket_nif.c: In function 'esock_cmsg_decode_scm_timestamping': [00731](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14151:54: error: dereferencing pointer to incomplete type 00732: if ((tsP = esock_init_cmsghdr(cmsgP, rem, sizeof(*tsP), usedP)) == NULL) 00733: ^ [00734](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14154:50: error: dereferencing pointer to incomplete type 00735: if (! esock_decode_timespec(env, eTs[0], &tsP->ts[0])) 00736: ^ [00737](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14156:50: error: dereferencing pointer to incomplete type 00738: if (! esock_decode_timespec(env, eTs[1], &tsP->ts[1])) 00739: ^ [00740](http://otp.ericsson.se/cgi-bin/otp_view_log?log=/net/bilbo/ldisk/daily_build/29_master-opu_o_x_sb_cross_sb.2026-01-25_21/logs/log09.cross_build_open#errors): nifs/common/prim_socket_nif.c:14158:50: error: dereferencing pointer to incomplete type 00741: if (! esock_decode_timespec(env, eTs[2], &tsP->ts[2]))

On that platform, the data type 'struct scm_timestamping' does not exist.
This should have been an easy (autoconf) fix, but my attempts (to write a
autoconf test for this) ended with 'storage size' errors on my own machine.

@NelsonVides
Copy link
Contributor Author

@bmk I've pushed a changed that "seems correct" to me, but I don't have a PowerPC at hand to verify 😅

Will try to setup a VM or so later, but maybe you'll do it faster than me, if you can confirm this works 🙏🏽

@bmk
Copy link
Contributor

bmk commented Jan 26, 2026

I was looking for this; AC_CHECK_TYPES, but managed to miss it (I tried to use AC_CHECK_MEMBERS
but ran into problems).
I will rebuild configure and we will se what happens tonight...

@bmk
Copy link
Contributor

bmk commented Jan 27, 2026

As it turns out, configure fails with the following:
conftest.c: In function 'main': conftest.c:155:13: error: invalid application of 'sizeof' to incomplete type 'struct scm_timestamping' 155 | if (sizeof (struct scm_timestamping)) | ^~~~~~
So, HAVE_STRUCT_SCM_TIMESTAMPING will never be defined.

@NelsonVides NelsonVides force-pushed the feat/so_timestamp_ns_ing branch from e1e266c to 14d6eed Compare January 27, 2026 10:02
@NelsonVides
Copy link
Contributor Author

NelsonVides commented Jan 27, 2026

Pushed a change, tested it in a local VM, it took 30min to build, damn QEMU is slow on my M4, but it passed both ./configure and make. Let's see how long it takes to run tests.


Edit, it took an hour to run tests 😜 But all green on my VM 👌🏽

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

Labels

team:PS Assigned to OTP team PS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants