From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B08B4439F63 for ; Fri, 31 Jul 2026 15:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785510914; cv=none; b=ZQorUoeT0/bxYoiH5EO6pj/CG3SZwfu98mi7fGW/DIlmh9jxSmI+FToBVqgQHxM4xaEsjsF+jusuzN9dLLpxdtg6KusS7wAhyUvOuoqz8Y38RRtRt4kZVvPKqWwDZ4bmkEa1HTIv19R4bidvP5kvUD1TQTsUvD2m1EZ60cNS4dI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785510914; c=relaxed/simple; bh=A3noVpkk4le+S0U8Rri7M6Js4eWHNKTb7JBke706bxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T1fMhhX6bVF6k7a2qrS8MC3JVLrhtv85wPVYs2/2QvounnzUncN7Rdtgt2lRx+nDk00yNDRIyR1gGhpxd30qAP86e6Uiac2R90zLMhpqW1nmlhUrdTk3n/ItnX/JDBCS/vuAiBuG1iRqeAfV9ykovz5qLVVxGWjmQylTLJj0saY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Obhhb9DT; arc=none smtp.client-ip=209.85.128.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Obhhb9DT" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-80e2cfe6918so11850967b3.0 for ; Fri, 31 Jul 2026 08:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785510911; x=1786115711; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YQqtFdxzNfQ2GMY5lHTyx8q45qE8mZiIcTjEqgZzs3I=; b=Obhhb9DTolFf+HwKG9lO9v75jQdPEHKnTqS8OZfzcQ1kiY3mVEbPBtDsd+wd+02WgY dNFpylfQ14nf1lnCHidoAVDFIOpLqTFK2Smo/ISb9C6CsiftLo1PokyqaDa1+4yf3VK0 vzBe2kz2p/HhOlgAeAsqWvdZumXJwrXB/MYODOHpcsGehRXEeGpuEsyJjbR8p1x9qd6k wZ0YC6C+jyUSiQyNmop3RKNzVq8qggOJIuPqxsfWy1YI8cJWR3awIFbsN2374YYNTXIo uHeem0/1A9shRf4K+/zuK62YQCTXPaFCuc7rck9ieSnf44TulqJLZed8Rkb2ZgSOQnUs iSZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785510911; x=1786115711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=YQqtFdxzNfQ2GMY5lHTyx8q45qE8mZiIcTjEqgZzs3I=; b=JEr7Mw16meBeCA90zE+sKpuSGALF6ehYBIJnBdsRwfuqoECB+3NYpN8ygBMWlSLNe1 OiLcP0vRYcIGzQJ96B0/AQNu6BMR/A9WNoM8G1wAimGJsyVsxnk0M3fjJ0o5ebFVp2OK 8MxhlZinz6B14+R4LY58fdofmDbHRxS6uR2QcB67LxfTbD8euFV8LAcl4te7R6ftU1Q9 nGEFBP/dWhK43KNshpm8k7nd+OpgYe1/lB+c9AAQRZ/sRJUogTRpgKjlbQ7s6uxnJUmo lvY3WIaW1yZgQLe1W1cXoyy77vOJgty+XtZKnGJvKLkUyygeZU/aYg13pSWfhuLQVo0k u/8Q== X-Forwarded-Encrypted: i=1; AHgh+Rpu20Yv1mhm/ol6evzWzdO4UQYhuYqHUVxfRlV8R/hIsXF3lFIw5F0gAUMVJYUhoa3BQaS/01VvpOFUE+c=@vger.kernel.org X-Gm-Message-State: AOJu0YyGlXQS+6ziVyc4afTN9X+yvVx1t0+jyh9Ebb9nGl9LqRLNd8yA EsudAWgA1IsqUUMjaPU/V3eLSggs1Q2P3wGKCFVDqOIw4Z4DqY+9TUBO X-Gm-Gg: AR+sD13Vv/ztgeNsnabZeyKBkRa3L02ANipir7AxS7Tl64la/PBFpB2z0MxgqzGOENv zdzqcB+o9OWfyc+1Y1a+GQkd/ZvbxE5fFAfpT6sC9Q0z25tnJW80LTZ4B5NPiIf3gid3ffYLqw4 ficHMkciIeLR+8i9N9dVNt7Z+qOisoziL4jUjQzwQtPC0zKvmd7D2o9N+GVxcb5POuizg+gfFZ4 NywZIskzKeHhLXSssE2oRvZsCEv1kIv0vNyRYviB4pzbXTVN3YQvfZPG0/jGTzNCer+yDs/jhYR J7jHVPScfR3ix0rQKkBPMn2oOydLpbWyGk0iuFFsWSW+6JJnfyr5ZsoCiArAj3b7LQFfaB+yQnK L89gMJtyE40kRpF9dt15noe4JnZIeklWxr3MI0f632MZobd5lElg1L791DCYGMK6B83jiWLHGj6 ZbtnDQ+02y4FxcdRvvi4kZhDx/ragypikkQJ+khTXn1f2nAFbQqPiz7m29lw== X-Received: by 2002:a05:690c:4442:b0:81e:c972:e8c3 with SMTP id 00721157ae682-81fd4ba85d1mr2580787b3.29.1785510911223; Fri, 31 Jul 2026 08:15:11 -0700 (PDT) Received: from llmbox.. ([38.81.85.65]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd0d6995sm8212147b3.32.2026.07.31.08.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 08:15:10 -0700 (PDT) From: Michael Jordan To: Ricardo Ribalda Cc: laurent.pinchart@ideasonboard.com, hansg@kernel.org, mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read Date: Fri, 31 Jul 2026 11:15:09 -0400 Message-ID: <20260731151509.577383-1-jordan.mymail@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Ricardo, On Fri, 31 Jul 2026 10:33:02 +0200, Ricardo Ribalda wrote: > Dear Michael Jordan > > (I always wanted to start an email like that :P) Happy to have been able to help with that. > I am not against the idea proposed by this patch, but I would like to > understand your use case a bit better. Do you want to know where the > camera is because: > - You want to do something continuously with that info (e.g., tagging > frames with the live position)? > - Or because you just want to know when the camera has actually > finished moving? The former. The application computes framing adjustments from the current pose -- "move 10 degrees left of wherever you are now" needs to know where "now" is -- and shows live position while the gimbal moves. A single end-of-move notification would not be enough even for the commanded-move case, and it does not exist at all for the autonomous one, which brings me to: > You also mentioned that the camera can reposition itself. Do you mean > that the camera could be tracking something and decide to move on its > own? Yes, exactly that. This camera (and similar PTZ conference cameras) has on-device AI tracking: once enabled, the gimbal follows a person continuously, for minutes at a time, with no host involvement at all. While tracking is active the position is a continuously varying quantity with no SET_CUR in flight and no "end of movement" to report. That is the case that made me give up on every event-shaped mechanism: > If it is the latter, you could use V4L2 control events. That should > work perfectly for signalling the end of a move: Three separate things go wrong, in increasing order of stubbornness: - uvcvideo's device-originated control events come from exactly one place, uvc_ctrl_status_event(), fed by the Control Change interrupt, and the spec only promises that interrupt "at the end of the movement" (4.2.2.1.15). So even a perfect device yields one event per move, not a trajectory. - This device never emits the interrupt at all. GET_INFO on CT_PANTILT_ABSOLUTE_CONTROL returns 0x03 -- neither D3 (Autoupdate) nor D4 (Asynchronous) -- so the event path has nothing to deliver. (Arguably a firmware defect per 2.4.4, but it looks systemic: the value is identical across every CT control on this device, so the firmware is not computing it per control.) - Under autonomous tracking there is no end of movement, so even compliant firmware would have nothing to hook the event to. > - Because your patch uses UVC_CTRL_DATA_CURRENT for the > read-modify-write path, the control will send (100, 300). That will > unintentionally move both axes, yanking the PAN back to 100 and > fighting the camera's autonomous tracking. The behaviour is real, but the patch does not introduce it: the write path is byte-identical before and after. What the RMW merges against today is decided by the device's GET_INFO bits, and both outcomes you are weighing already ship: - On a device whose GET_INFO clears AUTO_UPDATE (this one), ctrl->loaded stays set after the commit, so the tilt write merges against the cached setpoint and sends (100, 300) -- your scenario, reproduced exactly, on an unpatched kernel. - On a device that reports Autoupdate, uvc_ctrl_commit_entity() clears ctrl->loaded, so the tilt write does a fresh GET_CUR and merges against live data, sending (200, 300) -- kind to the tracker, but this is the variant that cancels a move the *user* commanded: issue two single-axis writes a few tens of milliseconds apart, and the second merges against a live reading in which the first axis has barely left its old position, and commits it right back. I have measured that second failure on real hardware (this camera keeps AUTO_UPDATE when probed while asleep, since it does not answer GET_INFO in that state -- its own small horror story): S_CTRL(pan), then S_CTRL(tilt) ~20ms later, and pan is yanked back to where it started. Same hardware with AUTO_UPDATE cleared, both axes reach their targets. Both merge sources are in the tree today; the patch adds neither and removes neither. If anything the patch improves your scenario slightly on Autoupdate devices: reads no longer set ctrl->loaded, so the write path can no longer merge against a stale sample frozen in the cache by an earlier G_CTRL. > What I think we should do instead is manage the cache validity based > on who "owns" the control. For ASYNCHRONOUS controls that have an > active handle (i.e., a user-commanded move that has not completed), we > mark them as "loaded". But when they are owned/updated by the device > autonomously, we never mark them as loaded. I think ownership is the right frame -- for the write path. Which merge source is correct genuinely depends on who owns the control: while a user move is in flight, the setpoint (live data cancels the move); while the device owns it, live data (the setpoint fights the tracker). That is a real pre-existing problem, your scenario is a good demonstration of one horn of it, and I would be glad to help fix it. But I do not think it can replace this patch, for the reason you already identified: > This specific logic still doesn't support polling the live mid-flight > position of a user-commanded move, but maybe V4L2 events can cover > your actual use case? Right -- and the mid-flight (or mid-tracking) position is the entire use case. However the write path picks its merge source, G_CTRL still has to report the actual position, which is what this patch does without touching the merge at all. The two compose: an ownership- based write path plus a live read path leaves nothing stale anywhere. Two practical notes on the pseudo-code: > - ctrl->loaded = 1; > + if (!FLAG_AUTO_UPDATE) > + ctrl->loaded = 1; __uvc_ctrl_load_cur() fills UVC_CTRL_DATA_CURRENT, which is the RMW source, so with this hunk every load puts live data where the write path merges -- the user-move cancellation above, now unconditional on every Autoupdate device. Keeping the live value in a buffer of its own is precisely how the patch avoids creating that. Separately, anything keyed on AUTO_UPDATE or ASYNCHRONOUS will not trigger on this device, since GET_INFO reports neither -- one reason the patch uses a static table flag that uvc_ctrl_get_flags() does not rewrite. The ownership logic would also need a completion signal for "the move has finished", and the only candidate is the Control Change interrupt this firmware never sends. Happy to respin if you would like any of this argued in the commit message itself -- the autonomous-tracking use case in particular is probably worth stating there rather than in a reply. Thanks again for the review. Best regards, Michael Jordan