]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: test-drivers: vivid: don't call schedule in loop
authorHans Verkuil <hverkuil@xs4all.nl>
Mon, 9 Dec 2024 15:00:16 +0000 (16:00 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 18 Feb 2025 07:11:36 +0000 (08:11 +0100)
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>
drivers/media/test-drivers/vivid/vivid-kthread-cap.c
drivers/media/test-drivers/vivid/vivid-kthread-out.c
drivers/media/test-drivers/vivid/vivid-kthread-touch.c
drivers/media/test-drivers/vivid/vivid-sdr-cap.c

index 669bd96da4c7956788b52efec6c6e2371c7493d5..273e8ed8c2a9084a6a839bdca7fe138bee92c72e 100644 (file)
@@ -789,9 +789,14 @@ static int vivid_thread_vid_cap(void *data)
                        next_jiffies_since_start = jiffies_since_start;
 
                wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-               while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
-                      !kthread_should_stop())
-                       schedule();
+               if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
+                       continue;
+
+               wait_queue_head_t wait;
+
+               init_waitqueue_head(&wait);
+               wait_event_interruptible_timeout(wait, kthread_should_stop(),
+                                       cur_jiffies + wait_jiffies - jiffies);
        }
        dprintk(dev, 1, "Video Capture Thread End\n");
        return 0;
index fac6208b51da84bfaf8d9e4858579289ebe6ce34..015a7b166a1e61d09d68917650a8042ddf70f784 100644 (file)
@@ -235,9 +235,14 @@ static int vivid_thread_vid_out(void *data)
                        next_jiffies_since_start = jiffies_since_start;
 
                wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-               while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
-                      !kthread_should_stop())
-                       schedule();
+               if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
+                       continue;
+
+               wait_queue_head_t wait;
+
+               init_waitqueue_head(&wait);
+               wait_event_interruptible_timeout(wait, kthread_should_stop(),
+                                       cur_jiffies + wait_jiffies - jiffies);
        }
        dprintk(dev, 1, "Video Output Thread End\n");
        return 0;
index fa711ee36a3fbca1bfe07a8806e241e134581e0b..c862689786b69c052440623720fa5a93120e1fd7 100644 (file)
@@ -135,9 +135,14 @@ static int vivid_thread_touch_cap(void *data)
                        next_jiffies_since_start = jiffies_since_start;
 
                wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-               while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
-                      !kthread_should_stop())
-                       schedule();
+               if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
+                       continue;
+
+               wait_queue_head_t wait;
+
+               init_waitqueue_head(&wait);
+               wait_event_interruptible_timeout(wait, kthread_should_stop(),
+                                       cur_jiffies + wait_jiffies - jiffies);
        }
        dprintk(dev, 1, "Touch Capture Thread End\n");
        return 0;
index 74a91d28c8be936b2c4cb0cc297625d91d7a27a7..c633fc2ed664f5437fc2fd0bba17fcf7d11f97ee 100644 (file)
@@ -206,9 +206,14 @@ static int vivid_thread_sdr_cap(void *data)
                        next_jiffies_since_start = jiffies_since_start;
 
                wait_jiffies = next_jiffies_since_start - jiffies_since_start;
-               while (time_is_after_jiffies(cur_jiffies + wait_jiffies) &&
-                      !kthread_should_stop())
-                       schedule();
+               if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
+                       continue;
+
+               wait_queue_head_t wait;
+
+               init_waitqueue_head(&wait);
+               wait_event_interruptible_timeout(wait, kthread_should_stop(),
+                                       cur_jiffies + wait_jiffies - jiffies);
        }
        dprintk(dev, 1, "SDR Capture Thread End\n");
        return 0;