Debian Codegraph @

tests/lib/common.sh

raw symbols SCIP
1 # -*- mode: shell-script; sh-shell: bash -*-
2 #
3 # Copyright (C) 2020-2025 Linutronix GmbH
4 # Author Kurt Kanzenbach <[email protected]>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause
7 #
8 # Test setup library.
9 #
10
11 #
12 # load_kernel_modules()
13 #
14 # Load require kernel modules for Tx scheduling.
15 #
16 load_kernel_modules() {
17 modprobe sch_taprio || true
18 modprobe sch_mqprio || true
19 modprobe sch_etf || true
20 }
21
22 #
23 # napi_defer_hard_irqs($interface, $cycle_time_ns)
24 #
25 # Configure napi_defer_hard_irqs and gro_flush_timeout for busy polling:
26 # - napi_defer_hard_irqs: How often will the NAPI processing be defered?
27 # - gro_flush_timeout: Timeout when the kernel will take over NAPI processing.
28 # Has to be greather than the $cycle_time_ns
29 #
30 napi_defer_hard_irqs() {
31 local interface=$1
32 local cycle_time=$2
33 local gro_flush_timeout
34
35 gro_flush_timeout=$(echo "$cycle_time * 2" | bc)
36 echo 10 >"/sys/class/net/${interface}/napi_defer_hard_irqs"
37 echo "${gro_flush_timeout}" >"/sys/class/net/${interface}/gro_flush_timeout"
38 }
39
40 #
41 # setup_threaded_napi($interface)
42 #
43 # Enable NAPI threaded mode: This allows the NAPI processing being executed in dedicated kernel
44 # threads instead of using NET_RX soft irq. Using these allows to prioritize the Rx processing in
45 # accordance to use case.
46 #
47 # Increase NAPI thread priorities. By default, every NAPI thread uses SCHED_OTHER.
48 #
49 setup_threaded_napi() {
50 local interface=$1
51 local napithreads
52
53 echo 1 >"/sys/class/net/${interface}/threaded"
54
55 napithreads=$(ps aux | grep napi | grep "${interface}" | awk '{ print $2; }')
56 for task in ${napithreads}; do
57 chrt -p -f 85 "$task"
58 done
59 }
60
61 #
62 # setup_irqs($interface)
63 #
64 # Increase IRQ thread priorities. By default, every IRQ thread has priority 50.
65 #
66 setup_irqs() {
67 local interface=$1
68 local irqthreads
69
70 irqthreads=$(ps aux | grep irq | grep "${interface}" | awk '{ print $2; }')
71
72 for task in ${irqthreads}; do
73 chrt -p -f 85 "$task"
74 done
75 }