Skip to content

Commit 60d20cb

Browse files
hverkuilopsiff
authored andcommitted
media: test-drivers: vivid: don't call schedule in loop
[ Upstream commit e474011 ] Artem reported that the CPU load was 100% when capturing from vivid at low resolution with ffmpeg. This was caused by: while (time_is_after_jiffies(cur_jiffies + wait_jiffies) && !kthread_should_stop()) schedule(); If there are no other processes running that can be scheduled, then this is basically a busy-loop. Change it to wait_event_interruptible_timeout() which doesn't have that problem. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Reported-by: Artem S. Tashkinov <aros@gmx.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219570 Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit a9b2bb8a4f25b0b85a541625c310f892271fd794)
1 parent aed3a1f commit 60d20cb

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

drivers/media/test-drivers/vivid/vivid-kthread-cap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,14 @@ static int vivid_thread_vid_cap(void *data)
765765
next_jiffies_since_start = jiffies_since_start;
766766

767767
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
768-
while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
769-
!kthread_should_stop())
770-
schedule();
768+
if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
769+
continue;
770+
771+
wait_queue_head_t wait;
772+
773+
init_waitqueue_head(&wait);
774+
wait_event_interruptible_timeout(wait, kthread_should_stop(),
775+
cur_jiffies + wait_jiffies - jiffies);
771776
}
772777
dprintk(dev, 1, "Video Capture Thread End\n");
773778
return 0;

drivers/media/test-drivers/vivid/vivid-kthread-out.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,14 @@ static int vivid_thread_vid_out(void *data)
235235
next_jiffies_since_start = jiffies_since_start;
236236

237237
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
238-
while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
239-
!kthread_should_stop())
240-
schedule();
238+
if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
239+
continue;
240+
241+
wait_queue_head_t wait;
242+
243+
init_waitqueue_head(&wait);
244+
wait_event_interruptible_timeout(wait, kthread_should_stop(),
245+
cur_jiffies + wait_jiffies - jiffies);
241246
}
242247
dprintk(dev, 1, "Video Output Thread End\n");
243248
return 0;

drivers/media/test-drivers/vivid/vivid-kthread-touch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ static int vivid_thread_touch_cap(void *data)
135135
next_jiffies_since_start = jiffies_since_start;
136136

137137
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
138-
while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
139-
!kthread_should_stop())
140-
schedule();
138+
if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
139+
continue;
140+
141+
wait_queue_head_t wait;
142+
143+
init_waitqueue_head(&wait);
144+
wait_event_interruptible_timeout(wait, kthread_should_stop(),
145+
cur_jiffies + wait_jiffies - jiffies);
141146
}
142147
dprintk(dev, 1, "Touch Capture Thread End\n");
143148
return 0;

drivers/media/test-drivers/vivid/vivid-sdr-cap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,14 @@ static int vivid_thread_sdr_cap(void *data)
206206
next_jiffies_since_start = jiffies_since_start;
207207

208208
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
209-
while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
210-
!kthread_should_stop())
211-
schedule();
209+
if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
210+
continue;
211+
212+
wait_queue_head_t wait;
213+
214+
init_waitqueue_head(&wait);
215+
wait_event_interruptible_timeout(wait, kthread_should_stop(),
216+
cur_jiffies + wait_jiffies - jiffies);
212217
}
213218
dprintk(dev, 1, "SDR Capture Thread End\n");
214219
return 0;

0 commit comments

Comments
 (0)