Re: [RFC PATCH v7 8/8] samples: rust: Add JobQueue Tester

From: Younes Akhouayri

Date: Tue Nov 03 2026 - 17:28:06 EST


On Tue, 3 Nov 2026 16:31:38 +0100, Philipp Stanner wrote:
> + drop(jq); // Release lock.
> + T::run_job(work.fctx, runnable_job);
> + jq = work.inner.lock(); // Retake lock.
> +
> + // run_job() above needs to be called without lock protection. Thus,
> + // it is possible that the driver instructed completion right before
> + // we could re-take the lock.
> + if jq.last_completed >= seqno {
> + fence.signal(Ok(()));
> +
> + // Drop here directly if possible. Otherwise, let the DropWorker
> + // take care of it.
> + if core::mem::needs_drop::<T::JobDataType>() {
> + jq.drop_list.push_back(job);
> + }
> + } else {
> + jq.running_jobs.push_back(job);
> + }

Hi Philip,

The job's cost is subtracted from jq.capacity further up in the loop.
complete_jobs_up_to_seqno() restores capacity only for jobs it pops from
running_jobs, and a job that takes this branch never gets there. So each
completion that wins the race against the worker leaves `cost` credits
consumed for good, and a queue with a small capacity would stall after a few
of them.

The tester takes this branch too, since it calls complete_jobs_up_to_seqno()
right after submit, before the worker has run. Each job costs 1 out of a
capacity of 1_000_000, so the leak never shows there.

Is there a reason the credits are meant to stay consumed here, or should
this branch do

+ *jq.as_mut().project().capacity += u64::from(job.cost);

as well?

> + last_completed: 0,

FenceContext::new(initial_seqno, ...) hands out initial_seqno as the first
fence seqno, and both the doc example and the tester pass 0. For that first
job the check above becomes `0 >= 0`, so the worker signals the fence Ok
right after run_job() returns, while the hardware is still working on it.

Should last_completed start at initial_seqno.wrapping_sub(1), or is
initial_seqno >= 1 an intended requirement that just needs documenting?

Best regards,
Younes