Skip to contentSkip to conversation

Documentation: real-time: Add runtime tuning guide

PATCH In review Zixin Wang 4 participants 8 messages Nov 25

Subsystems (2)
lore
Share & tools
lore

Zixin Wang

author
#0 lore raw

PATCH v6 1/1 Documentation: real-time: Add runtime tuning guide

Runtime tuning options such as C-state limits, EFI runtime services, CPU isolation, RCU callback offloading, and interrupt affinity are not kernel configuration options. Move them out of the configuration guide into a separate real-time runtime tuning guide, so the configuration guide stays focused on Kconfig options.

Keep the existing configuration section anchors in place and link to the new guide from the relevant configuration options. This preserves the documentation links generated by kconfig-checker.

---
v5 -> v6:
- Split runtime tuning out of kernel-configuration.rst into runtime-tuning.rst, following Ahmed's review.
- Keep the CONFIG_* section anchors so kconfig-checker links stay valid, and link to the new guide from the related options.
- Add the new guide to the real-time documentation index.

Testing:
make SPHINXDIRS="core-api" htmldocs and checkpatch.pl pass.

kconfig-checker preempt_rt rules: all generated documentation links resolve to anchors in the built HTML.

---
 Documentation/core-api/real-time/index.rst    |   8 +-
 .../real-time/kernel-configuration.rst        |  44 ++--
 .../core-api/real-time/runtime-tuning.rst     | 203 ++++++++++++++++++
 3 files changed, 230 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/core-api/real-time/runtime-tuning.rst
Documentation/core-api/real-time/index.rst +5 -3
index a17a3de..28b65cf 100644
@@ -4,9 +4,10 @@
 Real-time preemption
 =====================
 
-This documentation is intended for Linux kernel developers and contributors
-interested in the inner workings of PREEMPT_RT. It explains key concepts and
-the required changes compared to a non-PREEMPT_RT configuration.
+This documentation is intended for Linux kernel developers, contributors, and
+system integrators interested in the inner workings of PREEMPT_RT. It explains
+key concepts and the required changes compared to a non-PREEMPT_RT
+configuration.
 
 .. toctree::
    :maxdepth: 2
@@ -16,3 +17,4 @@ the required changes compared to a non-PREEMPT_RT configuration.
    hardware
    architecture-porting
    kernel-configuration
+   runtime-tuning
Documentation/core-api/real-time/kernel-configuration.rst +22 -22

77 lines not on this page · raw message

Documentation/core-api/real-time/runtime-tuning.rst new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
2.54.0
maintainer Reviewed-by on v6 1/1
#1 lore raw
Quoted 6 lines · Zixin Wang

Runtime tuning options such as C-state limits, EFI runtime services, CPU isolation, RCU callback offloading, and interrupt affinity are not kernel configuration options. Move them out of the configuration guide into a separate real-time runtime tuning guide, so the configuration guide stays focused on Kconfig options.

Quoted 7 lines

Keep the existing configuration section anchors in place and link to the new guide from the relevant configuration options. This preserves the documentation links generated by kconfig-checker.

This looks good. We don't have too many copies of the content anymore. Any objections from anyone?

Sebastian

#2 lore raw
In reply to Zixin Wang
Quoted 2 lines · Zixin Wang

+CPU isolation
+=============

Isn't it kind of duplicating Documentation/admin-guide/cpu-isolation.rst ?

Documentation/core-api/real-time/runtime-tuning.rst line 110

Quoted 9 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +9 -0
+
+.. caution::
+
+  CPU isolation is best effort.  Work that is explicitly bound to an
+  isolated CPU, such as per-CPU kernel threads, bound workqueues, and
+  interrupts, may still run there unless it is steered away.  Measure
+  the resulting latency with tools such as ``osnoise``, ``timerlat``,
+  and ``rtla`` rather than assuming that an isolated CPU is free of
+  kernel noise.  See Documentation/timers/no_hz.rst and

And cpunoise but that's all in Documentation/admin-guide/cpu-isolation.rst

Quoted 18 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +18 -0
+RCU callback offloading
+=======================
+
+``CONFIG_RCU_NOCB_CPU`` in
+Documentation/core-api/real-time/kernel-configuration.rst enables support
+for offloading RCU callback invocation from selected CPUs to per-CPU
+``rcuo`` kthreads.  The offload is selected with ``rcu_nocbs=``, implied
+by ``nohz_full=``, or enabled for all CPUs by
+``CONFIG_RCU_NOCB_CPU_DEFAULT_ALL`` when neither parameter is given.
+
+``rcu_nocbs[=cpu-list]``
+  Offload RCU callback invocation from the listed CPUs to the
+  corresponding ``rcuo`` kthread, which can run on a housekeeping CPU.
+  This reduces callback-processing jitter on the CPU that enqueued them.
+  On a non-real-time kernel this also moves invocation out of softirq
+  context; with PREEMPT_RT, callbacks already run in kthread context
+  because ``rcutree.use_softirq`` is false, and the offload only changes
+  where they run.  If the parameter is given without a CPU list, no CPU

