From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684659225; x=1687251225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sqtDDozTOlthebRUJxjtH4raL3FSx7h0r6eE1CFuZwQ=; b=ZsfkswJ1XArrXM1UiXeFv8wTu1BckVu/bc73wWmp/n+gcLiziUBOapNWZ+MlvYTMES 4pW5L5owVsONFaP2izil7BKNWwEkmBeAnSIej2+nwMzpGyVip69WrQ7/f9crC6TSk1+W gRgf6sZwIK0ok2qQrAoD7/Xm6fC2gg9tFGAupBvbalrnXzTONDSoPR0GiGfLge7PY0cP DVo12b7GC63/TJG/p+KwBM577Ow3dX6X1Arg1VMsDLQQfHabLYpQgV7HO3rn8TEJ6NrK NSntQI2jTjgWTYsQ36LYc7MeJ6avTkn9qp9MuOh3z5qGN0YHYA/e6QBz54fUdSUSgk3z G2Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684659225; x=1687251225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sqtDDozTOlthebRUJxjtH4raL3FSx7h0r6eE1CFuZwQ=; b=P1sIN5E9dQ3rVv1yg5HXawENuVkw/S8o+ZOynHGC26sg7KWlSaGcQvgXDy9NoHgxEl cJd/LIFt+op36RNX80Tu9bUAAeYXgZ+tV/EOfe47S51hf2Rkriub+35MjuxufO/Vjjy5 TIuw4DbTa+kO6Nn/UkTOLO73Bw85gKX7wuzt1V+3FgiYNqrH6WCF/HYC3tPpEM++38Jx NsWv/1md6fGIWBLuoCfpzPKV5ZHc/EaXaoCVmYllzkL5njQKt31xw+XdIOvVNabqgCru Go7nFh6zRYKvVo85OyDmJYJ1oVwbFitC/3CgVfuUnR4xga8YcJ6X8V2MGmufCTHdJOvZ BkPQ== X-Gm-Message-State: AC+VfDxTE1ctxVaAvTvy7cB1dD9/yJK7Rs6XUTlTxmRvEwz3Gv+pUCTF XVWgMWKb1blnKdhmTPP82mNZfHUjmEQ= X-Google-Smtp-Source: ACHHUZ49VT5TkqGmSfyHlO9RvFxTi0prUuwIqKuANXn0xQWEDmEaXfjYITkRpwhI32IgiFum6dPWMw== X-Received: by 2002:a5d:4b12:0:b0:309:4b55:419d with SMTP id v18-20020a5d4b12000000b003094b55419dmr2624582wrq.8.1684659225374; Sun, 21 May 2023 01:53:45 -0700 (PDT) From: Alexey Gladkov To: make-initrd@lists.altlinux.org Date: Sun, 21 May 2023 10:53:26 +0200 Message-Id: <20230521085326.308119-1-gladkov.alexey@gmail.com> X-Mailer: git-send-email 2.33.8 In-Reply-To: <5522f0c1-adac-3db7-e569-05cda6d05d58@gmail.com> References: <5522f0c1-adac-3db7-e569-05cda6d05d58@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [make-initrd] [PATCH] ueventd: Don't use a epoll timeout when it's not needed X-BeenThere: make-initrd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: make-initrd@lists.altlinux.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 May 2023 08:53:48 -0000 Archived-At: List-Archive: The timeout is used to process queues that have unprocessed events (dirty ones) even when no new events have arrived in the queue. When there are no dirty queues, then there is no point in extra iterations of the main loop. Signed-off-by: Alexey Gladkov --- datasrc/ueventd/ueventd.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/datasrc/ueventd/ueventd.c b/datasrc/ueventd/ueventd.c index 857d3b4f..afe050d0 100644 --- a/datasrc/ueventd/ueventd.c +++ b/datasrc/ueventd/ueventd.c @@ -56,7 +56,8 @@ enum { PIPE_MAX, }; -int pipefd[PIPE_MAX]; +static int pipefd[PIPE_MAX]; +static int dirty_queues = 0; #define EV_PAUSE_MASK (IN_CREATE | IN_DELETE | IN_ONLYDIR) #define EV_ROOT_MASK (IN_CREATE | IN_ONLYDIR) @@ -121,8 +122,10 @@ int watch_path(int inotifyfd, const char *dir, const char *name, uint32_t mask, new->next = watch_list; if (flags & F_QUEUE_DIR) { - if (!empty_directory(path)) + if (!empty_directory(path)) { new->q_flags |= F_DIRTY; + dirty_queues++; + } new->q_parentfd = pipefd[PIPE_WRITE]; } @@ -339,8 +342,10 @@ int process_inotify_events(int inotifyfd) continue; } - if (!(p->q_flags & F_DIRTY)) + if (!(p->q_flags & F_DIRTY)) { p->q_flags |= F_DIRTY; + dirty_queues++; + } } } return 0; @@ -375,8 +380,10 @@ int process_pipefd_events(int readfd) for (p = watch_list; p; p = p->next) { if (!(p->q_flags & F_QUEUE_DIR) || p->q_watchfd != value) continue; - if (!(p->q_flags & F_DIRTY)) + if (!(p->q_flags & F_DIRTY)) { p->q_flags |= F_DIRTY; + dirty_queues++; + } break; } } @@ -521,7 +528,7 @@ int main(int argc, char **argv) int fdcount; errno = 0; - fdcount = epoll_wait(epollfd, ev, EV_MAX, 250); + fdcount = epoll_wait(epollfd, ev, EV_MAX, (dirty_queues ? 250 : -1)); if (fdcount < 0) { if (errno == EINTR) @@ -542,6 +549,12 @@ int main(int argc, char **argv) for (e = watch_list; e; e = e->next) { if (!(e->q_flags & F_QUEUE_DIR) || !(e->q_flags & F_DIRTY) || (e->q_pid != 0) || (e->q_flags & F_PAUSED)) continue; + + if (dirty_queues == 0) + rd_fatal("BUG: dirty_queues == 0, but dirty queues are present"); + + dirty_queues--; + e->q_flags &= ~F_DIRTY; e->q_pid = spawn_worker(epollfd, e); } -- 2.33.8