diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 763f4d77..25e62f15 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2466,7 +2466,7 @@ impl<'a> WaveGuard<'a> { enable_edge_filter: fctx.enable_edge_filter.with(std::cell::Cell::get), last_col: cols - 1, }); - let batch = crate::par::Batch::new(); + let batch = crate::par::Batch::new("ec-av1-recon"); for _ in 0..threads { let st = std::sync::Arc::clone(&st); batch.submit(move || wave_worker(&st)); @@ -2601,68 +2601,6 @@ fn push_intra( }); } -/// [`push_intra`] for a caller whose residual is dead after the record -- -/// the three fused coefficient readers, i.e. nearly every recorded write. -#[allow(clippy::too_many_arguments)] -fn push_intra_owned( - plane: usize, - x: usize, - y: usize, - side: usize, - mode: usize, - angle_delta: i32, - reach: Reach, - residual: Vec, - cfl: Option<(i32, CflSrc)>, - filter_intra: Option, - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, -) { - if inline_intra( - plane, x, y, side, side, false, mode, angle_delta, reach, &residual, cfl, filter_intra, - smooth_neighbor, fctx, - ) { - return; - } - let pred = take_palette_pred(fctx); - push_op(fctx, ReconOp::Intra { - plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach, - residual: Residual::Done(residual), cfl, filter_intra, smooth_neighbor, pred, - }); -} - -/// [`push_mc_rect`] with the residual moved in -- see [`push_intra_owned`]. -#[allow(clippy::too_many_arguments)] -fn push_mc_rect_owned( - plane: usize, - x: usize, - y: usize, - stride: usize, - w: usize, - h: usize, - prediction: Pred<'_>, - residual: Vec, fctx: &crate::decode::FrameCtx, -) { - let (src, stride) = match prediction.inline(stride) { - Some(v) => v, - None => { - let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; - push_op(fctx, ReconOp::Mc { - plane, x, y, stride: ss, w, h, - prediction: PredSrc::Cur { plane: sp, off, src: ss }, - residual: Residual::Done(residual), - }); - return; - } - }; - if inline_mc(plane, x, y, stride, w, h, src, &residual, fctx) { - return; - } - push_op(fctx, ReconOp::Mc { - plane, x, y, stride, w, h, prediction: PredSrc::Owned(src.to_vec()), - residual: Residual::Done(residual), - }); -} - /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)). #[allow(clippy::too_many_arguments)] fn push_intra_rect( @@ -34502,9 +34440,12 @@ mod tests { // below, are the real diagnosis. let mut stdin = child.stdin.take().expect("ffmpeg stdin"); let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); + let writer = std::thread::Builder::new() + .name("ec-av1-ffmpeg-in".into()) + .spawn(move || { + let _ = stdin.write_all(&payload); + }) + .expect("spawning the ffmpeg stdin writer"); let out = child.wait_with_output().expect("ffmpeg failed to run"); writer.join().expect("ffmpeg stdin writer thread"); assert!( @@ -34552,9 +34493,12 @@ mod tests { // below, are the real diagnosis. let mut stdin = child.stdin.take().expect("ffmpeg stdin"); let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); + let writer = std::thread::Builder::new() + .name("ec-av1-ffmpeg-in".into()) + .spawn(move || { + let _ = stdin.write_all(&payload); + }) + .expect("spawning the ffmpeg stdin writer"); let out = child.wait_with_output().expect("ffmpeg failed to run"); writer.join().expect("ffmpeg stdin writer thread"); assert!( diff --git a/crates/ec-av1/src/film_grain.rs b/crates/ec-av1/src/film_grain.rs index beb1e225..888f217d 100644 --- a/crates/ec-av1/src/film_grain.rs +++ b/crates/ec-av1/src/film_grain.rs @@ -1247,7 +1247,7 @@ pub(crate) fn apply_grain( y += row_step; } }); - drop(so); + let _ = so; out } diff --git a/crates/ec-av1/src/par.rs b/crates/ec-av1/src/par.rs index 911d1009..11149e91 100644 --- a/crates/ec-av1/src/par.rs +++ b/crates/ec-av1/src/par.rs @@ -125,7 +125,7 @@ where // lane-pool1: same shape as the `thread::scope` this replaced -- // band 0 inline, the rest on this thread's persistent pool, all // waited out by `batch`'s drop at the end of the block. - let batch = Batch::new(); + let batch = Batch::new("ec-av1-filter"); for &(a, b) in rest { let ctx = crate::decode::filter_ctx_copy(fctx); let f = &f; @@ -239,7 +239,12 @@ impl Pool { /// Queues `job` and makes sure a worker is free for it: the pool grows to /// `busy + queued` threads and never shrinks, so a submitted job always /// starts, even when every other running job is blocked waiting for it. - fn push(&mut self, job: Job) { + /// `class` names the submitting site of the job that grows the pool, so a + /// profiler attributes the thread to the work that created it + /// (`ec-av1-frame`, `ec-av1-recon`, `ec-av1-filter`). One pool serves + /// every class a thread submits, so later classes on the same pool reuse + /// the threads an earlier one named. + fn push(&mut self, job: Job, class: &'static str) { let want = { let mut q = self.inner.q.lock().unwrap(); q.jobs.push_back(job); @@ -247,8 +252,13 @@ impl Pool { }; while self.handles.len() < want { let inner = std::sync::Arc::clone(&self.inner); - self.handles - .push(std::thread::spawn(move || pool_worker(&inner))); + let name = format!("{class}-{}", self.handles.len()); + self.handles.push( + std::thread::Builder::new() + .name(name) + .spawn(move || pool_worker(&inner)) + .expect("spawning an ec-av1 pool worker"), + ); } self.inner.cv.notify_one(); } @@ -289,12 +299,16 @@ struct BatchState { /// indentation for the same guarantee. pub(crate) struct Batch<'a> { st: std::sync::Arc, + class: &'static str, _p: std::marker::PhantomData<&'a ()>, } impl<'a> Batch<'a> { - pub(crate) fn new() -> Self { + /// `class` is the thread-name prefix for any pool worker this batch has + /// to spawn -- see [`Pool::push`]. + pub(crate) fn new(class: &'static str) -> Self { Self { + class, st: std::sync::Arc::new(BatchState { left: std::sync::Mutex::new(0), cv: std::sync::Condvar::new(), @@ -325,7 +339,7 @@ impl<'a> Batch<'a> { let job: Job = unsafe { std::mem::transmute::, Job>(job) }; POOL.with(|p| { let mut p = p.borrow_mut(); - p.get_or_insert_with(Pool::new).push(job); + p.get_or_insert_with(Pool::new).push(job, self.class); }); } } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b02bd714..d55cad0a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -487,7 +487,7 @@ pub fn decode_stream_with_threads( // across frames, so their `thread_local!` decode scratch survives the // frame). `jobs` is declared here and dropped at the end of the function, // including on `?`, so no job outlives the data it borrows. - let jobs = crate::par::Batch::new(); + let jobs = crate::par::Batch::new("ec-av1-frame"); // lane-thread1: this stream's per-frame decode state (was 38 thread_local // statics in decode.rs) -- one object, threaded down the decode call graph. let fctx = &crate::decode::FrameCtx::new(); @@ -3002,9 +3002,12 @@ mod tests { // below, are the real diagnosis. let mut stdin = child.stdin.take().expect("ffmpeg stdin"); let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); + let writer = std::thread::Builder::new() + .name("ec-av1-ffmpeg-in".into()) + .spawn(move || { + let _ = stdin.write_all(&payload); + }) + .expect("spawning the ffmpeg stdin writer"); let out = child.wait_with_output().expect("ffmpeg failed to run"); writer.join().expect("ffmpeg stdin writer thread"); assert!( @@ -3064,9 +3067,12 @@ mod tests { // below, are the real diagnosis. let mut stdin = child.stdin.take().expect("ffmpeg stdin"); let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); + let writer = std::thread::Builder::new() + .name("ec-av1-ffmpeg-in".into()) + .spawn(move || { + let _ = stdin.write_all(&payload); + }) + .expect("spawning the ffmpeg stdin writer"); let out = child.wait_with_output().expect("ffmpeg failed to run"); writer.join().expect("ffmpeg stdin writer thread"); assert!( @@ -11203,9 +11209,12 @@ mod tests { // does (one 384x256 cq-10 encode hung for 40 minutes). let mut aom_stdin = child.stdin.take().expect("aomenc stdin"); let y4m_bytes = y4m.stdout; - let feeder = std::thread::spawn(move || { - aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc"); - }); + let feeder = std::thread::Builder::new() + .name("ec-av1-aomenc-in".into()) + .spawn(move || { + aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc"); + }) + .expect("spawning the aomenc stdin feeder"); let out = child.wait_with_output().expect("aomenc failed to run"); feeder.join().expect("y4m feeder thread"); assert!(