forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-t900' (196962d8): worker threads named by class (frame/recon/filter), dead wavefront helpers deleted, last warning cleared; byte-exact

Browse files at this commit

f37b756d14d2b3d4c4c367b97c9ba96e5c0314a0Ahmet Kaan GümüşParent: 2504add9a4d798
crates/ec-av1/src/decode.rsmodified+13 -69
@@ -2466,7 +2466,7 @@ impl<'a> WaveGuard<'a> {
2466 enable_edge_filter: fctx.enable_edge_filter.with(std::cell::Cell::get),2466 enable_edge_filter: fctx.enable_edge_filter.with(std::cell::Cell::get),
2467 last_col: cols - 1,2467 last_col: cols - 1,
2468 });2468 });
2469- let batch = crate::par::Batch::new();2469+ let batch = crate::par::Batch::new("ec-av1-recon");
2470 for _ in 0..threads {2470 for _ in 0..threads {
2471 let st = std::sync::Arc::clone(&st);2471 let st = std::sync::Arc::clone(&st);
2472 batch.submit(move || wave_worker(&st));2472 batch.submit(move || wave_worker(&st));
@@ -2601,68 +2601,6 @@ fn push_intra(
2601 });2601 });
2602 }2602 }
2603 2603
2604-/// [`push_intra`] for a caller whose residual is dead after the record --
2605-/// the three fused coefficient readers, i.e. nearly every recorded write.
2606-#[allow(clippy::too_many_arguments)]
2607-fn push_intra_owned(
2608- plane: usize,
2609- x: usize,
2610- y: usize,
2611- side: usize,
2612- mode: usize,
2613- angle_delta: i32,
2614- reach: Reach,
2615- residual: Vec<i32>,
2616- cfl: Option<(i32, CflSrc)>,
2617- filter_intra: Option<usize>,
2618- smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2619-) {
2620- if inline_intra(
2621- plane, x, y, side, side, false, mode, angle_delta, reach, &residual, cfl, filter_intra,
2622- smooth_neighbor, fctx,
2623- ) {
2624- return;
2625- }
2626- let pred = take_palette_pred(fctx);
2627- push_op(fctx, ReconOp::Intra {
2628- plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
2629- residual: Residual::Done(residual), cfl, filter_intra, smooth_neighbor, pred,
2630- });
2631-}
2632-
2633-/// [`push_mc_rect`] with the residual moved in -- see [`push_intra_owned`].
2634-#[allow(clippy::too_many_arguments)]
2635-fn push_mc_rect_owned(
2636- plane: usize,
2637- x: usize,
2638- y: usize,
2639- stride: usize,
2640- w: usize,
2641- h: usize,
2642- prediction: Pred<'_>,
2643- residual: Vec<i32>, fctx: &crate::decode::FrameCtx,
2644-) {
2645- let (src, stride) = match prediction.inline(stride) {
2646- Some(v) => v,
2647- None => {
2648- let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() };
2649- push_op(fctx, ReconOp::Mc {
2650- plane, x, y, stride: ss, w, h,
2651- prediction: PredSrc::Cur { plane: sp, off, src: ss },
2652- residual: Residual::Done(residual),
2653- });
2654- return;
2655- }
2656- };
2657- if inline_mc(plane, x, y, stride, w, h, src, &residual, fctx) {
2658- return;
2659- }
2660- push_op(fctx, ReconOp::Mc {
2661- plane, x, y, stride, w, h, prediction: PredSrc::Owned(src.to_vec()),
2662- residual: Residual::Done(residual),
2663- });
2664-}
2665-
2666 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).2604 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).
2667 #[allow(clippy::too_many_arguments)]2605 #[allow(clippy::too_many_arguments)]
2668 fn push_intra_rect(2606 fn push_intra_rect(
@@ -34502,9 +34440,12 @@ mod tests {
34502 // below, are the real diagnosis.34440 // below, are the real diagnosis.
34503 let mut stdin = child.stdin.take().expect("ffmpeg stdin");34441 let mut stdin = child.stdin.take().expect("ffmpeg stdin");
34504 let payload = stream.to_vec();34442 let payload = stream.to_vec();
34505- let writer = std::thread::spawn(move || {34443+ let writer = std::thread::Builder::new()
34506- let _ = stdin.write_all(&payload);34444+ .name("ec-av1-ffmpeg-in".into())
34507- });34445+ .spawn(move || {
34446+ let _ = stdin.write_all(&payload);
34447+ })
34448+ .expect("spawning the ffmpeg stdin writer");
34508 let out = child.wait_with_output().expect("ffmpeg failed to run");34449 let out = child.wait_with_output().expect("ffmpeg failed to run");
34509 writer.join().expect("ffmpeg stdin writer thread");34450 writer.join().expect("ffmpeg stdin writer thread");
34510 assert!(34451 assert!(
@@ -34552,9 +34493,12 @@ mod tests {
34552 // below, are the real diagnosis.34493 // below, are the real diagnosis.
34553 let mut stdin = child.stdin.take().expect("ffmpeg stdin");34494 let mut stdin = child.stdin.take().expect("ffmpeg stdin");
34554 let payload = stream.to_vec();34495 let payload = stream.to_vec();
34555- let writer = std::thread::spawn(move || {34496+ let writer = std::thread::Builder::new()
34556- let _ = stdin.write_all(&payload);34497+ .name("ec-av1-ffmpeg-in".into())
34557- });34498+ .spawn(move || {
34499+ let _ = stdin.write_all(&payload);
34500+ })
34501+ .expect("spawning the ffmpeg stdin writer");
34558 let out = child.wait_with_output().expect("ffmpeg failed to run");34502 let out = child.wait_with_output().expect("ffmpeg failed to run");
34559 writer.join().expect("ffmpeg stdin writer thread");34503 writer.join().expect("ffmpeg stdin writer thread");
34560 assert!(34504 assert!(
crates/ec-av1/src/film_grain.rsmodified+1 -1
@@ -1247,7 +1247,7 @@ pub(crate) fn apply_grain(
1247 y += row_step;1247 y += row_step;
1248 }1248 }
1249 });1249 });
1250- drop(so);1250+ let _ = so;
1251 1251
1252 out1252 out
1253 }1253 }
crates/ec-av1/src/par.rsmodified+20 -6
@@ -125,7 +125,7 @@ where
125 // lane-pool1: same shape as the `thread::scope` this replaced --125 // lane-pool1: same shape as the `thread::scope` this replaced --
126 // band 0 inline, the rest on this thread's persistent pool, all126 // band 0 inline, the rest on this thread's persistent pool, all
127 // waited out by `batch`'s drop at the end of the block.127 // waited out by `batch`'s drop at the end of the block.
128- let batch = Batch::new();128+ let batch = Batch::new("ec-av1-filter");
129 for &(a, b) in rest {129 for &(a, b) in rest {
130 let ctx = crate::decode::filter_ctx_copy(fctx);130 let ctx = crate::decode::filter_ctx_copy(fctx);
131 let f = &f;131 let f = &f;
@@ -239,7 +239,12 @@ impl Pool {
239 /// Queues `job` and makes sure a worker is free for it: the pool grows to239 /// Queues `job` and makes sure a worker is free for it: the pool grows to
240 /// `busy + queued` threads and never shrinks, so a submitted job always240 /// `busy + queued` threads and never shrinks, so a submitted job always
241 /// starts, even when every other running job is blocked waiting for it.241 /// starts, even when every other running job is blocked waiting for it.
242- fn push(&mut self, job: Job) {242+ /// `class` names the submitting site of the job that grows the pool, so a
243+ /// profiler attributes the thread to the work that created it
244+ /// (`ec-av1-frame`, `ec-av1-recon`, `ec-av1-filter`). One pool serves
245+ /// every class a thread submits, so later classes on the same pool reuse
246+ /// the threads an earlier one named.
247+ fn push(&mut self, job: Job, class: &'static str) {
243 let want = {248 let want = {
244 let mut q = self.inner.q.lock().unwrap();249 let mut q = self.inner.q.lock().unwrap();
245 q.jobs.push_back(job);250 q.jobs.push_back(job);
@@ -247,8 +252,13 @@ impl Pool {
247 };252 };
248 while self.handles.len() < want {253 while self.handles.len() < want {
249 let inner = std::sync::Arc::clone(&self.inner);254 let inner = std::sync::Arc::clone(&self.inner);
250- self.handles255+ let name = format!("{class}-{}", self.handles.len());
251- .push(std::thread::spawn(move || pool_worker(&inner)));256+ self.handles.push(
257+ std::thread::Builder::new()
258+ .name(name)
259+ .spawn(move || pool_worker(&inner))
260+ .expect("spawning an ec-av1 pool worker"),
261+ );
252 }262 }
253 self.inner.cv.notify_one();263 self.inner.cv.notify_one();
254 }264 }
@@ -289,12 +299,16 @@ struct BatchState {
289 /// indentation for the same guarantee.299 /// indentation for the same guarantee.
290 pub(crate) struct Batch<'a> {300 pub(crate) struct Batch<'a> {
291 st: std::sync::Arc<BatchState>,301 st: std::sync::Arc<BatchState>,
302+ class: &'static str,
292 _p: std::marker::PhantomData<&'a ()>,303 _p: std::marker::PhantomData<&'a ()>,
293 }304 }
294 305
295 impl<'a> Batch<'a> {306 impl<'a> Batch<'a> {
296- pub(crate) fn new() -> Self {307+ /// `class` is the thread-name prefix for any pool worker this batch has
308+ /// to spawn -- see [`Pool::push`].
309+ pub(crate) fn new(class: &'static str) -> Self {
297 Self {310 Self {
311+ class,
298 st: std::sync::Arc::new(BatchState {312 st: std::sync::Arc::new(BatchState {
299 left: std::sync::Mutex::new(0),313 left: std::sync::Mutex::new(0),
300 cv: std::sync::Condvar::new(),314 cv: std::sync::Condvar::new(),
@@ -325,7 +339,7 @@ impl<'a> Batch<'a> {
325 let job: Job = unsafe { std::mem::transmute::<Box<dyn FnOnce() + Send + 'a>, Job>(job) };339 let job: Job = unsafe { std::mem::transmute::<Box<dyn FnOnce() + Send + 'a>, Job>(job) };
326 POOL.with(|p| {340 POOL.with(|p| {
327 let mut p = p.borrow_mut();341 let mut p = p.borrow_mut();
328- p.get_or_insert_with(Pool::new).push(job);342+ p.get_or_insert_with(Pool::new).push(job, self.class);
329 });343 });
330 }344 }
331 }345 }
crates/ec-av1/src/stream.rsmodified+19 -10
@@ -487,7 +487,7 @@ pub fn decode_stream_with_threads(
487 // across frames, so their `thread_local!` decode scratch survives the487 // across frames, so their `thread_local!` decode scratch survives the
488 // frame). `jobs` is declared here and dropped at the end of the function,488 // frame). `jobs` is declared here and dropped at the end of the function,
489 // including on `?`, so no job outlives the data it borrows.489 // including on `?`, so no job outlives the data it borrows.
490- let jobs = crate::par::Batch::new();490+ let jobs = crate::par::Batch::new("ec-av1-frame");
491 // lane-thread1: this stream's per-frame decode state (was 38 thread_local491 // lane-thread1: this stream's per-frame decode state (was 38 thread_local
492 // statics in decode.rs) -- one object, threaded down the decode call graph.492 // statics in decode.rs) -- one object, threaded down the decode call graph.
493 let fctx = &crate::decode::FrameCtx::new();493 let fctx = &crate::decode::FrameCtx::new();
@@ -3002,9 +3002,12 @@ mod tests {
3002 // below, are the real diagnosis.3002 // below, are the real diagnosis.
3003 let mut stdin = child.stdin.take().expect("ffmpeg stdin");3003 let mut stdin = child.stdin.take().expect("ffmpeg stdin");
3004 let payload = stream.to_vec();3004 let payload = stream.to_vec();
3005- let writer = std::thread::spawn(move || {3005+ let writer = std::thread::Builder::new()
3006- let _ = stdin.write_all(&payload);3006+ .name("ec-av1-ffmpeg-in".into())
3007- });3007+ .spawn(move || {
3008+ let _ = stdin.write_all(&payload);
3009+ })
3010+ .expect("spawning the ffmpeg stdin writer");
3008 let out = child.wait_with_output().expect("ffmpeg failed to run");3011 let out = child.wait_with_output().expect("ffmpeg failed to run");
3009 writer.join().expect("ffmpeg stdin writer thread");3012 writer.join().expect("ffmpeg stdin writer thread");
3010 assert!(3013 assert!(
@@ -3064,9 +3067,12 @@ mod tests {
3064 // below, are the real diagnosis.3067 // below, are the real diagnosis.
3065 let mut stdin = child.stdin.take().expect("ffmpeg stdin");3068 let mut stdin = child.stdin.take().expect("ffmpeg stdin");
3066 let payload = stream.to_vec();3069 let payload = stream.to_vec();
3067- let writer = std::thread::spawn(move || {3070+ let writer = std::thread::Builder::new()
3068- let _ = stdin.write_all(&payload);3071+ .name("ec-av1-ffmpeg-in".into())
3069- });3072+ .spawn(move || {
3073+ let _ = stdin.write_all(&payload);
3074+ })
3075+ .expect("spawning the ffmpeg stdin writer");
3070 let out = child.wait_with_output().expect("ffmpeg failed to run");3076 let out = child.wait_with_output().expect("ffmpeg failed to run");
3071 writer.join().expect("ffmpeg stdin writer thread");3077 writer.join().expect("ffmpeg stdin writer thread");
3072 assert!(3078 assert!(
@@ -11203,9 +11209,12 @@ mod tests {
11203 // does (one 384x256 cq-10 encode hung for 40 minutes).11209 // does (one 384x256 cq-10 encode hung for 40 minutes).
11204 let mut aom_stdin = child.stdin.take().expect("aomenc stdin");11210 let mut aom_stdin = child.stdin.take().expect("aomenc stdin");
11205 let y4m_bytes = y4m.stdout;11211 let y4m_bytes = y4m.stdout;
11206- let feeder = std::thread::spawn(move || {11212+ let feeder = std::thread::Builder::new()
11207- aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc");11213+ .name("ec-av1-aomenc-in".into())
11208- });11214+ .spawn(move || {
11215+ aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc");
11216+ })
11217+ .expect("spawning the aomenc stdin feeder");
11209 let out = child.wait_with_output().expect("aomenc failed to run");11218 let out = child.wait_with_output().expect("aomenc failed to run");
11210 feeder.join().expect("y4m feeder thread");11219 feeder.join().expect("y4m feeder thread");
11211 assert!(11220 assert!(