From 0fa2c543ec252a30e56257c5e54b6d6167441f61 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 9 Nov 2012 12:04:13 +0100 Subject: [PATCH] added pcre jit support --- core/regexp.c | 15 ++++++++++++++- core/uwsgi.c | 11 +++++++++++ uwsgi.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/regexp.c b/core/regexp.c index dc721066..3930e3c6 100644 --- a/core/regexp.c +++ b/core/regexp.c @@ -1,6 +1,17 @@ #ifdef UWSGI_PCRE #include "uwsgi.h" +extern struct uwsgi_server uwsgi; + +void uwsgi_opt_pcre_jit(char *opt, char *value, void *foobar) { +#if defined(PCRE_STUDY_JIT_COMPILE) && defined(PCRE_CONFIG_JIT) + int has_jit = 0, ret; + ret = pcre_config(PCRE_CONFIG_JIT, &has_jit); + if (ret != 0 || has_jit != 1) return; + uwsgi.pcre_jit = PCRE_STUDY_JIT_COMPILE; +#endif +} + int uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra) { const char *errstr; @@ -12,7 +23,9 @@ int uwsgi_regexp_build(char *re, pcre **pattern, pcre_extra **pattern_extra) { return -1; } - *pattern_extra = (pcre_extra *) pcre_study((const pcre*)*pattern, 0, &errstr); + int opt = uwsgi.pcre_jit; + + *pattern_extra = (pcre_extra *) pcre_study((const pcre*)*pattern, opt, &errstr); if (*pattern_extra == NULL && errstr != NULL) { pcre_free(*pattern); uwsgi_log("pcre (study) error: %s\n", errstr); diff --git a/core/uwsgi.c b/core/uwsgi.c index 9728e842..aa7a13db 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -279,6 +279,9 @@ static struct uwsgi_option uwsgi_base_options[] = { #ifdef MADV_MERGEABLE {"ksm", optional_argument, 0, "enable Linux KSM", uwsgi_opt_set_int, &uwsgi.linux_ksm, 0}, #endif +#endif +#ifdef UWSGI_PCRE + {"pcre-jit", no_argument, 0, "enable pcre jit (if available)", uwsgi_opt_pcre_jit, NULL, UWSGI_OPT_IMMEDIATE}, #endif {"never-swap", no_argument, 0, "lock all memory pages avoiding swapping", uwsgi_opt_true, &uwsgi.never_swap, 0}, {"touch-reload", required_argument, 0, "reload uWSGI if the specified file is modified/touched", uwsgi_opt_add_string_list, &uwsgi.touch_reload, UWSGI_OPT_MASTER}, @@ -1906,6 +1909,14 @@ int main(int argc, char *argv[], char *envp[]) { } uwsgi_log_initial("clock source: %s\n", uwsgi.clock->name); +#ifdef UWSGI_PCRE + if (uwsgi.pcre_jit) { + uwsgi_log_initial("pcre jit enabled\n"); + } + else { + uwsgi_log_initial("pcre jit disabled\n"); + } +#endif #ifdef __BIG_ENDIAN__ uwsgi_log_initial("*** big endian arch detected ***\n"); diff --git a/uwsgi.h b/uwsgi.h index 6ee3262a..491937cf 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1472,6 +1472,7 @@ struct uwsgi_server { struct uwsgi_string_list *requested_logger; #ifdef UWSGI_PCRE + int pcre_jit; struct uwsgi_regexp_list *log_drain_rules; struct uwsgi_regexp_list *log_filter_rules; struct uwsgi_regexp_list *log_route; @@ -2986,6 +2987,7 @@ void uwsgi_opt_set_str_spaced(char *, char *, void *); void uwsgi_opt_add_string_list(char *, char *, void *); void uwsgi_opt_add_dyn_dict(char *, char *, void *); #ifdef UWSGI_PCRE +void uwsgi_opt_pcre_jit(char *, char *, void *); void uwsgi_opt_add_regexp_dyn_dict(char *, char *, void *); void uwsgi_opt_add_regexp_list(char *, char *, void *); void uwsgi_opt_add_regexp_custom_list(char *, char *, void *);