LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Eric Anholt <eric@anholt.net>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	linux-rpi-kernel@lists.infradead.org,
	Stefan Wahren <stefan.wahren@i2se.com>
Cc: Eric Anholt <eric@anholt.net>,
	Dave Stevenson <dave.stevenson@raspberrypi.org>
Subject: [PATCH 04/15] staging: bcm2835-camera: Allocate context once per buffer
Date: Thu, 10 May 2018 12:42:08 -0700	[thread overview]
Message-ID: <20180510194220.30675-5-eric@anholt.net> (raw)
In-Reply-To: <20180510194220.30675-1-eric@anholt.net>

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

The struct mmal_msg_context was being allocated for every message
being sent to the VPU, and freed when it came back.  Whilst that is
required behaviour for some messages (mainly the synchronous ones), it
is wasteful for the video buffers that make up the majority of the
traffic.

Add to the buffer_init/cleanup hooks that it allocates/frees the
msg_context required.

v2: changes by anholt from the downstream tree: clean up indentation,
    pass an error value through, forward-declare the struct so we have
    less void *

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Eric Anholt <eric@anholt.net>
---
 .../bcm2835-camera/bcm2835-camera.c           | 30 +++++++++++++--
 .../bcm2835-camera/mmal-common.h              |  4 ++
 .../vc04_services/bcm2835-camera/mmal-vchiq.c | 38 ++++++++++++++-----
 .../vc04_services/bcm2835-camera/mmal-vchiq.h |  3 ++
 4 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 7b32c3a93873..dc1c2775bc0b 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -278,6 +278,20 @@ static int queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
+static int buffer_init(struct vb2_buffer *vb)
+{
+	struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
+	struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
+
+	v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p, vb %p\n",
+		 __func__, dev, vb);
+	buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+	buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
+
+	return mmal_vchi_buffer_init(dev->instance, buf);
+}
+
 static int buffer_prepare(struct vb2_buffer *vb)
 {
 	struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
@@ -300,6 +314,17 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
+static void buffer_cleanup(struct vb2_buffer *vb)
+{
+	struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
+	struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
+
+	v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p, vb %p\n",
+		 __func__, dev, vb);
+	mmal_vchi_buffer_cleanup(buf);
+}
+
 static inline bool is_capturing(struct bm2835_mmal_dev *dev)
 {
 	return dev->capture.camera_port ==
@@ -467,9 +492,6 @@ static void buffer_queue(struct vb2_buffer *vb)
 	v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
 		 "%s: dev:%p buf:%p\n", __func__, dev, buf);
 
-	buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
-	buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
-
 	ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
 	if (ret < 0)
 		v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
@@ -632,7 +654,9 @@ static void bm2835_mmal_unlock(struct vb2_queue *vq)
 
 static const struct vb2_ops bm2835_mmal_video_qops = {
 	.queue_setup = queue_setup,
+	.buf_init = buffer_init,
 	.buf_prepare = buffer_prepare,
+	.buf_cleanup = buffer_cleanup,
 	.buf_queue = buffer_queue,
 	.start_streaming = start_streaming,
 	.stop_streaming = stop_streaming,
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
index e68ca1bf7222..fe079d054174 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
@@ -19,6 +19,8 @@
 /** Special value signalling that time is not known */
 #define MMAL_TIME_UNKNOWN (1LL<<63)
 
+struct mmal_msg_context;
+
 /* mapping between v4l and mmal video modes */
 struct mmal_fmt {
 	char  *name;
@@ -43,6 +45,8 @@ struct mmal_buffer {
 
 	void *buffer; /* buffer pointer */
 	unsigned long buffer_size; /* size of allocated buffer */
+
+	struct mmal_msg_context *msg_context;
 };
 
 /* */
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index a91ef6ea29ce..037c68b83df9 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -321,8 +321,6 @@ static void buffer_work_cb(struct work_struct *work)
 					    msg_context->u.bulk.dts,
 					    msg_context->u.bulk.pts);
 
-	/* release message context */
-	release_msg_context(msg_context);
 }
 
 /* enqueue a bulk receive for a given message context */
