Skip to content

feat: GNSS and DPLL emulation for hardware-free T-GM testing - #9

Open
edcdavid wants to merge 16 commits into
mainfrom
fix-dashboard
Open

feat: GNSS and DPLL emulation for hardware-free T-GM testing#9
edcdavid wants to merge 16 commits into
mainfrom
fix-dashboard

Conversation

@edcdavid

@edcdavid edcdavid commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds kernel-side GNSS and DPLL behavior so netdevsim can stand in for a WPC NIC (U-blox + E810 DPLL) in Kind/ptp-operator CI, without GNSS hardware.

This is the fix-dashboard stack rebased onto current main (virtual CLOCK_REALTIME + kernel 7.0).

GNSS device

  • Registers a kernel GNSS device per WPC netdevsim (wpc=1) that gpsd/ts2phc can open as /dev/gnssN.
  • Echoes NMEA; GGA quality drives lock: fix quality 0 → HOLDOVER, quality ≥ 1 → LOCKED.
  • Speaks enough UBX for linuxptp-daemon: CFG-MSG, CFG-VALSET (signal block), MON-VER, and real NAV-STATUS / NAV-CLOCK payloads (ACK-only replies left T-GM stuck at GNSS s0).
  • udev MODE=0666 on gnss* so gpsd (nobody) can keep the device; otherwise ts2phc starves for NMEA.

DPLL

  • PPS + EEC DPLL devices with a GNSS pin and four EXT pins (SMA/U.FL-style).
  • User-space lock_status via per-device PCI sysfs (/sys/bus/pci/devices/<addr>/dpll/lock_status): locked / holdover / freerun.
  • On Kind, sysfs is often read-only, so NMEA GGA NoFix (and UBX signal block) also drive HOLDOVER → FREERUN after a 30s holdover window (aligned with gnss-sim / TGMBC CC7 cascade).

Mock PHC

  • CLOCK_MONOTONIC timekeeping with TAI-aligned EXTTS so phc2sys cannot step the mock clock.
  • E810-style pins: GNSS-1PPS + SMA1/SMA2/U.FL1/U.FL2; 1PPS EXTTS once per TAI second.
  • PCI ptp/ sysfs symlink so tools find the clock next to the fake PCI device.

Netdev / CI

  • ndo_open / ndo_stop carrier; drop IFF_MULTICAST; forward PTP without dev_forward_skb so hwtstamps survive cross-netns (kernel 6.11+).
  • Bind-mount /sys/class/nsim_ptp over /sys/class/ptp for dashboard/pin sysfs.
  • CI runs test-dpll.sh after module load.

