linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] TC-ETF support PTP clocks series
@ 2020-10-01 20:51 Erez Geva
  2020-10-01 20:51 ` [PATCH 1/7] POSIX clock ID check function Erez Geva
                   ` (7 more replies)
  0 siblings, 8 replies; 23+ messages in thread
From: Erez Geva @ 2020-10-01 20:51 UTC (permalink / raw)
  To: linux-kernel, netdev, Cong Wang, David S . Miller,
	Jakub Kicinski, Jamal Hadi Salim, Jiri Pirko, Andrei Vagin,
	Dmitry Safonov, Eric W . Biederman, Ingo Molnar, John Stultz,
	Michal Kubecek, Oleg Nesterov, Peter Zijlstra, Richard Cochran,
	Stephen Boyd, Thomas Gleixner, Vladis Dronov,
	Sebastian Andrzej Siewior, Frederic Weisbecker, Eric Dumazet
  Cc: Jesus Sanchez-Palencia, Vinicius Costa Gomes, Vedang Patel,
	Simon Sudler, Andreas Meisinger, Andreas Bucher, Henning Schild,
	Jan Kiszka, Andreas Zirkler, Ermin Sakic, An Ninh Nguyen,
	Michael Saenger, Bernd Maehringer, Gisela Greinert, Erez Geva,
	Erez Geva

Add support for using PTP clock with
 Traffic control Earliest TxTime First (ETF) Qdisc.

Why do we need ETF to use PTP clock?
Current ETF requires to synchronization the system clock
 to the PTP Hardware clock (PHC) we want to send through.
But there are cases that we can not synchronize the system clock with
 the desire NIC PHC.
1. We use several NICs with several PTP domains that our device
    is not allowed to be PTP master.
   And we are not allowed to synchronize these PTP domains.
2. We are using another clock source which we need for our system.
   Yet our device is not allowed to be PTP master.
Regardless of the exact topology, as the Linux tradition is to allow
 the user the freedom to choose, we propose a patch that will allow
 the user to configure the TC-ETF with a PTP clock as well as
 using the system clock.
* NOTE: we do encourage the users to synchronize the system clock with
  a PTP clock.
 As the ETF watchdog uses the system clock.
 Synchronizing the system clock with a PTP clock will probably
  reduce the frequency different of the PHC and the system clock.
 As sequence, the user might be able to reduce the ETF delta time
  and the packets latency cross the network.

Follow the decision to derive a dynamic clock ID from the file description
 of an opened PTP clock device file.
We propose a simple way to use the dynamic clock ID with the ETF Qdisc.
We will submit a patch to the "tc" tool from the iproute2 project
 once this patch is accepted.

The patches contain:
1. Add function to verify that a dynamic clock ID is derived
    from file description.
   The function follows the clock ID convention for dynamic clock ID
    for file description.
  The function will be used in the second patch.

2. Function to get main system oscillator calibration state.

3. Functions to get and put POSIX clock reference of
    a PTP Hardware Clock (PHC).
   The get function uses a dynamic clock ID created by application space.
   The purpose is that a module can hold a POSIX clock reference after the
    configuration application closed the PTP clock device file,
    and though the dynamic clock ID can not be used any further.
   The POSIX clock refereces are used by the TC-ETF.

4. A fix of the range check in qdisc_watchdog_schedule_range_ns().

5. During testing of ETF, we notice issue with the high-resolution timer
    the ETF Qdisc watchdog uses.
   The timer was set for a sleep of 300 nanoseconds but
    end up sleeping for 3 milliseconds.
   The problem happens when the timer is already active and
    the current expire is earlier then a new expire.
   So, we add a new TC schedule function that do not reprogram the timer
    under these conditions.
   The use of the function make sense as the Qdisc watchdog does act as
    watchdog.
   The Qdisc watchdog can expire earlier.
   However, if the watchdog is late, packets are dropped.

6. Add kernel configuration for TC-ETF watchdog range.
   As the range is characteristic of Hardware,
   that seems to be the proper way.

7. Add support for using PHC clock with TC-ETF.

Erez Geva (7):
  POSIX clock ID check function
  Function to retrieve main clock state
  Functions to fetch POSIX dynamic clock object
  Fix qdisc_watchdog_schedule_range_ns range check
  Traffic control using high-resolution timer issue
  TC-ETF code improvements
  TC-ETF support PTP clocks

 include/linux/posix-clock.h     |  39 +++++++++
 include/linux/posix-timers.h    |   5 ++
 include/linux/timex.h           |   1 +
 include/net/pkt_sched.h         |   2 +
 include/uapi/linux/net_tstamp.h |   5 ++
 kernel/time/posix-clock.c       |  76 ++++++++++++++++
 kernel/time/posix-timers.c      |   2 +-
 kernel/time/timekeeping.c       |   9 ++
 net/sched/Kconfig               |   8 ++
 net/sched/sch_api.c             |  36 +++++++-
 net/sched/sch_etf.c             | 148 +++++++++++++++++++++++++-------
 11 files changed, 298 insertions(+), 33 deletions(-)


base-commit: a1b8638ba1320e6684aa98233c15255eb803fac7
-- 
2.20.1


^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [PATCH 0/7] TC-ETF support PTP clocks series
@ 2020-10-14  9:12 Meisinger, Andreas
  2020-10-15 23:16 ` Thomas Gleixner
  0 siblings, 1 reply; 23+ messages in thread
From: Meisinger, Andreas @ 2020-10-14  9:12 UTC (permalink / raw)
  To: tglx, vinicius.gomes, Geva, Erez, linux-kernel, netdev,
	xiyou.wangcong, davem, kuba, jhs, jiri, avagin, 0x7f454c46,
	ebiederm, mingo, john.stultz, mkubecek, oleg, peterz,
	richardcochran, sboyd, vdronov, bigeasy, frederic, edumazet
  Cc: jesus.sanchez-palencia, vedang.patel, Sudler, Simon, Bucher,
	Andreas, henning.schild, jan.kiszka, Zirkler, Andreas, Sakic,
	Ermin, anninh.nguyen, Saenger, Michael, Maehringer, Bernd,
	gisela.greinert, Geva, Erez, ErezGeva2, guenter.steindl

Hello Thomas,
Sorry about the wrong format/style of my last mail, hope I did get it right this time.

Let me first point at an important thing because we did have discussions here about it too. As of the manpages Linux CLOCK_TAI seems to be defined as an nonsettable clock which does have the same behaviour as of international atomic time TAI. Yet if it's nonsettable it can't be linked or synchronized to the value of International Atomic Time?
On the other hand there seems to be code in place to change the CLOCK_TAI offset thus making it basically sort of "setable"?

> The user space daemon which does the correlation between these PTP domains and TAI is required in any case, so the magic
> clock TAI_PRIVATE is not having any advantage.

I think a userspace daemon handling the translation information between different clocks would be fine. I think it's not really that relevant who exactly does apply the translation. Kernel level might be a little bit more precise but I guess it'd depend on other factors too.
Yet all translation based approaches have in common, setting a clock, renders translations done in past invalid. It would be required to fix old translated values along with setting the clock. I assume we couldn't distinguish between "translated" values and genuine values after translation, so fixing them might not be possible at all.
In our usecase we do have a clock for network operation which can't be set. We can guarantee this because we are able to define the network not being operational when the defined time is not available 😉.
Having this defined the remaining option would  be the target clock to be set. As of your suggestion that would be CLOCK_TAI. So at this point "setable" or "nonsettable" would become important. Here "setable" would introduce a dependency between the clocks. Being independent from clocks outside of our control was exactly the reason to introduce the separate network clock. To me this means if CLOCK_TAI could be changed by anything it couldn't be the base clock for our usecase if it can't it might be a solution.

> Depending on the frequency drift between CLOCK_TAI and clock PTP/$N the timer expiry might be slightly inaccurate, but
> surely not more inaccurate than if that conversion is done purely in user space.
>
> The self rearming posix timers would work too, but the self rearming is based on CLOCK_TAI, so rounding errors and drift
> would be accumulative. So I'd rather stay away from them.

As of the time ranges typically used in tsn networks the drift error for single shot timers most likely isn't a big deal. But as you suggest I'd stay away from long running timers as well rearming ones too, I guess they'd be mostly unusable.

> If such a coordination exists, then the whole problem in the TSN stack is gone. The core can always operate on TAI and the
> network device which runs in a different time universe would use the same conversion data e.g. to queue a packet for HW
> based time triggered transmission. Again subject to slight inaccuracy, but it does not come with all the problems of dynamic
> clocks, locking issues etc. As the frequency drift between PTP domains is neither fast changing nor randomly jumping around
> the inaccuracy might even be a mostly academic problem.

These multiple conversion errors would happen even for applications aware of it's target timescale.
This might usually be an academic issue but for some of our usecases conversion errors aren’t allowed at all.
In any case adding conversion errors sounds strange as our goal is to improve precision.

I don't see a way to avoid conversion errors except of somehow passing the original timestamp down to network card level.
Right now there's only one timestamp in CLOCK_TAI format which is used by ETF as well as by network card thus causing trouble if time is not same there.
If we'd add an (optional) second timestamp to SKB which would have to be set to network card time we could avoid the conversion error. As we do know which network card will be used for sending the SKB we wouldn't need a clock identifier for the second timestamp.
For situations where the application is not aware of the network cards timespace it wouldn't provide the second timestamp. In these situations it'd behave identical to your suggestion. Here the CLOCK_TAI timestamp would be translated to network card time based on the information of the userspace daemon.

What's your opinion about a second timestamp?

Best regards
Andreas Meisinger

Siemens AG
Digital Industries
Process Automation
DI PA DCP
Gleiwitzer Str. 555
90475 Nürnberg, Deutschland
Tel.: +49 911 95822720
mailto:andreas.meisinger@siemens.com


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2020-10-15 23:16 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 20:51 [PATCH 0/7] TC-ETF support PTP clocks series Erez Geva
2020-10-01 20:51 ` [PATCH 1/7] POSIX clock ID check function Erez Geva
2020-10-01 21:56   ` Thomas Gleixner
2020-10-01 20:51 ` [PATCH 2/7] Function to retrieve main clock state Erez Geva
2020-10-01 22:05   ` Thomas Gleixner
2020-10-02  0:19     ` Thomas Gleixner
2020-10-01 20:51 ` [PATCH 3/7] Functions to fetch POSIX dynamic clock object Erez Geva
2020-10-01 23:35   ` Thomas Gleixner
2020-10-01 20:51 ` [PATCH 4/7] Fix qdisc_watchdog_schedule_range_ns range check Erez Geva
2020-10-01 22:44   ` Thomas Gleixner
2020-10-01 20:51 ` [PATCH 5/7] Traffic control using high-resolution timer issue Erez Geva
2020-10-01 23:07   ` Thomas Gleixner
2020-10-01 20:51 ` [PATCH 6/7] TC-ETF code improvements Erez Geva
2020-10-01 20:51 ` [PATCH 7/7] TC-ETF support PTP clocks Erez Geva
2020-10-02  0:33   ` Thomas Gleixner
2020-10-02 11:05     ` Geva, Erez
2020-10-02 19:01 ` [PATCH 0/7] TC-ETF support PTP clocks series Vinicius Costa Gomes
2020-10-02 19:56   ` Geva, Erez
2020-10-03  0:10   ` Thomas Gleixner
2020-10-09 11:17     ` AW: " Meisinger, Andreas
2020-10-09 15:39       ` Thomas Gleixner
2020-10-14  9:12 Meisinger, Andreas
2020-10-15 23:16 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).