[{"id":37525,"web_url":"https://patchwork.libcamera.org/comment/37525/","msgid":"<20260107235434.GJ20168@pendragon.ideasonboard.com>","date":"2026-01-07T23:54:34","subject":"Re: [PATCH v1] libcamera: base: event_dispatcher_poll: Dispatch\n\t`POLLPRI` first","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Wed, Jan 07, 2026 at 08:55:37PM +0100, Barnabás Pőcze wrote:\n> When `poll()` returns multiple events for a given file descriptor, it is better\n> to service priority events first. So dispatch those first, and not last.\n> \n> For example, a v4l2 capture device might be a source of v4l2 events (e.g. frame\n\ns/v4l2/V4L2/g\n\n> start) as well as a source of dequeue-able buffers. In such cases, given the\n> appropriate scheduling, it is possible with the current event dispatch order\n> that dequeueing the buffer happens before processing the corresponding frame\n> start event. Such occurrence will most likely trip up any internal state machine.\n\nHmmm... This is a tricky one. I think this patch is fine for now, but we\nmay later need to make the order configurable per file descriptor.\nDespite the name, there's no universal rule that I'm aware of that\nindicates POLLPRI events always need to be processed first in all use\ncases.\n\nFor V4L2 devices and our usage patterns I think this is fine. We don't\nuse POLLPRI for any other device type at the moment, so I think we can\njust merge this and hope it won't come to bite us back. And when it\nwill, we'll see how to address the issues.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> The above is suspected to contribute to [0], however, that is not confirmed.\n> \n> [0]: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  src/libcamera/base/event_dispatcher_poll.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp\n> index 52bfb34e2..006e223f8 100644\n> --- a/src/libcamera/base/event_dispatcher_poll.cpp\n> +++ b/src/libcamera/base/event_dispatcher_poll.cpp\n> @@ -244,9 +244,9 @@ void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pol\n>  \t\tEventNotifier::Type type;\n>  \t\tshort events;\n>  \t} events[] = {\n> +\t\t{ EventNotifier::Exception, POLLPRI },\n>  \t\t{ EventNotifier::Read, POLLIN },\n>  \t\t{ EventNotifier::Write, POLLOUT },\n> -\t\t{ EventNotifier::Exception, POLLPRI },\n>  \t};\n>  \n>  \tprocessingEvents_ = true;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C7810BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  7 Jan 2026 23:54:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1AA2761FC1;\n\tThu,  8 Jan 2026 00:54:55 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B19161F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Jan 2026 00:54:53 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-152.bb.dnainternet.fi\n\t[81.175.209.152])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 10BFF3A2;\n\tThu,  8 Jan 2026 00:54:30 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"p63ADBmx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1767830071;\n\tbh=IQd0W1AGa1U1r1lNducX2m7IbKAcM536aZIrKhsVMTU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=p63ADBmxFiq3DB3QaloSsikECxuIZL932Feukfs2PNP9x7SG5BQTCRGwYmt/kq509\n\tnQRz28d2U34rMNxonoNaQ+K+I7gAp2PfGppwMX7b4I4bb22+ZagK4HNV4/04W2zEdD\n\tAJuNiXmi/n8niaKWd6ZvGXQMVXJtEEGB05fiqlkg=","Date":"Thu, 8 Jan 2026 01:54:34 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tDavid Plowman <david.plowman@raspberrypi.com>","Subject":"Re: [PATCH v1] libcamera: base: event_dispatcher_poll: Dispatch\n\t`POLLPRI` first","Message-ID":"<20260107235434.GJ20168@pendragon.ideasonboard.com>","References":"<20260107195537.2180637-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260107195537.2180637-1-barnabas.pocze@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":37559,"web_url":"https://patchwork.libcamera.org/comment/37559/","msgid":"<CAEmqJPr76tvS+e=SZibWK7JE+J8QTJ11BwF8_TqSxfQHHRqPnw@mail.gmail.com>","date":"2026-01-12T09:47:37","subject":"Re: [PATCH v1] libcamera: base: event_dispatcher_poll: Dispatch\n\t`POLLPRI` first","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Barnabás,\n\nThank you for this patch\n\nOn Wed, 7 Jan 2026 at 19:55, Barnabás Pőcze\n<barnabas.pocze@ideasonboard.com> wrote:\n>\n> When `poll()` returns multiple events for a given file descriptor, it is better\n> to service priority events first. So dispatch those first, and not last.\n>\n> For example, a v4l2 capture device might be a source of v4l2 events (e.g. frame\n> start) as well as a source of dequeue-able buffers. In such cases, given the\n> appropriate scheduling, it is possible with the current event dispatch order\n> that dequeueing the buffer happens before processing the corresponding frame\n> start event. Such occurrence will most likely trip up any internal state machine.\n>\n> The above is suspected to contribute to [0], however, that is not confirmed.\n>\n> [0]: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n\nThere is definitely an assumption in DelayedControls that the frame\nstart v4l2 event occurs before the dequeue event.  It should be quite\neasy to fix, but the behavior would be suboptimal in terms of setting\nsensor parameters.  I think this fix should be applied regardless.\n\n>\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  src/libcamera/base/event_dispatcher_poll.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp\n> index 52bfb34e2..006e223f8 100644\n> --- a/src/libcamera/base/event_dispatcher_poll.cpp\n> +++ b/src/libcamera/base/event_dispatcher_poll.cpp\n> @@ -244,9 +244,9 @@ void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pol\n>                 EventNotifier::Type type;\n>                 short events;\n>         } events[] = {\n> +               { EventNotifier::Exception, POLLPRI },\n>                 { EventNotifier::Read, POLLIN },\n>                 { EventNotifier::Write, POLLOUT },\n> -               { EventNotifier::Exception, POLLPRI },\n>         };\n>\n>         processingEvents_ = true;\n> --\n> 2.52.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2454CBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jan 2026 09:48:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BA76761FC1;\n\tMon, 12 Jan 2026 10:48:16 +0100 (CET)","from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com\n\t[IPv6:2607:f8b0:4864:20::e2f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A565661F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jan 2026 10:48:14 +0100 (CET)","by mail-vs1-xe2f.google.com with SMTP id\n\tada2fe7eead31-5ed048478b0so167104137.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jan 2026 01:48:14 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"p6A2SJNO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1768211293; x=1768816093;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=G7hmsXJAtxsIFL7znd15RkiI36h+D4T8yOT0+mvEVdI=;\n\tb=p6A2SJNOSPmDMB4omLXEUK2Qs9ED0Rd5HD02QjzrsBniFD+SsBkLPOZ2ASnOGtb5zE\n\tEpgmThGuQMSIoa6bwlGsUs3+t6NAEJghcsA9jBezonCMrGhm0Ed8o8i0UpL62oNICDYj\n\tumglJv51w7DOAhu56EsrL7RxhjA3ngcxKvhdBWw0xdVfr2bC/n1gT7VvGyjLlIEfQcen\n\tfRE7D84DqGqCGAAiRG8lx6ugSL8ZVd4iqKFedR44W4TmpU/SXvCpYzQ+/QkG0vrR0wDW\n\tkZjFa732KCOFOIRl47pz7EQ8xlcncDE1E5eUAEhv/H9yzedSHGdfc+hv8d6gncVlDU9S\n\t1O1A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1768211293; x=1768816093;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=G7hmsXJAtxsIFL7znd15RkiI36h+D4T8yOT0+mvEVdI=;\n\tb=IO58iOTeF1+NqOu3FpCua9z6M8ZhZEGNMnptysi+emJmXoErJJbZMA7/35EkFeh1Ub\n\tl1L/BVvM2J2q8XgvKyMNKL3xcrXwK8wSEllEtktG415X2+FkVmA9RtA1/7s+1qcJ0mjw\n\tFx15d4oQsklyQlZQqENbKkTt4DnsPyAtLrQWxNgDJmSFwTnE05fVi9oGK5w+P93X/VqG\n\t9q0LC61BArHs3Mz7LmXfKP2Rco2BesFVlGxRHctJoi6LUOgKjS19arQudwfaS3NltQVL\n\tJduplNkUitdR2f2lnxtvBM2ceMPAsXfHXf07FeSjGLtsppWKbj5Wmx51oJYdcMRFIBVP\n\trBhQ==","X-Gm-Message-State":"AOJu0Yywp7j3b1PyB+KdsIECSz431tzjUz6o9+6vjeaiExAYf3SjGrTR\n\tcUgRZDAestdxKnI+secZXz/59NnxRzRSurxdfqglH6EeoZ0a7iqAd98gcfBFa/Nm0xM1co/ovOb\n\tjlKBE2qSCFfZmlm8c3kwEFBvlxLoq8LV+UUqvHEu4kQ==","X-Gm-Gg":"AY/fxX6fwd7Q7CQQWxweTeSE1C2z/MlTuh6Vhv+TL2080/d2LZllpoqkF1/vlr0o2Nr\n\tbunN1hyujLsr9nI+r3DpsASjcUtWBQEvGa1gCOQvnFr6oXbmYwXEowTfHRJobql2ut94aFc2O6J\n\t7cl8fnIdLgRuNtp7YThyMGaETJy1K6wAtSqE2YaMnVrDWb4hAMhpsq/U1zd2PnY9Pbu91VdYVKS\n\tLbhHRCSefRBH7Mx9Tt84PFtZHTn1PEMs9PgZ1DafVyBFe/vHxScqx6oBgtcBwckXqVTTkjuFnEv\n\t54SypNbSIvoSnxWMteQORfJS3WE=","X-Google-Smtp-Source":"AGHT+IG1yie8Mui4PZnm1FDJ30zhGmfuffXop7XO9J5gU27cwOhXBfPytdY4gQhjJijF66/0A4v2Kf4rZEwCvZAJhRU=","X-Received":"by 2002:a67:c497:0:b0:5e1:8746:85ed with SMTP id\n\tada2fe7eead31-5ecb6918f85mr3021458137.4.1768211293607;\n\tMon, 12 Jan 2026 01:48:13 -0800 (PST)","MIME-Version":"1.0","References":"<20260107195537.2180637-1-barnabas.pocze@ideasonboard.com>","In-Reply-To":"<20260107195537.2180637-1-barnabas.pocze@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 12 Jan 2026 09:47:37 +0000","X-Gm-Features":"AZwV_Qj8uJuqBLAbVqMuu7r_jS1KYMnRAGfOwBRfuwniMxhE0KditHH0ew_jREM","Message-ID":"<CAEmqJPr76tvS+e=SZibWK7JE+J8QTJ11BwF8_TqSxfQHHRqPnw@mail.gmail.com>","Subject":"Re: [PATCH v1] libcamera: base: event_dispatcher_poll: Dispatch\n\t`POLLPRI` first","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tDavid Plowman <david.plowman@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]