Skip to content

Commit ddd9fc2

Browse files
committed
contest: vm: use select() in drain_to_prompt()
We see possible issues with the txtimestamp test related to IO blocking the test for a long time. Our current scheme is to poll the io every 30msec, which is not very often. Improve the code by using select() to react to pending input more quickly. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 773f4ee commit ddd9fc2

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

contest/remote/lib/vm.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import unicodedata
44
import requests
55
import subprocess
6-
from time import sleep
76
import fcntl
87
import json
98
import os
109
import psutil
1110
import re
11+
import select
1212
import shutil
1313
import signal
14+
import time
1415
from .crash import has_crash, extract_crash
1516

1617

@@ -301,7 +302,10 @@ def drain_to_prompt(self, prompt="xx__-> ", dump_after=None, deadline=None):
301302
total_wait = 0
302303
stdout = ""
303304
stderr = ""
305+
last_read = time.monotonic()
304306
while True:
307+
select.select([self.p.stdout, self.p.stderr], [], [], 0.1)
308+
305309
read_some, out = self._read_pipe_nonblock(self.p.stdout)
306310
self.log_out += out
307311
stdout += out
@@ -310,6 +314,11 @@ def drain_to_prompt(self, prompt="xx__-> ", dump_after=None, deadline=None):
310314
self.log_err += err
311315
stderr += err
312316

317+
now = time.monotonic()
318+
elapsed = now - last_read
319+
last_read = now
320+
total_wait += elapsed
321+
313322
if read_some:
314323
if stdout.endswith(prompt):
315324
break
@@ -322,12 +331,10 @@ def drain_to_prompt(self, prompt="xx__-> ", dump_after=None, deadline=None):
322331
# logs elsewhere try to get a new prompt by sending a new line.
323332
if prompt in out:
324333
self.cmd('\n')
325-
sleep(0.25)
334+
time.sleep(0.25)
326335
waited = 0
327336
else:
328-
total_wait += 0.03
329-
waited += 0.03
330-
sleep(0.03)
337+
waited += elapsed
331338

332339
if total_wait > hard_stop:
333340
self.log_err += f'\nHARD STOP ({hard_stop})\n'
@@ -413,7 +420,7 @@ def check_health(self):
413420
self.drain_to_prompt()
414421
# kmemleak needs objects to be at least MSECS_MIN_AGE (5000)
415422
# before it considers them to have been leaked
416-
sleep(5)
423+
time.sleep(5)
417424
# Second scan, to identify what has really leaked
418425
self.cmd("echo scan > /sys/kernel/debug/kmemleak && cat /sys/kernel/debug/kmemleak")
419426
self.drain_to_prompt()

0 commit comments

Comments
 (0)