Ignore:
Timestamp:
Jan 12, 2021, 12:34:08 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58f99b3
Parents:
77fde9d5
Message:

Web server seems to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io/setup.cfa

    r77fde9d5 r426f60c  
    5252                #include <pthread.h>
    5353                #include <sys/epoll.h>
     54                #include <sys/eventfd.h>
    5455                #include <sys/mman.h>
    5556                #include <sys/syscall.h>
     
    185186                                $io_ctx_thread * io_ctx = ($io_ctx_thread *)(uintptr_t)events[i].data.u64;
    186187                                /* paranoid */ verify( io_ctx );
    187                                 __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Unparking io poller %p\n", io_ctx);
     188                                __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Unparking io poller %d (%p)\n", io_ctx->ring->fd, io_ctx);
    188189                                #if !defined( __CFA_NO_STATISTICS__ )
    189190                                        __cfaabi_tls.this_stats = io_ctx->self.curr_cluster->stats;
     
    309310        }
    310311
     312        extern void signal_unblock( int sig );
     313        extern void signal_block  ( int sig );
     314
    311315        static void __io_create( __io_data & this, const io_context_params & params_in ) {
    312316                // Step 1 : call to setup
     
    377381                        abort("KERNEL ERROR: IO_URING MMAP3 - %s\n", strerror(errno));
    378382                }
    379 
     383                memset(sq.sqes, 0xde, size);
     384
     385                verify( 0 != (params.features & IORING_FEAT_NODROP) );
     386
     387                // Step 3 : Initialize the data structure
    380388                // Get the pointers from the kernel to fill the structure
    381389                // submit queue
     
    392400                        const __u32 num = *sq.num;
    393401                        for( i; num ) {
    394                                 sq.sqes[i].user_data = 0ul64;
     402                                sq.sqes[i].opcode = IORING_OP_LAST;
     403                                sq.sqes[i].user_data = 3ul64;
    395404                        }
    396405                }
     
    422431                cq.cqes = (struct io_uring_cqe *)(((intptr_t)cq.ring_ptr) + params.cq_off.cqes);
    423432
     433                signal_block( SIGUSR1 );
     434
     435                // Step 4 : eventfd
     436                int efd = eventfd(0, 0);
     437                if (efd < 0) {
     438                        abort("KERNEL ERROR: IO_URING EVENTFD - %s\n", strerror(errno));
     439                }
     440
     441                int ret = syscall( __NR_io_uring_register, fd, IORING_REGISTER_EVENTFD, &efd, 1);
     442                if (ret < 0) {
     443                        abort("KERNEL ERROR: IO_URING EVENTFD REGISTER - %s\n", strerror(errno));
     444                }
     445
     446                signal_unblock( SIGUSR1 );
     447
    424448                // some paranoid checks
    425449                /* paranoid */ verifyf( (*cq.mask) == ((*cq.num) - 1ul32), "IO_URING Expected mask to be %u (%u entries), was %u", (*cq.num) - 1ul32, *cq.num, *cq.mask  );
     
    436460                this.ring_flags = params.flags;
    437461                this.fd         = fd;
     462                this.efd        = efd;
    438463                this.eager_submits  = params_in.eager_submits;
    439464                this.poller_submits = params_in.poller_submits;
     
    458483                // close the file descriptor
    459484                close(this.fd);
     485                close(this.efd);
    460486
    461487                free( this.submit_q.ready ); // Maybe null, doesn't matter
     
    467493
    468494        void __ioctx_register($io_ctx_thread & ctx, struct epoll_event & ev) {
    469                 ev.events = EPOLLIN | EPOLLONESHOT;
     495                ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
    470496                ev.data.u64 = (__u64)&ctx;
    471                 int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_ADD, ctx.ring->fd, &ev);
     497                int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_ADD, ctx.ring->efd, &ev);
    472498                if (ret < 0) {
    473499                        abort( "KERNEL ERROR: EPOLL ADD - (%d) %s\n", (int)errno, strerror(errno) );
     
    476502
    477503        void __ioctx_prepare_block($io_ctx_thread & ctx, struct epoll_event & ev) {
    478                 __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Re-arming io poller %p\n", &ctx);
    479                 int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_MOD, ctx.ring->fd, &ev);
     504                __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Re-arming io poller %d (%p)\n", ctx.ring->fd, &ctx);
     505                int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_MOD, ctx.ring->efd, &ev);
    480506                if (ret < 0) {
    481507                        abort( "KERNEL ERROR: EPOLL REARM - (%d) %s\n", (int)errno, strerror(errno) );
Note: See TracChangeset for help on using the changeset viewer.