1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
"""
Test napi threaded states.
"""
from lib.py import ksft_run, ksft_exit
from lib.py import ksft_eq, ksft_ne, ksft_ge
from lib.py import NetDrvEnv, NetdevFamily
from lib.py import cmd, defer, ethtool
def _assert_napi_threaded_enabled(nl, napi_id) -> None:
napi = nl.napi_get({'id': napi_id})
ksft_eq(napi['threaded'], 'enabled')
ksft_ne(napi.get('pid'), None)
def _assert_napi_threaded_disabled(nl, napi_id) -> None:
napi = nl.napi_get({'id': napi_id})
ksft_eq(napi['threaded'], 'disabled')
ksft_eq(napi.get('pid'), None)
def _set_threaded_state(cfg, threaded) -> None:
with open(f"/sys/class/net/{cfg.ifname}/threaded", "wb") as fp:
fp.write(str(threaded).encode('utf-8'))
def _setup_deferred_cleanup(cfg) -> None:
combined = ethtool(f"-l {cfg.ifname}", json=True)[0].get("combined", 0)
ksft_ge(combined, 2)
defer(ethtool, f"-L {cfg.ifname} combined {combined}")
threaded = cmd(f"cat /sys/class/net/{cfg.ifname}/threaded").stdout
defer(_set_threaded_state, cfg, threaded)
return combined
def napi_init(cfg, nl) -> None:
"""
Test that threaded state (in the persistent NAPI config) gets updated
even when NAPI with given ID is not allocated at the time.
"""
qcnt = _setup_deferred_cleanup(cfg)
_set_threaded_state(cfg, 1)
cmd(f"ethtool -L {cfg.ifname} combined 1")
_set_threaded_state(cfg, 0)
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
for napi in napis:
ksft_eq(napi['threaded'], 'disabled')
ksft_eq(napi.get('pid'), None)
cmd(f"ethtool -L {cfg.ifname} combined 1")
_set_threaded_state(cfg, 1)
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
for napi in napis:
ksft_eq(napi['threaded'], 'enabled')
ksft_ne(napi.get('pid'), None)
def enable_dev_threaded_disable_napi_threaded(cfg, nl) -> None:
"""
Test that when napi threaded is enabled at device level and
then disabled at napi level for one napi, the threaded state
of all napis is preserved after a change in number of queues.
"""
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
ksft_ge(len(napis), 2)
napi0_id = napis[0]['id']
napi1_id = napis[1]['id']
qcnt = _setup_deferred_cleanup(cfg)
# set threaded
_set_threaded_state(cfg, 1)
# check napi threaded is set for both napis
_assert_napi_threaded_enabled(nl, napi0_id)
_assert_napi_threaded_enabled(nl, napi1_id)
# disable threaded for napi1
nl.napi_set({'id': napi1_id, 'threaded': 'disabled'})
cmd(f"ethtool -L {cfg.ifname} combined 1")
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
_assert_napi_threaded_enabled(nl, napi0_id)
_assert_napi_threaded_disabled(nl, napi1_id)
def change_num_queues(cfg, nl) -> None:
"""
Test that when napi threaded is enabled at device level,
the napi threaded state is preserved after a change in
number of queues.
"""
napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True)
ksft_ge(len(napis), 2)
napi0_id = napis[0]['id']
napi1_id = napis[1]['id']
qcnt = _setup_deferred_cleanup(cfg)
# set threaded
_set_threaded_state(cfg, 1)
# check napi threaded is set for both napis
_assert_napi_threaded_enabled(nl, napi0_id)
_assert_napi_threaded_enabled(nl, napi1_id)
cmd(f"ethtool -L {cfg.ifname} combined 1")
cmd(f"ethtool -L {cfg.ifname} combined {qcnt}")
# check napi threaded is set for both napis
_assert_napi_threaded_enabled(nl, napi0_id)
_assert_napi_threaded_enabled(nl, napi1_id)
def main() -> None:
""" Ksft boiler plate main """
with NetDrvEnv(__file__, queue_count=2) as cfg:
ksft_run([napi_init,
change_num_queues,
enable_dev_threaded_disable_napi_threaded],
args=(cfg, NetdevFamily()))
ksft_exit()
if __name__ == "__main__":
main()
|