Experimental threaded udev
Now available for your delight and/or horror.
<http://github.com/sourcejedi/udev/commits/threading-v0.3>
For now, I'm still treating this as a patch series. That is, I may publish future versions with a rewritten history. I'll preserve the old branches though.
It turns out the MADV_DONTFORK hack I was so proud of is implementation-dependant, i.e. a dirty hack. However, I'm confident that glibc can and should be modified to do it for all programs. And it is so worth it. On my test machine, threading alone goes from 2s boot-time coldplug to 1.3-ish. MADV_DONTFORK takes it down to 0.7-ish. The hack is contained in the last patch, "when forking a program, only copy the stack of the _current_ thread".
Thanks for your time and encouragement
Alan
udevd: don't use alarm() for timeouts
Build udevd with pthreads
Protect selinux context against concurrent modification Add close-on-exec wrappers for open(), fopen(), pipe() and socket() Convert udevd and libudev to use close-on-exec wrapper functions Add abstraction layer for udev event tasks
Run udev event tasks in threads
udevd: when forking a program, only copy the stack of the
_current_ thread
configure.ac | 15 ++ extras/ata_id/Makefile.am | 3 +- extras/cdrom_id/Makefile.am | 3 +- extras/collect/Makefile.am | 3 +- extras/edd_id/Makefile.am | 3 +- extras/floppy/Makefile.am | 1 + extras/fstab_import/Makefile.am | 3 +- extras/scsi_id/Makefile.am | 3 +- extras/usb_id/Makefile.am | 3 +- m4/acx_pthread.m4 | 280 ++++++++++++++++++++++++++++++ udev/Makefile.am | 8 + udev/lib/Makefile.am | 1 + udev/lib/libudev-cloexec.c | 226 ++++++++++++++++++++++++ udev/lib/libudev-ctrl.c | 2 +- udev/lib/libudev-device-db-write.c | 2 +- udev/lib/libudev-device.c | 6 +- udev/lib/libudev-monitor.c | 4 +- udev/lib/libudev-private.h | 13 ++ udev/lib/libudev-queue.c | 2 +- udev/lib/libudev-sysdeps.h | 96 ++++++++++ udev/lib/libudev.c | 18 ++- udev/test-udev.c | 7 - udev/udev-event.c | 335 +++++++++++++++++++++++++++++++++++- udev/udev-node.c | 2 +- udev/udev-rules.c | 53 +++--- udev/udev-selinux.c | 9 +- udev/udev-task.c | 295 +++++++++++++++++++++++++++++++ udev/udev-util.c | 211 ----------------------- udev/udev.h | 23 +++- udev/udevd.c | 323 ++++++++++++++++++----------------- 30 files changed, 1527 insertions(+), 426 deletions(-) create mode 100644 m4/acx_pthread.m4 create mode 100644 udev/lib/libudev-cloexec.c create mode 100644 udev/lib/libudev-sysdeps.h create mode 100644 udev/udev-task.c
Quoted 8 lines · Alan Jenkins
Now available for your delight and/or horror.
<http://github.com/sourcejedi/udev/commits/threading-v0.3>
For now, I'm still treating this as a patch series. That is, I may publish future versions with a rewritten history. I'll preserve the old branches though.
Quoted 7 lines
It turns out the
MADV_DONTFORKhack I was so proud of is implementation-dependant, i.e. a dirty hack. However, I'm confident that glibc can and should be modified to do it for all programs. And it is so worth it. On my test machine, threading alone goes from 2s boot-time coldplug to 1.3-ish. MADV_DONTFORK takes it down to 0.7-ish. The hack is contained in the last patch, "when forking a program, only copy the stack of the _current_ thread".
Is that a single or dual CPU box?
With the threaded version, it's 0.18 (1.51 -> 1.33) seconds faster here for a full coldplug run on a:
Intel(R) Core(TM)2 Duo CPU U9400 @ 1.40GHz.
It might be that the threaded version will only behave that much better on a single CPU machine?
Thanks,
Kay
Quoted 19 lines · Kay Sievers
Quoted 8 lines · Alan Jenkins
Now available for your delight and/or horror.
<http://github.com/sourcejedi/udev/commits/threading-v0.3>
For now, I'm still treating this as a patch series. That is, I may publish future versions with a rewritten history. I'll preserve the old branches though.
Quoted 8 lines
It turns out the
MADV_DONTFORKhack I was so proud of is implementation-dependant, i.e. a dirty hack. However, I'm confident that glibc can and should be modified to do it for all programs. And it is so worth it. On my test machine, threading alone goes from 2s boot-time coldplug to 1.3-ish.MADV_DONTFORKtakes it down to 0.7-ish. The hack is contained in the last patch, "when forking a program, only copy the stack of the _current_ thread".
Quoted 2 lines
Is that a single or dual CPU box?
Single CPU - its my Celeron 630Mhz netbook.
Quoted 10 lines
With the threaded version, it's 0.18 (1.51 -> 1.33) seconds faster here for a full coldplug run on a:
Intel(R) Core(TM)2 Duo CPU U9400 @ 1.40GHz.It might be that the threaded version will only behave that much better on a single CPU machine?
Thanks,
Kay
I'll have a look on my Core2Duo desktop. My netbook core is much slower than a C2D desktop, but it does require explanation.
There are a couple of global locks. The selinux context is per-process, so that's locked. If you don't have full close-on-exec support, it has to fallback to locking. I haven't tested the full close-on-exec support yet.
My memory says my desktop machine steams through coldplug in a fraction of a second, but I've not measured it recently.
Thanks
Alan
Quoted 19 lines · Kay Sievers
Quoted 8 lines · Alan Jenkins
Now available for your delight and/or horror.
<http://github.com/sourcejedi/udev/commits/threading-v0.3>
For now, I'm still treating this as a patch series. That is, I may publish future versions with a rewritten history. I'll preserve the old branches though.
Quoted 8 lines
It turns out the
MADV_DONTFORKhack I was so proud of is implementation-dependant, i.e. a dirty hack. However, I'm confident that glibc can and should be modified to do it for all programs. And it is so worth it. On my test machine, threading alone goes from 2s boot-time coldplug to 1.3-ish.MADV_DONTFORKtakes it down to 0.7-ish. The hack is contained in the last patch, "when forking a program, only copy the stack of the _current_ thread".
Quoted 9 lines
Is that a single or dual CPU box?
With the threaded version, it's 0.18 (1.51 -> 1.33) seconds faster here for a full coldplug run on a:
Intel(R) Core(TM)2 Duo CPU U9400 @ 1.40GHz.It might be that the threaded version will only behave that much better on a single CPU machine?
No, it's not that. I'm afraid the result of ~0.7 seconds result was an accident; the bootchart looks suspicious and it didn't obtain when I retested. The "fixed" version of the last patch doesn't work, and I don't think it can.
The version that crashed on boot may be useful for comparison purposes though. I will try and see how much I can reduce the page fault overhead without using threads. Maybe just recycling the event processes would bring similar gains, with less of the risks of threads.
Alan
Quoted 2 lines · Alan Jenkins
 Maybe just recycling the event processes would bring similar gains, with less of the risks of threads.