@@ -503,11 +501,13 @@ buffer_from_host(struct vchiq_mmal_instance *instance,
 		return -EINTR;
 
 	/* get context */
-	msg_context = get_msg_context(instance);
-	if (IS_ERR(msg_context)) {
-		ret = PTR_ERR(msg_context);
+	if (!buf->msg_context) {
+		pr_err("%s: msg_context not allocated, buf %p\n", __func__,
+		       buf);
+		ret = -EINVAL;
 		goto unlock;
 	}
+	msg_context = buf->msg_context;
 
 	/* store bulk message context for when data arrives */
 	msg_context->u.bulk.instance = instance;
@@ -557,11 +557,6 @@ buffer_from_host(struct vchiq_mmal_instance *instance,
 					sizeof(struct mmal_msg_header) +
 					sizeof(m.u.buffer_from_host));
 
-	if (ret != 0) {
-		release_msg_context(msg_context);
-		/* todo: is this correct error value? */
-	}
-
 	vchi_service_release(instance->handle);
 
 unlock:
@@ -1775,6 +1770,29 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
 	return 0;
 }
 
+int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
+			  struct mmal_buffer *buf)
+{
+	struct mmal_msg_context *msg_context = get_msg_context(instance);
+
+	if (IS_ERR(msg_context))
+		return (PTR_ERR(msg_context));
+
+	buf->msg_context = msg_context;
+	return 0;
+}
+
+int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf)
+{
+	struct mmal_msg_context *msg_context = buf->msg_context;
+
+	if (msg_context)
+		release_msg_context(msg_context);
+	buf->msg_context = NULL;
+
+	return 0;
+}
+
 /* Initialise a mmal component and its ports
  *
  */
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
index b1f22b6dca10..dadf47fe1bdc 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
@@ -168,4 +168,7 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
 			     struct vchiq_mmal_port *port,
 			     struct mmal_buffer *buf);
 
+int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
+			  struct mmal_buffer *buf);
+int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
 #endif /* MMAL_VCHIQ_H */
-- 
2.17.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2018-05-10 19:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10 19:42 [PATCH 00/15] staging: bcm2835-camera probing and cleanup Eric Anholt
2018-05-10 19:42 ` [PATCH 01/15] staging/vc04_services: Register a platform device for the camera driver Eric Anholt
2018-05-10 19:42 ` [PATCH 02/15] staging/bcm2835-camera: Set ourselves up as a platform driver Eric Anholt
2018-05-10 19:42 ` [PATCH 03/15] staging: bcm2835-camera: Skip ISP pass to eliminate padding Eric Anholt
2018-05-10 19:42 ` Eric Anholt [this message]
2018-05-10 19:42 ` [PATCH 05/15] staging: bcm2835-camera: Remove bulk_mutex as it is not required Eric Anholt
2018-05-10 19:42 ` [PATCH 06/15] staging: bcm2835-camera: Match MMAL buffer count to V4L2 Eric Anholt
2018-05-10 19:42 ` [PATCH 07/15] staging: bcm2835-camera: Remove V4L2/MMAL buffer remapping Eric Anholt
2018-05-10 19:42 ` [PATCH 08/15] staging: bcm2835-camera: Add multiple include protection Eric Anholt
2018-05-10 19:42 ` [PATCH 09/15] staging: bcm2835-camera: Move struct vchiq_mmal_rect Eric Anholt
2018-05-10 19:42 ` [PATCH 10/15] staging: bcm2835-camera: Replace BUG_ON with return error Eric Anholt
2018-05-10 19:42 ` [PATCH 11/15] staging: bcm2835-camera: Fix comment typos Eric Anholt
2018-05-10 19:42 ` [PATCH 12/12] staging: bcm2835-camera: Fix identation of tables Eric Anholt
2018-05-10 19:57   ` Eric Anholt
2018-05-10 19:42 ` [PATCH 12/15] staging: bcm2835-camera: Fix indentation " Eric Anholt
2018-05-10 19:42 ` [PATCH 13/15] staging: bcm2835-camera: Fix warnings about string ops on v4l2 uapi Eric Anholt
2018-05-15  9:22   ` Dan Carpenter
2018-05-10 19:42 ` [PATCH 14/15] staging: bcm2835: Remove dead code related to framerate Eric Anholt
2018-05-10 19:42 ` [PATCH 15/15] staging: bcm2835: Fix mmal_port_parameter_get() signed/unsigned warnings Eric Anholt

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=20180510194220.30675-5-eric@anholt.net \
    --to=eric@anholt.net \
    --cc=dave.stevenson@raspberrypi.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=stefan.wahren@i2se.com \
    --subject='Re: [PATCH 04/15] staging: bcm2835-camera: Allocate context once per buffer' \
    /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

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).