manoj 99/04/14 15:44:58
Modified: pthreads/src/include acceptlock.h http_accept.h pthreads/src/main acceptlock.c http_accept.c http_main.c Log: Cleanup and bug fixes. This patch removes the link between ap_acceptors_per_child and the number of listen fds, to support the new poll-accept model. As a result, we don't create a bunch of accept mutexes we don't need, and there isn't a pile of phantom threads that we attempt to count and operate on. Revision Changes Path 1.3 +7 -7 apache-apr/pthreads/src/include/acceptlock.h Index: acceptlock.h =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/include/acceptlock.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- acceptlock.h 1999/03/07 00:47:43 1.2 +++ acceptlock.h 1999/04/14 22:44:55 1.3 @@ -65,7 +65,7 @@ /* Prototyps for the accept mutex functions. */ #if defined (USE_USLOCK_SERIALIZED_ACCEPT) #define accept_mutex_child_init(x) -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); @@ -73,33 +73,33 @@ void accept_mutex_child_cleanup(void *); void accept_mutex_child_init(pool *); void accept_mutex_cleanup(void *); -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); #elif defined (USE_SYSVSEM_SERIALIZED_ACCEPT) void accept_mutex_cleanup(void *); -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); #elif defined(USE_FCNTL_SERIALIZED_ACCEPT) #define accept_mutex_child_init(x) -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); #elif defined(USE_FLOCK_SERIALIZED_ACCEPT) void accept_mutex_cleanup(void *); void accept_mutex_child_init(pool *); -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); #elif defined(USE_OS2SEM_SERIALIZED_ACCEPT) void accept_mutex_cleanup(void *); void accept_mutex_child_init(pool *); -void accept_mutex_init(pool *); +void accept_mutex_init(pool *, int); void accept_mutex_on(int); void accept_mutex_off(int); @@ -109,7 +109,7 @@ * the sockets. */ #define NO_SERIALIZED_ACCEPT #define accept_mutex_child_init(x) -#define accept_mutex_init(x) +#define accept_mutex_init(x, y) #define accept_mutex_on(x) #define accept_mutex_off(x) #endif 1.4 +2 -2 apache-apr/pthreads/src/include/http_accept.h Index: http_accept.h =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/include/http_accept.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -u -r1.3 -r1.4 --- http_accept.h 1999/04/14 21:38:28 1.3 +++ http_accept.h 1999/04/14 22:44:55 1.4 @@ -79,8 +79,8 @@ #define USE_ACCEPT_QUEUE /*#define USE_MULTI_ACCEPT*/ -void accept_parent_init(pool*); -void accept_child_init(pool*, int, int); +void accept_parent_init(pool*, int); +void accept_child_init(pool*, int); void start_accepting_connections(int); int get_connection(struct sockaddr *); void stop_accepting_connections(pool*); 1.5 +34 -26 apache-apr/pthreads/src/main/acceptlock.c Index: acceptlock.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/acceptlock.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -u -r1.4 -r1.5 --- acceptlock.c 1999/04/14 06:26:12 1.4 +++ acceptlock.c 1999/04/14 22:44:56 1.5 @@ -79,6 +79,8 @@ #include "pthread.h" +/* Number of cross-process locks we're managing */ +static int lock_count; #if defined(USE_FCNTL_SERIALIZED_ACCEPT) || defined(USE_FLOCK_SERIALIZED_ACCEPT) static void init_lock_fname(pool *p) @@ -102,15 +104,16 @@ -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { ptrdiff_t old; usptr_t *us; int i; - uslock = (ulock_t *)ap_palloc(p, ap_acceptors_per_child * sizeof(ulock_t)); + lock_count = number_of_locks; + uslock = (ulock_t *)ap_palloc(p, lock_count * sizeof(ulock_t)); - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { /* default is 8, allocate enough for all the children plus the parent */ if ((old = usconfig(CONF_INITUSERS, HARD_SERVER_LIMIT + 1)) == -1) { perror("usconfig(CONF_INITUSERS)"); @@ -180,7 +183,7 @@ int i; if (accept_mutex != (void *)(caddr_t)-1) { - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { if (have_accept_mutex[i]) { pthread_mutex_unlock(&accept_mutex[i]); } @@ -198,20 +201,21 @@ if (accept_mutex != (void *)(caddr_t)-1 && munmap((caddr_t) accept_mutex, - sizeof(pthread_mutex_t) * ap_acceptors_per_child)) { + sizeof(pthread_mutex_t) * lock_count)) { perror("munmap"); } accept_mutex = (void *)(caddr_t)-1; } -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { pthread_mutexattr_t mattr; int fd; int i; + lock_count = number_of_locks; have_accept_mutex = (int *)ap_palloc(p, - ap_acceptors_per_child * sizeof(int)); + lock_count * sizeof(int)); fd = open("/dev/zero", O_RDWR); if (fd == -1) { @@ -219,7 +223,7 @@ exit(APEXIT_INIT); } accept_mutex = (pthread_mutex_t *) mmap((caddr_t) 0, - sizeof(pthread_mutex_t) * ap_acceptors_per_child, + sizeof(pthread_mutex_t) * lock_count, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (accept_mutex == (void *) (caddr_t) - 1) { perror("mmap"); @@ -235,7 +239,7 @@ perror("pthread_mutexattr_setpshared"); exit(APEXIT_INIT); } - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { if ((errno = pthread_mutex_init(&accept_mutex[i], &mattr))) { perror("pthread_mutex_init"); exit(APEXIT_INIT); @@ -329,7 +333,7 @@ union semun ick; int i; - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { if (sem_id[i] < 0) return; /* this is ignored anyhow */ @@ -340,15 +344,16 @@ -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { union semun ick; struct semid_ds buf; int i; - sem_id = (int *)ap_palloc(p, ap_acceptors_per_child * sizeof(int)); + lock_count = number_of_locks; + sem_id = (int *)ap_palloc(p, lock_count * sizeof(int)); - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { /* acquire the semaphore */ sem_id[i] = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600); if (sem_id[i] < 0) { @@ -413,12 +418,13 @@ * Initialize mutex lock. * Must be safe to call this on a restart. */ -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { int i; char * lock_fname; - lock_fd = (int *)ap_palloc(p, ap_acceptors_per_child * sizeof(int *)); + lock_count = number_of_locks; + lock_fd = (int *)ap_palloc(p, lock_count * sizeof(int *)); lock_it.l_whence = SEEK_SET; /* from current point */ lock_it.l_start = 0; /* -"- */ lock_it.l_len = 0; /* until end of file */ @@ -431,7 +437,7 @@ unlock_it.l_pid = 0; /* pid not actually interesting */ init_lock_fname(p); - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { lock_fname = expand_lock_fname(p, i); lock_fd[i] = ap_popenf(p, lock_fname, O_CREAT | O_WRONLY | O_EXCL, 0644); @@ -488,7 +494,7 @@ int i; char * lock_fname; - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { lock_fname = expand_lock_fname(foo, i); unlink(lock_fname); } @@ -502,7 +508,7 @@ { int i; - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { char *lock_fname = expand_lock_fname(p, i); lock_fd[i] = ap_popenf(p, lock_fname, O_WRONLY, 0600); @@ -519,14 +525,15 @@ * Initialize mutex lock. * Must be safe to call this on a restart. */ -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { int i; char *lock_fname; - lock_fd = (int *)ap_palloc(p, ap_acceptors_per_child * sizeof(int *)); + lock_count = number_of_locks; + lock_fd = (int *)ap_palloc(p, lock_count * sizeof(int *)); init_lock_fname(p); - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { lock_fname = expand_lock_fname(p, i); unlink(lock_fname); lock_fd[i] = ap_popenf(p, lock_fname, @@ -574,7 +581,7 @@ { int i; - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { DosReleaseMutexSem(lock_sem[i]); DosCloseMutexSem(lock_sem[i]); } @@ -588,7 +595,7 @@ { int i; - for(i = 0; i < ap_acceptors_per_child; i++) { + for(i = 0; i < lock_count; i++) { int rc = DosOpenMutexSem(NULL, &lock_sem[locknum]); if (rc != 0) { @@ -602,14 +609,15 @@ * Initialize mutex lock. * Must be safe to call this on a restart. */ -void accept_mutex_init(pool *p) +void accept_mutex_init(pool *p, int number_of_locks) { int rc; int i; - lock_fd = (int *)ap_palloc(p, ap_acceptors_per_child * sizeof(int *)); + lock_count = number_of_locks; + lock_fd = (int *)ap_palloc(p, lock_count * sizeof(int *)); - for (i = 0; i < ap_acceptors_per_child; i++) { + for (i = 0; i < lock_count; i++) { rc = DosCreateMutexSem(NULL, &lock_sem[i], DC_SEM_SHARED, FALSE); if (rc != 0) { 1.6 +12 -12 apache-apr/pthreads/src/main/http_accept.c Index: http_accept.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/http_accept.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -u -r1.5 -r1.6 --- http_accept.c 1999/04/14 21:38:28 1.5 +++ http_accept.c 1999/04/14 22:44:57 1.6 @@ -69,6 +69,7 @@ * threads can now exit */ static int workers_may_exit = 0; static int requests_this_child; +static int num_listenfds; #if defined (USE_ACCEPT_QUEUE) /* The queue of sockets we've accepted */ @@ -181,9 +182,10 @@ } } -void accept_parent_init(pool *pconf) +void accept_parent_init(pool *pconf, int listener_count) { - SAFE_ACCEPT(accept_mutex_init(pconf)); + SAFE_ACCEPT(accept_mutex_init(pconf, listener_count)); + ap_acceptors_per_child = num_listenfds = listener_count; } /* @@ -197,10 +199,9 @@ * 4. Simply access the globals (yech...) */ void accept_child_init(pool* pchild, - int worker_threads_per_child, - int acceptor_threads_per_child) + int worker_threads_per_child) { - int queue_capacity = worker_threads_per_child + acceptor_threads_per_child; + int queue_capacity = worker_threads_per_child + ap_acceptors_per_child; SAFE_ACCEPT(accept_mutex_child_init(pchild)); requests_this_child = ap_max_requests_per_child; queue_init(&csd_queue, queue_capacity, pchild); @@ -315,17 +316,17 @@ * Worker threads do the accept and process the request. */ static listen_rec *head_listener; -static int num_listenfds; static struct pollfd *listenfds; -void accept_parent_init(pool *pconf) +void accept_parent_init(pool *pconf, int listener_count) { - SAFE_ACCEPT(accept_mutex_init(pconf)); + SAFE_ACCEPT(accept_mutex_init(pconf, 1)); + num_listenfds = listener_count; + ap_acceptors_per_child = 0; } void accept_child_init(pool* pchild, - int worker_threads_per_child, - int acceptors_per_child) + int worker_threads_per_child) { int i; listen_rec *lr; @@ -333,7 +334,6 @@ SAFE_ACCEPT(accept_mutex_child_init(pchild)); requests_this_child = ap_max_requests_per_child; head_listener = ap_listeners; - num_listenfds = acceptors_per_child; listenfds = ap_palloc(pchild, sizeof(struct pollfd) * num_listenfds); @@ -343,8 +343,8 @@ listenfds[i].events = POLLIN; /* should we add POLLPRI ?*/ listenfds[i].revents = 0; } - } + void start_accepting_connections(int my_child_num) { } 1.71 +8 -6 apache-apr/pthreads/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/http_main.c,v retrieving revision 1.70 retrieving revision 1.71 diff -u -u -r1.70 -r1.71 --- http_main.c 1999/04/14 21:38:29 1.70 +++ http_main.c 1999/04/14 22:44:57 1.71 @@ -1467,13 +1467,13 @@ /* open sockets, and turn the listeners list into a singly linked ring */ -static void setup_listeners(pool *p) +static int setup_listeners(pool *p) { listen_rec *lr; int fd; + int listener_count = 0; lr = ap_listeners; - ap_acceptors_per_child = 0; for (;;) { fd = find_listener(lr); if (fd < 0) { @@ -1483,7 +1483,7 @@ ap_note_cleanups_for_socket(p, fd); } if (fd >= 0) { - ++ap_acceptors_per_child; + ++listener_count; } lr->fd = fd; if (lr->next == NULL) @@ -1504,6 +1504,7 @@ "SERIALIZED_ACCEPT."); } #endif + return listener_count; } @@ -1948,7 +1949,7 @@ /*stuff to do before we switch id's, so we have permissions.*/ reopen_scoreboard(pchild); - accept_child_init(pchild, ap_threads_per_child, ap_acceptors_per_child); + accept_child_init(pchild, ap_threads_per_child); set_group_privs(); @@ -2294,6 +2295,7 @@ static void one_config_cycle(void) { int remaining_children_to_start; + int listener_count; copy_listeners(pconf); if (!is_graceful) { @@ -2302,13 +2304,13 @@ ap_clear_pool(pconf); ptemp = ap_make_sub_pool(pconf); server_conf = ap_read_config(pconf, ptemp, ap_server_confname); - setup_listeners(pconf); + listener_count = setup_listeners(pconf); ap_open_logs(server_conf, pconf); ap_log_pid(pconf, ap_pid_fname); ap_set_version(); ap_init_modules(pconf, server_conf); version_locked++; - accept_parent_init(pconf); + accept_parent_init(pconf, listener_count); if (!is_graceful) { reinit_scoreboard(pconf); }