Documentation/core-api/real-time/runtime-tuning.rst line 190

Quoted 10 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +10 -0
+  is offloaded at boot; the mode can still be toggled at runtime through
+  cpusets.  The parameter takes precedence over
+  ``CONFIG_RCU_NOCB_CPU_DEFAULT_ALL``.
+
+``rcu_nocb_poll``
+  Make the ``rcuo`` kthreads poll for callbacks instead of requiring the
+  offloaded CPUs to wake them.  This improves the real-time response at
+  the cost of higher power consumption, because the kthreads wake up
+  periodically to do the polling.  Consider this option only when wakeup
+  latency matters more than power.

Does nocb polling really improve real time response? I have doubts.

It checks callbacks and grace periods every jiffy instead of waiting for actual callbacks and grace period events.

This means introducing jiffy worst case latencies.

Thanks.

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author
#3 lore raw

Hi Frederic,

Thanks for the review. You are correct: the CPU isolation section duplicated Documentation/admin-guide/cpu-isolation.rst. I checked the remaining runtime tuning content for similar overlap with other documentation and will keep the canonical material referenced instead of duplicated.

On the second point, I ran a local QEMU test with the PREEMPT_RT kernel (7.3.5, HZ=1000). The guest had 8 vCPUs; the test process was pinned to CPU 6 with:

isolcpus=domain,nohz,6-7 nohz_full=6-7 rcu_nocbs=6-7 irqaffinity=0-5

The only difference between the two runs was the presence of rcu_nocb_poll. The workload repeatedly created and closed perf events and epoll instances, which enqueued RCU callbacks on CPU 6; I traced rcu_callback, rcu_invoke_callback, and rcu_nocb_wake, and measured enqueue-to-invocation latency (including the grace period). I ran three 80-iteration guest runs per mode, giving 480 callbacks per mode.

without rcu_nocb_poll:

    median 4.012 ms, p95 4.203 ms, max 7.040 ms
  with rcu_nocb_poll:
    median 7.003 ms, p95 9.971 ms, max 12.542 ms

The polling mode showed Poll/WakeNotPoll events and no WakeEmpty/DoWake events. Thus, in this test, polling did not improve real-time response; it made callback invocation latency worse.

I have updated the guide accordingly: the CPU isolation details now point to Documentation/admin-guide/cpu-isolation.rst instead of being duplicated, and the rcu_nocb_poll description no longer claims a real-time benefit. It now states that the kthreads poll every jiffy and can delay callback and grace-period processing.

So far only you and Sebastian have replied to this patch. I am waiting for more reviewer feedback before sending v7.

The kernel-parameters.txt entry still says that rcu_nocb_poll improves real-time response; I left that file untouched in this patch, but it may need a separate correction.

The test logs and summary are available locally; I can share them if useful.

Thanks,
Zixin

#4 lore raw
Quoted 13 lines · Zixin Wang

On the second point, I ran a local QEMU test with the PREEMPT_RT kernel (7.3.5, HZ=1000). The guest had 8 vCPUs; the test process was pinned to CPU 6 with:

isolcpus=domain,nohz,6-7 nohz_full=6-7 rcu_nocbs=6-7 irqaffinity=0-5

The only difference between the two runs was the presence of rcu_nocb_poll. The workload repeatedly created and closed perf events and epoll instances, which enqueued RCU callbacks on CPU 6; I traced rcu_callback, rcu_invoke_callback, and rcu_nocb_wake, and measured enqueue-to-invocation latency (including the grace period). I ran three 80-iteration guest runs per mode, giving 480 callbacks per mode.

Quoted 4 lines

without rcu_nocb_poll:

    median 4.012 ms, p95 4.203 ms, max 7.040 ms
  with rcu_nocb_poll:
    median 7.003 ms, p95 9.971 ms, max 12.542 ms

This is pointless. The enqueue-to-invocation latency is meaningless. If you have a RT task which preempts another task in its RCU-read section then the grace period (and the invocation of all callbacks) will be delayed until that RT task is done. Either way, even with things like RCU-LAZY the callbacks can be delayed even further. That is fine. Nothing really should rely on the callback execution.

The important part would be time spent in call_rcu(). And the latency observed by an "real-time task" outside of RCU that is affected by this. Also I prefer testing these things on bare metal so the host not pause the guest for some reason.

Quoted 2 lines

So far only you and Sebastian have replied to this patch. I am waiting for more reviewer feedback before sending v7.

