mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gjorgji Rosikopulos (Consultant)" <gjorgji.rosikopulos@oss.qualcomm.com>
To: Loic Poulain <loic.poulain@oss.qualcomm.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v4 11/14] media: qcom: camss: Stamp the buffer the write master is filling
Date: Fri, 4 Dec 2026 15:31:26 +0200	[thread overview]
Message-ID: <0d6301cd-8720-4bdc-b83b-2393e425d3c0@oss.qualcomm.com> (raw)
In-Reply-To: <20261203-camss-hw-ts-v4-11-c271022b4b0d@oss.qualcomm.com>

Hi Loic,

On 12/3/2026 6:53 PM, Loic Poulain wrote:
> The SOF timestamp is read at buf done and applied to the buffer that
> just completed, which assumes the frame that last started is the frame
> being handed back. With two buffers in flight that is one frame out: the
> buffer completing was started by the previous SOF, not the one whose
> timestamp is still on record.
> 
> Describe the buffer from the frame start instead. Ask the write master
> which address it is filling, match it against the buffers the output
> holds and stamp that one, leaving vfe_buf_done() to describe only
> buffers nobody got to, which keeps hardware without an address report
> working as before. A zero timestamp is the sentinel for that, which vb2
> guarantees by clearing it on every queue.
> 
> Buffers are filled in order, so a frame starting into the second slot
> while the first has never been described means that first frame start
> never reached us. Say so rather than describing the wrong buffer.
> 
> Suggested-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
> Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
> ---
>  drivers/media/platform/qcom/camss/camss-vfe.c | 70 ++++++++++++++++++++++++---
>  drivers/media/platform/qcom/camss/camss-vfe.h |  2 +
>  2 files changed, 66 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
> index 87fc09f7849c6e147d2a3a8fc85233c2e1f52ebb..0d06728e54456ea56923611cf9c19f3a0cacec98 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe.c
> @@ -473,12 +473,15 @@ void vfe_buf_done(struct vfe_device *vfe, int wm)
>  		goto out_unlock;
>  	}
>  
> -	if (line->sof) {
> -		ready_buf->vb.vb2_buf.timestamp = atomic64_read(&line->sof->ts);
> -		ready_buf->vb.sequence = atomic_read(&line->sof->seq);
> -	} else {
> -		ready_buf->vb.vb2_buf.timestamp = ktime_get_ns();
> -		ready_buf->vb.sequence = output->sequence++;
> +	/* Tag TS/seq info now if not already done */
> +	if (!ready_buf->vb.vb2_buf.timestamp) {
> +		if (line->sof) {
> +			ready_buf->vb.vb2_buf.timestamp = atomic64_read(&line->sof->ts);
> +			ready_buf->vb.sequence = atomic_read(&line->sof->seq);
> +		} else {
> +			ready_buf->vb.vb2_buf.timestamp = ktime_get_ns();
> +			ready_buf->vb.sequence = output->sequence++;
> +		}
>  	}
>  
>  	index = 0;
> @@ -509,6 +512,55 @@ void vfe_buf_done(struct vfe_device *vfe, int wm)
>  	spin_unlock_irqrestore(&vfe->output_lock, flags);
>  }
>  
> +/* Retrieve the buffer starting at a given address. */
> +static struct camss_buffer *vfe_wm_curr_buf(struct vfe_device *vfe,
> +					    struct vfe_output *output, u32 addr)
> +{
> +	lockdep_assert_held(&vfe->output_lock);
> +
> +	for (unsigned int i = 0; i < ARRAY_SIZE(output->buf); i++)
> +		if (output->buf[i] && output->buf[i]->addr[0] == addr)
> +			return output->buf[i];
> +
> +	return NULL;
> +}
> +
> +/* On SOF, associate the current buffer with the seq number and timestamp. */
> +static void vfe_sof_notify(void *priv)
> +{
> +	struct vfe_line *line = priv;
> +	struct vfe_output *output = &line->output;
> +	struct vfe_device *vfe = to_vfe(line);
> +	struct camss_buffer *buf;
> +	u32 addr;
> +
> +	guard(spinlock_irqsave)(&vfe->output_lock);

Nice. But i think we should have constant usage of the spinlock/mutex api's
It will be nice to modernize the whole code and use RAII patterns for allocation
and locking... But as of today adding it just here i am little bit against.

> +
> +	if (output->state != VFE_OUTPUT_ON)
> +		return;
> +
> +	addr = vfe->res->hw_ops->vfe_wm_curr_addr(vfe, output->wm_idx[0]);
> +	if (!addr)
> +		return;
> +
> +	buf = vfe_wm_curr_buf(vfe, output, addr);
> +	if (!buf) {
> +		dev_warn_ratelimited(vfe->camss->dev,
> +				     "VFE:%d line:%d SOF while no buffer ready at 0x%x\n",
> +				     vfe->id, line->id, addr);
> +		return;
> +	}
> +
> +	/* Buffers are filled in order */
> +	if (buf == output->buf[1] && output->buf[0] &&
> +	    !output->buf[0]->vb.vb2_buf.timestamp)
> +		dev_warn_ratelimited(vfe->camss->dev, "VFE:%d line:%d missed SOF\n",
> +				     vfe->id, line->id);

This is interesting. But if this is the case most probably the buf done was also missed,
do you think we should add code to make buf_done on stalled buffers? Note that Atanas
is hitting this stability error with his tests once or twice when system fully loaded.
And in ife pixel path implementation if this is detected we are returning the done
buffers to userspace (most probably they are not corrupted just that we have missed
to serve the irq on time).

Atanas has some local patch which can be posted later if you think it should not
be part of this series.

> +
> +	buf->vb.vb2_buf.timestamp = atomic64_read(&line->sof->ts);
> +	buf->vb.sequence = atomic_read(&line->sof->seq);
> +}
> +
>  int vfe_enable_output_v2(struct vfe_line *line)
>  {
>  	struct vfe_device *vfe = to_vfe(line);
> @@ -569,6 +621,9 @@ int vfe_enable_output_v2(struct vfe_line *line)
>  			ops->reg_update(vfe, line->id);
>  	}
>  
> +	if (line->sof && ops->vfe_wm_curr_addr)
> +		csid_set_sof_notify(line->sof, vfe_sof_notify, line);
> +
>  	spin_unlock_irqrestore(&vfe->output_lock, flags);
>  
>  	return 0;
> @@ -849,6 +904,9 @@ int vfe_disable(struct vfe_line *line)
>  	struct vfe_device *vfe = to_vfe(line);
>  	int ret = 0;
>  
> +	if (line->sof)
> +		csid_set_sof_notify(line->sof, NULL, NULL);