Yeah, I thought that too, without having tested anything, it could be, that we just want to keep a pipe to the event process, and let the event process send a signal back to the main daemon, that it has handled the event, and it goes to sleep after that. The main daemon can recycle a sleeping event process and push a new event over the pipe to it. If no events are queued anymore, the main daemon just closes the pipe, and the event process will exit.
With that model we might be able to reduce the number of fork()s significantly. And we would still have the process separation, it's robustness, and the lock-free behavior for malloc, cloexec and all these issues.
Thanks,
Kay
Quoted 13 lines · Kay Sievers
Quoted 2 lines · Alan Jenkins
Maybe just recycling the event processes would bring
similar gains, with less of the risks of threads.Yeah, I thought that too, without having tested anything, it could be, that we just want to keep a pipe to the event process, and let the event process send a signal back to the main daemon, that it has handled the event, and it goes to sleep after that. The main daemon can recycle a sleeping event process and push a new event over the pipe to it. If no events are queued anymore, the main daemon just closes the pipe, and the event process will exit.
Quoted 4 lines
With that model we might be able to reduce the number of fork()s significantly. And we would still have the process separation, it's robustness, and the lock-free behavior for malloc, cloexec and all these issues.
Here is a rough hack to check how it behaves. It boots my box, nothing else I really checked.
It clones the event processes as the current version does, but the event process stays around to get re-used as a worker for later events. Further messages are send over netlink to the worker processes, and the worker process signals its state back with sigqueue() rt-signals. When the events have settled, the workers get killed after a few seconds of idle time.
The current git version:
$ time (udevadm trigger; udevadm settle) real 0m1.566s ...
$ time /sbin/udevd.orig [] user 0m0.420s sys 0m1.412s
The thread-version:
$ time (udevadm trigger -Snet; udevadm settle) real 0m1.336s
$ time udev/udevd [] user 0m0.310s sys 0m0.679s
The worker-version:
$ time (udevadm trigger; udevadm settle) real 0m1.171s ...
$ time udev/udevd [] user 0m0.057s sys 0m0.095s
The thread- and worker-versions do not create as many COW page-faults in the daemon after every cloned event-process, and therefore need much less CPU.
At least on the dual-core laptop here, the pool of workers seems to be faster than the threads.
Thanks,
Kay
lib/libudev-monitor.c | 41 +--- lib/libudev-private.h | 2 udev-event.c | 7 udev.h | 6 udevd.c | 500 +++++++++++++++++++++++++++++++------------------- 5 files changed, 333 insertions(+), 223 deletions(-)
udev/lib/libudev-monitor.c +13 -28
@@ -32,7 +32,6 @@ struct udev_monitor {int refcount;int sock;struct sockaddr_nl snl; -struct sockaddr_nl snl_peer;struct sockaddr_un sun;socklen_t addrlen;struct udev_list_node filter_subsystem_list;
@@ -171,8 +170,8 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const charreturn NULL ;if (name =NULL ) -return NULL ; -if (strcmp (name,"kernel" ) =0 ) + group =0 ; +else if (strcmp (name,"kernel" ) =0 ) group =UDEV_MONITOR_KERNEL ;else if (strcmp (name,"udev" ) =0 ) group =UDEV_MONITOR_UDEV ;
@@ -193,8 +192,6 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char udev_monitor->snl.nl_family =AF_NETLINK ; udev_monitor->snl.nl_groups = group; - udev_monitor->snl_peer.nl_family =AF_NETLINK ; - udev_monitor->snl_peer.nl_groups =UDEV_MONITOR_UDEV ;dbg (udev,"monitor %p created with NETLINK_KOBJECT_UEVENT (%u)\n" , udev_monitor, group);return udev_monitor;
@@ -434,7 +431,6 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitostruct iovec iov;char cred_msg[CMSG_SPACE (sizeof (struct ucred ))];struct cmsghdr *cmsg; -struct sockaddr_nl snl;struct ucred *cred;char buf[8192 ];ssize_t buflen;
@@ -459,11 +455,6 @@ retry: smsg.msg_control = cred_msg; smsg.msg_controllen =sizeof (cred_msg); -if (udev_monitor->snl.nl_family !=0 ) { - smsg.msg_name = &snl; - smsg.msg_namelen =sizeof (snl); - } - buflen =recvmsg (udev_monitor->sock, &smsg,0 );if (buflen <0 ) {if (errno !=EINTR )
@@ -476,20 +467,6 @@ retry:return NULL ; } -if (udev_monitor->snl.nl_family !=0 ) { -if (snl.nl_groups =0 ) { -info (udev_monitor->udev,"unicast netlink message ignored\n" ); -return NULL ; - } -if (snl.nl_groups =UDEV_MONITOR_KERNEL ) { -if (snl.nl_pid >0 ) { -info (udev_monitor->udev,"multicast kernel netlink message from pid %d ignored\n" , snl.nl_pid); -return NULL ; - } - is_kernel =1 ; - } - } - cmsg =CMSG_FIRSTHDR (&smsg);if (cmsg =NULL || cmsg->cmsg_type !=SCM_CREDENTIALS ) {info (udev_monitor->udev,"no sender credentials received, message ignored\n" );
@@ -621,7 +598,7 @@ retry:return udev_device; } -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device) +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid) {struct msghdr smsg;struct iovec iov[2 ];
@@ -660,6 +637,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi }else if (udev_monitor->snl.nl_family !=0 ) {const char *val;struct udev_monitor_netlink_header nlh; +struct sockaddr_nl snl_peer;/* add versioned header */
@@ -680,11 +658,18 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi iov[1 ].iov_base = (char *)buf; iov[1 ].iov_len = blen; +/* we will always get ECONNREFUSED when sending to the muticast group */ +memset (&snl_peer,0x00 ,sizeof (struct sockaddr_nl )); + snl_peer.nl_family =AF_NETLINK ; +if (pid >0 ) + snl_peer.nl_pid = pid; +else + snl_peer.nl_groups =UDEV_MONITOR_UDEV ; +memset (&smsg,0x00 ,sizeof (struct msghdr )); smsg.msg_iov = iov; smsg.msg_iovlen =2 ; -/* no destination besides the muticast group, we will always get ECONNREFUSED */ - smsg.msg_name = &udev_monitor->snl_peer; + smsg.msg_name = &snl_peer; smsg.msg_namelen =sizeof (struct sockaddr_nl ); }else {return -1 ;
udev/lib/libudev-private.h +1 -1
@@ -86,7 +86,7 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor =NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor, event->dev,0 );udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev.h +0 -6
@@ -53,7 +53,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +63,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +71,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
udev/udevd.c +318 -182
751 lines not on this page · raw message
Quoted 64 lines · Kay Sievers
Quoted 14 lines · Kay Sievers
Quoted 3 lines · Alan Jenkins
Maybe just recycling the event processes would bring
similar gains, with less of the risks of threads.Yeah, I thought that too, without having tested anything, it could be, that we just want to keep a pipe to the event process, and let the event process send a signal back to the main daemon, that it has handled the event, and it goes to sleep after that. The main daemon can recycle a sleeping event process and push a new event over the pipe to it. If no events are queued anymore, the main daemon just closes the pipe, and the event process will exit.
Quoted 5 lines
With that model we might be able to reduce the number of fork()s significantly. And we would still have the process separation, it's robustness, and the lock-free behavior for malloc, cloexec and all these issues.
Here is a rough hack to check how it behaves. It boots my box, nothing else I really checked.
It clones the event processes as the current version does, but the event process stays around to get re-used as a worker for later events. Further messages are send over netlink to the worker processes, and the worker process signals its state back with
sigqueue()rt-signals. When the events have settled, the workers get killed after a few seconds of idle time.The current git version:
$ time (udevadm trigger; udevadm settle) real 0m1.566s ...$ time /sbin/udevd.orig [] user 0m0.420s sys 0m1.412sThe thread-version:
$ time (udevadm trigger -Snet; udevadm settle) real 0m1.336s$ time udev/udevd [] user 0m0.310s sys 0m0.679sThe worker-version:
$ time (udevadm trigger; udevadm settle) real 0m1.171s ...$ time udev/udevd [] user 0m0.057s sys 0m0.095s
Quoted 7 lines
The thread- and worker-versions do not create as many COW page-faults in the daemon after every cloned event-process, and therefore need much less CPU.
At least on the dual-core laptop here, the pool of workers seems to be faster than the threads.
Great, you beat me to it. It makes sense that this would be _bit_ faster than threads. As I say I tried to avoid the page faults caused (somehow) by forking the extra thread-stack mappings, but it didn't really work out. I'm surprised by quite how much faster it is though!
I have some thoughts which may help in bringing the code up from "rough hack" quality :-).
Aren't signal queues unreliable? If you exceed the maximum number of queued signals, sigqueue will fail with EAGAIN, and I don't think there's a blocking version :-). I think a pipe would be better, or maybe you can do something with netlink.
+ /* wait for more device messages from udevd */
+ do
+ dev = udev_monitor_receive_device(monitor);
+ while (dev = NULL);
I think this loop should finish when the signal handler sets worker_exit? But maybe you didn't actually install a handler for SIGTERM and it's still being reset to the default action:
/* set signal handlers */
memset(&act, 0x00, sizeof(act));
act.sa_handler = event_sig_handler;
@@ -154,66 +203,135 @@ static void event_fork(struct udev_event *event)
sigaction(SIGTERM, &act, NULL);I'm not sure you're handling worker processes crashing, it looks like you might leave the event in limbo if you get SIGCHLD for a worker in state WORKER_RUNNING. I'm sure you'll test that though.
Talking of unexpected crashes. I anticipated using a connection-oriented socketpair for passing events. Using netlink for this means the worker threads don't get a nice notification if the daemon dies without killing them. Unless this is covered by udevd being the session leader, or something like that? I'll test this empirically
- maybe it's not important, but I think it's good to know what will happen.
BTW I had a go at this too, but a couple of my workers fail in about 1 run out of 20, apparently because calloc() returns NULL without setting errno. I'm sure it's my fault but I'll try to track it down. Obviously I'll let you know if your patch could be affected by the same problem.
Thanks
Alan
Quoted 4 lines · Alan Jenkins
Quoted 4 lines
The thread- and worker-versions do not create as many COW page-faults in the daemon after every cloned event-process, and therefore need much less CPU.
Quoted 8 lines
Quoted 3 lines
At least on the dual-core laptop here, the pool of workers seems to be faster than the threads.
Great, you beat me to it. It makes sense that this would be _bit_ faster than threads. As I say I tried to avoid the page faults caused (somehow) by forking the extra thread-stack mappings, but it didn't really work out. I'm surprised by quite how much faster it is though!
Yeah, the 1.2 sec system time looked a bit too scary.
Quoted 2 lines
I have some thoughts which may help in bringing the code up from "rough hack" quality :-).
Cool. :)
Quoted 3 lines
Aren't signal queues unreliable? If you exceed the maximum number of queued signals, sigqueue will fail with EAGAIN, and I don't think there's a blocking version :-).
Right, it's a rlimit, and I think I checked and remember 40.000+ signals here. The workers could detect, and re-send a non-queued signal, if needed.
Quoted 1 line
I think a pipe would be better
Maybe. I was lazy and tried to avoid file descriptors, in case we get a really large number of workers to maintain. :)
Quoted 1 line
or maybe you can do something with netlink.
Right, but then, I guess, we would need to do MSG_PEEK, or something, to find out if the main daemon received a kernel message or a worker message, before trying to do a receive_device().
Quoted 8 lines
+ /* wait for more device messages from udevd */
+ do
+ dev =udev_monitor_receive_device(monitor);
+ while (dev = NULL);I think this loop should finish when the signal handler sets
worker_exit? But maybe you didn't actually install a handler for SIGTERM and it's still being reset to the default action:
Yeah, it's not handled with worker_exit. Now, it's not reliable to kill event processes from something else than the main daemon. The worker_exit might be nice for valgrind tests though.
Quoted 3 lines
I'm not sure you're handling worker processes crashing, it looks like you might leave the event in limbo if you get SIGCHLD for a worker in state
WORKER_RUNNING. I'm sure you'll test that though.
Maybe we can set the event to QUEUED, when a worker dies with an event attached.
Quoted 4 lines
Talking of unexpected crashes. I anticipated using a connection-oriented socketpair for passing events. Using netlink for this means the worker threads don't get a nice notification if the daemon dies without killing them.
Right, thats not too nice. I guess we have pretty much lost if the main daemon dies unexpectedly. We need to find out, if we want netlink and signals, or socketpair()s here, I guess.
Quoted 3 lines
Unless this is covered by udevd being the session leader, or something like that? I'll test this empirically - maybe it's not important, but I think it's good to know what will happen.
If the main daemon exits normally, it sends TERM to the entire process group
Quoted 4 lines
BTW I had a go at this too, but a couple of my workers fail in about 1 run out of 20, apparently because
calloc()returns NULL without setting errno. I'm sure it's my fault but I'll try to track it down. Obviously I'll let you know if your patch could be affected by the same problem.
Oh, strange. Would be good to know what causes this.
Thanks,
Kay
Quoted 9 lines · Kay Sievers
Quoted 3 lines · Alan Jenkins
I think this loop should finish when the signal handler sets
worker_exit? But maybe you didn't actually install a handler for SIGTERM and it's still being reset to the default action:Yeah, it's not handled with
worker_exit. Now, it's not reliable to kill event processes from something else than the main daemon. Theworker_exitmight be nice for valgrind tests though.
Here is version 2 of the patch, with a few things corrected.
Thanks,
Kay
udev/lib/libudev-monitor.c +13 -28
@@ -32,7 +32,6 @@ struct udev_monitor {int refcount;int sock;struct sockaddr_nl snl; -struct sockaddr_nl snl_peer;struct sockaddr_un sun;socklen_t addrlen;struct udev_list_node filter_subsystem_list;
@@ -171,8 +170,8 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const charreturn NULL ;if (name ==NULL ) -return NULL ; -if (strcmp (name,"kernel" ) ==0 ) + group =0 ; +else if (strcmp (name,"kernel" ) ==0 ) group =UDEV_MONITOR_KERNEL ;else if (strcmp (name,"udev" ) ==0 ) group =UDEV_MONITOR_UDEV ;
@@ -193,8 +192,6 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char udev_monitor->snl.nl_family =AF_NETLINK ; udev_monitor->snl.nl_groups = group; - udev_monitor->snl_peer.nl_family =AF_NETLINK ; - udev_monitor->snl_peer.nl_groups =UDEV_MONITOR_UDEV ;dbg (udev,"monitor %p created with NETLINK_KOBJECT_UEVENT (%u)\n" , udev_monitor, group);return udev_monitor;
@@ -434,7 +431,6 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitostruct iovec iov;char cred_msg[CMSG_SPACE (sizeof (struct ucred ))];struct cmsghdr *cmsg; -struct sockaddr_nl snl;struct ucred *cred;char buf[8192 ];ssize_t buflen;
@@ -459,11 +455,6 @@ retry: smsg.msg_control = cred_msg; smsg.msg_controllen =sizeof (cred_msg); -if (udev_monitor->snl.nl_family !=0 ) { - smsg.msg_name = &snl; - smsg.msg_namelen =sizeof (snl); - } - buflen =recvmsg (udev_monitor->sock, &smsg,0 );if (buflen <0 ) {if (errno !=EINTR )
@@ -476,20 +467,6 @@ retry:return NULL ; } -if (udev_monitor->snl.nl_family !=0 ) { -if (snl.nl_groups ==0 ) { -info (udev_monitor->udev,"unicast netlink message ignored\n" ); -return NULL ; - } -if (snl.nl_groups ==UDEV_MONITOR_KERNEL ) { -if (snl.nl_pid >0 ) { -info (udev_monitor->udev,"multicast kernel netlink message from pid %d ignored\n" , snl.nl_pid); -return NULL ; - } - is_kernel =1 ; - } - } - cmsg =CMSG_FIRSTHDR (&smsg);if (cmsg ==NULL || cmsg->cmsg_type !=SCM_CREDENTIALS ) {info (udev_monitor->udev,"no sender credentials received, message ignored\n" );
@@ -621,7 +598,7 @@ retry:return udev_device; } -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device) +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid) {struct msghdr smsg;struct iovec iov[2 ];
@@ -660,6 +637,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi }else if (udev_monitor->snl.nl_family !=0 ) {const char *val;struct udev_monitor_netlink_header nlh; +struct sockaddr_nl snl_peer;/* add versioned header */
@@ -680,11 +658,18 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi iov[1 ].iov_base = (char *)buf; iov[1 ].iov_len = blen; +/* we will always get ECONNREFUSED when sending to the muticast group */ +memset (&snl_peer,0x00 ,sizeof (struct sockaddr_nl )); + snl_peer.nl_family =AF_NETLINK ; +if (pid >0 ) + snl_peer.nl_pid = pid; +else + snl_peer.nl_groups =UDEV_MONITOR_UDEV ; +memset (&smsg,0x00 ,sizeof (struct msghdr )); smsg.msg_iov = iov; smsg.msg_iovlen =2 ; -/* no destination besides the muticast group, we will always get ECONNREFUSED */ - smsg.msg_name = &udev_monitor->snl_peer; + smsg.msg_name = &snl_peer; smsg.msg_namelen =sizeof (struct sockaddr_nl ); }else {return -1 ;
udev/lib/libudev-private.h +1 -1
@@ -86,7 +86,7 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor ==NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor, event->dev,0 );udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev.h +0 -6
@@ -53,7 +53,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +63,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +71,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
udev/udevd.c +324 -183
764 lines not on this page · raw message
Quoted 1 line · Kay Sievers
Here is version 2 of the patch, with a few things corrected.
Pretty weird test, but it seems to survive on my Dual Core 1.5 GHz laptop:
Create lots of devices:
$ time (modprobe scsi_debug add_host max_luns2 num_tgts num_parts=2; udevadm settle) real 11m28.193s
23.000 block devices:
$ find /sys/class/block/ | wc -l 23824
72.000 sysfs devices:
$ find /sys/ -name uevent | wc -l 72224
We created 262 workers:
$ ps afx | grep udevd | wc -l 262
And 10 seconds later, all workers are gone:
$ ps afx | grep udevd | wc -l 2
Kay
Quoted 26 lines · Kay Sievers
Quoted 4 lines · Alan Jenkins
Quoted 4 lines
The thread- and worker-versions do not create as many COW page-faults in the daemon after every cloned event-process, and therefore need much less CPU.
Quoted 9 lines
Quoted 4 lines
At least on the dual-core laptop here, the pool of workers seems to be faster than the threads.
Great, you beat me to it. It makes sense that this would be _bit_ faster than threads. As I say I tried to avoid the page faults caused (somehow) by forking the extra thread-stack mappings, but it didn't really work out. I'm surprised by quite how much faster it is though!
Yeah, the 1.2 sec system time looked a bit too scary.
Quoted 3 lines
I have some thoughts which may help in bringing the code up from "rough hack" quality :-).
Cool. :)
Quoted 9 lines
Quoted 4 lines
Aren't signal queues unreliable? If you exceed the maximum number of queued signals, sigqueue will fail with EAGAIN, and I don't think there's a blocking version :-).
Right, it's a rlimit, and I think I checked and remember 40.000+ signals here. The workers could detect, and re-send a non-queued signal, if needed.
Non-queued signal transmission isn't blocking either. The signal just gets dropped if there's already one in-flight.
Quoted 8 lines
Quoted 3 lines
I think a pipe would be better
Maybe. I was lazy and tried to avoid file descriptors, in case we get a really large number of workers to maintain. :)
Quoted 7 lines
Quoted 2 lines
or maybe you can do something with netlink.
Right, but then, I guess, we would need to do
MSG_PEEK, or something, to find out if the main daemon received a kernel message or a worker message, before trying to do areceive_device().
Ok. I meant we could send all the completions down the same pipe, which wouldn't require lots of FDs. Before this patch, we were happily sharing kernel_monitor->sock between all the child processes.
Quoted 15 lines
Quoted 9 lines
(quoted diff) +4
-0+ /* wait for more device messages from udevd */ + do + dev = udev_monitor_receive_device(monitor); + while (dev = NULL);I think this loop should finish when the signal handler sets
worker_exit?
But maybe you didn't actually install a handler for SIGTERM and it's still
being reset to the default action:Yeah, it's not handled with
worker_exit. Now, it's not reliable to kill event processes from something else than the main daemon. Theworker_exitmight be nice for valgrind tests though.
Quoted 7 lines
Quoted 4 lines
I'm not sure you're handling worker processes crashing, it looks like you might leave the event in limbo if you get SIGCHLD for a worker in state
WORKER_RUNNING. I'm sure you'll test that though.Maybe we can set the event to QUEUED, when a worker dies with an event attached.
Retry the event, you mean? How many times? :-).
The code looked like you freed the worker, but left the event RUNNING, and it would never be released. I would delete the event instead, just like the old system.
I haven't read V2 yet though, maybe you fixed it.
Quoted 20 lines
Quoted 6 lines
Talking of unexpected crashes. I anticipated using a connection-oriented socketpair for passing events. Using netlink for this means the worker threads don't get a nice notification if the daemon dies without killing them.
Right, thats not too nice. I guess we have pretty much lost if the main daemon dies unexpectedly. We need to find out, if we want netlink and signals, or socketpair()s here, I guess.
Quoted 4 lines
Unless this is covered by udevd being the session leader, or something like that? I'll test this empirically - maybe it's not important, but I think it's good to know what will happen.
If the main daemon exits normally, it sends TERM to the entire process group
Quoted 8 lines
Quoted 5 lines
BTW I had a go at this too, but a couple of my workers fail in about 1 run out of 20, apparently because
calloc()returns NULL without setting errno.
I'm sure it's my fault but I'll try to track it down. Obviously I'll let
you know if your patch could be affected by the same problem.Oh, strange. Would be good to know what causes this.
Don't worry about it, it was just my buggy code :-). I used event->udev after udev_event_unref(event).
Thanks
Alan
Quoted 6 lines · Alan Jenkins
Quoted 3 lines
Right, it's a rlimit, and I think I checked and remember 40.000+ signals here. The workers could detect, and re-send a non-queued signal, if needed.
Non-queued signal transmission isn't blocking either. The signal just gets dropped if there's already one in-flight.
Oh, I meant we get an error back, if we can not queue the signal, so we can re-send it. The rt-signals should be fully reliable regarding that.
Quoted 3 lines
Ok. I meant we could send all the completions down the same pipe, which wouldn't require lots of FDs. Before this patch, we were happily sharing
kernel_monitor->sockbetween all the child processes.
Ah, I see. Yeah, we share the inotify fd still, I think. We could have a pie, sure, if it's better for some reason. Scott mentioned signalfd, which we could look at too. Rt-signals might be bit more efficient than a pipe, we should find that out.
Quoted 5 lines
Quoted 3 lines
Maybe we can set the event to QUEUED, when a worker dies with an event attached.
Retry the event, you mean? How many times? :-).
Not sure. :)
Quoted 5 lines
The code looked like you freed the worker, but left the event RUNNING, and it would never be released. I would delete the event instead, just like the old system.
I haven't read V2 yet though, maybe you fixed it.
I just set it back to QUEUED for now. Not sure if droppin git or re-trying it a few times would be better.
Thanks,
Kay
Quoted 8 lines · Kay Sievers
Quoted 5 lines
The code looked like you freed the worker, but left the event RUNNING, and it would never be released. I would delete the event instead, just like the old system.
I haven't read V2 yet though, maybe you fixed it.
I just set it back to QUEUED for now. Not sure if droppin git or re-trying it a few times would be better.
Version 3, which should clean up events with a worker that died. Also kills all workers if the config has changed.
I guess we should find out if we go for rtsignals, a pipe and/or signalfd. Any ideas?
Would be good to start with something in a repository, instead of sending huge patches, I guess.
It's so much faster than the current clone per event, seems we want to have something like that in a released version.
Thanks,
Kay
udev/lib/libudev-monitor.c +13 -28
@@ -32,7 +32,6 @@ struct udev_monitor {int refcount;int sock;struct sockaddr_nl snl; -struct sockaddr_nl snl_peer;struct sockaddr_un sun;socklen_t addrlen;struct udev_list_node filter_subsystem_list;
@@ -171,8 +170,8 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const charreturn NULL ;if (name ==NULL ) -return NULL ; -if (strcmp (name,"kernel" ) ==0 ) + group =0 ; +else if (strcmp (name,"kernel" ) ==0 ) group =UDEV_MONITOR_KERNEL ;else if (strcmp (name,"udev" ) ==0 ) group =UDEV_MONITOR_UDEV ;
@@ -193,8 +192,6 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char udev_monitor->snl.nl_family =AF_NETLINK ; udev_monitor->snl.nl_groups = group; - udev_monitor->snl_peer.nl_family =AF_NETLINK ; - udev_monitor->snl_peer.nl_groups =UDEV_MONITOR_UDEV ;dbg (udev,"monitor %p created with NETLINK_KOBJECT_UEVENT (%u)\n" , udev_monitor, group);return udev_monitor;
@@ -434,7 +431,6 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitostruct iovec iov;char cred_msg[CMSG_SPACE (sizeof (struct ucred ))];struct cmsghdr *cmsg; -struct sockaddr_nl snl;struct ucred *cred;char buf[8192 ];ssize_t buflen;
@@ -459,11 +455,6 @@ retry: smsg.msg_control = cred_msg; smsg.msg_controllen =sizeof (cred_msg); -if (udev_monitor->snl.nl_family !=0 ) { - smsg.msg_name = &snl; - smsg.msg_namelen =sizeof (snl); - } - buflen =recvmsg (udev_monitor->sock, &smsg,0 );if (buflen <0 ) {if (errno !=EINTR )
@@ -476,20 +467,6 @@ retry:return NULL ; } -if (udev_monitor->snl.nl_family !=0 ) { -if (snl.nl_groups ==0 ) { -info (udev_monitor->udev,"unicast netlink message ignored\n" ); -return NULL ; - } -if (snl.nl_groups ==UDEV_MONITOR_KERNEL ) { -if (snl.nl_pid >0 ) { -info (udev_monitor->udev,"multicast kernel netlink message from pid %d ignored\n" , snl.nl_pid); -return NULL ; - } - is_kernel =1 ; - } - } - cmsg =CMSG_FIRSTHDR (&smsg);if (cmsg ==NULL || cmsg->cmsg_type !=SCM_CREDENTIALS ) {info (udev_monitor->udev,"no sender credentials received, message ignored\n" );
@@ -621,7 +598,7 @@ retry:return udev_device; } -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device) +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid) {struct msghdr smsg;struct iovec iov[2 ];
@@ -660,6 +637,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi }else if (udev_monitor->snl.nl_family !=0 ) {const char *val;struct udev_monitor_netlink_header nlh; +struct sockaddr_nl snl_peer;/* add versioned header */
@@ -680,11 +658,18 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, struct udev_devi iov[1 ].iov_base = (char *)buf; iov[1 ].iov_len = blen; +/* we will always get ECONNREFUSED when sending to the muticast group */ +memset (&snl_peer,0x00 ,sizeof (struct sockaddr_nl )); + snl_peer.nl_family =AF_NETLINK ; +if (pid >0 ) + snl_peer.nl_pid = pid; +else + snl_peer.nl_groups =UDEV_MONITOR_UDEV ; +memset (&smsg,0x00 ,sizeof (struct msghdr )); smsg.msg_iov = iov; smsg.msg_iovlen =2 ; -/* no destination besides the muticast group, we will always get ECONNREFUSED */ - smsg.msg_name = &udev_monitor->snl_peer; + smsg.msg_name = &snl_peer; smsg.msg_namelen =sizeof (struct sockaddr_nl ); }else {return -1 ;
udev/lib/libudev-private.h +1 -1
@@ -86,7 +86,7 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor ==NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor, event->dev,0 );udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev.h +0 -6
@@ -53,7 +53,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +63,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +71,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
udev/udevd.c +334 -187
782 lines not on this page · raw message
Quoted 15 lines · Kay Sievers
Quoted 4 lines · Kay Sievers
On Mon, Jun 1, 2009 at 11:29, Alan Jenkins <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
I think this loop should finish when the signal handler sets
worker_exit?
But maybe you didn't actually install a handler for SIGTERM and it's still
being reset to the default action:Yeah, it's not handled with
worker_exit. Now, it's not reliable to kill event processes from something else than the main daemon. Theworker_exitmight be nice for valgrind tests though.
Quoted 5 lines
Here is version 2 of the patch, with a few things corrected.
Thanks,
Kay
Ok.
I don't think the signal handler should be doing list traversal, in case it interrupts list manipulation in the main loop. Or perhaps the main loop should only allow signals during ppoll().
Thanks
Alan
Quoted 3 lines · Alan Jenkins
I don't think the signal handler should be doing list traversal, in case it interrupts list manipulation in the main loop. Â Or perhaps the main loop should only allow signals during
ppoll().
Make sense. we can block them during list mangling, or just go for signalfd, and convert all the signal handling to it.
Thanks,
Kay
Quoted 8 lines · Kay Sievers
Quoted 3 lines · Alan Jenkins
I don't think the signal handler should be doing list traversal, in case it interrupts list manipulation in the main loop. Or perhaps the main loop should only allow signals during
ppoll().Make sense. we can block them during list mangling, or just go for signalfd, and convert all the signal handling to it.
Here is a version that uses signalfd(), and a socketpair() from the workers to pass data back. Same numbers so far, but the code looks a lot simpler.
Kay
configure.ac +0 -4
@@ -23,10 +23,6 @@ AC_SUBST(LIBUDEV_LT_AGE) AC_PATH_PROG([XSLTPROC], [xsltproc]) -AC_CHECK_LIB(c, inotify_init, - [AC_DEFINE([HAVE_INOTIFY], 1, [inotify available])], - [AC_MSG_WARN([inotify support disabled])]) - AC_ARG_WITH(udev-prefix, AS_HELP_STRING([--with-udev-prefix=DIR], [add prefix to internal udev path names]), [], [with_udev_prefix='${exec_prefix}'])
udev/Makefile.am +0 -1
@@ -14,7 +14,6 @@ common_ldadd = common_files = \ udev.h \ - udev-sysdeps.h \ udev-event.c \ udev-watch.c \ udev-node.c \
udev/lib/libudev-monitor.c +13 -28
98 lines not on this page · raw message
udev/lib/libudev-private.h +1 -1
@@ -86,7 +86,7 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor ==NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor, event->dev,0 );udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev-sysdeps.h deleted +0 -44
44 lines not on this page · raw message
udev/udev-watch.c +3 -6
@@ -26,27 +26,24 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#ifdef HAVE_INOTIFY #include <sys/inotify.h> -#endif #include "udev.h" -int inotify_fd =-1 ; +static int inotify_fd =-1 ;/* inotify descriptor, will be shared with rules directory; * set to cloexec since we need our children to be able to add * watches for us */ -void udev_watch_init (struct udev *udev) +int udev_watch_init (struct udev *udev) { inotify_fd =inotify_init ();if (inotify_fd >=0 )util_set_fd_cloexec (inotify_fd); -else if (errno ==ENOSYS ) -info (udev,"unable to use inotify, udevd will not monitor rule files changes\n" );else err (udev,"inotify_init failed: %m\n" ); +return inotify_fd; }/* move any old watches directory out of the way, and then restore
udev/udev.h +1 -9
@@ -22,7 +22,6 @@#include <sys/types.h> #include <sys/param.h> -#include "udev-sysdeps.h" #include "lib/libudev.h" #include "lib/libudev-private.h"
@@ -53,7 +52,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +62,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +70,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
@@ -101,8 +94,7 @@ int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string, char *result, size_t maxsize, int read_value);/* udev-watch.c */ -extern int inotify_fd; -void udev_watch_init (struct udev *udev); +int udev_watch_init (struct udev *udev);void udev_watch_restore (struct udev *udev);void udev_watch_begin (struct udev *udev,struct udev_device *dev);void udev_watch_end (struct udev *udev,struct udev_device *dev);
udev/udevd.c +431 -320
1,013 lines not on this page · raw message
Quoted 7 lines · Kay Sievers
Quoted 4 lines · Kay Sievers
Quoted 4 lines
The code looked like you freed the worker, but left the event RUNNING, and it would never be released. I would delete the event instead, just like the old system.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
I haven't read V2 yet though, maybe you fixed it.
I just set it back to QUEUED for now. Not sure if droppin git or re-trying it a few times would be better.
Version 3, which should clean up events with a worker that died. Also kills all workers if the config has changed.
For strict correctness, I guess we need to do the same for "udevadm control --log-priority" and "udevadm control --env".
Hmm, it says worker_kill_idle(). If there are running events at the time, their stale workers will survive. At the moment kill(worker->pid, SIGTERM) allows the current event to finish before it terminates, so one solution would be to just kill all the workers.
Regards
Alan
Quoted 9 lines · Kay Sievers
Quoted 8 lines · Kay Sievers
Quoted 4 lines · Alan Jenkins
I don't think the signal handler should be doing list traversal, in case it
interrupts list manipulation in the main loop. Or perhaps the main loop should only allow signals duringppoll().
Quoted 8 lines
Quoted 2 lines
Make sense. we can block them during list mangling, or just go for signalfd, and convert all the signal handling to it.
Here is a version that uses
signalfd(), and asocketpair()from the workers to pass data back. Same numbers so far, but the code looks a lot simpler.Kay
Yes, that looks great.
Alan
Quoted 5 lines · Alan Jenkins
Quoted 2 lines
Version 3, which should clean up events with a worker that died. Also kills all workers if the config has changed.
For strict correctness, I guess we need to do the same for "udevadm control --log-priority" and "udevadm control --env".
Yeah, makes sense, will add that.
Quoted 4 lines
Hmm, it says
worker_kill_idle(). If there are running events at the time, their stale workers will survive. At the momentkill(worker->pid, SIGTERM)allows the current event to finish before it terminates, so one solution would be to just kill all the workers.
The main daemon will wakeup with a timeout as long as workers exists. There meigt be several rounds of killing, until all workers are gone.
Thanks,
Kay
Quoted 8 lines · Kay Sievers
Quoted 5 lines · Alan Jenkins
Quoted 2 lines
Version 3, which should clean up events with a worker that died. Also kills all workers if the config has changed.
For strict correctness, I guess we need to do the same for "udevadm control --log-priority" and "udevadm control --env".
Yeah, makes sense, will add that.
Did that.
Quoted 7 lines
Quoted 4 lines
Hmm, it says
worker_kill_idle(). If there are running events at the time, their stale workers will survive. At the momentkill(worker->pid, SIGTERM)allows the current event to finish before it terminates, so one solution would be to just kill all the workers.The main daemon will wakeup with a timeout as long as workers exists. There migt be several rounds of killing, until all workers are gone.
We kill all workers now.
Version 5. I guess we should go for the signalfd stuff, it looks prett nice. The socketpair instead of the rtsignal is also nice, it allows us to pass back arbitrary data from finished events to the main daemon.
This is a full coldplug run for 520 devices:
$ time udev/udevd [] user 0m0.016s sys 0m0.049s
We need less than a second now (compared to 1.5 for the current version):
$ time (udevadm trigger; udevadm settle) real 0m0.983s
It spawned 35 workers for 500 events:
$ ps ax | grep udevd | wc -l 35
Now that the page faults are gone, and the main daemon does not need that much CPU anymore, all the silly things show up, like running a few shell scripts. :)
$ time (udevadm trigger; udevadm settle) real 0m0.959s
$ mv /lib/udev/path_id /lib/udev/path_id.0
$ time (udevadm trigger -Snet; udevadm settle) real 0m0.714s
Thanks,
Kay
NEWS +2 -0
@@ -2,6 +2,8 @@ udev 143 ======== Bugfixes. +Inotify support is required now to compile and run udev. + The format of the queue exported by the udev damon has changed. There is no longer a /dev/.udev/queue/ directory. The queue can be accessed with udevadm settle and libudedv.
configure.ac +0 -4
@@ -23,10 +23,6 @@ AC_SUBST(LIBUDEV_LT_AGE) AC_PATH_PROG([XSLTPROC], [xsltproc]) -AC_CHECK_LIB(c, inotify_init, - [AC_DEFINE([HAVE_INOTIFY], 1, [inotify available])], - [AC_MSG_WARN([inotify support disabled])]) - AC_ARG_WITH(udev-prefix, AS_HELP_STRING([--with-udev-prefix=DIR], [add prefix to internal udev path names]), [], [with_udev_prefix='${exec_prefix}'])
udev/Makefile.am +0 -1
@@ -14,7 +14,6 @@ common_ldadd = common_files = \ udev.h \ - udev-sysdeps.h \ udev-event.c \ udev-watch.c \ udev-node.c \
udev/lib/libudev-monitor.c +13 -28
98 lines not on this page · raw message
udev/lib/libudev-private.h +1 -1
@@ -86,7 +86,7 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device,pid_t pid);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor ==NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor, event->dev,0 );udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev-sysdeps.h deleted +0 -44
44 lines not on this page · raw message
udev/udev-watch.c +3 -6
@@ -26,27 +26,24 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#ifdef HAVE_INOTIFY #include <sys/inotify.h> -#endif #include "udev.h" -int inotify_fd =-1 ; +static int inotify_fd =-1 ;/* inotify descriptor, will be shared with rules directory; * set to cloexec since we need our children to be able to add * watches for us */ -void udev_watch_init (struct udev *udev) +int udev_watch_init (struct udev *udev) { inotify_fd =inotify_init ();if (inotify_fd >=0 )util_set_fd_cloexec (inotify_fd); -else if (errno ==ENOSYS ) -info (udev,"unable to use inotify, udevd will not monitor rule files changes\n" );else err (udev,"inotify_init failed: %m\n" ); +return inotify_fd; }/* move any old watches directory out of the way, and then restore
udev/udev.h +1 -9
@@ -22,7 +22,6 @@#include <sys/types.h> #include <sys/param.h> -#include "udev-sysdeps.h" #include "lib/libudev.h" #include "lib/libudev-private.h"
@@ -53,7 +52,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +62,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +70,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
@@ -101,8 +94,7 @@ int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string, char *result, size_t maxsize, int read_value);/* udev-watch.c */ -extern int inotify_fd; -void udev_watch_init (struct udev *udev); +int udev_watch_init (struct udev *udev);void udev_watch_restore (struct udev *udev);void udev_watch_begin (struct udev *udev,struct udev_device *dev);void udev_watch_end (struct udev *udev,struct udev_device *dev);
udev/udevadm.xml +3 -3
@@ -285,9 +285,9 @@ <term><option>--reload-rules</option></term> <listitem> <para>Signal udevd to reload the rules files. - Usually the udev daemon detects changes automatically, this may - only be needed on systems without inotify support. Reloading rules - does not apply any changes to already existing devices.</para> + The udev daemon detects changes automatically, this option is + usually not needed. Reloading rules does not apply any changes + to already existing devices.</para> </listitem> </varlistentry> <varlistentry>
udev/udevd.c +462 -334
1,098 lines not on this page · raw message
Quoted 4 lines · Kay Sievers
Version 5. I guess we should go for the signalfd stuff, it looks prett nice. The socketpair instead of the rtsignal is also nice, it allows us to pass back arbitrary data from finished events to the main daemon.
Version 7. We need to handle the netlink unicast addresses, they are not neccessarily the process pid, so we need to remember the netlink address.
We also keep 2 workers around, and don't kill them, to handle incoming events without forking.
Thanks,
Kay
NEWS +10 -2
@@ -2,9 +2,17 @@ udev 143 ======== Bugfixes. +Event processes now get re-used after they handled an event. This reduces +pressure on the CPU significantly because cloned event processes no longer +cause page faults in the main daemon. After the events have settled, the +no longer needed worker processes get killed. + +To be able to use signalfd(), udev depends on kernel version 2.6.25 now. +Also inotify support is required now to run udev. + The format of the queue exported by the udev damon has changed. There is -no longer a /dev/.udev/queue/ directory. The queue can be accessed with -udevadm settle and libudedv. +no longer a /dev/.udev/queue/ directory. The current event queue can be +accessed with udevadm settle and libudedv. udev 142 ========
README +12 -13
@@ -9,11 +9,13 @@ Important Note: recommend to replace a distro's udev installation with the upstream version. Requirements: - - Version 2.6.22 of the Linux kernel for reliable operation of this release of - udev. The kernel must not use the CONFIG_SYSFS_DEPRECATED* option. + - Version 2.6.25 of the Linux kernel with sysfs, procfs, signalfd, inotify, + unix domain sockets, networking and hotplug enabled. - - The kernel must have sysfs, unix domain sockets and networking enabled. - Unix domain sockets (CONFIG_UNIX) as a loadable kernel module is not + - For reliable operation, the kernel must not use the CONFIG_SYSFS_DEPRECATED* + option. + + - Unix domain sockets (CONFIG_UNIX) as a loadable kernel module is not supported. - The proc filesystem must be mounted on /proc/, the sysfs filesystem must
@@ -29,21 +31,18 @@ Operation: Udev creates and removes device nodes in /dev/, based on events the kernel sends out on device discovery or removal. - - Very early in the boot process, the /dev/ directory should get a 'tmpfs' - filesystem mounted, which is populated from scratch by udev. Created nodes - or changed permissions will not survive a reboot, which is intentional. + - Early in the boot process, the /dev/ directory should get a 'tmpfs' + filesystem mounted, which is maintained by udev. Created nodes or changed + permissions will not survive a reboot, which is intentional. - The content of /lib/udev/devices/ directory which contains the nodes, symlinks and directories, which are always expected to be in /dev, should be copied over to the tmpfs mounted /dev, to provide the required nodes to initialize udev and continue booting. - - The old hotplug helper /sbin/hotplug should be disabled on bootup, before - actions like loading kernel modules are taken, which may cause a lot of - events. - - - The udevd daemon must be started on bootup to receive netlink uevents - from the kernel driver core. + - The old hotplug helper /sbin/hotplug should be disabled in the kernel + configuration, it is not needed, and may render the system unusable + because of a fork-bombing behavior. - All kernel events are matched against a set of specified rules in /lib/udev/rules.d/ which make it possible to hook into the event
TODO +1 -0
@@ -1,3 +1,4 @@ + o add tests for kernel provided DEVNAME logic o drop modprobe floppy alias (SUSE), it will be in the module (2.6.30) o remove MMC rules, they got a modalias now (2.6.30)
configure.ac +1 -4
@@ -5,6 +5,7 @@ AC_PREREQ(2.60) AM_INIT_AUTOMAKE([check-news foreign 1.9 dist-bzip2]) AC_DISABLE_STATIC AC_USE_SYSTEM_EXTENSIONS +dnl AM_SILENT_RULES AC_SYS_LARGEFILE AC_CONFIG_MACRO_DIR([m4]) AC_PROG_LIBTOOL
@@ -23,10 +24,6 @@ AC_SUBST(LIBUDEV_LT_AGE) AC_PATH_PROG([XSLTPROC], [xsltproc]) -AC_CHECK_LIB(c, inotify_init, - [AC_DEFINE([HAVE_INOTIFY], 1, [inotify available])], - [AC_MSG_WARN([inotify support disabled])]) - AC_ARG_WITH(udev-prefix, AS_HELP_STRING([--with-udev-prefix=DIR], [add prefix to internal udev path names]), [], [with_udev_prefix='${exec_prefix}'])
udev/Makefile.am +0 -1
@@ -14,7 +14,6 @@ common_ldadd = common_files = \ udev.h \ - udev-sysdeps.h \ udev-event.c \ udev-watch.c \ udev-node.c \
udev/lib/libudev-monitor.c +59 -15
136 lines not on this page · raw message
udev/lib/libudev-private.h +4 -1
@@ -86,7 +86,10 @@ int udev_device_delete_db(struct udev_device *udev_device);int udev_device_rename_db (struct udev_device *udev_device,const char *devpath);/* libudev-monitor - netlink/unix socket communication */ -int udev_monitor_send_device (struct udev_monitor *udev_monitor,struct udev_device *udev_device); +int udev_monitor_disconnect (struct udev_monitor *udev_monitor); +int udev_monitor_allow_unicast_sender (struct udev_monitor *udev_monitor,struct udev_monitor *sender); +int udev_monitor_send_device (struct udev_monitor *udev_monitor, +struct udev_monitor *destination,struct udev_device *udev_device);int udev_monitor_set_receive_buffer_size (struct udev_monitor *udev_monitor,int size);/* libudev-ctrl - daemon runtime setup */
udev/udev-event.c +1 -6
@@ -734,18 +734,13 @@ int udev_event_execute_run(struct udev_event *event) monitor =udev_monitor_new_from_socket (event->udev, &cmd[strlen ("socket:" )]);if (monitor ==NULL )continue ; -udev_monitor_send_device (monitor, event->dev); +udev_monitor_send_device (monitor,NULL , event->dev);udev_monitor_unref (monitor); }else {char program[UTIL_PATH_SIZE ];char **envp;udev_event_apply_format (event, cmd, program,sizeof (program)); -if (event->trace) -fprintf (stderr,"run %s (%llu) '%s'\n" , -udev_device_get_syspath (event->dev), -udev_device_get_seqnum (event->dev), - program); envp =udev_device_get_properties_envp (event->dev);if (util_run_program (event->udev, program, envp,NULL ,0 ,NULL ) !=0 ) {if (!udev_list_entry_get_flag (list_entry))
udev/udev-sysdeps.h deleted +0 -44
44 lines not on this page · raw message
udev/udev-watch.c +3 -6
@@ -26,27 +26,24 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#ifdef HAVE_INOTIFY #include <sys/inotify.h> -#endif #include "udev.h" -int inotify_fd =-1 ; +static int inotify_fd =-1 ;/* inotify descriptor, will be shared with rules directory; * set to cloexec since we need our children to be able to add * watches for us */ -void udev_watch_init (struct udev *udev) +int udev_watch_init (struct udev *udev) { inotify_fd =inotify_init ();if (inotify_fd >=0 )util_set_fd_cloexec (inotify_fd); -else if (errno ==ENOSYS ) -info (udev,"unable to use inotify, udevd will not monitor rule files changes\n" );else err (udev,"inotify_init failed: %m\n" ); +return inotify_fd; }/* move any old watches directory out of the way, and then restore
udev/udev.h +1 -9
@@ -22,7 +22,6 @@#include <sys/types.h> #include <sys/param.h> -#include "udev-sysdeps.h" #include "lib/libudev.h" #include "lib/libudev-private.h"
@@ -53,7 +52,6 @@ static inline void logging_close(void) }struct udev_event { -struct udev_list_node node;struct udev *udev;struct udev_device *dev;struct udev_device *dev_parent;
@@ -64,10 +62,6 @@ struct udev_event {uid_t uid;gid_t gid;struct udev_list_node run_list; -pid_t pid; -int exitstatus; -time_t queue_time; -unsigned long long int delaying_seqnum; unsigned int group_final:1; unsigned int owner_final:1; unsigned int mode_final:1;
@@ -76,7 +70,6 @@ struct udev_event { unsigned int run_final:1; unsigned int ignore_device:1; unsigned int inotify_watch:1; - unsigned int trace:1; };struct udev_watch {
@@ -101,8 +94,7 @@ int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string, char *result, size_t maxsize, int read_value);/* udev-watch.c */ -extern int inotify_fd; -void udev_watch_init (struct udev *udev); +int udev_watch_init (struct udev *udev);void udev_watch_restore (struct udev *udev);void udev_watch_begin (struct udev *udev,struct udev_device *dev);void udev_watch_end (struct udev *udev,struct udev_device *dev);
udev/udevadm.xml +3 -3
@@ -285,9 +285,9 @@ <term><option>--reload-rules</option></term> <listitem> <para>Signal udevd to reload the rules files. - Usually the udev daemon detects changes automatically, this may - only be needed on systems without inotify support. Reloading rules - does not apply any changes to already existing devices.</para> + The udev daemon detects changes automatically, this option is + usually not needed. Reloading rules does not apply any changes + to already existing devices.</para> </listitem> </varlistentry> <varlistentry>
udev/udevd.c +485 -335
1,124 lines not on this page · raw message
Quoted 13 lines · Kay Sievers
Quoted 5 lines · Kay Sievers
Version 5. I guess we should go for the signalfd stuff, it looks prett nice. The socketpair instead of the rtsignal is also nice, it allows us to pass back arbitrary data from finished events to the main daemon.
Version 7. We need to handle the netlink unicast addresses, they are not neccessarily the process pid, so we need to remember the netlink address.
Quoted 6 lines
We also keep 2 workers around, and don't kill them, to handle incoming events without forking.
Thanks,
Kay
Ok.
I think the patch breaks the settle control message. It now sends the signal back to udevadm immediately, instead of postponing it until after handle_inotify(), which was apparently the point.
"
Now udevadm settle will send a control message to udevd, which will respond by sending SIGUSR1 back to the waiting udevadm settle once it has completed the main loop iteration in which it received the control message.
If there were no pending inotify events, this will simply wake up the udev daemon and allow settle to continue. *If there are pending inotify events, they are handled first in the main loop* so when settle is continued they will have been turned into uevents and the kernel sequence number will have been incremented.
"
Perhaps it would be simplest to reorder the main loop so that handle_ctrl() comes after handle_inotify(). If I'm right, it could benefit from a comment pointing out that this order is significant and should be preserved.
That said, I don't completely understand the settle control message. I don't get why udevadm-settle only sends it once at the start, instead of incorporating it as part of the delay loop.
Thanks
Alan
Quoted 7 lines · Alan Jenkins
I think the patch breaks the settle control message. It now sends the signal back to udevadm immediately, instead of postponing it until after
handle_inotify(), which was apparently the point.Perhaps it would be simplest to reorder the main loop so that
handle_ctrl()comes afterhandle_inotify(). If I'm right, it could benefit from a comment pointing out that this order is significant and should be preserved.
Yeah, that sounds good. Thanks!
Quoted 3 lines
That said, I don't completely understand the settle control message. I don't get why udevadm-settle only sends it once at the start, instead of incorporating it as part of the delay loop.
I think, it's only needed to cover the delayed wakeup of udevd. When no event is pending after close() of a device file, there is nothing we can miss after that point, I think.
Thanks,
Kay
On Thu, Jun 4, 2009 at 00:20, Kay Sievers <[email protected]> wrote:
No more patches. I've commit the current version to the git tree.
I get now:
$ time (udevadm trigger; udevadm settle) real 0m0.558s
I guess the path_id script need to be replaced with somethin better now. :)
$ mv /lib/udev/path_id /lib/udev/path_id.0 $ time (udevadm trigger; udevadm settle) real 0m0.368s
Thanks,
Kay
Quoted 5 lines · Kay Sievers
I guess the
path_idscript need to be replaced with something better now. :)$ mv /lib/udev/path_id /lib/udev/path_id.0 $ time (udevadm trigger; udevadm settle) real 0m0.368s
We got a C version of path_id now:
$ time (udevadm trigger; udevadm settle) real 0m0.378s
Fibre Channel, iSCSI, SAS, S390, IDE support needs to be ported to it. If one of these is found for a block device, the old shell script is called instead of the C version. If anybody uses any of these subsystems, would be great to get patches. :)
Thanks,
Kay
Quoted 3 lines · Kay Sievers
Version 7.
+Also inotify support is required now to run udev.
Hmm. Unsure if this was the intention or not, but this breaks compiling against "old" glibc versions (the change to unconditionally include <sys/signalfd.h> doesn't help either).
I have two machines; both run fairly old glibcs, but very recent kernels (2.6.28.x and 2.6.29.x). I have no <sys/signalfd.h> on one, and neither that nor <sys/inotify.h> on the other. (I compiled these systems' glibcs in about 2006 and 2003. Upgrading the kernel is easy; upgrading glibc to something that will have support for signalfd would entail recompiling the entire machine, in both cases.)
Below is a patch to emulate <sys/signalfd.h> and <sys/inotify.h> if those headers don't exist at configure time (via inline functions that use syscall() directly). It has to pull __NR_xxx (for the various xxx syscalls) from the kernel includes, which are per-arch, so there are a few new configure.ac tests to find the appropriate arch. This takes a while, but isn't run if both <sys/signalfd.h> and <sys/inotify.h> are present.
Lots of this is copied from glibc-2.10.1, some from the kernel.
----
Don't require glibc to support signalfd and inotify: provide syscall wrappers if needed.
configure.ac | 18 ++++++++ udev/Makefile.am | 1 + udev/udev-sysdeps.h | 107 ++++++++++++++++++++++++++++++++++++++++++++++ udev/udev-watch.c | 2 +- udev/udevd.c | 3 +- 5 files changed, 128 insertions(+), 3 deletions(-)
configure.ac +17 -0
@@ -24,6 +24,24 @@ AC_SUBST(LIBUDEV_LT_AGE) AC_PATH_PROG([XSLTPROC], [xsltproc]) +AC_CHECK_HEADER([sys/signalfd.h]) +AC_CHECK_HEADER([sys/inotify.h]) + +if test x"$ac_cv_header_sys_signalfd_h" = xno || \ + test x"$ac_cv_header_sys_inotify_h" = xno ; then + AC_MSG_CHECKING([kernel architecture string]) + KERN_BASE=/lib/modules/`uname -r`/source + KERN_ARCH=`make -C $KERN_BASE -n -p | \ + sed -n -e '/^hdr-arch/ { s/.*:= // p }'` + KERN_UNISTD=$KERN_BASE/arch/$KERN_ARCH/include/asm/unistd.h + AC_MSG_RESULT([$KERN_ARCH]) +else + KERN_UNISTD+fi + +AC_DEFINE_UNQUOTED([KERN_UNISTD], ["$KERN_UNISTD"], + [Path to kernel unistd.h]) + AC_ARG_WITH(udev-prefix, AS_HELP_STRING([--with-udev-prefix=DIR], [add prefix to internal udev
path names]),
[], [with_udev_prefix='${exec_prefix}'])
udev/Makefile.am +1 -0
@@ -14,6 +14,7 @@ common_ldadd common_files = \ udev.h \ + udev-sysdeps.h \ udev-event.c \ udev-watch.c \ udev-node.c \
udev/udev-sysdeps.h new file +107 -0
107 lines not on this page · raw message
udev/udev-watch.c +1 -1
@@ -26,8 +26,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include <sys/inotify.h> +#include "udev-sysdeps.h" #include "udev.h" static int inotify_fd =-1 ;
udev/udevd.c +1 -2
@@ -32,14 +32,13 @@#include <dirent.h> #include <sys/prctl.h> #include <sys/socket.h> -#include <sys/signalfd.h> #include <sys/select.h> #include <sys/poll.h> #include <sys/wait.h> #include <sys/stat.h> #include <sys/ioctl.h> -#include <sys/inotify.h> +#include "udev-sysdeps.h" #include "udev.h" #define UDEVD_PRIORITY -4
Quoted 8 lines · Bryan Kadzban
Below is a patch to emulate <
sys/signalfd.h> and <sys/inotify.h> if those headers don't exist at configure time (via inline functions that usesyscall()directly). It has to pull__NR_xxx(for the various xxx syscalls) from the kernel includes, which are per-arch, so there are a few new configure.ac tests to find the appropriate arch. This takes a while, but isn't run if both <sys/signalfd.h> and <sys/inotify.h> are present.
For upstart, I made a deliberate decision not to do this anymore; if you want to use an up-to-date set of plumbing tools, you should at least update your glibc ;) (my opinion, at least)
Scott
Signature · 2 lines
Scott James Remnant [email protected]
Quoted 10 lines · Scott James Remnant
Quoted 7 lines · Bryan Kadzban
Below is a patch to emulate <
sys/signalfd.h> and <sys/inotify.h> if those headers don't exist at configure time (via inline functions that usesyscall()directly). It has to pull__NR_xxx(for the various xxx syscalls) from the kernel includes, which are per-arch, so there are a few new configure.ac tests to find the appropriate arch. This takes a while, but isn't run if both <sys/signalfd.h> and <sys/inotify.h> are present.
Quoted 3 lines
For upstart, I made a deliberate decision not to do this anymore; if you want to use an up-to-date set of plumbing tools, you should at least update your glibc ;) (my opinion, at least)
There are two issues with this that I can think of. First is that the only glibc versions that support signalfd are not that old; the older they were, the less I'd complain. :-)
Second is that I'm fairly sure upgrading glibc requires a recompile of basically the entire rest of the system. For the same reason that you can't dump a new kernel's headers in /usr/include/linux at will: in that case the (new) structure sizes won't match what the (old) syscall wrappers in glibc are sending to the kernel when invoking the (old) syscalls when new programs are compiled. In this case, the new glibc will be calling the new syscalls using the new kernel headers, and new structures; this works great for newly-compiled programs. But every existing binary on the system was built against the older structures, so the syscall wrapper will call the wrong thing for them.
When glibc's foo(2) wrapper calls syscall(__NR_foo, foo), which expects a pointer to "struct foo", but the new glibc's foo(2) wrapper calls into syscall(__NR_foo2, foo2) instead, which expects a pointer to "struct foo2" which has more members, current programs all break.
(Though I know glibc does weird stuff with symbol versioning: if that also means they keep the "old" foo(2) wrapper around when a newer glibc is compiled, then this argument is mostly wrong. But I don't believe they do this; I don't see multiple mount(2) wrappers, for instance.)
And I'd rather not spend a week rebuilding everything when I can spend a couple hours writing this patch...