Yes, and if Frederick ask for different isolcpu handling then it needs to be honoured ;)

Quoted 2 lines

Thanks,
Zixin

Sebastian

#5 lore raw
In reply to Frederic Weisbecker
Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Zixin Wang

+CPU isolation
+=============

Isn't it kind of duplicating Documentation/admin-guide/cpu-isolation.rst ?

That is why you are here. I would suggest a minimum here to make sense and point the details to that one.

Quoted 44 lines

Documentation/core-api/real-time/runtime-tuning.rst line 110

Quoted 9 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +9 -0
+
+.. caution::
+
+  CPU isolation is best effort.  Work that is explicitly bound to an
+  isolated CPU, such as per-CPU kernel threads, bound workqueues, and
+  interrupts, may still run there unless it is steered away.  Measure
+  the resulting latency with tools such as ``osnoise``, ``timerlat``,
+  and ``rtla`` rather than assuming that an isolated CPU is free of
+  kernel noise.  See Documentation/timers/no_hz.rst and

And cpunoise but that's all in Documentation/admin-guide/cpu-isolation.rst

Quoted 18 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +18 -0
+RCU callback offloading
+=======================
+
+``CONFIG_RCU_NOCB_CPU`` in
+Documentation/core-api/real-time/kernel-configuration.rst enables support
+for offloading RCU callback invocation from selected CPUs to per-CPU
+``rcuo`` kthreads.  The offload is selected with ``rcu_nocbs=``, implied
+by ``nohz_full=``, or enabled for all CPUs by
+``CONFIG_RCU_NOCB_CPU_DEFAULT_ALL`` when neither parameter is given.
+
+``rcu_nocbs[=cpu-list]``
+  Offload RCU callback invocation from the listed CPUs to the
+  corresponding ``rcuo`` kthread, which can run on a housekeeping CPU.
+  This reduces callback-processing jitter on the CPU that enqueued them.
+  On a non-real-time kernel this also moves invocation out of softirq
+  context; with PREEMPT_RT, callbacks already run in kthread context
+  because ``rcutree.use_softirq`` is false, and the offload only changes
+  where they run.  If the parameter is given without a CPU list, no CPU

Documentation/core-api/real-time/runtime-tuning.rst line 190

Quoted 10 lines
Documentation/core-api/real-time/runtime-tuning.rst new file +10 -0
+  is offloaded at boot; the mode can still be toggled at runtime through
+  cpusets.  The parameter takes precedence over
+  ``CONFIG_RCU_NOCB_CPU_DEFAULT_ALL``.
+
+``rcu_nocb_poll``
+  Make the ``rcuo`` kthreads poll for callbacks instead of requiring the
+  offloaded CPUs to wake them.  This improves the real-time response at
+  the cost of higher power consumption, because the kthreads wake up
+  periodically to do the polling.  Consider this option only when wakeup
+  latency matters more than power.

Does nocb polling really improve real time response? I have doubts.

Quoted 4 lines

It checks callbacks and grace periods every jiffy instead of waiting for actual callbacks and grace period events.

This means introducing jiffy worst case latencies.

The wording is the old "RCU documentation" and it is a bit strong. The "power consumption" comes from the part that the RCU threads are woken up to check for work. The better improved "real-time response" response comes the fact things like call_rcu() do less work (in their IRQ-off section, including waking a task) so the critical section is smaller. I wouldn't expect a huge difference except on small HW where every opcode becomes visible.

Quoted 1 line

Thanks.

Sebastian

#6 lore raw
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Zixin Wang

+CPU isolation
+=============

Isn't it kind of duplicating Documentation/admin-guide/cpu-isolation.rst ?

That is why you are here. I would suggest a minimum here to make sense and point the details to that one.

Right.

Quoted 7 lines

The wording is the old "RCU documentation" and it is a bit strong. The "power consumption" comes from the part that the RCU threads are woken up to check for work. The better improved "real-time response" response comes the fact things like call_rcu() do less work (in their IRQ-off section, including waking a task) so the critical section is smaller. I wouldn't expect a huge difference except on small HW where every opcode becomes visible.

Ah yes indeed, from the call_rcu() perspective it's indeed less work, especially if the queue is empty, the first callback doesn't need to do the wake-up. That could be worth mentioning.

Thanks.

Quoted 4 lines
Quoted 2 lines

Thanks.

Sebastian

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
#7 lore raw
In reply to Zixin Wang
Quoted 6 lines · Zixin Wang

v5 -> v6:
- Split runtime tuning out of kernel-configuration.rst into runtime-tuning.rst, following Ahmed's review.
- Keep the CONFIG_* section anchors so kconfig-checker links stay valid, and link to the new guide from the related options.

Thanks!