Why we are doing this here can we get some explanation?

> +
>  	vfe_disable_output(line);
>  
>  	vfe_put_output(line);
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe.h b/drivers/media/platform/qcom/camss/camss-vfe.h
> index b0921e348f2c73a5533c196400c70da187be2cee..ca2d47219545ea91b1bbf1a616bb0b4b36b507d6 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe.h
> +++ b/drivers/media/platform/qcom/camss/camss-vfe.h
> @@ -122,6 +122,8 @@ struct vfe_hw_ops {
>  			     struct vfe_line *line);
>  	void (*vfe_wm_stop)(struct vfe_device *vfe, u8 wm);
>  	void (*vfe_buf_done)(struct vfe_device *vfe, int port_id);
> +	/* Address of the frame the write master is filling, 0 if unsupported */
> +	u32 (*vfe_wm_curr_addr)(struct vfe_device *vfe, u8 wm);
>  	void (*vfe_wm_update)(struct vfe_device *vfe, u8 wm, u32 addr,
>  			      struct vfe_line *line);
>  };
> 

~Gjorgji


  reply	other threads:[~2026-12-04 13:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:53 [PATCH v4 00/14] media: qcom: camss: Report the hardware SOF timestamp Loic Poulain
2026-12-03 16:53 ` [PATCH v4 01/14] media: qcom: camss: Add csid pad to port helper Loic Poulain
2026-12-03 16:53 ` [PATCH v4 02/14] media: qcom: camss: csid: Add an operation to read the SOF timestamp Loic Poulain
2026-12-04  7:31   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 03/14] media: qcom: camss: csid-340: Report the hardware " Loic Poulain
2026-12-03 16:53 ` [PATCH v4 04/14] media: camss: Define timestamp registers for csid-gen2 Loic Poulain
2026-12-03 16:53 ` [PATCH v4 05/14] media: camss: csid-gen2: Report the hardware SOF timestamp Loic Poulain
2026-12-03 16:53 ` [PATCH v4 06/14] media: qcom: camss: csid-gen3: Fix the RDI timestamp controls on Titan 690 Loic Poulain
2026-12-04  7:44   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 07/14] media: qcom: camss: csid-gen3: Report the hardware SOF timestamp Loic Poulain
2026-12-03 16:53 ` [PATCH v4 08/14] media: qcom: camss: Timestamp buffers at start of frame Loic Poulain
2026-12-04  7:59   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 09/14] media: qcom: camss: Tell userspace we're using start-of-frame timestamps Loic Poulain
2026-12-04  8:54   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 10/14] media: qcom: camss: csid: Let a consumer hook into the frame start Loic Poulain
2026-12-04 13:18   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 11/14] media: qcom: camss: Stamp the buffer the write master is filling Loic Poulain
2026-12-04 13:31   ` Gjorgji Rosikopulos (Consultant) [this message]
2026-12-03 16:53 ` [PATCH v4 12/14] media: qcom: camss: vfe-gen3: Report the address of the current frame Loic Poulain
2026-12-04 13:32   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 13/14] media: qcom: camss: vfe-680: " Loic Poulain
2026-12-04 14:49   ` Gjorgji Rosikopulos (Consultant)
2026-12-03 16:53 ` [PATCH v4 14/14] media: qcom: camss: vfe-340: " Loic Poulain

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=0d6301cd-8720-4bdc-b83b-2393e425d3c0@oss.qualcomm.com \
    --to=gjorgji.rosikopulos@oss.qualcomm.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=mchehab@kernel.org \
    --cc=vladimir.zapolskiy@linaro.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

all inboxes | Powered by JetHome®