Try to fix qemu freezing due to full socket buffers
The following changes since commit a3d228a484cf471e999b6537987e2897d8a7bd4e:
bitbake: main: Handle RuntimeError exception in list_extension_modules (2015-08-20 22:04:43 +0100)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib rewitt/logthread
for you to fetch changes up to c0f8b3c28c4410031dc763e714bc2ad0f87171d6:
qemurunner: Use two serial ports and log console with a thread (2015-08-20 14:16:29 -0700)
----------------------------------------------------------------
Randy Witt (3):
qemurunner.py: Move some class variables that should only be local
qemurunner: Make create_socket() return data and use exceptions
qemurunner: Use two serial ports and log console with a thread
meta/conf/machine/qemuarm.conf | 2 +- meta/conf/machine/qemuarm64.conf | 2 +- meta/conf/machine/qemumips.conf | 2 +- meta/conf/machine/qemumips64.conf | 2 +- meta/conf/machine/qemuppc.conf | 2 +- meta/conf/machine/qemux86-64.conf | 2 +- meta/conf/machine/qemux86.conf | 2 +- meta/lib/oeqa/utils/qemurunner.py | 174 ++++++++++++++++++++++++++++++++------ 8 files changed, 155 insertions(+), 33 deletions(-)
PATCH v2 1/3 qemurunner.py: Move some class variables that should only be local
The bootlog and qemusock variables were set in the class as part of the create_socket() routine. However those variables are never used outside of the same function and thus serve no purpose as class variables.
This initializes those variables near where they are used.
--- meta/lib/oeqa/utils/qemurunner.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +9 -10
@@ -43,9 +43,6 @@ class QemuRunner: def create_socket(self): - self.bootlog = '' - self.qemusock = None - try: self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server_socket.setblocking(0)
@@ -145,22 +142,24 @@ class QemuRunner: socklist = [self.server_socket] reachedlogin = False stopread = False + qemusock = None + bootlog = '' while time.time() < endtime and not stopread: sread, swrite, serror = select.select(socklist, [], [], 5) for sock in sread: if sock is self.server_socket: - self.qemusock, addr = self.server_socket.accept() - self.qemusock.setblocking(0) - socklist.append(self.qemusock) + qemusock, addr = self.server_socket.accept() + qemusock.setblocking(0) + socklist.append(qemusock) socklist.remove(self.server_socket) logger.info("Connection from %s:%s" % addr) else: data = sock.recv(1024) if data: self.log(data) - self.bootlog += data - if re.search(".* login:", self.bootlog): - self.server_socket = self.qemusock + bootlog += data + if re.search(".* login:", bootlog): + self.server_socket = qemusock stopread = True reachedlogin = True logger.info("Reached login banner")
@@ -171,7 +170,7 @@ class QemuRunner: if not reachedlogin: logger.info("Target didn't reached login boot in %d seconds" % self.boottime) - lines = "\n".join(self.bootlog.splitlines()[-25:]) + lines = "\n".join(bootlog.splitlines()[-25:]) logger.info("Last 25 lines of text:\n%s" % lines) logger.info("Check full boot log: %s" % self.logfile) self.stop()
Signature · 1 line
2.4.3
PATCH v2 2/3 qemurunner: Make create_socket() return data and use exceptions
In reply to Randy WittSo that create_socket() can be called more than once to create sockets, it now returns the socket and port rather than setting class variables directly.
create_socket() now only uses exceptions for errors, not the return value from the function.
--- meta/lib/oeqa/utils/qemurunner.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +15 -14
@@ -42,20 +42,18 @@ class QemuRunner: self.runqemutime = 60 def create_socket(self): - try: - self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.server_socket.setblocking(0) - self.server_socket.bind(("127.0.0.1",0)) - self.server_socket.listen(2) - self.serverport = self.server_socket.getsockname()[1] - logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % self.serverport) - return True - except socket.error, msg: - self.server_socket.close() - logger.error("Failed to create listening socket: %s" % msg[1]) - return False - + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setblocking(0) + sock.bind(("127.0.0.1",0)) + sock.listen(2) + port = sock.getsockname()[1] + logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % port) + return (sock, port) + + except socket.error: + sock.close() + raise def log(self, msg): if self.logfile:
@@ -82,7 +80,10 @@ class QemuRunner: else: os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image - if not self.create_socket(): + try: + self.server_socket, self.serverport = self.create_socket() + except socket.error, msg: + logger.error("Failed to create listening socket: %s" % msg[1]) return False # Set this flag so that Qemu doesn't do any grabs as SDL grabs interact
Signature · 1 line
2.4.3
PATCH v2 3/3 qemurunner: Use two serial ports and log console with a thread
In reply to Randy Wittqemu can freeze and stop responding if the socket buffer connected to a tcp serial connection fills up. This happens of course when the reader of the serial data doesn't actually read it.
This happened in the qemurunner code, because after checking for the "login:" sentinel, data was never again read from the serial connection.
This patch solves the potential freeze by adding a thread to continuously read the data from the console and log it. So it also will give a full log of the console, rather than just up to the login prompt.
To simplify this patch, another serial port was also added to use for the sole purpose of watching for the sentinel as well as being the interactive serial port. This will also prevent the possibility of lots of debug data on the console preventing the sentinel value from being seen due to interleaved text.
--- meta/conf/machine/qemuarm.conf | 2 +- meta/conf/machine/qemuarm64.conf | 2 +- meta/conf/machine/qemumips.conf | 2 +- meta/conf/machine/qemumips64.conf | 2 +- meta/conf/machine/qemuppc.conf | 2 +- meta/conf/machine/qemux86-64.conf | 2 +- meta/conf/machine/qemux86.conf | 2 +- meta/lib/oeqa/utils/qemurunner.py | 126 +++++++++++++++++++++++++++++++++++++- 8 files changed, 131 insertions(+), 9 deletions(-)
meta/conf/machine/qemuarm.conf +1 -1
@@ -8,5 +8,5 @@ require conf/machine/include/tune-arm926ejs.inc KERNEL_IMAGETYPE = "zImage" -SERIAL_CONSOLE = "115200 ttyAMA0" +SERIAL_CONSOLES = "115200;ttyAMA0 115200;ttyAMA1"
meta/conf/machine/qemuarm64.conf +1 -1
@@ -9,4 +9,4 @@ MACHINE_FEATURES = "" KERNEL_IMAGETYPE = "Image" -SERIAL_CONSOLE = "38400 ttyAMA0" +SERIAL_CONSOLES = "38400;ttyAMA0 38400;ttyAMA1"
meta/conf/machine/qemumips.conf +1 -1
@@ -8,6 +8,6 @@ require conf/machine/include/tune-mips32r2.inc KERNEL_IMAGETYPE = "vmlinux" KERNEL_ALT_IMAGETYPE = "vmlinux.bin" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" MACHINE_EXTRA_RRECOMMENDS = " kernel-modules"
meta/conf/machine/qemumips64.conf +1 -1
@@ -8,6 +8,6 @@ require conf/machine/include/tune-mips64.inc KERNEL_IMAGETYPE = "vmlinux" KERNEL_ALT_IMAGETYPE = "vmlinux.bin" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" MACHINE_EXTRA_RRECOMMENDS = " kernel-modules"
meta/conf/machine/qemuppc.conf +1 -1
@@ -7,5 +7,5 @@ require conf/machine/include/tune-ppc7400.inc KERNEL_IMAGETYPE = "vmlinux" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1"
meta/conf/machine/qemux86-64.conf +1 -1
@@ -13,7 +13,7 @@ require conf/machine/include/tune-core2.inc KERNEL_IMAGETYPE = "bzImage" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" XSERVER = "xserver-xorg \ ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast', '', d)} \
meta/conf/machine/qemux86.conf +1 -1
@@ -12,7 +12,7 @@ require conf/machine/include/tune-i586.inc KERNEL_IMAGETYPE = "bzImage" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" XSERVER = "xserver-xorg \ ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast', '', d)} \
meta/lib/oeqa/utils/qemurunner.py +124 -2
171 lines not on this page · raw message
Signature · 1 line
2.4.3
v2 cover Try to fix qemu freezing due to full socket buffers
In reply to Randy WittFix copy and pasted error message that had no meaning to the actual timeout.
PATCH v2 1/3 qemurunner.py: Move some class variables that should only be local
The bootlog and qemusock variables were set in the class as part of the create_socket() routine. However those variables are never used outside of the same function and thus serve no purpose as class variables.
This initializes those variables near where they are used.
--- meta/lib/oeqa/utils/qemurunner.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +9 -10
@@ -43,9 +43,6 @@ class QemuRunner: def create_socket(self): - self.bootlog = '' - self.qemusock = None - try: self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server_socket.setblocking(0)
@@ -145,22 +142,24 @@ class QemuRunner: socklist = [self.server_socket] reachedlogin = False stopread = False + qemusock = None + bootlog = '' while time.time() < endtime and not stopread: sread, swrite, serror = select.select(socklist, [], [], 5) for sock in sread: if sock is self.server_socket: - self.qemusock, addr = self.server_socket.accept() - self.qemusock.setblocking(0) - socklist.append(self.qemusock) + qemusock, addr = self.server_socket.accept() + qemusock.setblocking(0) + socklist.append(qemusock) socklist.remove(self.server_socket) logger.info("Connection from %s:%s" % addr) else: data = sock.recv(1024) if data: self.log(data) - self.bootlog += data - if re.search(".* login:", self.bootlog): - self.server_socket = self.qemusock + bootlog += data + if re.search(".* login:", bootlog): + self.server_socket = qemusock stopread = True reachedlogin = True logger.info("Reached login banner")
@@ -171,7 +170,7 @@ class QemuRunner: if not reachedlogin: logger.info("Target didn't reached login boot in %d seconds" % self.boottime) - lines = "\n".join(self.bootlog.splitlines()[-25:]) + lines = "\n".join(bootlog.splitlines()[-25:]) logger.info("Last 25 lines of text:\n%s" % lines) logger.info("Check full boot log: %s" % self.logfile) self.stop()
Signature · 1 line
2.4.3
PATCH v2 2/3 qemurunner: Make create_socket() return data and use exceptions
In reply to Randy WittSo that create_socket() can be called more than once to create sockets, it now returns the socket and port rather than setting class variables directly.
create_socket() now only uses exceptions for errors, not the return value from the function.
--- meta/lib/oeqa/utils/qemurunner.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +15 -14
@@ -42,20 +42,18 @@ class QemuRunner: self.runqemutime = 60 def create_socket(self): - try: - self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.server_socket.setblocking(0) - self.server_socket.bind(("127.0.0.1",0)) - self.server_socket.listen(2) - self.serverport = self.server_socket.getsockname()[1] - logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % self.serverport) - return True - except socket.error, msg: - self.server_socket.close() - logger.error("Failed to create listening socket: %s" % msg[1]) - return False - + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setblocking(0) + sock.bind(("127.0.0.1",0)) + sock.listen(2) + port = sock.getsockname()[1] + logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % port) + return (sock, port) + + except socket.error: + sock.close() + raise def log(self, msg): if self.logfile:
@@ -82,7 +80,10 @@ class QemuRunner: else: os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image - if not self.create_socket(): + try: + self.server_socket, self.serverport = self.create_socket() + except socket.error, msg: + logger.error("Failed to create listening socket: %s" % msg[1]) return False # Set this flag so that Qemu doesn't do any grabs as SDL grabs interact
Signature · 1 line
2.4.3
PATCH v2 3/3 qemurunner: Use two serial ports and log console with a thread
In reply to Randy Wittqemu can freeze and stop responding if the socket buffer connected to a tcp serial connection fills up. This happens of course when the reader of the serial data doesn't actually read it.
This happened in the qemurunner code, because after checking for the "login:" sentinel, data was never again read from the serial connection.
This patch solves the potential freeze by adding a thread to continuously read the data from the console and log it. So it also will give a full log of the console, rather than just up to the login prompt.
To simplify this patch, another serial port was also added to use for the sole purpose of watching for the sentinel as well as being the interactive serial port. This will also prevent the possibility of lots of debug data on the console preventing the sentinel value from being seen due to interleaved text.
--- meta/conf/machine/qemuarm.conf | 2 +- meta/conf/machine/qemuarm64.conf | 2 +- meta/conf/machine/qemumips.conf | 2 +- meta/conf/machine/qemumips64.conf | 2 +- meta/conf/machine/qemuppc.conf | 2 +- meta/conf/machine/qemux86-64.conf | 2 +- meta/conf/machine/qemux86.conf | 2 +- meta/lib/oeqa/utils/qemurunner.py | 128 +++++++++++++++++++++++++++++++++++++- 8 files changed, 133 insertions(+), 9 deletions(-)
meta/conf/machine/qemuarm.conf +1 -1
@@ -8,5 +8,5 @@ require conf/machine/include/tune-arm926ejs.inc KERNEL_IMAGETYPE = "zImage" -SERIAL_CONSOLE = "115200 ttyAMA0" +SERIAL_CONSOLES = "115200;ttyAMA0 115200;ttyAMA1"
meta/conf/machine/qemuarm64.conf +1 -1
@@ -9,4 +9,4 @@ MACHINE_FEATURES = "" KERNEL_IMAGETYPE = "Image" -SERIAL_CONSOLE = "38400 ttyAMA0" +SERIAL_CONSOLES = "38400;ttyAMA0 38400;ttyAMA1"
meta/conf/machine/qemumips.conf +1 -1
@@ -8,6 +8,6 @@ require conf/machine/include/tune-mips32r2.inc KERNEL_IMAGETYPE = "vmlinux" KERNEL_ALT_IMAGETYPE = "vmlinux.bin" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" MACHINE_EXTRA_RRECOMMENDS = " kernel-modules"
meta/conf/machine/qemumips64.conf +1 -1
@@ -8,6 +8,6 @@ require conf/machine/include/tune-mips64.inc KERNEL_IMAGETYPE = "vmlinux" KERNEL_ALT_IMAGETYPE = "vmlinux.bin" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" MACHINE_EXTRA_RRECOMMENDS = " kernel-modules"
meta/conf/machine/qemuppc.conf +1 -1
@@ -7,5 +7,5 @@ require conf/machine/include/tune-ppc7400.inc KERNEL_IMAGETYPE = "vmlinux" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1"
meta/conf/machine/qemux86-64.conf +1 -1
@@ -13,7 +13,7 @@ require conf/machine/include/tune-core2.inc KERNEL_IMAGETYPE = "bzImage" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" XSERVER = "xserver-xorg \ ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast', '', d)} \
meta/conf/machine/qemux86.conf +1 -1
@@ -12,7 +12,7 @@ require conf/machine/include/tune-i586.inc KERNEL_IMAGETYPE = "bzImage" -SERIAL_CONSOLE = "115200 ttyS0" +SERIAL_CONSOLES = "115200;ttyS0 115200;ttyS1" XSERVER = "xserver-xorg \ ${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'mesa-driver-swrast', '', d)} \
meta/lib/oeqa/utils/qemurunner.py +126 -2
173 lines not on this page · raw message
Signature · 1 line
2.4.3
Quoted 4 lines · Randy Witt
Randy Witt (3):
qemurunner.py: Move some class variables that should only be local
qemurunner: Makecreate_socket()return data and use exceptions
qemurunner: Use two serial ports and log console with a thread
If this was meant to fix the ttyS1 hangs, I'm sorry :(
Ross
Quoted 11 lines · Ross
On 20 August 2015 at 23:24, Randy Witt <[email protected]> wrote:
Randy Witt (3):
qemurunner.py: Move some class variables that should
only be local
qemurunner: Makecreate_socket()return data and use
exceptions
qemurunner: Use two serial ports and log console with a
thread
Quoted 4 lines
Quoted 1 line
If this was meant to fix the ttyS1 hangs, I'm sorry :(
It was meant to fix the issue where qemu hangs and stops responding to network requests. Its a useful datapoint that the systemd issues remain though. Was there a systemd upgrade in mut out of interest (as another data point)?
Cheers,
Richard
Quoted 5 lines · Richard Purdie
It was meant to fix the issue where qemu hangs and stops responding to network requests. Its a useful datapoint that the systemd issues remain though. Was there a systemd upgrade in mut out of interest (as another data point)?
There's still plenty of builds so lets see what happens...
There wasn't a systemd in that MUT, no.
Ross