diff -r 78b4e10b4367 auto/unix
|
a
|
b
|
|
| 297 | 297 | fi |
| 298 | 298 | fi |
| 299 | 299 | |
| | 300 | ngx_feature="clock_gettime(CLOCK_MONOTONIC)" |
| | 301 | ngx_feature_name="NGX_HAVE_CLOCK_MONOTONIC" |
| | 302 | ngx_feature_run=no |
| | 303 | ngx_feature_incs="#include <time.h>" |
| | 304 | ngx_feature_path= |
| | 305 | ngx_feature_libs= |
| | 306 | ngx_feature_test="struct timespec monotime; clock_gettime(CLOCK_MONOTONIC, &monotime);" |
| | 307 | . auto/feature |
| | 308 | |
| | 309 | |
| | 310 | if [ $ngx_found != yes ]; then |
| | 311 | |
| | 312 | ngx_feature="clock_gettime(CLOCK_MONOTONIC) in librt" |
| | 313 | ngx_feature_libs="-lrt" |
| | 314 | . auto/feature |
| | 315 | |
| | 316 | if [ $ngx_found = yes ]; then |
| | 317 | CORE_LIBS="$CORE_LIBS -lrt" |
| | 318 | fi |
| | 319 | fi |
| 300 | 320 | |
| 301 | 321 | ngx_feature="SO_SETFIB" |
| 302 | 322 | ngx_feature_name="NGX_HAVE_SETFIB" |
diff -r 78b4e10b4367 contrib/vim/syntax/nginx.vim
|
a
|
b
|
|
| 240 | 240 | syn keyword ngxDirective min_delete_depth |
| 241 | 241 | syn keyword ngxDirective modern_browser |
| 242 | 242 | syn keyword ngxDirective modern_browser_value |
| | 243 | syn keyword ngxDirective monotonic_timers |
| 243 | 244 | syn keyword ngxDirective mp4 |
| 244 | 245 | syn keyword ngxDirective mp4_buffer_size |
| 245 | 246 | syn keyword ngxDirective mp4_max_buffer_size |
diff -r 78b4e10b4367 src/core/nginx.c
|
a
|
b
|
|
| 133 | 133 | 0, |
| 134 | 134 | NULL }, |
| 135 | 135 | |
| | 136 | #if (NGX_HAVE_CLOCK_MONOTONIC) |
| | 137 | { ngx_string("monotonic_timers"), |
| | 138 | NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG, |
| | 139 | ngx_conf_set_flag_slot, |
| | 140 | 0, |
| | 141 | offsetof(ngx_core_conf_t, monotonic_timers), |
| | 142 | NULL }, |
| | 143 | #endif |
| | 144 | |
| 136 | 145 | ngx_null_command |
| 137 | 146 | }; |
| 138 | 147 | |
| … |
… |
|
| 968 | 977 | ccf->daemon = NGX_CONF_UNSET; |
| 969 | 978 | ccf->master = NGX_CONF_UNSET; |
| 970 | 979 | ccf->timer_resolution = NGX_CONF_UNSET_MSEC; |
| | 980 | ccf->monotonic_timers = NGX_CONF_UNSET; |
| 971 | 981 | |
| 972 | 982 | ccf->worker_processes = NGX_CONF_UNSET; |
| 973 | 983 | ccf->debug_points = NGX_CONF_UNSET; |
| … |
… |
|
| 996 | 1006 | ngx_conf_init_value(ccf->daemon, 1); |
| 997 | 1007 | ngx_conf_init_value(ccf->master, 1); |
| 998 | 1008 | ngx_conf_init_msec_value(ccf->timer_resolution, 0); |
| | 1009 | ngx_conf_init_value(ccf->monotonic_timers, 0); |
| 999 | 1010 | |
| 1000 | 1011 | ngx_conf_init_value(ccf->worker_processes, 1); |
| 1001 | 1012 | ngx_conf_init_value(ccf->debug_points, 0); |
diff -r 78b4e10b4367 src/core/ngx_cycle.h
|
a
|
b
|
|
| 103 | 103 | |
| 104 | 104 | ngx_array_t env; |
| 105 | 105 | char **environment; |
| | 106 | |
| | 107 | ngx_flag_t monotonic_timers; |
| 106 | 108 | } ngx_core_conf_t; |
| 107 | 109 | |
| 108 | 110 | |
diff -r 78b4e10b4367 src/core/ngx_times.c
|
a
|
b
|
|
| 24 | 24 | static ngx_atomic_t ngx_time_lock; |
| 25 | 25 | |
| 26 | 26 | volatile ngx_msec_t ngx_current_msec; |
| | 27 | volatile ngx_msec_t ngx_mono_msec; |
| 27 | 28 | volatile ngx_time_t *ngx_cached_time; |
| 28 | 29 | volatile ngx_str_t ngx_cached_err_log_time; |
| 29 | 30 | volatile ngx_str_t ngx_cached_http_time; |
| … |
… |
|
| 59 | 60 | static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 60 | 61 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
| 61 | 62 | |
| | 63 | #if (NGX_HAVE_CLOCK_MONOTONIC) |
| | 64 | static ngx_flag_t enable_monotonic = 0; |
| | 65 | #endif |
| | 66 | |
| 62 | 67 | void |
| 63 | 68 | ngx_time_init(void) |
| 64 | 69 | { |
| … |
… |
|
| 73 | 78 | ngx_time_update(); |
| 74 | 79 | } |
| 75 | 80 | |
| | 81 | void |
| | 82 | ngx_time_enable_monotonic(ngx_flag_t enable) |
| | 83 | { |
| | 84 | #if (NGX_HAVE_CLOCK_MONOTONIC) |
| | 85 | enable_monotonic = enable; |
| | 86 | ngx_time_update(); |
| | 87 | #endif |
| | 88 | } |
| 76 | 89 | |
| 77 | 90 | void |
| 78 | 91 | ngx_time_update(void) |
| … |
… |
|
| 95 | 108 | |
| 96 | 109 | ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; |
| 97 | 110 | |
| | 111 | #if (NGX_HAVE_CLOCK_MONOTONIC) |
| | 112 | if (enable_monotonic) { |
| | 113 | struct timespec monotime; |
| | 114 | clock_gettime(CLOCK_MONOTONIC, &monotime); |
| | 115 | ngx_mono_msec = (ngx_msec_t) (monotime.tv_sec) * 1000 + (monotime.tv_nsec / 1000 / 1000); |
| | 116 | } else { |
| | 117 | #endif |
| | 118 | ngx_mono_msec = ngx_current_msec; |
| | 119 | #if (NGX_HAVE_CLOCK_MONOTONIC) |
| | 120 | } |
| | 121 | #endif |
| | 122 | |
| | 123 | |
| 98 | 124 | tp = &cached_time[slot]; |
| 99 | 125 | |
| 100 | 126 | if (tp->sec == sec) { |
diff -r 78b4e10b4367 src/core/ngx_times.h
|
a
|
b
|
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | void ngx_time_init(void); |
| | 24 | void ngx_time_enable_monotonic(ngx_flag_t enable); |
| 24 | 25 | void ngx_time_update(void); |
| 25 | 26 | void ngx_time_sigsafe_update(void); |
| 26 | 27 | u_char *ngx_http_time(u_char *buf, time_t t); |
| … |
… |
|
| 47 | 48 | * used in event timers |
| 48 | 49 | */ |
| 49 | 50 | extern volatile ngx_msec_t ngx_current_msec; |
| | 51 | extern volatile ngx_msec_t ngx_mono_msec; |
| 50 | 52 | |
| 51 | 53 | |
| 52 | 54 | #endif /* _NGX_TIMES_H_INCLUDED_ */ |
diff -r 78b4e10b4367 src/event/ngx_event.c
|
a
|
b
|
|
| 602 | 602 | ngx_queue_init(&ngx_posted_accept_events); |
| 603 | 603 | ngx_queue_init(&ngx_posted_events); |
| 604 | 604 | |
| | 605 | /* |
| | 606 | * Monotonic time must be enabled before the first timer is created. Otherwise |
| | 607 | * monotonic and realtime timestamps would be mixed in the rbtree. |
| | 608 | */ |
| | 609 | ngx_time_enable_monotonic(ccf->monotonic_timers); |
| 605 | 610 | if (ngx_event_timer_init(cycle->log) == NGX_ERROR) { |
| 606 | 611 | return NGX_ERROR; |
| 607 | 612 | } |
diff -r 78b4e10b4367 src/event/ngx_event_timer.c
|
a
|
b
|
|
| 44 | 44 | |
| 45 | 45 | node = ngx_rbtree_min(root, sentinel); |
| 46 | 46 | |
| 47 | | timer = (ngx_msec_int_t) (node->key - ngx_current_msec); |
| | 47 | timer = (ngx_msec_int_t) (node->key - ngx_mono_msec); |
| 48 | 48 | |
| 49 | 49 | return (ngx_msec_t) (timer > 0 ? timer : 0); |
| 50 | 50 | } |
| … |
… |
|
| 69 | 69 | |
| 70 | 70 | /* node->key > ngx_current_time */ |
| 71 | 71 | |
| 72 | | if ((ngx_msec_int_t) (node->key - ngx_current_msec) > 0) { |
| | 72 | if ((ngx_msec_int_t) (node->key - ngx_mono_msec) > 0) { |
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
diff -r 78b4e10b4367 src/event/ngx_event_timer.h
|
a
|
b
|
|
| 53 | 53 | ngx_msec_t key; |
| 54 | 54 | ngx_msec_int_t diff; |
| 55 | 55 | |
| 56 | | key = ngx_current_msec + timer; |
| | 56 | key = ngx_mono_msec + timer; |
| 57 | 57 | |
| 58 | 58 | if (ev->timer_set) { |
| 59 | 59 | |