Consumed by ptp-operator GNSS simulation (k8snetworkplumbingwg/ptp-operator#229).

Test plan

  • make dkms-install on Ubuntu 24.04
  • make test-dpll / test-phc / test-gnss-ubx (or make test-all)
  • UBX NAV-STATUS reports gpsFix=3 when locked; GGA quality 0 moves DPLL to holdover then FREERUN after 30s
  • ptp-operator netdevsim CI tgm / tgmoc / tgmbc against this branch

Assisted-By: Cursor

- Updated the DPLL initialization process to unregister the kernel's
  built-in DPLL netlink family and register a custom one for netdevsim
  devices, using a boolean flag instead of a static kernel pointer.
- Prevent restoration of the kernel's built-in DPLL family during module
  exit, addressing potential memory issues on aarch64.
- Added support for external pins in the nsim_dpll structure, including
  properties and capabilities for four new external pins.
- Improved notification handling for external pins during DPLL device
  changes.
- Adjusted cleanup routines to ensure proper unregistration of external
  pins on exit.
- Improved logging to clarify the status of the kernel DPLL family during
  initialization and cleanup.
- Updated the .gitignore file to include additional build artifacts.
- Changed the timecounter initialization in mock_phc_create to utilize ktime_get_clocktai_ns() instead of ktime_get_real_ns(), ensuring accurate timekeeping in the mock PHC implementation.
- Added a writable sysfs interface to allow user-space applications to control the lock status of DPLL devices.
- Introduced `lock_status_show` and `lock_status_store` functions to handle reading and writing the lock status.
- Updated the `nsim_dpll` structure to include a `lock_status` field and a pointer to the sysfs device.
- Ensured proper cleanup of sysfs entries during DPLL device exit.
- Initialized the lock status to `DPLL_LOCK_STATUS_LOCKED_HO_ACQ` during DPLL initialization.
- Added `dkms-install` and `dkms-uninstall` targets to the Makefile for managing DKMS modules, including installation and removal procedures.
- Introduced `test-dpll` target in the Makefile to facilitate running DPLL unit tests.
- Updated README to include detailed instructions for running DPLL unit tests, including usage examples and test coverage details.
- Added a new script `test-dpll.sh` for executing DPLL unit tests, covering various aspects of DPLL emulation and device management.
- Replaced the global class-based sysfs interface with a per-instance kobject for DPLL devices, allowing multiple instances to coexist without naming conflicts.
- Updated the `lock_status_show` and `lock_status_store` functions to use the new kobject structure.
- Modified the `nsim_dpll` structure to include a kobject pointer and a kobj_attribute for lock status.
- Enhanced the Makefile clean target to remove build artifacts more efficiently.
- Updated the test script to reflect changes in the sysfs path for lock status, ensuring accurate testing of DPLL functionality.
- Updated the mock PHC implementation to capture the internal counter at the PPS edge, improving accuracy in timestamping external events.
- Resynchronized the PHC timecounter to current TAI upon enabling external timestamping, ensuring minimal offset for timekeeping.
- Added necessary spin locks to protect timecounter reads and initialization, enhancing thread safety in the mock implementation.
- Introduced TAI-based timekeeping in the mock PHC implementation, allowing for more accurate time synchronization.
- Added fields for offset, frequency correction, and last TAI snapshot to the mock_phc structure.
- Updated timekeeping functions to utilize the new TAI-based approach, ensuring the PHC time remains closely aligned with real TAI.
- Removed unnecessary timecounter and cyclecounter references, streamlining the code for better clarity and performance.
- Updated the Makefile to include new test targets: `test-phc`, `test-gnss-ubx`, and `test-all`, facilitating comprehensive testing of the mock PHC and GNSS functionalities.
- Introduced `test-gnss-ubx.sh` for unit testing GNSS device emulation and UBX protocol handling, covering various scenarios including signal blocking and NMEA parsing.
- Added `test-phc.sh` for testing the mock PTP Hardware Clock, including time read/write, frequency adjustments, and event delivery.
- Modified the mock PHC implementation to utilize CLOCK_MONOTONIC for improved timekeeping accuracy, ensuring resilience against time jumps.
- Updated the PTP mock implementation to support a new pin layout, including GNSS-1PPS and four external connectors (SMA1, SMA2, U.FL1, U.FL2).
- Introduced a sysfs symlink for the PTP clock, allowing tools to easily locate the PTP device under the PCI device path.
- Added a new function to retrieve the kobject for the mock PHC, improving device management and integration with the sysfs interface.
- Enhanced the netdevsim structure to include a kobject for PTP compatibility, ensuring proper cleanup during device exit.
- Implemented the nsim_open and nsim_stop functions to manage the network device's carrier state.
- Updated the nsim_netdev_ops and nsim_vf_netdev_ops structures to include the new open and stop operations, enhancing the netdevsim functionality.
- Eliminated the multicast flag from the net_device structure in the nsim_setup function, ensuring proper configuration for the simulated network device.
- Introduced a new field `last_extts_sec` in the `mock_phc` structure to prevent duplicate external timestamp events.
- Updated the external timestamping logic to poll the PHC time and emit events only when the second counter increments, ensuring accurate event delivery.
- Improved the timer rescheduling mechanism for better performance and reliability in timestamp generation.
- Enhanced the `mock_phc_enable` function to properly initialize the external timestamping state.
linuxptp-daemon needs NAV-STATUS gpsFix to leave GNSS freerun; ACK-only
replies left T-GM stuck at s0 despite locked DPLL and ts2phc.
Keep mock PHC on CLOCK_MONOTONIC with TAI-aligned EXTTS, drive DPLL
holdover/freerun from NMEA GGA NoFix (Kind /sys is RO), and open GNSS
devices with MODE=0666 for gpsd.
Give TGMBC cascading-holdover tests enough time to observe GM CC7 on the
BC before the DPLL drops to FREERUN/CC248.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant