ale-leehrtz has uploaded this change for review.
doc: manual: describe dahdi-trunkdev and the SD-RI-PLL
Add a section on the dahdi-trunkdev driver to the drivers chapter, which
was not documented so far, and a new chapter on the SD-RI-PLL software
clock recovery: principle of operation, self-tuning of the gains, kernel
requirements, the new 'pll' VTY commands, monitoring (show interface,
log messages, CSV columns), guidance on the estimation window based on
the test runs, and a summary of the validation and of the contribution,
with a reference to the ISPCS 2026 paper.
Also add an example configuration for an OCTOI client on a DAHDI
trunkdev with the SD-RI-PLL in self-tuning mode.
Related: OS#7116
Change-Id: If04665cb352f1976d085883f44998037a724eecc
---
A doc/examples/osmo-e1d-dahdi-trunkdev-pll.cfg
M doc/manuals/chapters/drivers.adoc
A doc/manuals/chapters/sdripll.adoc
M doc/manuals/osmoe1d-usermanual.adoc
4 files changed, 354 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/33/44233/1
diff --git a/doc/examples/osmo-e1d-dahdi-trunkdev-pll.cfg b/doc/examples/osmo-e1d-dahdi-trunkdev-pll.cfg
new file mode 100644
index 0000000..2e3bede
--- /dev/null
+++ b/doc/examples/osmo-e1d-dahdi-trunkdev-pll.cfg
@@ -0,0 +1,35 @@
+!
+! osmo-e1d example configuration: E1-over-IP client on a DAHDI trunkdev,
+! with the SD-RI-PLL recovering the remote E1 clock in software.
+!
+! The dahdi_trunkdev kernel module must be loaded with
+! permit_clock_master=1, and the trunkdev "octoi" must exist in DAHDI.
+!
+log stderr
+ logging filter all 1
+ logging color 1
+ logging print category-hex 0
+ logging print category 1
+ logging timestamp 1
+ logging print file basename last
+ logging print level 1
+ logging level e1d info
+ logging level linp info
+ logging level trunkdev notice
+!
+line vty
+ no login
+!
+e1d
+ interface 0 dahdi-trunkdev
+ trunkdev-name octoi
+ pll log-file /var/log/osmocom/sdripll.csv
+ pll mode self-tuning
+ line 0
+ mode e1oip
+octoi-client 192.0.2.1 10013
+ local-bind 0.0.0.0 3333
+ account my_user_1
+ mode dahdi-trunkdev
+ dahdi-trunkdev name octoi
+ dahdi-trunkdev line-number 0
diff --git a/doc/manuals/chapters/drivers.adoc b/doc/manuals/chapters/drivers.adoc
index e4a3858..27b961d 100644
--- a/doc/manuals/chapters/drivers.adoc
+++ b/doc/manuals/chapters/drivers.adoc
@@ -83,3 +83,38 @@
You can subsequently use the Lines just like you would use physical E1
lines. Any data you transmit on one line will be received on the other
line, and vice versa.
+
+[[driver-dahdi-trunkdev]]
+=== The `dahdi-trunkdev` driver for DAHDI virtual trunks
+
+The `dahdi-trunkdev` driver connects `osmo-e1d` to a _trunkdev_ of the
+osmocom fork of DAHDI: a virtual E1 span inside the DAHDI kernel
+subsystem. This lets DAHDI-based applications use an E1 line that
+`osmo-e1d` transports over IP (see <<octoi>>) instead of a physical E1
+card.
+
+The trunkdev has to be created on the DAHDI side before `osmo-e1d`
+opens it, for example with the `dahdi_trunkdev` tool of the osmocom fork
+of `dahdi-tools`, followed by the usual `dahdi_cfg`.
+
+==== Configuration
+
+.Example configuration snippet for a DAHDI trunkdev used for E1-over-IP
+----
+e1d
+ interface 0 dahdi-trunkdev
+ trunkdev-name octoi
+ line 0
+ mode e1oip
+octoi-client 192.0.2.1 10013
+ account my_user_1
+ mode dahdi-trunkdev
+ dahdi-trunkdev name octoi
+ dahdi-trunkdev line-number 0
+----
+
+`trunkdev-name` must match the name of the trunkdev created in DAHDI.
+
+Without a hardware clock source, DAHDI is paced by its coretimer, which
+does not follow the clock of the remote E1. To recover that clock in
+software, see <<sdripll>>.
diff --git a/doc/manuals/chapters/sdripll.adoc b/doc/manuals/chapters/sdripll.adoc
new file mode 100644
index 0000000..868d70e
--- /dev/null
+++ b/doc/manuals/chapters/sdripll.adoc
@@ -0,0 +1,282 @@
+[[sdripll]]
+== Software clock recovery (SD-RI-PLL)
+
+When `osmo-e1d` terminates an E1-over-IP (OCTOI) line through a DAHDI
+trunkdev (see <<driver-dahdi-trunkdev>>) on a host without a hardware E1
+clock source, DAHDI is paced by its _coretimer_, which runs from the
+host's own clock. That clock is not the clock of the remote E1 that
+paces the incoming E1-over-IP stream. As a result the IP->E1 FIFO
+slowly drains or fills up, which eventually leads to underruns or
+overflows, and to frame slips on the E1 side.
+
+The _software-defined, reference-independent PLL_ (SD-RI-PLL) closes
+this loop in software. It needs no GPS receiver, no disciplined
+oscillator and no other external reference: the timing information it
+uses is the rate at which E1 frames arrive over IP. The design and its
+evaluation on a live E1 link of a community telephone network are
+described in <<sdripll-ispcs2026>>. The feature is tracked in
+<<sdripll-os7116>>.
+
+The SD-RI-PLL is _disabled by default_.
+
+=== Principle of operation
+
+The loop has three parts:
+
+Phase detector:: The fill level of the IP->E1 FIFO of line 0 is used as
+a proxy for the phase error between the remote E1 clock and the local
+coretimer. If the coretimer runs slow, the FIFO fills up; if it runs
+fast, the FIFO drains. The setpoint is a FIFO level of 248 frames by
+default.
+
+Controller:: Once per second, a PID controller in `osmo-e1d` compares
+the FIFO level against the setpoint and computes a rate correction, the
+_fudge_. The integral term has anti-windup, and the output is clamped
+to +/-2000000, which corresponds to about +/-466 ppm.
+
+Controlled oscillator:: The fudge is passed to the kernel with the
+`DAHDI_SW_CLOCK_SET` ioctl. From then on the DAHDI coretimer runs at a
+rate of
++
+----
+(2^32 + fudge) / 2^32
+----
++
+When a new fudge is applied, the kernel re-anchors its raw and fudged
+time offsets, so the coretimer stays phase-continuous across the
+change. The scaling is done with 96-bit fixed-point arithmetic built
+from 32-bit limbs, so the kernel needs neither 64-bit division nor
+floating point, and it allocates no memory in timer context.
+
+The default PID gains are Kp = 1.0, Ki = 0.05 and Kd = 0.1, the values
+used in <<sdripll-ispcs2026>>. With these gains the loop is slow and
+weakly damped: the FIFO swings around the setpoint with a period of
+several hours. For better regulation, use the self-tuning mode
+described below, or configure other gains.
+
+=== Self-tuning of the gains
+
+The right loop bandwidth depends on the link. On a link with a noisy
+FIFO level, the loop must be slow so it does not chase the noise; with
+an oscillator that wanders a lot, it must be fast so it can follow. In
+`self-tuning` mode, a self-tuning regulator layer adapts the gains of
+the (unchanged) PID law to the measured link:
+
+* The _measurement noise_ sigma_v of the FIFO level is estimated from
+ the 1-second differences of the FIFO level. It is never taken to be
+ lower than the quantization noise of the FIFO, 8/sqrt(12) = 2.3
+ frames, as DAHDI moves the FIFO in chunks of 8 frames.
+* The _frequency wander_ q_phi of the oscillator is estimated from the
+ frequency offset measured over consecutive _estimation windows_ (1 h
+ each by default), comparing the variances of its changes at lags of
+ 1 and 4 windows.
+* From both, the loop bandwidth is chosen as
++
+----
+wn = (q_phi / sigma_v^2)^(1/4)
+----
++
+bounded to a loop period between 10 minutes and 8 hours, and the gains
+follow by pole placement with a damping of 0.707:
++
+----
+Kp = 2 * 0.707 * wn / K Ki = wn^2 * T / K K = 8000 / 2^32
+----
++
+where T is the 1-second tick. The error is additionally smoothed with
+a time constant of 1 / (10 * wn), and FIFO samples far off the smoothed
+error are rejected as outliers.
+
+A self-tuning run has two phases:
+
+baseline:: The configured gains are used, and the tuner only observes.
+This phase lasts at least `pll self-tuning hold-time`, and in any case
+until the tuner has its first estimate. The first estimate needs about
+10 _valid_ estimation windows. A window is only valid if at most 5 % of
+its ticks are bad (FIFO empty, or no TDM received for more than 3
+seconds), so on a link with many underruns this phase can take much
+longer than 10 windows.
+
+tuned:: The self-tuned gains are applied without a bump in the output,
+and re-computed at the end of every valid window. The bandwidth may
+change by at most a factor of 1.5 per update. While the FIFO is empty
+or no TDM arrives, the output is held (holdover) and the integral does
+not wind up.
+
+A watchdog guards the tuned phase: if more than half of the ticks over
+the last ~30 minutes are bad (FIFO empty, or more than 300 frames away
+from the setpoint while TDM is arriving), the controller reverts to the
+configured gains and stays there (phase `reverted`).
+
+=== Requirements
+
+The SD-RI-PLL needs the osmocom fork of DAHDI with the software clock
+ioctls `DAHDI_SW_CLOCK_GET` and `DAHDI_SW_CLOCK_SET` (ioctl numbers 252
+and 251). `osmo-e1d` defines them itself if the installed DAHDI headers
+lack them, so it also builds against DAHDI headers without them; but on a kernel without
+support, the PLL logs an error and disables itself.
+
+As the trunkdev span is the DAHDI timing master in this setup, the
+`dahdi_trunkdev` kernel module must be loaded with the module parameter
+`permit_clock_master=1`. Without it, the kernel hits a `BUG()` as soon
+as the trunkdev span becomes timing master.
+
+.Loading the trunkdev module for use with the SD-RI-PLL
+----
+modprobe dahdi
+modprobe dahdi_trunkdev permit_clock_master=1
+----
+
+To make this persistent, add a line
+`options dahdi_trunkdev permit_clock_master=1` to a file in
+`/etc/modprobe.d/`.
+
+=== Configuration
+
+The SD-RI-PLL is configured per E1 interface, in the node of a
+`dahdi-trunkdev` interface:
+
+.Example configuration snippet with the SD-RI-PLL in self-tuning mode
+----
+e1d
+ interface 0 dahdi-trunkdev
+ trunkdev-name octoi
+ pll log-file /var/log/osmocom/sdripll.csv
+ pll mode self-tuning
+ line 0
+ mode e1oip
+----
+
+A complete example is installed as
+`doc/examples/osmo-e1d-dahdi-trunkdev-pll.cfg`.
+
+[options="header",cols="2,1,4"]
+|===
+|Command|Default|Meaning
+|`pll mode (off\|fixed\|self-tuning)`|`off`|`off` leaves the coretimer alone. `fixed` runs the PID with the configured gains. `self-tuning` runs the PID with the configured gains first, then with self-tuned gains.
+|`pll pid-gains KP KI KD`|`1 0.05 0.1`|PID gains for `fixed` mode, and the initial gains for `self-tuning` mode.
+|`pll target-fifo <1-1792>`|`248`|Setpoint of the IP->E1 FIFO, in E1 frames.
+|`pll self-tuning hold-time <0-31536000>`|`86400`|Minimum duration of the baseline phase, in seconds.
+|`pll self-tuning window <600-86400>`|`3600`|Length of the estimation windows, in seconds. See <<sdripll-window>>.
+|`pll log-file FILENAME`|none|Append one CSV line per tick to this file. `no pll log-file` stops logging.
+|===
+
+Any change of a `pll` setting on a running interface restarts the
+controller from scratch: the coretimer is set back to a fudge of 0, and
+the integral and the tuner estimates are reset.
+
+[[sdripll-window]]
+==== Choosing the estimation window
+
+Shorter estimation windows give a first estimate sooner, but noisier
+estimates, as the frequency change within a short window is small
+compared to the noise of the FIFO level. The noise then looks like
+oscillator wander, and the tuner tends to choose too high a bandwidth.
+
+On the link used for testing (against the sysmocom OCTOI hub), this
+was clearly visible:
+
+* With the default window of 1 hour, a 53-hour A/B run (24 hours with
+ the default gains, then self-tuned) raised the share of time with
+ the FIFO between 160 and 280 frames from 71 % to 90 %, and lowered
+ the standard deviation of the FIFO level from 70 to 47 frames.
+* With a window of 600 seconds, over a 22-day run, the tuner stayed at
+ the upper bandwidth bound (loop period 10 minutes, Kp of about 7950)
+ for the whole tuned phase. Compared to the baseline, the FIFO spent
+ more time near the setpoint, but short underruns rose from about
+ 7.3 % to about 11.1 % of the time (long network outages excluded).
+
+Unless you have a reason to change it, keep the default of 1 hour.
+
+=== Monitoring
+
+`show interface` shows the FIFO levels of the E1-over-IP line and the
+state of the SD-RI-PLL:
+
+.Output of `show interface` during the baseline phase
+----
+osmo-e1d> show interface 0
+Interface #0 (octoi), Driver: dahdi-trunkdev
+ FIFO E1->IP: 16 frames, IP->E1: 248 frames
+ Software PLL: baseline, fudge -1358, Kp 1, Ki 0.05
+----
+
+The state is `inactive` while the PLL is off, `fixed` in fixed mode,
+and `baseline`, `tuned` or `reverted` in self-tuning mode.
+
+At the `NOTICE` level, the `DTRUNKDEV` log category reports when the
+controller starts, every set of self-tuned gains, and a tripped
+watchdog:
+
+.Example log messages
+----
+SD-RI-PLL: started, mode self-tuning, target FIFO 248
+SD-RI-PLL: configured gains for at least 86400 s, then self-tuned gains (estimation window 3600 s)
+SD-RI-PLL: gains Kp=2727.3 Ki=6.9275 tau_f=28s (sigma_v=11.5, loop period 0.49 h)
+----
+
+At the `DEBUG` level, every tick is logged. For offline analysis,
+`pll log-file` writes one CSV line per tick with these columns:
+
+[options="header",cols="1,4"]
+|===
+|Column|Meaning
+|`t`|Wall-clock time, in seconds since the epoch
+|`fifo`|IP->E1 FIFO level, in frames (0 if unknown)
+|`fudge`|Fudge applied to the coretimer
+|`kp`, `ki`|Current PID gains
+|`tau_f`|Smoothing time constant of the error, in seconds (0 if not smoothed)
+|`sigma_v`|Estimated measurement noise, in frames (-1 if not self-tuning)
+|`q_phi`|Estimated frequency wander (-1 if not self-tuning, 0 before the first estimate)
+|`link_up`|In `self-tuning` mode, 1 if the tick was usable (TDM arriving and FIFO not empty). In `fixed` mode, 1 whenever the FIFO level is known.
+|`phase`|0 baseline (or fixed mode), 1 tuned, 2 reverted
+|===
+
+=== Validation
+
+<<sdripll-ispcs2026>> evaluates the SD-RI-PLL over 11 days on a live E1
+link serving community telephone networks, against a node running
+open-loop on the same setup. The regulated node kept its mean FIFO
+occupancy 0.5 samples from the setpoint, against 90.8 samples for the
+open-loop node, and its time in band (as defined in the paper) was
+48.7 %, against 28.7 %. That evaluation used an earlier revision of the
+code, before the changes made for upstream inclusion.
+
+This implementation was additionally tested against the sysmocom OCTOI
+hub with the A/B runs described in <<sdripll-window>>. It ran for 22
+days without interruption.
+
+=== Summary of the contribution
+
+The SD-RI-PLL consists of the following parts:
+
+In the osmocom DAHDI fork (`dahdi-linux`)::
+* Software clock correction of the DAHDI coretimer, with
+ phase-continuous re-anchoring and 96-bit fixed-point time scaling.
+* The `DAHDI_SW_CLOCK_GET` and `DAHDI_SW_CLOCK_SET` ioctls.
+* The `permit_clock_master` parameter of the `dahdi_trunkdev` module.
+
+In `osmo-e1d`::
+* The PID controller (`pll_pid.c`).
+* The self-tuning regulator layer (`pll_tune.c`), which realizes the
+ adaptive gain selection proposed as future work in
+ <<sdripll-ispcs2026>>.
+* The integration into the `dahdi-trunkdev` driver, the `pll` VTY
+ commands, the CSV log and the PLL state in `show interface`.
+
+The SD-RI-PLL was developed by C. Alejandra Carreón-Jiménez at the
+University of Texas at El Paso, with Christoph Lauter and Gabriel
+Miki.
+
+[bibliography]
+=== References
+
+- [[[sdripll-ispcs2026]]] C. A. Carreón-Jiménez, G. Miki, C. Lauter:
+ _SD-RI-PLL: A Software-Defined, Reference-Independent Phase-Locked
+ Loop for Fault-Tolerant E1 Synchronization in Resource-Constrained
+ Community Networks_. 2026 IEEE International Symposium on Precision
+ Clock Synchronization for Measurement, Control, and Communication
+ (ISPCS), Brescia, Italy, October 2026.
+- [[[sdripll-os7116]]] Osmocom feature ticket OS#7116: _SD-RI-PLL:
+ software clock recovery for DAHDI trunkdev (E1-over-IP)_.
+ https://osmocom.org/issues/7116
diff --git a/doc/manuals/osmoe1d-usermanual.adoc b/doc/manuals/osmoe1d-usermanual.adoc
index 58bd20f..7f859af 100644
--- a/doc/manuals/osmoe1d-usermanual.adoc
+++ b/doc/manuals/osmoe1d-usermanual.adoc
@@ -16,6 +16,8 @@
include::{srcdir}/chapters/drivers.adoc[]
+include::{srcdir}/chapters/sdripll.adoc[]
+
include::{srcdir}/chapters/tdmoip.adoc[]
//include::{srcdir}/chapters/control.adoc[]
To view, visit change 44233. To unsubscribe, or for help writing mail filters, visit settings.