Lines Matching refs:thread
396 isc_thread_t thread; member
477 process_ctlfd(isc__socketthread_t *thread);
608 thread_log(isc__socketthread_t *thread, isc_logcategory_t *category,
612 thread_log(isc__socketthread_t *thread, isc_logcategory_t *category, in thread_log() argument
626 "sockmgr %p thread %d: %s", thread->manager, in thread_log()
627 thread->threadid, msgbuf); in thread_log()
685 watch_fd(isc__socketthread_t *thread, int fd, int msg) { in watch_fd() argument
699 if (kevent(thread->kqueue_fd, &evchange, 1, NULL, 0, NULL) != 0) { in watch_fd()
710 oldevents = thread->epoll_events[fd]; in watch_fd()
712 thread->epoll_events[fd] |= EPOLLIN; in watch_fd()
714 thread->epoll_events[fd] |= EPOLLOUT; in watch_fd()
717 event.events = thread->epoll_events[fd]; in watch_fd()
722 if (thread->fds[fd] != NULL) { in watch_fd()
723 LOCK(&thread->fds[fd]->lock); in watch_fd()
725 ret = epoll_ctl(thread->epoll_fd, op, fd, &event); in watch_fd()
726 if (thread->fds[fd] != NULL) { in watch_fd()
727 UNLOCK(&thread->fds[fd]->lock); in watch_fd()
751 if (write(thread->devpoll_fd, &pfd, sizeof(pfd)) == -1) { in watch_fd()
755 thread->fdpollinfo[fd].want_read = 1; in watch_fd()
757 thread->fdpollinfo[fd].want_write = 1; in watch_fd()
763 LOCK(&thread->manager->lock); in watch_fd()
765 FD_SET(fd, thread->read_fds); in watch_fd()
768 FD_SET(fd, thread->write_fds); in watch_fd()
770 UNLOCK(&thread->manager->lock); in watch_fd()
777 unwatch_fd(isc__socketthread_t *thread, int fd, int msg) { in unwatch_fd() argument
791 if (kevent(thread->kqueue_fd, &evchange, 1, NULL, 0, NULL) != 0) { in unwatch_fd()
802 thread->epoll_events[fd] &= ~(EPOLLIN); in unwatch_fd()
804 thread->epoll_events[fd] &= ~(EPOLLOUT); in unwatch_fd()
807 event.events = thread->epoll_events[fd]; in unwatch_fd()
812 ret = epoll_ctl(thread->epoll_fd, op, fd, &event); in unwatch_fd()
834 if (msg == SELECT_POKE_READ && thread->fdpollinfo[fd].want_write == 1) { in unwatch_fd()
839 if (msg == SELECT_POKE_WRITE && thread->fdpollinfo[fd].want_read == 1) { in unwatch_fd()
845 if (write(thread->devpoll_fd, pfds, writelen) == -1) { in unwatch_fd()
849 thread->fdpollinfo[fd].want_read = 0; in unwatch_fd()
851 thread->fdpollinfo[fd].want_write = 0; in unwatch_fd()
857 LOCK(&thread->manager->lock); in unwatch_fd()
859 FD_CLR(fd, thread->read_fds); in unwatch_fd()
861 FD_CLR(fd, thread->write_fds); in unwatch_fd()
863 UNLOCK(&thread->manager->lock); in unwatch_fd()
874 wakeup_socket(isc__socketthread_t *thread, int fd, int msg) { in wakeup_socket() argument
884 INSIST(fd >= 0 && fd < (int)thread->manager->maxsocks); in wakeup_socket()
887 LOCK(&thread->fdlock[lockid]); in wakeup_socket()
888 INSIST(thread->fdstate[fd] == CLOSE_PENDING); in wakeup_socket()
889 thread->fdstate[fd] = CLOSED; in wakeup_socket()
890 (void)unwatch_fd(thread, fd, SELECT_POKE_READ); in wakeup_socket()
891 (void)unwatch_fd(thread, fd, SELECT_POKE_WRITE); in wakeup_socket()
893 UNLOCK(&thread->fdlock[lockid]); in wakeup_socket()
897 LOCK(&thread->fdlock[lockid]); in wakeup_socket()
898 if (thread->fdstate[fd] == CLOSE_PENDING) { in wakeup_socket()
907 (void)unwatch_fd(thread, fd, SELECT_POKE_READ); in wakeup_socket()
908 (void)unwatch_fd(thread, fd, SELECT_POKE_WRITE); in wakeup_socket()
909 UNLOCK(&thread->fdlock[lockid]); in wakeup_socket()
912 if (thread->fdstate[fd] != MANAGED) { in wakeup_socket()
913 UNLOCK(&thread->fdlock[lockid]); in wakeup_socket()
920 result = watch_fd(thread, fd, msg); in wakeup_socket()
932 UNLOCK(&thread->fdlock[lockid]); in wakeup_socket()
977 select_readmsg(isc__socketthread_t *thread, int *fd, int *msg) { in select_readmsg() argument
982 cc = read(thread->pipe_fds[0], buf, sizeof(buf)); in select_readmsg()
1798 socketclose(isc__socketthread_t *thread, isc_socket_t *sock, int fd) { in socketclose() argument
1804 LOCK(&thread->fdlock[lockid]); in socketclose()
1805 thread->fds[fd] = NULL; in socketclose()
1807 thread->fdstate[fd] = CLOSED; in socketclose()
1809 thread->fdstate[fd] = CLOSE_PENDING; in socketclose()
1810 UNLOCK(&thread->fdlock[lockid]); in socketclose()
1821 (void)unwatch_fd(thread, fd, SELECT_POKE_READ); in socketclose()
1822 (void)unwatch_fd(thread, fd, SELECT_POKE_WRITE); in socketclose()
1824 select_poke(thread->manager, thread->threadid, fd, in socketclose()
1827 inc_stats(thread->manager->stats, sock->statsindex[STATID_CLOSE]); in socketclose()
1831 dec_stats(thread->manager->stats, in socketclose()
1842 LOCK(&thread->manager->lock); in socketclose()
1843 if (thread->maxfd == fd) { in socketclose()
1846 thread->maxfd = 0; in socketclose()
1850 LOCK(&thread->fdlock[lockid]); in socketclose()
1851 if (thread->fdstate[i] == MANAGED) { in socketclose()
1852 thread->maxfd = i; in socketclose()
1853 UNLOCK(&thread->fdlock[lockid]); in socketclose()
1856 UNLOCK(&thread->fdlock[lockid]); in socketclose()
1858 if (thread->maxfd < thread->pipe_fds[0]) { in socketclose()
1859 thread->maxfd = thread->pipe_fds[0]; in socketclose()
1863 UNLOCK(&thread->manager->lock); in socketclose()
1872 isc__socketthread_t *thread = NULL; in destroy() local
1887 thread = &manager->threads[sock->threadid]; in destroy()
1894 socketclose(thread, sock, fd); in destroy()
2483 isc__socketthread_t *thread; in socket_create() local
2530 thread = &manager->threads[sock->threadid]; in socket_create()
2539 LOCK(&thread->fdlock[lockid]); in socket_create()
2540 thread->fds[sock->fd] = sock; in socket_create()
2541 thread->fdstate[sock->fd] = MANAGED; in socket_create()
2543 thread->epoll_events[sock->fd] = 0; in socket_create()
2546 INSIST(thread->fdpollinfo[sock->fd].want_read == 0 && in socket_create()
2547 thread->fdpollinfo[sock->fd].want_write == 0); in socket_create()
2549 UNLOCK(&thread->fdlock[lockid]); in socket_create()
2554 if (thread->maxfd < sock->fd) { in socket_create()
2555 thread->maxfd = sock->fd; in socket_create()
2594 isc__socketthread_t *thread; in isc_socket_open() local
2613 thread = &sock->manager->threads[sock->threadid]; in isc_socket_open()
2616 LOCK(&thread->fdlock[lockid]); in isc_socket_open()
2617 thread->fds[sock->fd] = sock; in isc_socket_open()
2618 thread->fdstate[sock->fd] = MANAGED; in isc_socket_open()
2620 thread->epoll_events[sock->fd] = 0; in isc_socket_open()
2623 INSIST(thread->fdpollinfo[sock->fd].want_read == 0 && in isc_socket_open()
2624 thread->fdpollinfo[sock->fd].want_write == 0); in isc_socket_open()
2626 UNLOCK(&thread->fdlock[lockid]); in isc_socket_open()
2630 if (thread->maxfd < sock->fd) { in isc_socket_open()
2631 thread->maxfd = sock->fd; in isc_socket_open()
2676 isc__socketthread_t *thread; in isc_socket_close() local
2692 thread = &manager->threads[sock->threadid]; in isc_socket_close()
2708 socketclose(thread, sock, fd); in isc_socket_close()
2822 isc__socketthread_t *thread, *nthread; in internal_accept() local
2838 thread = &manager->threads[sock->threadid]; in internal_accept()
2848 unwatch_fd(thread, sock->fd, SELECT_POKE_ACCEPT); in internal_accept()
2968 unwatch_fd(thread, sock->fd, SELECT_POKE_ACCEPT); in internal_accept()
3073 watch_fd(thread, sock->fd, SELECT_POKE_ACCEPT); in internal_accept()
3229 process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) { in process_fd() argument
3236 LOCK(&thread->fdlock[lockid]); in process_fd()
3237 if (thread->fdstate[fd] == CLOSE_PENDING) { in process_fd()
3238 UNLOCK(&thread->fdlock[lockid]); in process_fd()
3240 (void)unwatch_fd(thread, fd, SELECT_POKE_READ); in process_fd()
3241 (void)unwatch_fd(thread, fd, SELECT_POKE_WRITE); in process_fd()
3245 sock = thread->fds[fd]; in process_fd()
3247 UNLOCK(&thread->fdlock[lockid]); in process_fd()
3262 UNLOCK(&thread->fdlock[lockid]); in process_fd()
3286 UNLOCK(&thread->fdlock[lockid]); in process_fd()
3301 process_fds(isc__socketthread_t *thread, struct kevent *events, int nevents) { in process_fds() argument
3306 if (nevents == thread->nevents) { in process_fds()
3312 thread_log(thread, ISC_LOGCATEGORY_GENERAL, in process_fds()
3319 REQUIRE(events[i].ident < thread->manager->maxsocks); in process_fds()
3320 if (events[i].ident == (uintptr_t)thread->pipe_fds[0]) { in process_fds()
3326 process_fd(thread, events[i].ident, readable, writable); in process_fds()
3330 done = process_ctlfd(thread); in process_fds()
3337 process_fds(isc__socketthread_t *thread, struct epoll_event *events, in process_fds() argument
3343 if (nevents == thread->nevents) { in process_fds()
3344 thread_log(thread, ISC_LOGCATEGORY_GENERAL, in process_fds()
3351 REQUIRE(events[i].data.fd < (int)thread->manager->maxsocks); in process_fds()
3352 if (events[i].data.fd == thread->pipe_fds[0]) { in process_fds()
3367 events[i].events |= thread->epoll_events[fd]; in process_fds()
3369 process_fd(thread, events[i].data.fd, in process_fds()
3375 done = process_ctlfd(thread); in process_fds()
3382 process_fds(isc__socketthread_t *thread, struct pollfd *events, int nevents) { in process_fds() argument
3387 if (nevents == thread->nevents) { in process_fds()
3388 thread_log(thread, ISC_LOGCATEGORY_GENERAL, in process_fds()
3395 REQUIRE(events[i].fd < (int)thread->manager->maxsocks); in process_fds()
3396 if (events[i].fd == thread->pipe_fds[0]) { in process_fds()
3400 process_fd(thread, events[i].fd, in process_fds()
3406 done = process_ctlfd(thread); in process_fds()
3413 process_fds(isc__socketthread_t *thread, int maxfd, fd_set *readfds, in process_fds() argument
3417 REQUIRE(maxfd <= (int)thread->manager->maxsocks); in process_fds()
3420 if (i == thread->pipe_fds[0] || i == thread->pipe_fds[1]) { in process_fds()
3423 process_fd(thread, i, FD_ISSET(i, readfds), in process_fds()
3430 process_ctlfd(isc__socketthread_t *thread) { in process_ctlfd() argument
3434 select_readmsg(thread, &fd, &msg); in process_ctlfd()
3436 thread_log(thread, IOEVENT, in process_ctlfd()
3462 wakeup_socket(thread, fd, msg); in process_ctlfd()
3477 isc__socketthread_t *thread = uap; in netthread() local
3478 isc_socketmgr_t *manager = thread->manager; in netthread()
3505 ctlfd = thread->pipe_fds[0]; in netthread()
3511 cc = kevent(thread->kqueue_fd, NULL, 0, thread->events, in netthread()
3512 thread->nevents, NULL); in netthread()
3514 cc = epoll_wait(thread->epoll_fd, thread->events, in netthread()
3515 thread->nevents, -1); in netthread()
3520 if (thread->calls++ > 1000U) { in netthread()
3523 &thread->open_max); in netthread()
3525 thread->open_max = 64; in netthread()
3527 thread->calls = 0; in netthread()
3530 dvp.dp_fds = thread->events; in netthread()
3531 dvp.dp_nfds = thread->nevents; in netthread()
3532 if (dvp.dp_nfds >= thread->open_max) { in netthread()
3533 dvp.dp_nfds = thread->open_max - 1; in netthread()
3545 cc = ioctl(thread->devpoll_fd, DP_POLL, &dvp); in netthread()
3553 &thread->open_max); in netthread()
3555 thread->open_max = 64; in netthread()
3567 memmove(thread->read_fds_copy, thread->read_fds, in netthread()
3568 thread->fd_bufsize); in netthread()
3569 memmove(thread->write_fds_copy, thread->write_fds, in netthread()
3570 thread->fd_bufsize); in netthread()
3571 maxfd = thread->maxfd + 1; in netthread()
3574 cc = select(maxfd, thread->read_fds_copy, in netthread()
3575 thread->write_fds_copy, NULL, NULL); in netthread()
3601 thread_log(thread, in netthread()
3613 done = process_fds(thread, thread->events, cc); in netthread()
3615 process_fds(thread, maxfd, thread->read_fds_copy, in netthread()
3616 thread->write_fds_copy); in netthread()
3621 if (FD_ISSET(ctlfd, thread->read_fds_copy)) { in netthread()
3622 done = process_ctlfd(thread); in netthread()
3628 thread_log(thread, TRACE, "watcher exiting"); in netthread()
3651 setup_thread(isc__socketthread_t *thread) { in setup_thread() argument
3656 REQUIRE(thread != NULL); in setup_thread()
3657 REQUIRE(VALID_MANAGER(thread->manager)); in setup_thread()
3658 REQUIRE(thread->threadid >= 0 && in setup_thread()
3659 thread->threadid < thread->manager->nthreads); in setup_thread()
3661 thread->fds = in setup_thread()
3662 isc_mem_get(thread->manager->mctx, in setup_thread()
3663 thread->manager->maxsocks * sizeof(isc_socket_t *)); in setup_thread()
3665 memset(thread->fds, 0, in setup_thread()
3666 thread->manager->maxsocks * sizeof(isc_socket_t *)); in setup_thread()
3668 thread->fdstate = isc_mem_get(thread->manager->mctx, in setup_thread()
3669 thread->manager->maxsocks * sizeof(int)); in setup_thread()
3671 memset(thread->fdstate, 0, thread->manager->maxsocks * sizeof(int)); in setup_thread()
3673 thread->fdlock = isc_mem_get(thread->manager->mctx, in setup_thread()
3677 isc_mutex_init(&thread->fdlock[i]); in setup_thread()
3680 if (pipe(thread->pipe_fds) != 0) { in setup_thread()
3686 RUNTIME_CHECK(make_nonblock(thread->pipe_fds[0]) == ISC_R_SUCCESS); in setup_thread()
3689 thread->nevents = ISC_SOCKET_MAXEVENTS; in setup_thread()
3690 thread->events = isc_mem_get(thread->manager->mctx, in setup_thread()
3691 sizeof(struct kevent) * thread->nevents); in setup_thread()
3693 thread->kqueue_fd = kqueue(); in setup_thread()
3694 if (thread->kqueue_fd == -1) { in setup_thread()
3699 isc_mem_put(thread->manager->mctx, thread->events, in setup_thread()
3700 sizeof(struct kevent) * thread->nevents); in setup_thread()
3704 result = watch_fd(thread, thread->pipe_fds[0], SELECT_POKE_READ); in setup_thread()
3706 close(thread->kqueue_fd); in setup_thread()
3707 isc_mem_put(thread->manager->mctx, thread->events, in setup_thread()
3708 sizeof(struct kevent) * thread->nevents); in setup_thread()
3713 thread->nevents = ISC_SOCKET_MAXEVENTS; in setup_thread()
3714 thread->epoll_events = in setup_thread()
3715 isc_mem_get(thread->manager->mctx, in setup_thread()
3716 (thread->manager->maxsocks * sizeof(uint32_t))); in setup_thread()
3718 memset(thread->epoll_events, 0, in setup_thread()
3719 thread->manager->maxsocks * sizeof(uint32_t)); in setup_thread()
3721 thread->events = in setup_thread()
3722 isc_mem_get(thread->manager->mctx, in setup_thread()
3723 sizeof(struct epoll_event) * thread->nevents); in setup_thread()
3725 thread->epoll_fd = epoll_create(thread->nevents); in setup_thread()
3726 if (thread->epoll_fd == -1) { in setup_thread()
3734 result = watch_fd(thread, thread->pipe_fds[0], SELECT_POKE_READ); in setup_thread()
3738 thread->nevents = ISC_SOCKET_MAXEVENTS; in setup_thread()
3740 &thread->open_max); in setup_thread()
3742 thread->open_max = 64; in setup_thread()
3744 thread->calls = 0; in setup_thread()
3745 thread->events = isc_mem_get(thread->manager->mctx, in setup_thread()
3746 sizeof(struct pollfd) * thread->nevents); in setup_thread()
3752 thread->fdpollinfo = in setup_thread()
3753 isc_mem_get(thread->manager->mctx, in setup_thread()
3754 sizeof(pollinfo_t) * thread->manager->maxsocks); in setup_thread()
3755 memset(thread->fdpollinfo, 0, in setup_thread()
3756 sizeof(pollinfo_t) * thread->manager->maxsocks); in setup_thread()
3757 thread->devpoll_fd = open("/dev/poll", O_RDWR); in setup_thread()
3758 if (thread->devpoll_fd == -1) { in setup_thread()
3763 isc_mem_put(thread->manager->mctx, thread->events, in setup_thread()
3764 sizeof(struct pollfd) * thread->nevents); in setup_thread()
3765 isc_mem_put(thread->manager->mctx, thread->fdpollinfo, in setup_thread()
3766 sizeof(pollinfo_t) * thread->manager->maxsocks); in setup_thread()
3769 result = watch_fd(thread, thread->pipe_fds[0], SELECT_POKE_READ); in setup_thread()
3771 close(thread->devpoll_fd); in setup_thread()
3772 isc_mem_put(thread->manager->mctx, thread->events, in setup_thread()
3773 sizeof(struct pollfd) * thread->nevents); in setup_thread()
3774 isc_mem_put(thread->manager->mctx, thread->fdpollinfo, in setup_thread()
3775 sizeof(pollinfo_t) * thread->manager->maxsocks); in setup_thread()
3789 thread->fd_bufsize = howmany(manager->maxsocks, NFDBITS) * in setup_thread()
3792 thread->fd_bufsize = sizeof(fd_set); in setup_thread()
3795 thread->read_fds = isc_mem_get(thread->manager->mctx, in setup_thread()
3796 thread->fd_bufsize); in setup_thread()
3797 thread->read_fds_copy = isc_mem_get(thread->manager->mctx, in setup_thread()
3798 thread->fd_bufsize); in setup_thread()
3799 thread->write_fds = isc_mem_get(thread->manager->mctx, in setup_thread()
3800 thread->fd_bufsize); in setup_thread()
3801 thread->write_fds_copy = isc_mem_get(thread->manager->mctx, in setup_thread()
3802 thread->fd_bufsize); in setup_thread()
3803 memset(thread->read_fds, 0, thread->fd_bufsize); in setup_thread()
3804 memset(thread->write_fds, 0, thread->fd_bufsize); in setup_thread()
3806 (void)watch_fd(thread, thread->pipe_fds[0], SELECT_POKE_READ); in setup_thread()
3807 thread->maxfd = thread->pipe_fds[0]; in setup_thread()
3814 cleanup_thread(isc_mem_t *mctx, isc__socketthread_t *thread) { in cleanup_thread() argument
3818 result = unwatch_fd(thread, thread->pipe_fds[0], SELECT_POKE_READ); in cleanup_thread()
3823 close(thread->kqueue_fd); in cleanup_thread()
3824 isc_mem_put(mctx, thread->events, in cleanup_thread()
3825 sizeof(struct kevent) * thread->nevents); in cleanup_thread()
3827 close(thread->epoll_fd); in cleanup_thread()
3829 isc_mem_put(mctx, thread->events, in cleanup_thread()
3830 sizeof(struct epoll_event) * thread->nevents); in cleanup_thread()
3832 close(thread->devpoll_fd); in cleanup_thread()
3833 isc_mem_put(mctx, thread->events, in cleanup_thread()
3834 sizeof(struct pollfd) * thread->nevents); in cleanup_thread()
3835 isc_mem_put(mctx, thread->fdpollinfo, in cleanup_thread()
3836 sizeof(pollinfo_t) * thread->manager->maxsocks); in cleanup_thread()
3838 if (thread->read_fds != NULL) { in cleanup_thread()
3839 isc_mem_put(mctx, thread->read_fds, thread->fd_bufsize); in cleanup_thread()
3841 if (thread->read_fds_copy != NULL) { in cleanup_thread()
3842 isc_mem_put(mctx, thread->read_fds_copy, thread->fd_bufsize); in cleanup_thread()
3844 if (thread->write_fds != NULL) { in cleanup_thread()
3845 isc_mem_put(mctx, thread->write_fds, thread->fd_bufsize); in cleanup_thread()
3847 if (thread->write_fds_copy != NULL) { in cleanup_thread()
3848 isc_mem_put(mctx, thread->write_fds_copy, thread->fd_bufsize); in cleanup_thread()
3851 for (i = 0; i < (int)thread->manager->maxsocks; i++) { in cleanup_thread()
3852 if (thread->fdstate[i] == CLOSE_PENDING) { in cleanup_thread()
3859 isc_mem_put(thread->manager->mctx, thread->epoll_events, in cleanup_thread()
3860 thread->manager->maxsocks * sizeof(uint32_t)); in cleanup_thread()
3862 isc_mem_put(thread->manager->mctx, thread->fds, in cleanup_thread()
3863 thread->manager->maxsocks * sizeof(isc_socket_t *)); in cleanup_thread()
3864 isc_mem_put(thread->manager->mctx, thread->fdstate, in cleanup_thread()
3865 thread->manager->maxsocks * sizeof(int)); in cleanup_thread()
3868 isc_mutex_destroy(&thread->fdlock[i]); in cleanup_thread()
3870 isc_mem_put(thread->manager->mctx, thread->fdlock, in cleanup_thread()
3919 &manager->threads[i].thread); in isc_socketmgr_create2()
3922 isc_thread_setname(manager->threads[i].thread, tname); in isc_socketmgr_create2()
3987 isc_thread_join(manager->threads[i].thread, NULL); in isc_socketmgr_destroy()
5649 isc__socketthread_t *thread; in isc_socket_fdwatchcreate() local
5671 thread = &manager->threads[sock->threadid]; in isc_socket_fdwatchcreate()
5680 LOCK(&thread->fdlock[lockid]); in isc_socket_fdwatchcreate()
5681 thread->fds[sock->fd] = sock; in isc_socket_fdwatchcreate()
5682 thread->fdstate[sock->fd] = MANAGED; in isc_socket_fdwatchcreate()
5688 INSIST(thread->fdpollinfo[sock->fd].want_read == 0 && in isc_socket_fdwatchcreate()
5689 thread->fdpollinfo[sock->fd].want_write == 0); in isc_socket_fdwatchcreate()
5691 UNLOCK(&thread->fdlock[lockid]); in isc_socket_fdwatchcreate()
5696 if (thread->maxfd < sock->fd) in isc_socket_fdwatchcreate()
5697 thread->maxfd = sock->fd; in isc_socket_fdwatchcreate()