Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3754504ybl; Sun, 25 Aug 2019 23:23:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlFAj8eMg+1+A78KgWR/VCbYcwtbGPRX18QkXoaOjouZMGhbejqeR5jwKYC4rJ2WdTHEdL X-Received: by 2002:a63:2447:: with SMTP id k68mr15166791pgk.219.1566800628402; Sun, 25 Aug 2019 23:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566800628; cv=none; d=google.com; s=arc-20160816; b=xSEOO8Lss0vWiVRJLuaMsnySIHOPXqc669srm4E2P3gP+Q6FePRy2SSDcqe8DjkiHs b+QVAERNAiRJCuw4sDwEKATEBWLDExLIoD0WPNbeaNKQhaZ2cyMv1tlQmoT+xoDyW5Ed fqdmHTeIbup7FLCr3OEA4v/3EB7GU9Jxbkct6+1KoqHx+aKM4vX1/oRgEDxTeWMvC6nd 6tVtM96Hw5NuXNo9QiJuo7uAvL9tc67sWesWmTcT9dkDDnJb/78zQWxXeWEj5jGVSveO 5OOQKNBBFEsEv7lkHYg+vyzSslENqsConABgKq2PU9kt61dwwcN6jTx+mATuidxyMJyM 6E9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=wDJPpqFkDpum0KlfoyxLcFgA3Du8dYy69+BTF6fymm0=; b=EvK+ARHGbYxhv+fro2wUrLsdh8SmCuepNVLAZiG5gSdaDdCUCRQOzM3feDCNhWvPmD v2bkPqTjb1Va0BXQwCZ6NOFIuGFPk6ZOkOP6PzP/dC6pJN3w7GrkkW4S9cv5FHSymVLT 8lfkQ7eMlqWjv9mMUoNT4RWbJWBAB8GhM8JlDvg5tTjaZu5Kfv9lo8HrL2sp5nKIzvCR zuffA/oP60/wEgOw9ByUiLiGPeeg9kANCFqysyY7dxKWzT5QeOYecvSMWcU39nyzMTA4 pn0W9W3xfYVadq8wBvlF1gtBJZP/e9sfZ+uDGiUoKwTL9dAF1d/gP8zqNGaSsyqJygG9 V79w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si8673509pjw.103.2019.08.25.23.23.32; Sun, 25 Aug 2019 23:23:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729787AbfHZGWa (ORCPT + 99 others); Mon, 26 Aug 2019 02:22:30 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:52088 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729535AbfHZGWa (ORCPT ); Mon, 26 Aug 2019 02:22:30 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D53A21F461; Mon, 26 Aug 2019 06:22:29 +0000 (UTC) Date: Mon, 26 Aug 2019 06:22:29 +0000 From: Eric Wong To: Heiher Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Why the edge-triggered mode doesn't work for epoll file descriptor? Message-ID: <20190826062229.pjvumg4ag3qwhji6@whir> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Heiher wrote: > Hello, > > I've added a pipe file descriptor (fd1) to an epoll (fd3) with > EPOLLOUT in edge-triggered mode, and then added the fd3 to another > epoll (fd4) with EPOLLIN in edge-triggered too. > > Next, waiting for fd4 without timeout. When fd1 to be writable, i > think epoll_wait(fd4, ...) only return once, because all file > descriptors are added in edge-triggered mode. > > But, the actual result is returns many and many times until do once > eopll_wait(fd3, ...). It looks like you can trigger a wakeup loop with printf writing to the terminal (not a pipe), and that write to the terminal triggering the EPOLLOUT wakeup over and over again. I don't know TTY stuff at all, but I assume it's intended for terminals. You refer to "pipe file descriptor (fd1)", but I can't reproduce the error when running your code piped to "tee" and using strace to check epoll_wait returns. "strace ./foo | tee /dev/null" only shows one epoll_wait returning. > e.events = EPOLLIN | EPOLLET; > e.data.u64 = 1; > if (epoll_ctl (efd[0], EPOLL_CTL_ADD, efd[1], &e) < 0) > return -3; > > e.events = EPOLLOUT | EPOLLET; > e.data.u64 = 2; > if (epoll_ctl (efd[1], EPOLL_CTL_ADD, 1, &e) < 0) > return -4; Since epfd[1] is waiting for stdout... > for (;;) { > struct epoll_event events[16]; > int nfds; > > nfds = epoll_wait (efd[0], events, 16, -1); > printf ("nfds: %d\n", nfds); Try outputting your message to stderr instead of stdout: fprintf(stderr, "nfds: %d\n", nfds); And then run your program so stdout and stderr point to different files: ./foo | tee /dev/null (so stdout becomes a pipe, and stderr remains your terminal)