selftests: drv-net: test drivers sleeping in ndo_get_stats64
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 selftests: drv-net: test drivers sleeping in ndo_get_stats64
Most of our tests use rtnetlink to read device stats, so they don't expose the drivers much to paths in which device stats are read under RCU. Add tests which hammer profcs reads to make sure drivers:
- don't sleep while reporting stats,
- can handle parallel reads,
- can handle device going down while reading.
Set ifname on the env class in NetDrvEnv, we already do that in NetDrvEpEnv.
KTAP version 1
1..7
ok 1 stats.check_pause
ok 2 stats.check_fec
ok 3 stats.pkt_byte_sum
ok 4 stats.qstat_by_ifindex
ok 5 stats.check_down
ok 6 stats.procfs_hammer
# completed up/down cycles: 6 ok 7 stats.procfs_downup_hammer # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- .../selftests/drivers/net/lib/py/env.py | 1 + tools/testing/selftests/drivers/net/stats.py | 94 ++++++++++++++++++- tools/testing/selftests/net/lib/py/ksft.py | 5 + 3 files changed, 97 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/lib/py/env.py +1 -0
@@ -48,6 +48,7 @@ from .remote import Remote else: self._ns = NetdevSimDev(**kwargs) self.dev = self._ns.nsims[0].dev + self.ifname = self.dev['ifname'] self.ifindex = self.dev['ifindex'] def __enter__(self):
tools/testing/selftests/drivers/net/stats.py +91 -3
113 lines not on this page · raw message
tools/testing/selftests/net/lib/py/ksft.py +5 -0
@@ -71,6 +71,11 @@ KSFT_DISRUPTIVE = True _fail("Check failed", a, "not in", b, comment) +def ksft_is(a, b, comment=""): + if a is not b: + _fail("Check failed", a, "is not", b, comment) + + def ksft_ge(a, b, comment=""): if a < b: _fail("Check failed", a, "<", b, comment)
Signature · 1 line
2.47.1
Quoted 19 lines · Jakub Kicinski
Most of our tests use rtnetlink to read device stats, so they don't expose the drivers much to paths in which device stats are read under RCU. Add tests which hammer profcs reads to make sure drivers:
- don't sleep while reporting stats,
- can handle parallel reads,
- can handle device going down while reading.Set ifname on the env class in NetDrvEnv, we already do that in NetDrvEpEnv.
KTAP version 1
1..7
ok 1 stats.check_pause
ok 2 stats.check_fec
ok 3 stats.pkt_byte_sum
ok 4 stats.qstat_by_ifindex
ok 5 stats.check_down
ok 6 stats.procfs_hammer
Quoted 5 lines
# completed up/down cycles: 6 ok 7 stats.procfs_downup_hammer # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0Signed-off-by Jakub Kicinski <[email protected]>
Two tiny comments, neither cause for respin.
tools/testing/selftests/drivers/net/stats.py rtnl = RtnlFamily() · line 223
Quoted 7 lines
+@ksft_disruptive
tools/testing/selftests/drivers/net/stats.py +6
-0+def procfs_downup_hammer(cfg) -> None: + """ + Reading stats via procfs only holds the RCU lock, drivers often try + to sleep when reading the stats, or don't protect against races. + """ + # Max out the queues, we'll flip between max an 1
s/an/and/
Quoted 7 lines
tools/testing/selftests/drivers/net/stats.py +7
-0+ channels = ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) + if channels['combined-count'] == 0: + rx_type = 'rx' + else: + rx_type = 'combined' + cur_queue_cnt = channels[f'{rx_type}-count'] + max_queue_cnt = channels[f'{rx_type}-max']
tools/testing/selftests/drivers/net/stats.py rtnl = RtnlFamily() · line 240
Quoted 10 lines
tools/testing/selftests/drivers/net/stats.py +10
-0+ + cmd(f"ethtool -L {cfg.ifname} {rx_type} {max_queue_cnt}") + defer(cmd, f"ethtool -L {cfg.ifname} {rx_type} {cur_queue_cnt}") + + # Real test stats + stats = __run_inf_loop("cat /proc/net/dev") + defer(stats.kill) + + ipset = f"ip link set dev {cfg.ifname}" + defer(ip, f"link set dev {cfg.ifname} up")
unimportant: could reference ipset here too, as in below.
Quoted 5 lines
tools/testing/selftests/drivers/net/stats.py +5
-0+ # The "echo -n 1" lets us count iterations below + updown = f"{ipset} down; sleep 0.05; {ipset} up; sleep 0.05; " + \ + f"ethtool -L {cfg.ifname} {rx_type} 1; " + \ + f"ethtool -L {cfg.ifname} {rx_type} {max_queue_cnt}; " + \ + "echo -n 1"
Jakub Kicinski
maintainerQuoted 1 line · On Sun, 05 Jan 2025 10:55:50 -0500 Willem de Bruijn wrote:
Two tiny comments, neither cause for respin.
Let me respin, not much work since comment changes shouldn't need a re-test..
Quoted 21 lines
tools/testing/selftests/drivers/net/stats.py rtnl = RtnlFamily() · line 223
Quoted 7 lines
+@ksft_disruptive
tools/testing/selftests/drivers/net/stats.py +6
-0+def procfs_downup_hammer(cfg) -> None: + """ + Reading stats via procfs only holds the RCU lock, drivers often try + to sleep when reading the stats, or don't protect against races. + """ + # Max out the queues, we'll flip between max an 1s/an/and/
Quoted 11 lines
tools/testing/selftests/drivers/net/stats.py +11
-0+ channels = ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) + if channels['combined-count'] == 0: + rx_type = 'rx' + else: + rx_type = 'combined' + cur_queue_cnt = channels[f'{rx_type}-count'] + max_queue_cnt = channels[f'{rx_type}-max'] + + cmd(f"ethtool -L {cfg.ifname} {rx_type} {max_queue_cnt}") + defer(cmd, f"ethtool -L {cfg.ifname} {rx_type} {cur_queue_cnt}") +
Quoted 8 lines
tools/testing/selftests/drivers/net/stats.py rtnl = RtnlFamily() · line 240
Quoted 6 lines
tools/testing/selftests/drivers/net/stats.py +6
-0+ # Real test stats + stats = __run_inf_loop("cat /proc/net/dev") + defer(stats.kill) + + ipset = f"ip link set dev {cfg.ifname}" + defer(ip, f"link set dev {cfg.ifname} up")unimportant: could reference ipset here too, as in below.
Ha, that's what I did initially, but then running it I discovered that ip() adds the initial "ip", so we end up executing:
ip ip link set...
Signature · 1 line
pw-bot: cr
Quoted 19 lines · Jakub Kicinski
Most of our tests use rtnetlink to read device stats, so they don't expose the drivers much to paths in which device stats are read under RCU. Add tests which hammer profcs reads to make sure drivers:
- don't sleep while reporting stats,
- can handle parallel reads,
- can handle device going down while reading.Set ifname on the env class in NetDrvEnv, we already do that in NetDrvEpEnv.
KTAP version 1
1..7
ok 1 stats.check_pause
ok 2 stats.check_fec
ok 3 stats.pkt_byte_sum
ok 4 stats.qstat_by_ifindex
ok 5 stats.check_down
ok 6 stats.procfs_hammer
Quoted 5 lines
# completed up/down cycles: 6 ok 7 stats.procfs_downup_hammer # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0Signed-off-by Jakub Kicinski <[email protected]>