Le 07/03/2016 10:21, Philippe Teuwen a écrit :
I recompiled libusb with debug symbols:
Normal CPU:
Thread 5 (Thread 0x7f0238fcb700 (LWP 24364)):
#0 0x00007f02394dfb6d in poll () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f0238fdbafc in poll (__timeout=-1, __nfds=2,
__fds=0x7f0238fcaee0)
at /usr/include/x86_64-linux-gnu/bits/poll2.h:46
#2 linux_udev_event_thread_main (arg=<optimized out>)
at ../../libusb/os/linux_udev.c:175
#3 0x00007f02397ab284 in start_thread (arg=0x7f0238fcb700)
at pthread_create.c:333
#4 0x00007f02394e8a4d in clone ()
at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
100% CPU:
Thread 5 (Thread 0x7fbeac2a4700 (LWP 24181)):
#0 0x00007fbeaca8cbdd in recvmsg () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007fbead2806ec in udev_monitor_receive_device ()
from /lib/x86_64-linux-gnu/libudev.so.1
#2 0x00007fbeac2b4b8b in linux_udev_event_thread_main (arg=<optimized out>)
at ../../libusb/os/linux_udev.c:186
#3 0x00007fbeaca84284 in start_thread (arg=0x7fbeac2a4700)
at pthread_create.c:333
#4 0x00007fbeac7c1a4d in clone ()
at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
So the diff happens in that code from libusb/os/linux_udev.c:
usbi_dbg("udev event thread entering.");
while (poll(fds, 2, -1) >= 0) {
if (fds[0].revents & POLLIN) {
r = usbi_read(udev_control_pipe[0], &dummy, sizeof(dummy));
if (r <= 0) {
usbi_warn(NULL, "udev control pipe read failed");
}
break;
}
if (fds[1].revents & POLLIN) {
usbi_mutex_static_lock(&linux_hotplug_lock);
udev_dev = udev_monitor_receive_device(udev_monitor);
if (udev_dev)
udev_hotplug_event(udev_dev);
usbi_mutex_static_unlock(&linux_hotplug_lock);
}
}
usbi_dbg("udev event thread exiting");
I added error msgs in the loop.
When 100% CPU, the poll() is non-blocking and the loop becomes a busy loop.
Great.
I reported the problem on the libusb mailing list
https://sourceforge.net/p/libusb/mailman/message/34914342/
Do you know a sequence of manipulations that triggers the bug?
I would like to reproduce the bug on my side.
Can you change the code of libusb to display the values fds[0].revents and
fds[1].revents
Something like:
--- /tmp/XP5vZa_linux_udev.c 2016-03-07 19:32:06.353701710 +0100
+++ libusb/os/linux_udev.c 2016-03-07 19:31:56.613374793 +0100
@@ -173,6 +173,7 @@ static void *linux_udev_event_thread_mai
usbi_dbg("udev event thread entering.");
while (poll(fds, 2, -1) >= 0) {
+ printf("fds: %d %d\n", fds[0].revents, fds[1].revents);
if (fds[0].revents & POLLIN) {
/* activity on control pipe, read the byte and exit */
r = usbi_read(udev_control_pipe[0], &dummy, sizeof(dummy));
What is the result when the problem occurs?
Bye
--
Dr. Ludovic Rousseau