[PATCH[ udevd race conditions and performance, assorted cleanups
This patch covers a number of areas:
1) sysfs.h is fixed up to use the common dbg() macro. This fixes the case where DEBUG is defined but USE_LOG isn't.
2) udevstart.c is modified to include the proper headers, rather than getting them indirectly which can break depending on Makefile flags
3) udevd.c gets some major changes:
a) I added a pipe from the signal handler. This fixes the race conditions that I mentioned earlier. Basically, the point of the pipe is to force the select() call to return immediately if a signal handler fired before we actually started the select() call. This then lets us run the appropriate code based on flags set in the signal handler proper.
b) I added a number of flags to coalesce calls to common routines. This should make things slightly more efficient.
c) since most calls will tend to come in with a sequence number larger than what has been received, I switched msg_queue_insert() to scan the msg_list backwards to improve performance.
Comments?
Chris
libsysfs/sysfs.h +1 -3
@@ -37,9 +37,7 @@#ifdef DEBUG #include "../logging.h" #define dprintf(format, arg...) \ - do { \ - log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \ - } while (0) + dbg(format, ##arg)#else #define dprintf(format, arg...) do { } while (0)#endif
udevd.c +136 -29
289 lines not on this page · raw message
udevstart.c +2 -0
@@ -29,6 +29,8 @@#include <ctype.h> #include <dirent.h> #include <sys/wait.h> +#include <sys/types.h> +#include <unistd.h> #include "logging.h"
Quoted 9 lines · Chris Friesen
This patch covers a number of areas:
1)
sysfs.his fixed up to use the commondbg()macro. This fixes the case where DEBUG is defined butUSE_LOGisn't.2)
udevstart.cis modified to include the proper headers, rather than getting them indirectly which can break depending onMakefileflags
Quoted 11 lines
3)
udevd.cgets some major changes:
a) I added a pipe from the signal handler. This fixes the race conditions that I mentioned earlier. Basically, the point of the pipe is to force theselect()call to return immediately if a signal handler fired before we actually started theselect()call. This then lets us run the appropriate code based on flags set in the signal handler proper.
b) I added a number of flags to coalesce calls to common routines. This should make things slightly more efficient.
c) since most calls will tend to come in with a sequence number larger than what has been received, I switchedmsg_queue_insert()to scan themsg_listbackwards to improve performance.
Looks really nice, seems a bit faster too.
Whitespace is broken, no tabs?
udevd.c line 463
Quoted 12 lines
udevd.c +6
-5while (1 ) { -handle_msg (ssock); - -while (msg_q_timeout) { - msg_q_timeout =0 ; -msg_queue_manager (); +fd_set workreadfds = readfds; + retval =select (maxsockplus, &workreadfds,NULL ,NULL ,NULL ); + +if (retval <0 ) { +dbg ("error in select: %s" ,strerror (errno)); +continue ;
We interrupt select() intentionally, so better do not call it "error" in syslog :)
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Chris Friesen
This patch covers a number of areas:
1)
sysfs.his fixed up to use the commondbg()macro. This fixes the case where DEBUG is defined butUSE_LOGisn't.2)
udevstart.cis modified to include the proper headers, rather than getting them indirectly which can break depending onMakefileflags
Quoted 11 lines
3)
udevd.cgets some major changes:
a) I added a pipe from the signal handler. This fixes the race conditions that I mentioned earlier. Basically, the point of the pipe is to force theselect()call to return immediately if a signal handler fired before we actually started theselect()call. This then lets us run the appropriate code based on flags set in the signal handler proper.
b) I added a number of flags to coalesce calls to common routines. This should make things slightly more efficient.
c) since most calls will tend to come in with a sequence number larger than what has been received, I switchedmsg_queue_insert()to scan themsg_listbackwards to improve performance.
Chris,
here is a patch on top of your nice improvements.
I fixed the whitespace and it hopefully fixes the stupid timestamp bug in udevd. Some stupid OS sets the hwclock to localtime and linux changes it to UTC while starting. If any events are pending they may be delayed by the users time distance from UTC :) So we use the uptime seconds now.
thanks,
Kay
===== Makefile 1.148 vs edited =====
Makefile +3 -2
@@ -220,6 +220,7 @@ ifeq ($(strip $(USE_KLIBC)),true) OBJS += klibc_fixups.o + KLIBC_FIXUP = klibc_fixups.o endif # header files automatically generated
@@ -266,8 +267,8 @@ $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(STRIPCMD) $@ -$(DAEMON): $(DAEMON).o udevd.h $(LIBC) - $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS) +$(DAEMON): $(DAEMON).o $(OBJS) udevd.h $(LIBC) + $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(STRIPCMD) $@ $(SENDER): $(SENDER).o udevd.h $(LIBC)
===== klibc_fixups.c 1.8 vs edited =====
klibc_fixups.c +2 -0
@@ -30,12 +30,14 @@#include "udev.h" #include "klibc_fixups.h" +#include "udev_lib.h" #include "logging.h" #define PW_FILE "/etc/passwd"#define GR_FILE "/etc/group"#define UTMP_FILE "/var/run/utmp" +_syscall1(int, sysinfo, struct sysinfo *, info);/* return the id of a passwd style line, selected by the users name */ static unsigned long get_id_by_name (const char *uname,const char *dbfile)
===== klibc_fixups.h 1.6 vs edited =====
klibc_fixups.h +5 -0
@@ -3,6 +3,11 @@ #ifndef KLIBC_FIXUPS_H #define KLIBC_FIXUPS_H +#include <linux/kernel.h> +#include <linux/unistd.h> + +int sysinfo(struct sysinfo *info); + struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* user password */
===== udevd.c 1.26 vs edited =====
udevd.c +47 -40
169 lines not on this page · raw message
===== udevd.h 1.8 vs edited =====
udevd.h +1 -1
@@ -34,7 +34,7 @@struct list_head list;pid_t pid;int seqnum; -time_t queue_time; +long queue_time;char action[ACTION_SIZE ];char devpath[DEVPATH_SIZE ];char subsystem[SUBSYSTEM_SIZE ];
===== udevsend.c 1.28 vs edited =====
udevsend.c +8 -9
@@ -26,13 +26,13 @@#include <sys/socket.h> #include <sys/wait.h> #include <sys/un.h> +#include <time.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> #include <unistd.h> -#include <time.h> #include <linux/stddef.h> #include "udev.h"
@@ -53,16 +53,15 @@ }#endif -static int build_hotplugmsg (struct hotplug_msg *msg,char *action, -char *devpath,char *subsystem,int seqnum) +static void build_hotplugmsg (struct hotplug_msg *msg,char *action, +char *devpath,char *subsystem,int seqnum) { -memset (msg,0x00 ,sizeof (*msg)); +memset (msg,0x00 ,sizeof (struct hotplug_msg ));strfieldcpy (msg->magic,UDEV_MAGIC ); msg->seqnum = seqnum;strfieldcpy (msg->action, action);strfieldcpy (msg->devpath, devpath);strfieldcpy (msg->subsystem, subsystem); -return sizeof (struct hotplug_msg ); }static int start_daemon (void )
@@ -108,7 +107,6 @@char *seqnum;int seq;int retval =1 ; -int size;int loop;struct timespec tspec;int sock;
@@ -155,18 +153,19 @@ goto exit; } -memset (&saddr,0x00 ,sizeof (saddr)); +memset (&saddr,0x00 ,sizeof (struct sockaddr_un )); saddr.sun_family =AF_LOCAL ;/* use abstract namespace for socket path */ strcpy (&saddr.sun_path[1 ],UDEVD_SOCK_PATH ); addrlen = offsetof(struct sockaddr_un , sun_path) +strlen (saddr.sun_path+1 ) +1 ; - size =build_hotplugmsg (&msg, action, devpath, subsystem, seq); +build_hotplugmsg (&msg, action, devpath, subsystem, seq);/* If we can't send, try to start daemon and resend message */ loop =UDEVSEND_CONNECT_RETRY ;while (loop--) { - retval =sendto (sock, &msg, size,0 , (struct sockaddr *)&saddr, addrlen); + retval =sendto (sock, &msg,sizeof (struct hotplug_msg ),0 , + (struct sockaddr *)&saddr, addrlen);if (retval !=-1 ) { retval =0 ; goto close_and_exit;
===== libsysfs/sysfs.h 1.8 vs edited =====
libsysfs/sysfs.h +1 -2
@@ -36,8 +36,7 @@/* Debugging */ #ifdef DEBUG #include "../logging.h" -#define dprintf(format, arg...) \ - dbg(format, ##arg) +#define dprintf(format, arg...) dbg(format, ##arg)#else #define dprintf(format, arg...) do { } while (0)#endif
Quoted 6 lines · Kay Sievers
Chris,
here is a patch on top of your nice improvements.
I fixed the whitespace and it hopefully fixes the stupid timestamp bug in udevd. Some stupid OS sets the hwclock to localtime and linux changes it to UTC while starting. If any events are pending they may be delayed by the users time distance from UTC :) So we use the uptime seconds now.
Looks good. Sorry about the whitespace stuff...I forgot to change my settings back after working on another project.
About the time stuff. Wouldn't it be nice if glibc had a wrapper around the various ways to get a high resolution monotonically increasing 64-bit timestamp of "time since boot"? So for x86 you'd end up using
the tsc, for ppc you'd use the tbr, etc, etc. Currently we've got no
portable way to get a high res time that can't go backwards.
Chris
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 21 lines · Chris Friesen
This patch covers a number of areas:
1)
sysfs.his fixed up to use the commondbg()macro. This fixes the case where DEBUG is defined butUSE_LOGisn't.2)
udevstart.cis modified to include the proper headers, rather than getting them indirectly which can break depending onMakefileflags3)
udevd.cgets some major changes:
a) I added a pipe from the signal handler. This fixes the race conditions that I mentioned earlier. Basically, the point of the pipe is to force theselect()call to return immediately if a signal handler fired before we actually started theselect()call. This then lets us run the appropriate code based on flags set in the signal handler proper.
b) I added a number of flags to coalesce calls to common routines. This should make things slightly more efficient.
c) since most calls will tend to come in with a sequence number larger than what has been received, I switchedmsg_queue_insert()to scan themsg_listbackwards to improve performance.
Quoted 1 line
Comments?
Thanks for doing this, applied.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Kay Sievers
here is a patch on top of your nice improvements.
I fixed the whitespace and it hopefully fixes the stupid timestamp bug in udevd. Some stupid OS sets the hwclock to localtime and linux changes it to UTC while starting. If any events are pending they may be delayed by the users time distance from UTC :) So we use the uptime seconds now.
Nice fix, applied.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel