Mercurial > hg > nginx
comparison src/event/modules/ngx_rtsig_module.c @ 391:b670db10cbbd
nginx-0.0.7-2004-07-14-20:01:42 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 Jul 2004 16:01:42 +0000 |
parents | 1471c6fb108a |
children | f209f3391020 |
comparison
equal
deleted
inserted
replaced
390:1471c6fb108a | 391:b670db10cbbd |
---|---|
20 int sigtimedwait(const sigset_t *set, siginfo_t *info, | 20 int sigtimedwait(const sigset_t *set, siginfo_t *info, |
21 const struct timespec *timeout) | 21 const struct timespec *timeout) |
22 { | 22 { |
23 return -1; | 23 return -1; |
24 } | 24 } |
25 | |
26 int ngx_linux_rtsig_max; | |
25 | 27 |
26 #endif | 28 #endif |
27 | 29 |
28 | 30 |
29 typedef struct { | 31 typedef struct { |
43 static ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle); | 45 static ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle); |
44 static ngx_int_t ngx_rtsig_process_overflow(ngx_cycle_t *cycle); | 46 static ngx_int_t ngx_rtsig_process_overflow(ngx_cycle_t *cycle); |
45 | 47 |
46 static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle); | 48 static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle); |
47 static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf); | 49 static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf); |
50 static char *ngx_check_ngx_overflow_threshold_bounds(ngx_conf_t *cf, | |
51 void *post, void *data); | |
48 | 52 |
49 | 53 |
50 static sigset_t set; | 54 static sigset_t set; |
51 static ngx_uint_t overflow, overflow_current; | 55 static ngx_uint_t overflow, overflow_current; |
52 static struct pollfd *overflow_list; | 56 static struct pollfd *overflow_list; |
53 | 57 |
54 | 58 |
55 static ngx_str_t rtsig_name = ngx_string("rtsig"); | 59 static ngx_str_t rtsig_name = ngx_string("rtsig"); |
56 | 60 |
57 static ngx_conf_num_bounds_t ngx_overflow_threshold_bounds = { | 61 static ngx_conf_num_bounds_t ngx_overflow_threshold_bounds = { |
58 ngx_conf_check_num_bounds, 2, 10 | 62 ngx_check_ngx_overflow_threshold_bounds, 2, 10 |
59 }; | 63 }; |
60 | 64 |
61 | 65 |
62 static ngx_command_t ngx_rtsig_commands[] = { | 66 static ngx_command_t ngx_rtsig_commands[] = { |
63 | 67 |
642 c = &cycle->connections[overflow_list[i].fd]; | 646 c = &cycle->connections[overflow_list[i].fd]; |
643 | 647 |
644 rev = c->read; | 648 rev = c->read; |
645 | 649 |
646 if (rev->active | 650 if (rev->active |
651 && !rev->closed | |
647 && rev->event_handler | 652 && rev->event_handler |
648 && (overflow_list[i].revents | 653 && (overflow_list[i].revents |
649 & (POLLIN|POLLERR|POLLHUP|POLLNVAL))) | 654 & (POLLIN|POLLERR|POLLHUP|POLLNVAL))) |
650 { | 655 { |
651 tested++; | 656 tested++; |
661 } | 666 } |
662 | 667 |
663 wev = c->write; | 668 wev = c->write; |
664 | 669 |
665 if (wev->active | 670 if (wev->active |
671 && !wev->closed | |
666 && wev->event_handler | 672 && wev->event_handler |
667 && (overflow_list[i].revents | 673 && (overflow_list[i].revents |
668 & (POLLOUT|POLLERR|POLLHUP|POLLNVAL))) | 674 & (POLLOUT|POLLERR|POLLHUP|POLLNVAL))) |
669 { | 675 { |
670 tested++; | 676 tested++; |
684 ngx_mutex_unlock(ngx_posted_events_mutex); | 690 ngx_mutex_unlock(ngx_posted_events_mutex); |
685 } | 691 } |
686 | 692 |
687 if (tested >= rtscf->overflow_test) { | 693 if (tested >= rtscf->overflow_test) { |
688 | 694 |
689 /* | 695 if (ngx_linux_rtsig_max) { |
690 * Check the current rt queue length to prevent the new overflow. | 696 |
691 * | 697 /* |
692 * Learn the /proc/sys/kernel/rtsig-max value because | 698 * Check the current rt queue length to prevent |
693 * it can be changed sisnce the last checking. | 699 * the new overflow. |
694 */ | 700 * |
695 | 701 * Learn the /proc/sys/kernel/rtsig-max value because |
696 name[0] = CTL_KERN; | 702 * it can be changed sisnce the last checking. |
697 name[1] = KERN_RTSIGMAX; | 703 */ |
698 len = sizeof(rtsig_max); | 704 |
699 if (sysctl(name, sizeof(name), &rtsig_max, &len, NULL, 0) == -1) { | 705 name[0] = CTL_KERN; |
700 ngx_log_error(NGX_LOG_ALERT, cycle->log, errno, | 706 name[1] = KERN_RTSIGMAX; |
701 "sysctl(KERN_RTSIGMAX) failed"); | 707 len = sizeof(rtsig_max); |
702 return NGX_ERROR; | 708 if (sysctl(name, sizeof(name), &rtsig_max, &len, NULL, 0) == -1) |
703 } | 709 { |
704 | 710 ngx_log_error(NGX_LOG_ALERT, cycle->log, errno, |
705 name[0] = CTL_KERN; | 711 "sysctl(KERN_RTSIGMAX) failed"); |
706 name[1] = KERN_RTSIGNR; | 712 return NGX_ERROR; |
707 len = sizeof(rtsig_nr); | 713 } |
708 if (sysctl(name, sizeof(name), &rtsig_nr, &len, NULL, 0) == -1) { | 714 |
709 ngx_log_error(NGX_LOG_ALERT, cycle->log, errno, | 715 name[0] = CTL_KERN; |
710 "sysctl(KERN_RTSIGNR) failed"); | 716 name[1] = KERN_RTSIGNR; |
711 return NGX_ERROR; | 717 len = sizeof(rtsig_nr); |
712 } | 718 if (sysctl(name, sizeof(name), &rtsig_nr, &len, NULL, 0) == -1) |
713 | 719 { |
714 /* | 720 ngx_log_error(NGX_LOG_ALERT, cycle->log, errno, |
715 * drain rt signal queue if the /proc/sys/kernel/rtsig-nr is bigger | 721 "sysctl(KERN_RTSIGNR) failed"); |
716 * than "/proc/sys/kernel/rtsig-max / rtsig_overflow_threshold" | 722 return NGX_ERROR; |
717 */ | 723 } |
718 | 724 |
719 if (rtsig_max / rtscf->overflow_threshold < rtsig_nr) { | 725 /* |
720 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 726 * drain rt signal queue if the /proc/sys/kernel/rtsig-nr |
721 "rtsig queue state: %d/%d", rtsig_nr, rtsig_max); | 727 * is bigger than |
728 * /proc/sys/kernel/rtsig-max / rtsig_overflow_threshold | |
729 */ | |
730 | |
731 if (rtsig_max / rtscf->overflow_threshold < rtsig_nr) { | |
732 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
733 "rtsig queue state: %d/%d", | |
734 rtsig_nr, rtsig_max); | |
735 while (ngx_rtsig_process_events(cycle) == NGX_OK) { | |
736 /* void */ | |
737 } | |
738 } | |
739 | |
740 } else { | |
741 | |
742 /* | |
743 * Linux has not KERN_RTSIGMAX since 2.6.6-mm2 | |
744 * so drain rt signal queue unconditionally | |
745 */ | |
746 | |
722 while (ngx_rtsig_process_events(cycle) == NGX_OK) { /* void */ } | 747 while (ngx_rtsig_process_events(cycle) == NGX_OK) { /* void */ } |
723 } | 748 } |
724 | 749 |
725 tested = 0; | 750 tested = 0; |
726 } | 751 } |
772 ngx_conf_init_value(rtscf->overflow_test, 32); | 797 ngx_conf_init_value(rtscf->overflow_test, 32); |
773 ngx_conf_init_value(rtscf->overflow_threshold, 10); | 798 ngx_conf_init_value(rtscf->overflow_threshold, 10); |
774 | 799 |
775 return NGX_CONF_OK; | 800 return NGX_CONF_OK; |
776 } | 801 } |
802 | |
803 | |
804 static char *ngx_check_ngx_overflow_threshold_bounds(ngx_conf_t *cf, | |
805 void *post, void *data) | |
806 { | |
807 if (ngx_linux_rtsig_max) { | |
808 return ngx_conf_check_num_bounds(cf, post, data); | |
809 } | |
810 | |
811 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
812 "\"rtsig_overflow_threshold\" is not supported " | |
813 "since Linux 2.6.6-mm2, ignored"); | |
814 | |
815 return NGX_CONF_OK; | |
816 } |