linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kaaira Gupta <kgupta@es.iitr.ac.in>
To: "Helen Koike" <helen.koike@collabora.com>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>
Cc: Kaaira Gupta <kgupta@es.iitr.ac.in>
Subject: [PATCH v2 2/3] media: vimc: Serialize vimc_streamer_s_stream()
Date: Fri, 24 Jul 2020 17:32:12 +0530	[thread overview]
Message-ID: <20200724120213.17119-3-kgupta@es.iitr.ac.in> (raw)
In-Reply-To: <20200724120213.17119-1-kgupta@es.iitr.ac.in>

Prepare for multiple video streams from the same sensor by serializing
vimc_streamer_s_stream(). Multiple streams will allow for multiple
concurrent calls to this function that could involve the same
subdevices.

If that happens the internal state of the involved subdevices could go
out of sync as they are being started and stopped at the same time,
prevent this by serializing starting and stopping of the vimc streamer.

[Kaaira: rebased the patch on current HEAD of media-tree
(8f2a4a9d5ff5202d0b3e3a144ebb9b67aabadd29)]

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
---
 .../media/test-drivers/vimc/vimc-streamer.c   | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c
index 451a32c0d034..5cd2f86a146a 100644
--- a/drivers/media/test-drivers/vimc/vimc-streamer.c
+++ b/drivers/media/test-drivers/vimc/vimc-streamer.c
@@ -192,18 +192,23 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
 			   struct vimc_ent_device *ved,
 			   int enable)
 {
+	static DEFINE_MUTEX(vimc_streamer_lock);
 	int ret;
 
 	if (!stream || !ved)
 		return -EINVAL;
 
+	ret = mutex_lock_interruptible(&vimc_streamer_lock);
+	if (ret)
+		return ret;
+
 	if (enable) {
 		if (stream->kthread)
-			return 0;
+			goto out;
 
 		ret = vimc_streamer_pipeline_init(stream, ved);
 		if (ret)
-			return ret;
+			goto out;
 
 		stream->kthread = kthread_run(vimc_streamer_thread, stream,
 					      "vimc-streamer thread");
@@ -211,14 +216,12 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
 		if (IS_ERR(stream->kthread)) {
 			ret = PTR_ERR(stream->kthread);
 			dev_err(ved->dev, "kthread_run failed with %d\n", ret);
-			vimc_streamer_pipeline_terminate(stream);
-			stream->kthread = NULL;
-			return ret;
+			goto out;
 		}
 
 	} else {
 		if (!stream->kthread)
-			return 0;
+			goto out;
 
 		ret = kthread_stop(stream->kthread);
 		/*
@@ -227,13 +230,17 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
 		 * a chance to run. Ignore errors to stop the stream in the
 		 * pipeline.
 		 */
-		if (ret)
+		if (ret) {
 			dev_dbg(ved->dev, "kthread_stop returned '%d'\n", ret);
+			goto out;
+		}
 
 		stream->kthread = NULL;
 
 		vimc_streamer_pipeline_terminate(stream);
 	}
+out:
+	mutex_unlock(&vimc_streamer_lock);
 
-	return 0;
+	return ret;
 }
-- 
2.17.1


  parent reply	other threads:[~2020-07-24 12:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 12:02 [PATCH v2 0/3] media: vimc: Allow multiple capture devices to use the same sensor Kaaira Gupta
2020-07-24 12:02 ` [PATCH v2 1/3] media: vimc: Add usage count to subdevices Kaaira Gupta
2020-07-24 12:02 ` Kaaira Gupta [this message]
2020-07-24 12:02 ` [PATCH v2 3/3] media: vimc: Join pipeline if one already exists Kaaira Gupta
2020-07-28 12:24   ` Dafna Hirschfeld
2020-07-28 12:48     ` Kaaira Gupta
2020-07-29 10:58       ` Dafna Hirschfeld
2020-07-24 12:15 ` [PATCH v2 0/3] media: vimc: Allow multiple capture devices to use the same sensor Niklas Söderlund
2020-07-24 12:21   ` Kaaira Gupta
2020-07-27 14:31     ` Kieran Bingham
2020-07-27 17:54       ` Helen Koike
2020-07-28 11:39         ` Kaaira Gupta
2020-07-28 12:07           ` Dafna Hirschfeld
2020-07-28 14:00             ` Dafna Hirschfeld
2020-07-28 14:26               ` Kaaira Gupta
2020-07-29 13:05               ` Kieran Bingham
2020-07-29 13:16                 ` Dafna Hirschfeld
2020-07-29 13:27                   ` Kieran Bingham
2020-07-29 15:24                     ` Dafna Hirschfeld
2020-07-31 17:22                       ` Kaaira Gupta
2020-08-04 10:24                         ` Kieran Bingham
2020-08-04 18:49                           ` Kaaira Gupta
2020-08-04 18:52                             ` Kaaira Gupta
2020-08-05 15:18                       ` Helen Koike
2020-07-30 10:51 ` Laurent Pinchart
2020-07-30 18:09   ` Kaaira Gupta
2020-07-30 22:21     ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200724120213.17119-3-kgupta@es.iitr.ac.in \
    --to=kgupta@es.iitr.ac.in \
    --cc=helen.koike@collabora.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).