All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Bara - SKIDATA <Benjamin.Bara@skidata.com>
To: "p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"mchehab@kernel.org" <mchehab@kernel.org>
Cc: "linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Richard Leitner - SKIDATA" <Richard.Leitner@skidata.com>
Subject: [PATCH] media: coda: avoid starvation on well-compressed data
Date: Fri, 21 Aug 2020 11:58:45 +0000	[thread overview]
Message-ID: <3b140eaf883b4666985c0be0db8d53e8@skidata.com> (raw)

The prefetcher requires two 256 byte periods beyond the current one.
However, currently it is only checked if there are at least 512 bytes
beyond the current meta available.
This only works under the assumption that every buffer has a size of
at least 256 bytes.

To ensure that the requirement is fulfilled with buffers < 256 bytes,
the queue head and the queue tail must not be below this threshold.
Otherwise, additional buffers are enqueued to ensure a full window.

Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com>
---
 drivers/media/platform/coda/coda-bit.c | 8 ++++++--
 drivers/media/platform/coda/coda.h     | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index b021604eceaa..8158f3b34b36 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -323,7 +323,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 {
 	struct vb2_v4l2_buffer *src_buf;
-	struct coda_buffer_meta *meta;
+	struct coda_buffer_meta *meta, *last_meta;
 	u32 start;
 
 	if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG)
@@ -343,6 +343,8 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 		    ctx->num_metas >= ctx->num_internal_frames) {
 			meta = list_first_entry(&ctx->buffer_meta_list,
 						struct coda_buffer_meta, list);
+			last_meta = list_last_entry(&ctx->buffer_meta_list,
+						struct coda_buffer_meta, list);
 
 			/*
 			 * If we managed to fill in at least a full reorder
@@ -352,7 +354,8 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 			 * the first buffer to fetch, we can safely stop queuing
 			 * in order to limit the decoder drain latency.
 			 */
-			if (coda_bitstream_can_fetch_past(ctx, meta->end))
+			if (!meta->below_threshold && !last_meta->below_threshold &&
+				coda_bitstream_can_fetch_past(ctx, meta->end))
 				break;
 		}
 
@@ -403,6 +406,7 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
 				meta->start = start;
 				meta->end = ctx->bitstream_fifo.kfifo.in;
 				meta->last = src_buf->flags & V4L2_BUF_FLAG_LAST;
+				meta->below_threshold = (meta->end - meta->start) < 256;
 				if (meta->last)
 					coda_dbg(1, ctx, "marking last meta");
 				spin_lock(&ctx->buffer_meta_lock);
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index b81f3aca9209..6f77553e81b8 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -160,6 +160,7 @@ struct coda_buffer_meta {
 	unsigned int		start;
 	unsigned int		end;
 	bool			last;
+	bool			below_threshold;
 };
 
 /* Per-queue, driver-specific private data */
-- 
2.25.1


             reply	other threads:[~2020-08-21 12:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 11:58 Benjamin Bara - SKIDATA [this message]
2020-08-21 11:59 ` [PATCH] media: coda: avoid starvation on well-compressed data Benjamin Bara - SKIDATA
2020-09-18  8:35   ` Benjamin Bara - SKIDATA
2020-09-28 20:06     ` Ezequiel Garcia
2020-10-06 14:56       ` Benjamin Bara - SKIDATA

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=3b140eaf883b4666985c0be0db8d53e8@skidata.com \
    --to=benjamin.bara@skidata.com \
    --cc=Richard.Leitner@skidata.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.