Ticket #189: monotonic_timers-3.patch
| File monotonic_timers-3.patch, 6.3 KB (added by , 10 years ago) |
|---|
-
auto/unix
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 320 321 if [ $ngx_found = yes ]; then 322 # We have clock_gettime with CLOCK_MONOTONIC. Now we test for faster 323 # variants (CLOCK_MONOTONIC_(FAST|COARSE)). ngx_feature_libs is set 324 # by previous tests to include librt if necessary. 325 ngx_feature="clock_gettime(CLOCK_MONOTONIC_FAST)" 326 ngx_feature_name="NGX_HAVE_CLOCK_MONOTONIC_FAST" 327 ngx_feature_test="struct timespec monotime; clock_gettime(CLOCK_MONOTONIC_FAST, &monotime);" 328 . auto/feature 329 330 ngx_feature="clock_gettime(CLOCK_MONOTONIC_COARSE)" 331 ngx_feature_name="NGX_HAVE_CLOCK_MONOTONIC_COARSE" 332 ngx_feature_test="struct timespec monotime; clock_gettime(CLOCK_MONOTONIC_COARSE, &monotime);" 333 . auto/feature 334 fi 300 335 301 336 ngx_feature="SO_SETFIB" 302 337 ngx_feature_name="NGX_HAVE_SETFIB" -
contrib/vim/syntax/nginx.vim
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 -
src/core/nginx.c
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); -
src/core/ngx_cycle.h
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 -
src/core/ngx_times.c
diff -r 78b4e10b4367 src/core/ngx_times.c
a b 59 59 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 60 60 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 61 61 62 #if (NGX_HAVE_CLOCK_MONOTONIC) 63 static ngx_flag_t enable_monotonic = 0; 64 static clockid_t monotonic_clock; 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 struct timespec monotime; 86 87 if (enable) { 88 /* Hack for the 'else if's to work correctly with the '#if's */ 89 if (0) { 90 } 91 #if (NGX_HAVE_CLOCK_MONOTONIC_FAST) 92 else if (clock_gettime(CLOCK_MONOTONIC_FAST, &monotime) == 0) { 93 monotonic_clock = CLOCK_MONOTONIC_FAST; 94 } 95 #endif 96 #if (NGX_HAVE_CLOCK_MONOTONIC_COARSE) 97 else if (clock_gettime(CLOCK_MONOTONIC_COARSE, &monotime) == 0) { 98 monotonic_clock = CLOCK_MONOTONIC_COARSE; 99 } 100 #endif 101 else if (clock_gettime(CLOCK_MONOTONIC_COARSE, &monotime) == 0) { 102 monotonic_clock = CLOCK_MONOTONIC; 103 } else { 104 /* No monotonic clock found at runtime, must disable. FIXME should this emit a warning? */ 105 enable = 0; 106 } 107 } 108 enable_monotonic = enable; 109 ngx_time_update(); 110 #endif 111 } 76 112 77 113 void 78 114 ngx_time_update(void) … … 93 129 sec = tv.tv_sec; 94 130 msec = tv.tv_usec / 1000; 95 131 96 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; 132 #if (NGX_HAVE_CLOCK_MONOTONIC) 133 if (enable_monotonic) { 134 struct timespec monotime; 135 clock_gettime(monotonic_clock, &monotime); 136 ngx_current_msec = (ngx_msec_t) (monotime.tv_sec) * 1000 + (monotime.tv_nsec / 1000 / 1000); 137 } else { 138 #endif 139 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; 140 #if (NGX_HAVE_CLOCK_MONOTONIC) 141 } 142 #endif 143 97 144 98 145 tp = &cached_time[slot]; 99 146 -
src/core/ngx_times.h
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); -
src/event/ngx_event.c
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 }
