V4L/DVB (9804): cx18: Avoid making firmware API calls with the queue lock held

cx18: Avoid making firmware API calls with the queue lock held.  The source
of MPEG strem corruption when not holding the queue lock was found to be that
the MPEG buffer could be retrieved by the user app before it was sync'ed for
the host cpu.  Incoming buffers are now sync'ed before being put on q_full and
releasing the queue lock.  We can thus avoid the sometimes lengthy call to
the firmware for CPU_DE_SET_MDL while holding the queue lock, so we can get
better performance.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Andy Walls 2008-12-12 15:50:27 -03:00 committed by Mauro Carvalho Chehab
parent 765f6f612e
commit abb096de82
4 changed files with 29 additions and 36 deletions

View File

@ -163,7 +163,7 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_epu_work_order *order)
* it's filled in). * it's filled in).
* *
* cx18_queue_get buf() will detect the lost buffers * cx18_queue_get buf() will detect the lost buffers
* and put them back in rotation eventually. * and send them back to q_free for fw rotation eventually.
*/ */
if ((order->flags & CX18_F_EWO_MB_STALE_UPON_RECEIPT) && if ((order->flags & CX18_F_EWO_MB_STALE_UPON_RECEIPT) &&
!(id >= s->mdl_offset && !(id >= s->mdl_offset &&
@ -174,24 +174,27 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_epu_work_order *order)
break; break;
} }
buf = cx18_queue_get_buf(s, id, mdl_ack->data_used); buf = cx18_queue_get_buf(s, id, mdl_ack->data_used);
CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id); CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id);
if (buf == NULL) { if (buf == NULL) {
CX18_WARN("Could not find buf %d for stream %s\n", CX18_WARN("Could not find buf %d for stream %s\n",
id, s->name); id, s->name);
/* Put as many buffers as possible back into fw use */
cx18_stream_load_fw_queue(s);
continue; continue;
} }
cx18_buf_sync_for_cpu(s, buf);
if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) { if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) {
CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n", CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n",
buf->bytesused); buf->bytesused);
dvb_dmx_swfilter(&s->dvb.demux, buf->buf, dvb_dmx_swfilter(&s->dvb.demux, buf->buf,
buf->bytesused); buf->bytesused);
}
/* Put as many buffers as possible back into fw use */
cx18_stream_load_fw_queue(s);
/* Put back TS buffer, since it was removed from all queues */
if (s->type == CX18_ENC_STREAM_TYPE_TS)
cx18_stream_put_buf_fw(s, buf); cx18_stream_put_buf_fw(s, buf);
} else
set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
} }
wake_up(&cx->dma_waitq); wake_up(&cx->dma_waitq);
if (s->id != -1) if (s->id != -1)

View File

@ -117,16 +117,18 @@ struct cx18_buffer *cx18_queue_get_buf(struct cx18_stream *s, u32 id,
} }
buf->bytesused = bytesused; buf->bytesused = bytesused;
/* Sync the buffer before we release the qlock */
cx18_buf_sync_for_cpu(s, buf);
if (s->type == CX18_ENC_STREAM_TYPE_TS) { if (s->type == CX18_ENC_STREAM_TYPE_TS) {
/* /*
* TS doesn't use q_full, but for sweeping up lost * TS doesn't use q_full. As we pull the buffer off of
* buffers, we want the TS to requeue the buffer just * the queue here, the caller will have to put it back.
* before sending the MDL back to the firmware, so we
* pull it off the list here.
*/ */
list_del_init(&buf->list); list_del_init(&buf->list);
} else { } else {
/* Move buffer from q_busy to q_full */
list_move_tail(&buf->list, &s->q_full.list); list_move_tail(&buf->list, &s->q_full.list);
set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
s->q_full.bytesused += buf->bytesused; s->q_full.bytesused += buf->bytesused;
atomic_inc(&s->q_full.buffers); atomic_inc(&s->q_full.buffers);
} }
@ -135,9 +137,6 @@ struct cx18_buffer *cx18_queue_get_buf(struct cx18_stream *s, u32 id,
ret = buf; ret = buf;
break; break;
} }
/* Put more buffers into the transfer rotation from q_free, if we can */
cx18_stream_load_fw_queue_nolock(s);
mutex_unlock(&s->qlock); mutex_unlock(&s->qlock);
return ret; return ret;
} }

View File

@ -419,31 +419,22 @@ struct cx18_queue *cx18_stream_put_buf_fw(struct cx18_stream *s,
return q; return q;
} }
/* Must hold s->qlock when calling */ void cx18_stream_load_fw_queue(struct cx18_stream *s)
void cx18_stream_load_fw_queue_nolock(struct cx18_stream *s)
{ {
struct cx18_queue *q;
struct cx18_buffer *buf; struct cx18_buffer *buf;
struct cx18 *cx = s->cx;
/* Move from q_free to q_busy notifying the firmware: 63 buf limit */ if (atomic_read(&s->q_free.buffers) == 0 ||
while (s->handle != CX18_INVALID_TASK_HANDLE && atomic_read(&s->q_busy.buffers) >= 63)
test_bit(CX18_F_S_STREAMING, &s->s_flags) && return;
atomic_read(&s->q_busy.buffers) < 63 &&
!list_empty(&s->q_free.list)) {
/* Move from q_free to q_busy */ /* Move from q_free to q_busy notifying the firmware, until the limit */
buf = list_entry(s->q_free.list.next, struct cx18_buffer, list); do {
list_move_tail(&buf->list, &s->q_busy.list); buf = cx18_dequeue(s, &s->q_free);
buf->bytesused = buf->readpos = buf->b_flags = buf->skipped = 0; if (buf == NULL)
atomic_dec(&s->q_free.buffers); break;
atomic_inc(&s->q_busy.buffers); q = cx18_stream_put_buf_fw(s, buf);
} while (atomic_read(&s->q_busy.buffers) < 63 && q == &s->q_busy);
/* Notify firmware */
cx18_buf_sync_for_device(s, buf);
cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
(void __iomem *) &cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
1, buf->id, s->buf_size);
}
} }
int cx18_start_v4l2_encode_stream(struct cx18_stream *s) int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
@ -543,8 +534,8 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
&cx->scb->cpu_mdl[buf->id].paddr); &cx->scb->cpu_mdl[buf->id].paddr);
cx18_writel(cx, s->buf_size, &cx->scb->cpu_mdl[buf->id].length); cx18_writel(cx, s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
} }
cx18_stream_load_fw_queue_nolock(s);
mutex_unlock(&s->qlock); mutex_unlock(&s->qlock);
cx18_stream_load_fw_queue(s);
/* begin_capture */ /* begin_capture */
if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) { if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {

View File

@ -29,7 +29,7 @@ int cx18_streams_register(struct cx18 *cx);
void cx18_streams_cleanup(struct cx18 *cx, int unregister); void cx18_streams_cleanup(struct cx18 *cx, int unregister);
/* Capture related */ /* Capture related */
void cx18_stream_load_fw_queue_nolock(struct cx18_stream *s); void cx18_stream_load_fw_queue(struct cx18_stream *s);
struct cx18_queue *cx18_stream_put_buf_fw(struct cx18_stream *s, struct cx18_queue *cx18_stream_put_buf_fw(struct cx18_stream *s,
struct cx18_buffer *buf); struct cx18_buffer *buf);
int cx18_start_v4l2_encode_stream(struct cx18_stream *s); int cx18_start_v4l2_encode_stream(struct cx18_stream *s);