Re: [PATCH] Patch to not fork/exec xkbcomp on X Server initialization
On Fri, Mar 27, 2009 at 11:17:14AM +1000, Peter Hutterer wrote: I think /var/cache instead of /var/lib is the better place to put the files. http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLIBVARIABLESTATEINFORMATION vs. http://www.pathname.com/fhs/pub/fhs-2.3.html#VARCACHEAPPLICATIONCACHEDATA OK, got it. In this patch there are also corrections to wrongly used TAB for indention of codes related to this function. If you don't like it I can move them to another standalone patch. Yes, please always do things like that (if needed at all) in a separate patch. If you correct tab/space issues in the code you're modifying it doesn't matter much, but this patch is quite noisy. OK, removed. I understood the difficulty of merging functions like this into mainstream. Or if we need to add an option to make this behaviour optional, rather than enabled by default. I'd like to follow on this until people is happy with it. It's looking good from a first pass, but I'd really like to see the patches split into one containing just the actual changes. I'm happy to test it then. Thanks. I'm sending the v2 patch soon replying this mail. -- Li, Yan ___ xorg mailing list xorg@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/xorg
Re: [PATCH] Patch to not fork/exec xkbcomp on X Server initialization
On Wed, Mar 25, 2009 at 02:58:36PM +0800, Li, Yan wrote: This is the patch that I wrote for Moblin as part of the efforts of fast-boot to save some load time of X server: xkbcomp outputs will be cached in files with hashed keymap as names (using SHA1). This saves boot time for around 1s on commodity netbooks. It is made against 1.6.0. I haven't read Paulo's latest patch that uses SHA1 as file names until I've finished my own (though I do have read early versions of his patch). Interestingly that we've employed similar idea. Comparing to Paulo's patch, this one is much simpler, with the goal that touch as few things as possible. And xkbcomp's output will be stored in /var/lib/xkb/ instead of somewhere under /usr/. I think /var/cache instead of /var/lib is the better place to put the files. http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLIBVARIABLESTATEINFORMATION vs. http://www.pathname.com/fhs/pub/fhs-2.3.html#VARCACHEAPPLICATIONCACHEDATA In this patch there are also corrections to wrongly used TAB for indention of codes related to this function. If you don't like it I can move them to another standalone patch. Yes, please always do things like that (if needed at all) in a separate patch. If you correct tab/space issues in the code you're modifying it doesn't matter much, but this patch is quite noisy. I understood the difficulty of merging functions like this into mainstream. Or if we need to add an option to make this behaviour optional, rather than enabled by default. I'd like to follow on this until people is happy with it. It's looking good from a first pass, but I'd really like to see the patches split into one containing just the actual changes. I'm happy to test it then. Cheers, Peter From e7046c26d7ac970bfd75cae16262845bef72423b Mon Sep 17 00:00:00 2001 From: Yan Li yan.i...@intel.com Date: Tue, 24 Mar 2009 17:43:12 +0800 Subject: [PATCH] Cache xkbcomp output for fast start-up xkbcomp outputs will be cached in files with hashed keymap as names. This saves boot time for around 1s on commodity netbooks. Signed-off-by: Yan Li yan.i...@intel.com --- xkb/ddxLoad.c | 188 +--- xkb/xkbfmisc.c | 18 +- 2 files changed, 153 insertions(+), 53 deletions(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index 4d5dfb6..799622d 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -32,6 +32,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include xkb-config.h #endif +#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +# include sha1.h +#else /* Use OpenSSL's libcrypto */ +# include stddef.h /* buggy openssl/sha.h wants size_t */ +# include openssl/sha.h +#endif #include stdio.h #include ctype.h #define NEED_EVENTS 1 @@ -159,25 +165,61 @@ OutputDirectory( size_t size) { #ifndef WIN32 -if (getuid() == 0 (strlen(XKM_OUTPUT_DIR) size)) -{ - /* if server running as root it *may* be able to write */ - /* FIXME: check whether directory is writable at all */ - (void) strcpy (outdir, XKM_OUTPUT_DIR); +if (getuid() == 0 (strlen(XKM_OUTPUT_DIR) size)) { +/* if server running as root it *may* be able to write */ +/* FIXME: check whether directory is writable at all */ +(void) strcpy (outdir, XKM_OUTPUT_DIR); } else #else -if (strlen(Win32TempDir()) + 1 size) -{ - (void) strcpy(outdir, Win32TempDir()); - (void) strcat(outdir, \\); +if (strlen(Win32TempDir()) + 1 size) { +(void) strcpy(outdir, Win32TempDir()); +(void) strcat(outdir, \\); } else #endif -if (strlen(/tmp/) size) -{ - (void) strcpy (outdir, /tmp/); +if (strlen(/tmp/) size) { +(void) strcpy (outdir, /tmp/); +} +} + +static Bool +Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input) +{ +int i; +unsigned char sha1[SHA_DIGEST_LENGTH]; + +#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +SHA1_CTX ctx; + +SHA1Init (ctx); +SHA1Update (ctx, input, strlen(input)); +SHA1Final (sha1, ctx); +#else /* Use OpenSSL's libcrypto */ +SHA_CTX ctx; +int success; + +success = SHA1_Init (ctx); +if (! success) + return BadAlloc; + +success = SHA1_Update (ctx, input, strlen(input)); +if (! success) + return BadAlloc; + +success = SHA1_Final (sha1, ctx); +if (! success) + return BadAlloc; +#endif + +/* convert sha1 to sha1_asc */ +for(i=0; iSHA_DIGEST_LENGTH; ++i) { +sprintf(sha1Asc+i*2, %02X, sha1[i]); } + +return Success; } +/* call xkbcomp and compile XKB keymap, return xkm file name in + nameRtrn */ static Bool XkbDDXCompileKeymapByNames( XkbDescPtr xkb, XkbComponentNamesPtrnames, @@ -187,7 +229,9 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
[PATCH] Patch to not fork/exec xkbcomp on X Server initialization
This is the patch that I wrote for Moblin as part of the efforts of fast-boot to save some load time of X server: xkbcomp outputs will be cached in files with hashed keymap as names (using SHA1). This saves boot time for around 1s on commodity netbooks. It is made against 1.6.0. I haven't read Paulo's latest patch that uses SHA1 as file names until I've finished my own (though I do have read early versions of his patch). Interestingly that we've employed similar idea. Comparing to Paulo's patch, this one is much simpler, with the goal that touch as few things as possible. And xkbcomp's output will be stored in /var/lib/xkb/ instead of somewhere under /usr/. In this patch there are also corrections to wrongly used TAB for indention of codes related to this function. If you don't like it I can move them to another standalone patch. I understood the difficulty of merging functions like this into mainstream. Or if we need to add an option to make this behaviour optional, rather than enabled by default. I'd like to follow on this until people is happy with it. Welcome comments. -- Li, Yan From e7046c26d7ac970bfd75cae16262845bef72423b Mon Sep 17 00:00:00 2001 From: Yan Li yan.i...@intel.com Date: Tue, 24 Mar 2009 17:43:12 +0800 Subject: [PATCH] Cache xkbcomp output for fast start-up xkbcomp outputs will be cached in files with hashed keymap as names. This saves boot time for around 1s on commodity netbooks. Signed-off-by: Yan Li yan.i...@intel.com --- xkb/ddxLoad.c | 188 +--- xkb/xkbfmisc.c | 18 +- 2 files changed, 153 insertions(+), 53 deletions(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index 4d5dfb6..799622d 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -32,6 +32,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include xkb-config.h #endif +#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +# include sha1.h +#else /* Use OpenSSL's libcrypto */ +# include stddef.h /* buggy openssl/sha.h wants size_t */ +# include openssl/sha.h +#endif #include stdio.h #include ctype.h #define NEED_EVENTS 1 @@ -159,25 +165,61 @@ OutputDirectory( size_t size) { #ifndef WIN32 -if (getuid() == 0 (strlen(XKM_OUTPUT_DIR) size)) -{ - /* if server running as root it *may* be able to write */ - /* FIXME: check whether directory is writable at all */ - (void) strcpy (outdir, XKM_OUTPUT_DIR); +if (getuid() == 0 (strlen(XKM_OUTPUT_DIR) size)) { +/* if server running as root it *may* be able to write */ +/* FIXME: check whether directory is writable at all */ +(void) strcpy (outdir, XKM_OUTPUT_DIR); } else #else -if (strlen(Win32TempDir()) + 1 size) -{ - (void) strcpy(outdir, Win32TempDir()); - (void) strcat(outdir, \\); +if (strlen(Win32TempDir()) + 1 size) { +(void) strcpy(outdir, Win32TempDir()); +(void) strcat(outdir, \\); } else #endif -if (strlen(/tmp/) size) -{ - (void) strcpy (outdir, /tmp/); +if (strlen(/tmp/) size) { +(void) strcpy (outdir, /tmp/); +} +} + +static Bool +Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input) +{ +int i; +unsigned char sha1[SHA_DIGEST_LENGTH]; + +#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +SHA1_CTX ctx; + +SHA1Init (ctx); +SHA1Update (ctx, input, strlen(input)); +SHA1Final (sha1, ctx); +#else /* Use OpenSSL's libcrypto */ +SHA_CTX ctx; +int success; + +success = SHA1_Init (ctx); +if (! success) + return BadAlloc; + +success = SHA1_Update (ctx, input, strlen(input)); +if (! success) + return BadAlloc; + +success = SHA1_Final (sha1, ctx); +if (! success) + return BadAlloc; +#endif + +/* convert sha1 to sha1_asc */ +for(i=0; iSHA_DIGEST_LENGTH; ++i) { +sprintf(sha1Asc+i*2, %02X, sha1[i]); } + +return Success; } +/* call xkbcomp and compile XKB keymap, return xkm file name in + nameRtrn */ static Bool XkbDDXCompileKeymapByNames( XkbDescPtr xkb, XkbComponentNamesPtr names, @@ -187,7 +229,9 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, int nameRtrnLen) { FILE * out; -char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX]; +char * buf = NULL, xkmfile[PATH_MAX], xkmOutputDir[PATH_MAX]; +char sha1Asc[SHA_DIGEST_LENGTH*2+1], xkbKeyMapBuf[1024]; +int ret; const char *emptystring = ; const char *xkbbasedirflag = emptystring; @@ -198,15 +242,58 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, /* WIN32 has no popen. The input must be stored in a file which is used as input for xkbcomp. xkbcomp does not read from stdin. */ char tmpname[PATH_MAX]; -const char *xkmfile = tmpname; +const char *xkbfile = tmpname; #else -const char *xkmfile = -; +const char *xkbfile = -; #endif +char * canonicalXkmfileName; + +/* Write XKBKeyMap (xkbfile contents) to xkbKeyMapBuf, of which + SHA1 is generated as XKB file