I''m packaging fontconfig 2.9.0 for debian today and found a couple of ancient patches in my local tree. The first patch, [PATCH 1/2] Use posix_fadvise to speed startup, should improve startup time for the first application using fontconfig by asking the kernel to queue reads of the entire font cache. The second patch, [PATCH 2/2] Use const more often, just sticks ''const'' declarations in a few more places within the implementation. These have been rebased on top of 2.9.0. -keith
Keith Packard
2012-Apr-16 18:28 UTC
[Fontconfig] [PATCH 1/2] Use posix_fadvise to speed startup
Given that fontconfig will scan all of the cache file data during the first font search, ask the kernel to start reading the pages right away. Signed-off-by: Keith Packard <keithp at keithp.com> --- configure.in | 2 +- src/fccache.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index da6ef95..a5e9e33 100644 --- a/configure.in +++ b/configure.in @@ -119,7 +119,7 @@ AC_TYPE_PID_T # Checks for library functions. AC_FUNC_VPRINTF AC_FUNC_MMAP -AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r]) +AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r posix_fadvise]) # # Checks for iconv diff --git a/src/fccache.c b/src/fccache.c index d8102d7..a72dbb6 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -612,6 +612,9 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat) { #if defined(HAVE_MMAP) || defined(__CYGWIN__) cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0); +#ifdef HAVE_POSIX_FADVISE + posix_fadvise(fd, 0, fd_stat->st_size, POSIX_FADV_WILLNEED); +#endif if (cache == MAP_FAILED) cache = NULL; #elif defined(_WIN32) -- 1.7.10
This eliminates several warnings about improper const usage as well as making it more prevalent in the implementation. Signed-off-by: Keith Packard <keithp at keithp.com> --- fc-lang/fc-lang.c | 6 +++--- src/fccache.c | 2 +- src/fccfg.c | 8 ++++---- src/fcint.h | 20 ++++++++++---------- src/fcxml.c | 14 +++++++------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c index 51717f9..d29dc10 100644 --- a/fc-lang/fc-lang.c +++ b/fc-lang/fc-lang.c @@ -136,7 +136,7 @@ static FcCharSet * scan (FILE *f, char *file, FcCharSetFreezer *freezer) { FcCharSet *c = 0; - FcCharSet *n; + const FcCharSet *n; FcBool del; int start, end, ucs4; char buf[1024]; @@ -164,7 +164,7 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer) c = FcCharSetCreate (); if (!FcCharSetMerge (c, n, NULL)) fatal (file, lineno, "out of memory"); - FcCharSetDestroy (n); + FcCharSetDestroy ((FcCharSet *) n); continue; } del = FcFalse; @@ -246,7 +246,7 @@ typedef struct _Entry { static int compare (const void *a, const void *b) { - const Entry *as = a, *bs = b; + const Entry const *as = a, *bs = b; return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *) bs->file); } diff --git a/src/fccache.c b/src/fccache.c index a72dbb6..5ed7edf 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -1000,7 +1000,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config) */ if (cache->size < FC_CACHE_MIN_MMAP && (skip = FcCacheFindByAddr (cache)) && - FcStat (cache_hashed, &cache_stat)) + FcStat ((const char *) cache_hashed, &cache_stat)) { skip->cache_dev = cache_stat.st_dev; skip->cache_ino = cache_stat.st_ino; diff --git a/src/fccfg.c b/src/fccfg.c index 9395f74..dcc0097 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -866,7 +866,7 @@ FcConfigCompareValue (const FcValue *left_o, #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d))) static FcValue -FcConfigEvaluate (FcPattern *p, FcExpr *e) +FcConfigEvaluate (FcPattern *p, const FcExpr *e) { FcValue v, vl, vr; FcResult r; @@ -913,7 +913,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) v = FcValueSave (v); break; case FcOpConst: - if (FcNameConstant (e->u.constant, &v.u.i)) + if (FcNameConstant ((FcChar8 *) e->u.constant, &v.u.i)) v.type = FcTypeInteger; else v.type = FcTypeVoid; @@ -1179,7 +1179,7 @@ FcConfigMatchValueList (FcPattern *p, FcValueList *values) { FcValueList *ret = 0; - FcExpr *e = t->expr; + const FcExpr *e = t->expr; FcValue value; FcValueList *v; @@ -1220,7 +1220,7 @@ FcConfigMatchValueList (FcPattern *p, } static FcValueList * -FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding) +FcConfigValues (FcPattern *p, const FcExpr *e, FcValueBinding binding) { FcValueList *l; diff --git a/src/fcint.h b/src/fcint.h index 8179195..fd327de 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -237,17 +237,17 @@ typedef enum _FcOp { typedef struct _FcExpr { FcOp op; union { - int ival; - double dval; - const FcChar8 *sval; - FcMatrix *mval; - FcBool bval; - FcCharSet *cval; - FcLangSet *lval; - FcObject object; - const FcChar8 *constant; + int ival; + double dval; + const FcChar8 *sval; + const FcMatrix *mval; + FcBool bval; + const FcCharSet *cval; + FcLangSet *lval; + FcObject object; + const FcChar8 *constant; struct { - struct _FcExpr *left, *right; + const struct _FcExpr *left, *right; } tree; } u; } FcExpr; diff --git a/src/fcxml.c b/src/fcxml.c index ff30b7b..794210b 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -61,7 +61,7 @@ #endif static void -FcExprDestroy (FcExpr *e); +FcExprDestroy (const FcExpr *e); void FcTestDestroy (FcTest *test) @@ -195,7 +195,7 @@ FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op, FcExpr *right) } static void -FcExprDestroy (FcExpr *e) +FcExprDestroy (const FcExpr *e) { if (!e) return; @@ -207,12 +207,12 @@ FcExprDestroy (FcExpr *e) case FcOpString: break; case FcOpMatrix: - FcMatrixFree (e->u.mval); + FcMatrixFree ((FcMatrix *) e->u.mval); break; case FcOpRange: break; case FcOpCharSet: - FcCharSetDestroy (e->u.cval); + FcCharSetDestroy ((FcCharSet *) e->u.cval); break; case FcOpLangSet: FcLangSetDestroy (e->u.lval); @@ -261,7 +261,7 @@ FcExprDestroy (FcExpr *e) break; } - e->op = FcOpNil; + ((FcExpr *) e)->op = FcOpNil; } void @@ -564,7 +564,7 @@ FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type) } static void -FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type) +FcTypecheckExpr (FcConfigParse *parse, const FcExpr *expr, FcType type) { const FcObjectType *o; const FcConstant *c; @@ -601,7 +601,7 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type) FcTypecheckValue (parse, o->type, type); break; case FcOpConst: - c = FcNameGetConstant (expr->u.constant); + c = FcNameGetConstant ((FcChar8 *) expr->u.constant); if (c) { o = FcNameGetObjectType (c->object); -- 1.7.10
Akira TAGOH
2012-Apr-17 01:40 UTC
[Fontconfig] [PATCH 1/2] Use posix_fadvise to speed startup
Thanks for the patch. I just wonder if it''s needed prior to read() too, particularly with POSIX_FADV_NOREUSE? What do you think? On Tue, Apr 17, 2012 at 3:28 AM, Keith Packard <keithp at keithp.com> wrote:> Given that fontconfig will scan all of the cache file data during the > first font search, ask the kernel to start reading the pages right away. > > Signed-off-by: Keith Packard <keithp at keithp.com> > --- > ?configure.in ?| ? ?2 +- > ?src/fccache.c | ? ?3 +++ > ?2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/configure.in b/configure.in > index da6ef95..a5e9e33 100644 > --- a/configure.in > +++ b/configure.in > @@ -119,7 +119,7 @@ AC_TYPE_PID_T > ?# Checks for library functions. > ?AC_FUNC_VPRINTF > ?AC_FUNC_MMAP > -AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r]) > +AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long sysconf ftruncate chsize rand random lrand48 random_r rand_r posix_fadvise]) > > ?# > ?# Checks for iconv > diff --git a/src/fccache.c b/src/fccache.c > index d8102d7..a72dbb6 100644 > --- a/src/fccache.c > +++ b/src/fccache.c > @@ -612,6 +612,9 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat) > ? ? { > ?#if defined(HAVE_MMAP) || defined(__CYGWIN__) > ? ? ? ?cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0); > +#ifdef HAVE_POSIX_FADVISE > + ? ? ? posix_fadvise(fd, 0, fd_stat->st_size, POSIX_FADV_WILLNEED); > +#endif > ? ? ? ?if (cache == MAP_FAILED) > ? ? ? ? ? ?cache = NULL; > ?#elif defined(_WIN32) > -- > 1.7.10 > > _______________________________________________ > Fontconfig mailing list > Fontconfig at lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/fontconfig-- Akira TAGOH
On Tue, Apr 17, 2012 at 3:28 AM, Keith Packard <keithp at keithp.com> wrote:> diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c > index 51717f9..d29dc10 100644 > --- a/fc-lang/fc-lang.c > +++ b/fc-lang/fc-lang.c > @@ -136,7 +136,7 @@ static FcCharSet * > ?scan (FILE *f, char *file, FcCharSetFreezer *freezer) > ?{ > ? ? FcCharSet ? ? ?*c = 0; > - ? ?FcCharSet ? ? ?*n; > + ? ?const FcCharSet *n; > ? ? FcBool ? ? ? ? del; > ? ? int ? ? ? ? ? ? ? ? ? ?start, end, ucs4; > ? ? char ? ? ? ? ? buf[1024]; > @@ -164,7 +164,7 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer) > ? ? ? ? ? ? ? ?c = FcCharSetCreate (); > ? ? ? ? ? ?if (!FcCharSetMerge (c, n, NULL)) > ? ? ? ? ? ? ? ?fatal (file, lineno, "out of memory"); > - ? ? ? ? ? FcCharSetDestroy (n); > + ? ? ? ? ? FcCharSetDestroy ((FcCharSet *) n); > ? ? ? ? ? ?continue; > ? ? ? ?} > ? ? ? ?del = FcFalse;Ah, this is tricky.. I guess that may be better add a comment "n" is FC_REF_CONSTANT? also we should add "const" to the return value of FcCharSetFreezeBase() too.> diff --git a/src/fccache.c b/src/fccache.c > index a72dbb6..5ed7edf 100644 > --- a/src/fccache.c > +++ b/src/fccache.c > @@ -1000,7 +1000,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config) > ? ? ?*/ > ? ? if (cache->size < FC_CACHE_MIN_MMAP && > ? ? ? ?(skip = FcCacheFindByAddr (cache)) && > - ? ? ? FcStat (cache_hashed, &cache_stat)) > + ? ? ? FcStat ((const char *) cache_hashed, &cache_stat))We don''t need this one anymore. FcStat() takes const FcChar8 * now by 647569d0.> @@ -913,7 +913,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) > ? ? ? ?v = FcValueSave (v); > ? ? ? ?break; > ? ? case FcOpConst: > - ? ? ? if (FcNameConstant (e->u.constant, &v.u.i)) > + ? ? ? if (FcNameConstant ((FcChar8 *) e->u.constant, &v.u.i)) > ? ? ? ? ? ?v.type = FcTypeInteger; > ? ? ? ?else > ? ? ? ? ? ?v.type = FcTypeVoid;This one too by 123d344f> diff --git a/src/fcint.h b/src/fcint.h > index 8179195..fd327de 100644 > --- a/src/fcint.h > +++ b/src/fcint.h > @@ -237,17 +237,17 @@ typedef enum _FcOp { > ?typedef struct _FcExpr { > ? ? FcOp ? op; > ? ? union { > - ? ? ? int ? ? ? ? ival; > - ? ? ? double ? ? ?dval; > - ? ? ? const FcChar8 ? ? ? *sval; > - ? ? ? FcMatrix ? ?*mval; > - ? ? ? FcBool ? ? ?bval; > - ? ? ? FcCharSet ? *cval; > - ? ? ? FcLangSet ? *lval; > - ? ? ? FcObject ? ?object; > - ? ? ? const FcChar8 ? ? ? *constant; > + ? ? ? int ? ? ? ? ? ? ival; > + ? ? ? double ? ? ? ? ?dval; > + ? ? ? const FcChar8 ? *sval; > + ? ? ? const FcMatrix ?*mval; > + ? ? ? FcBool ? ? ? ? ?bval; > + ? ? ? const FcCharSet *cval; > + ? ? ? FcLangSet ? ? ? *lval; > + ? ? ? FcObject ? ? ? ?object; > + ? ? ? const FcChar8 ? *constant; > ? ? ? ?struct { > - ? ? ? ? ? struct _FcExpr *left, *right; > + ? ? ? ? ? const struct _FcExpr *left, *right; > ? ? ? ?} tree; > ? ? } u; > ?} FcExpr;I''m not sure what this change tries to address. FcMatrix is created by FcExprCreateMatrix() only here and it''s surely allocated by malloc() in FcMatrixCopy(). also FcCharSet is came from FcParseCharSet() and FcCharSetCreate(). I don''t see any reason why you add a const there.> @@ -261,7 +261,7 @@ FcExprDestroy (FcExpr *e) > ? ? ? ?break; > ? ? } > > - ? ?e->op = FcOpNil; > + ? ?((FcExpr *) e)->op = FcOpNil; > ?} > > ?voidjust wonder what we get better with this dirty hack... ? -- Akira TAGOH
Mike Frysinger
2012-Apr-17 03:01 UTC
[Fontconfig] [PATCH 1/2] Use posix_fadvise to speed startup
On Monday 16 April 2012 21:40:00 Akira TAGOH wrote:> Thanks for the patch. I just wonder if it''s needed prior to read() > too, particularly with POSIX_FADV_NOREUSE? > > What do you think?i don''t think it''s needed with the read(). the kernel will process all of the request at the point of the syscall. -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20120416/36bd7ba1/attachment-0001.pgp>
Akira TAGOH
2012-Apr-17 03:22 UTC
[Fontconfig] [PATCH 1/2] Use posix_fadvise to speed startup
Okay, thanks. On Tue, Apr 17, 2012 at 12:01 PM, Mike Frysinger <vapier at gentoo.org> wrote:> On Monday 16 April 2012 21:40:00 Akira TAGOH wrote: >> Thanks for the patch. I just wonder if it''s needed prior to read() >> too, particularly with POSIX_FADV_NOREUSE? >> >> What do you think? > > i don''t think it''s needed with the read(). ?the kernel will process all of the > request at the point of the syscall. > -mike-- Akira TAGOH