#asahi-dev · 2023-08-04 07:20
marcanwhere's the deadlock?#asahi-dev · 2023-08-04 07:20
marcanif the queue has 6 empty buffers, you request 6 frames from ISP, they come back. you mark all those buffers as full. userspace dequeues one, enqueues it, dequeues another one, enqueues it, etc. until it either runs out of all 6 or the driver decides to ask ISP for more data#asahi-dev · 2023-08-04 07:19
marcanI'm lost#asahi-dev · 2023-08-04 07:19
eilndelivery/dequeue are the same#asahi-dev · 2023-08-04 07:19
eilnones I process are marked done and out of the queue#asahi-dev · 2023-08-04 07:18
marcanonce at least 2 are enqueued again you can fetch another batch (of at least size 2)#asahi-dev · 2023-08-04 07:18
marcanactually no, if you do 6 why wouldn't that work? they'd pop one, and add one, but there's 5 more left to pop so it won't block#asahi-dev · 2023-08-04 07:17
marcanyeah, so you never want to do the full queue size#asahi-dev · 2023-08-04 07:17
eiln** waits for me to process, which I'm blocking#asahi-dev · 2023-08-04 07:16
eilnthe buf_dq ioctl waits #asahi-dev · 2023-08-04 07:15
eilnif there's 6 in, I can process 2-6 at once. if i do 6, they'd pop one, and add one. the next dequeue would hang without a way to enqueue#asahi-dev · 2023-08-04 07:13
marcanI'm trying to understand how that works, sort of looks like an additional buffer count?#asahi-dev · 2023-08-04 07:13
marcaneiln: looks like queue_setup is allowed to do stuff with the buffer count, see e.g. v4l2-pci-skeleton.c#asahi-dev · 2023-08-04 07:07
marcanhttps://www.kernel.org/doc/html/v4.9/media/uapi/v4l/vidioc-g-parm.html <- you also need to set readbuffers to 2+ I think#asahi-dev · 2023-08-04 07:06
marcanso that would work perfectly fine with your use case#asahi-dev · 2023-08-04 07:06
marcanfwiw I just checked ffplay and it requests 256 buffers, gets 32, pops 6, then starts alternately queuing and dequeuing, eventually catching up with more queueing (?)#asahi-dev · 2023-08-04 07:05
eilnyeah, mostly the interrupt/ack dance#asahi-dev · 2023-08-04 07:05
marcanlarger batches = more efficient, more latency I assume#asahi-dev · 2023-08-04 07:04
marcannot sure, might be worth experimenting with.#asahi-dev · 2023-08-04 07:03
eilnshould I bother changing the batch count?#asahi-dev · 2023-08-04 07:03
eilnI'll definitely check with userspace#asahi-dev · 2023-08-04 07:02
marcanand only submit a request to ISP once you have at least 2#asahi-dev · 2023-08-04 07:02
marcanI think it's perfectly fine to block if there's only one buffer queued#asahi-dev · 2023-08-04 07:02
marcanyeah, but it looks like exactly your use case in practice#asahi-dev · 2023-08-04 07:01
eilnthat's only checked once before start_streaming is called#asahi-dev · 2023-08-04 07:01
marcanand that looks like exactly your use case#asahi-dev · 2023-08-04 07:01
marcanlooks like you need to set that to 2#asahi-dev · 2023-08-04 07:01
marcanhttps://www.kernel.org/doc/html/v4.9/media/kapi/v4l2-videobuf2.html <- see min_buffers_needed#asahi-dev · 2023-08-04 06:59
marcanone thing you *could* do is unconditionally always allocate at least 1 more buffer than userspace requested, so that if userspace is trying to allocate some exact number of buffers it wants "in flight", there will always be one extra one in the queue (but userspace could still use too many in that case anyway)#asahi-dev · 2023-08-04 06:59
marcanwithout any random blocks#asahi-dev · 2023-08-04 06:59
marcannormally you expect buffers to be dequeued, processed, and enqueued again#asahi-dev · 2023-08-04 06:58
marcanyeah, but is there any userspace out there that breaks like this?#asahi-dev · 2023-08-04 06:58
eilnit's that I need 2 queued, which isn't a requirement anywhere#asahi-dev · 2023-08-04 06:57
marcanthere's a reason there were 2+ buffers to begin with#asahi-dev · 2023-08-04 06:56
marcanif userspace refuses to give buffers back and waits for a new one, that's its problem#asahi-dev · 2023-08-04 06:56
marcanyeah, that's fine#asahi-dev · 2023-08-04 06:56
eilnIt'd be stuck cause userspace polls till dequeue signal#asahi-dev · 2023-08-04 06:56
marcanif we find stuff that breaks under that model, we get it fixed :)#asahi-dev · 2023-08-04 06:56
marcanthat's a userspace problem#asahi-dev · 2023-08-04 06:55
marcanyeah, so then that blocks#asahi-dev · 2023-08-04 06:55
eilnthey can dequeue all four at once, then enqueue just one, which leaves me with 1 frame#asahi-dev · 2023-08-04 06:55
marcanso the idea is you force the buffer count allocated to always be at least 2 (or 4), and then tell ISP it's okay to deliver 2 frames once 2 free buffers are available#asahi-dev · 2023-08-04 06:54
marcanright#asahi-dev · 2023-08-04 06:54
eilnunder read_frame in case IO_METHOD_MMAP, the user dequeues a (done) buffer, and enqueues another for processing#asahi-dev · 2023-08-04 06:53
marcanI think I don't really understand what the problem is#asahi-dev · 2023-08-04 06:53
eilnbut delivery is dequeue. http://www.infradead.org/~mchehab/kernel_docs/userspace-api/media/v4l/capture.c.html#asahi-dev · 2023-08-04 06:52
marcanif you want to guarantee you can double-buffer, you could make the minimum 4#asahi-dev · 2023-08-04 06:50
marcanisp delivers 2 frames, user pops one, user pops another one, isp delivers 2 frames, etc#asahi-dev · 2023-08-04 06:50
marcanyes, but then you have 2 buffers available so it should work, no?#asahi-dev · 2023-08-04 06:50
eilnafter starting the stream it's the user's job to re-queue to keep the stream going