Losing first frame after stop/start streaming VI4

I think the key point should be the timing of the sensor stream_on.

Can you be more precise please ? All the functions of the stream OFF are done before the functions of the stream ON as you can see in the logs I have added

Logs

Have try remove below code from the csi4_fops.c

csi4_phy_write(chan, phy_num, NVCSI_CIL_A_SW_RESET,
SW_RESET1_EN | SW_RESET0_EN);

csi4_phy_write(chan, phy_num, NVCSI_CIL_B_SW_RESET,
SW_RESET1_EN | SW_RESET0_EN);

Thank you very much, it is working now. Can you tell me what these line of codes are doing usually ?

This code reset the CSI logic.

Thank you for your answers. I now have a problem concerning the syncpoints.
I have applied the patch you mentionned which is correcting the camera shake issue from (tx2)the camera delay N+2 frame :

  •                           chan->syncpt[i][SOF_SYNCPT_IDX], thresh[i],
    
  •                           chan->syncpt[i][FE_SYNCPT_IDX], thresh[i],
    

It is working well but when I stop and start the streaming the ATOMP_FE threshold and the syncpoint are not synchronized anymore as you can see from log below :

this is causing to lose all the frames after. Do you know what is causing the ATOMP_FE threshold to be reseted to 0 ? I would need it to follow the same threshold as PXL_SOF.

You may try to modify the time of syncpt wait function to try it.

The problem is not the timeout, the problem is that we are waiting for an ATOMP_FE threshold value of 1 but the syncpt here is at 257 and incrementing. Do you know what is causing the ATOMP_FE threshold to be reseted to 0 ?

The value will roll back when it reach to max. But I don’t know what’s the max value.

But for any value if I do stop and start streaming it will be reseted to 0, so it isn’t because it is reaching max but because something is setting it to 0 I think.

What I need to understand and to avoid is the ATOMP_FE threadshold going from 257 to 1.

Please trace the vi4_fops.c and print all of them to figure it out.

I already did but I do not find the function setting the threshold back to 0. Do you have any idea of what it is ?

Maybe the driver been reinitialize or enter recovery cause it.

This is the trace when I stop and start the streaming

Trace
 vi-output, ov56-2717  [004] ....   337.896103: tegra_channel_capture_frame: sof:337.788354976
     kworker/0:0-4     [000] ....   337.903671: rtos_queue_peek_from_isr_failed: tstamp:10741362832 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   337.903703: rtcpu_vinotify_event: tstamp:10742634259 tag:CHANSEL_PXL_SOF channel:0x00 frame:16200 vi_tstamp:10742633532 data:0x00000001
     kworker/0:0-4     [000] ....   337.903707: rtcpu_vinotify_event: tstamp:10742634987 tag:ATOMP_FS channel:0x00 frame:16200 vi_tstamp:10742633537 data:0x00000000
     kworker/0:0-4     [000] ....   337.903710: rtcpu_vinotify_event: tstamp:10742654416 tag:CHANSEL_LOAD_FRAMED channel:0x10 frame:16200 vi_tstamp:10742653868 data:0x08000000
     kworker/0:0-4     [000] ....   337.903714: rtcpu_vinotify_event: tstamp:10742762461 tag:CHANSEL_PXL_EOF channel:0x00 frame:16200 vi_tstamp:10742761821 data:0x02000002
     kworker/0:0-4     [000] ....   337.903717: rtcpu_vinotify_event: tstamp:10742763914 tag:ATOMP_FE channel:0x00 frame:16200 vi_tstamp:10742763279 data:0x00000000
     kworker/0:0-4     [000] ....   338.015478: rtos_queue_peek_from_isr_failed: tstamp:10746362835 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   338.096140: tegra_channel_capture_frame: sof:337.988355392
     kworker/0:0-4     [000] ....   338.127535: rtcpu_vinotify_event: tstamp:10748884282 tag:CHANSEL_PXL_SOF channel:0x00 frame:16201 vi_tstamp:10748883545 data:0x00000001
     kworker/0:0-4     [000] ....   338.127548: rtcpu_vinotify_event: tstamp:10748885060 tag:ATOMP_FS channel:0x00 frame:16201 vi_tstamp:10748883549 data:0x00000000
     kworker/0:0-4     [000] ....   338.127553: rtcpu_vinotify_event: tstamp:10748905344 tag:CHANSEL_LOAD_FRAMED channel:0x10 frame:16201 vi_tstamp:10748904796 data:0x08000000
     kworker/0:0-4     [000] ....   338.127556: rtcpu_vinotify_event: tstamp:10749012468 tag:CHANSEL_PXL_EOF channel:0x00 frame:16201 vi_tstamp:10749011834 data:0x02000002
     kworker/0:0-4     [000] ....   338.127559: rtcpu_vinotify_event: tstamp:10749013902 tag:ATOMP_FE channel:0x00 frame:16201 vi_tstamp:10749013291 data:0x00000000
     kworker/0:0-4     [000] ....   338.183424: rtos_queue_peek_from_isr_failed: tstamp:10751362769 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   338.299545: tegra_channel_capture_frame: sof:337.988355392
     kworker/0:0-4     [000] ....   338.351420: rtos_queue_peek_from_isr_failed: tstamp:10756362784 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   338.503530: tegra_channel_capture_frame: sof:337.988355392
     kworker/0:0-4     [000] ....   338.519409: rtos_queue_peek_from_isr_failed: tstamp:10761362790 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   338.687396: rtos_queue_peek_from_isr_failed: tstamp:10766362790 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   338.707510: tegra_channel_capture_frame: sof:337.988355392
     kworker/0:0-4     [000] ....   338.855403: rtos_queue_peek_from_isr_failed: tstamp:10771362796 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   338.911574: tegra_channel_capture_frame: sof:337.988355392
     kworker/0:0-4     [000] ....   339.023461: rtos_queue_peek_from_isr_failed: tstamp:10776362802 queue:0x0b4b4500
 vi-output, ov56-2717  [004] ....   339.115542: tegra_channel_capture_frame: sof:337.988355392
       noxcamera-2685  [000] ....   339.116873: tegra_channel_set_stream: enable : 0x0
       noxcamera-2685  [000] ....   339.116883: tegra_channel_set_stream: ov5693 7-0036 : 0x0
       noxcamera-2685  [000] ....   339.116963: tegra_channel_set_stream: 150c0000.nvcsi--1 : 0x0
       noxcamera-2685  [000] ....   339.116979: csi_s_stream: enable : 0x0
       noxcamera-2685  [000] ....   339.124114: tegra_channel_close: vi-output, ov5693 7-0036
       noxcamera-2685  [000] ....   339.128917: tegra_channel_set_power: ov5693 7-0036 : 0x0
       noxcamera-2685  [000] ....   339.128964: camera_common_s_power: status : 0x0
       noxcamera-2685  [000] ....   339.131630: tegra_channel_set_power: 150c0000.nvcsi--1 : 0x0
       noxcamera-2685  [000] ....   339.131639: csi_s_power: enable : 0x0
       noxcamera-2685  [000] ....   339.132508: tegra_channel_open: vi-output, ov5693 7-0036
       noxcamera-2685  [000] ....   339.132541: tegra_channel_set_power: ov5693 7-0036 : 0x1
       noxcamera-2685  [000] ....   339.132566: camera_common_s_power: status : 0x1
     kworker/0:0-4     [000] ....   339.135430: rtos_queue_send_from_isr_failed: tstamp:10780765168 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.135442: rtos_queue_send_from_isr_failed: tstamp:10780765653 queue:0x0b4aad68
     kworker/0:0-4     [000] ....   339.135448: rtos_queue_send_from_isr_failed: tstamp:10780766112 queue:0x0b4ac998
     kworker/0:0-4     [000] ....   339.135454: rtos_queue_send_from_isr_failed: tstamp:10780766587 queue:0x0b4ae518
     kworker/0:0-4     [000] ....   339.135459: rtos_queue_send_from_isr_failed: tstamp:10780767042 queue:0x0b4af2d8
     kworker/0:0-4     [000] ....   339.135464: rtos_queue_send_from_isr_failed: tstamp:10780767497 queue:0x0b4b0098
     kworker/0:0-4     [000] ....   339.135469: rtos_queue_send_from_isr_failed: tstamp:10780767953 queue:0x0b4b0e58
     kworker/0:0-4     [000] ....   339.135474: rtos_queue_send_from_isr_failed: tstamp:10780768407 queue:0x0b4b1c18
     kworker/0:0-4     [000] ....   339.135487: rtos_queue_send_failed: tstamp:10780771060 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.135492: rtos_queue_send_from_isr_failed: tstamp:10780782011 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.135496: rtos_queue_send_from_isr_failed: tstamp:10780782603 queue:0x0b4aad68
     kworker/0:0-4     [000] ....   339.135502: rtos_queue_send_from_isr_failed: tstamp:10780783078 queue:0x0b4ac998
     kworker/0:0-4     [000] ....   339.135507: rtos_queue_send_from_isr_failed: tstamp:10780783560 queue:0x0b4ae518
     kworker/0:0-4     [000] ....   339.135512: rtos_queue_send_from_isr_failed: tstamp:10780784027 queue:0x0b4af2d8
     kworker/0:0-4     [000] ....   339.135517: rtos_queue_send_from_isr_failed: tstamp:10780784482 queue:0x0b4b0098
     kworker/0:0-4     [000] ....   339.135521: rtos_queue_send_from_isr_failed: tstamp:10780784936 queue:0x0b4b0e58
     kworker/0:0-4     [000] ....   339.135526: rtos_queue_send_from_isr_failed: tstamp:10780785391 queue:0x0b4b1c18
     kworker/0:0-4     [000] ....   339.135532: rtos_queue_send_failed: tstamp:10780787264 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.135539: rtos_queue_peek_from_isr_failed: tstamp:10781362789 queue:0x0b4b4500
       noxcamera-2685  [000] ....   339.137969: tegra_channel_set_power: 150c0000.nvcsi--1 : 0x1
       noxcamera-2685  [000] ....   339.137975: csi_s_power: enable : 0x1
     kworker/0:0-4     [000] ....   339.303457: rtos_queue_peek_from_isr_failed: tstamp:10786362830 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   339.472505: rtos_queue_peek_from_isr_failed: tstamp:10791362639 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   339.647398: rtos_queue_peek_from_isr_failed: tstamp:10796362645 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   339.815490: rtos_queue_peek_from_isr_failed: tstamp:10801362648 queue:0x0b4b4500
       noxcamera-2716  [000] ....   339.839239: tegra_channel_capture_setup: vnc_id 0 W 864 H 95 fmt cb
 vi-output, ov56-2779  [005] ....   339.839816: tegra_channel_set_stream: enable : 0x1
 vi-output, ov56-2779  [005] ....   339.854211: tegra_channel_set_stream: 150c0000.nvcsi--1 : 0x1
 vi-output, ov56-2779  [005] ....   339.854217: csi_s_stream: enable : 0x1
 vi-output, ov56-2779  [005] ....   339.854257: tegra_channel_set_stream: ov5693 7-0036 : 0x1
     kworker/0:0-4     [000] ....   339.871430: rtos_queue_send_from_isr_failed: tstamp:10803345889 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.871437: rtos_queue_send_from_isr_failed: tstamp:10803346173 queue:0x0b4aad68
     kworker/0:0-4     [000] ....   339.871441: rtos_queue_send_from_isr_failed: tstamp:10803346450 queue:0x0b4ac998
     kworker/0:0-4     [000] ....   339.871444: rtos_queue_send_from_isr_failed: tstamp:10803346718 queue:0x0b4ae518
     kworker/0:0-4     [000] ....   339.871448: rtos_queue_send_from_isr_failed: tstamp:10803346985 queue:0x0b4af2d8
     kworker/0:0-4     [000] ....   339.871451: rtos_queue_send_from_isr_failed: tstamp:10803347256 queue:0x0b4b0098
     kworker/0:0-4     [000] ....   339.871455: rtos_queue_send_from_isr_failed: tstamp:10803347522 queue:0x0b4b0e58
     kworker/0:0-4     [000] ....   339.871459: rtos_queue_send_from_isr_failed: tstamp:10803347790 queue:0x0b4b1c18
     kworker/0:0-4     [000] ....   339.871467: rtos_queue_send_failed: tstamp:10803348960 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.871470: rtos_queue_send_from_isr_failed: tstamp:10803359787 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.871474: rtos_queue_send_from_isr_failed: tstamp:10803360114 queue:0x0b4aad68
     kworker/0:0-4     [000] ....   339.871478: rtos_queue_send_from_isr_failed: tstamp:10803360382 queue:0x0b4ac998
     kworker/0:0-4     [000] ....   339.871481: rtos_queue_send_from_isr_failed: tstamp:10803360721 queue:0x0b4ae518
     kworker/0:0-4     [000] ....   339.871485: rtos_queue_send_from_isr_failed: tstamp:10803360988 queue:0x0b4af2d8
     kworker/0:0-4     [000] ....   339.871488: rtos_queue_send_from_isr_failed: tstamp:10803361256 queue:0x0b4b0098
     kworker/0:0-4     [000] ....   339.871491: rtos_queue_send_from_isr_failed: tstamp:10803361526 queue:0x0b4b0e58
     kworker/0:0-4     [000] ....   339.871495: rtos_queue_send_from_isr_failed: tstamp:10803361792 queue:0x0b4b1c18
     kworker/0:0-4     [000] ....   339.871498: rtos_queue_send_failed: tstamp:10803364989 queue:0x0b4a7258
     kworker/0:0-4     [000] ....   339.983400: rtos_queue_peek_from_isr_failed: tstamp:10806362728 queue:0x0b4b4500
 vi-output, ov56-2779  [004] ....   340.036261: tegra_channel_capture_frame: sof:339.928600480
     kworker/0:0-4     [000] ....   340.039536: rtcpu_vinotify_event: tstamp:10809516802 tag:CHANSEL_PXL_SOF channel:0x00 frame:16203 vi_tstamp:10809516197 data:0x00000001
     kworker/0:0-4     [000] ....   340.039547: rtcpu_vinotify_event: tstamp:10809517201 tag:ATOMP_FS channel:0x00 frame:16203 vi_tstamp:10809516201 data:0x00000000
     kworker/0:0-4     [000] ....   340.039551: rtcpu_vinotify_event: tstamp:10809532271 tag:CHANSEL_LOAD_FRAMED channel:0x10 frame:16203 vi_tstamp:10809531820 data:0x08000000
     kworker/0:0-4     [000] ....   340.039555: rtcpu_vinotify_event: tstamp:10809550635 tag:CHANSEL_PXL_EOF channel:0x00 frame:16203 vi_tstamp:10809549846 data:0x005e0002
     kworker/0:0-4     [000] ....   340.039557: rtcpu_vinotify_event: tstamp:10809550924 tag:ATOMP_FE channel:0x00 frame:16203 vi_tstamp:10809549867 data:0x00000000
     kworker/0:0-4     [000] ....   340.095451: rtos_queue_peek_from_isr_failed: tstamp:10811362729 queue:0x0b4b4500
 vi-output, ov56-2779  [004] ....   340.236271: tegra_channel_capture_frame: sof:340.128600896
     kworker/0:0-4     [000] ....   340.263543: rtcpu_vinotify_event: tstamp:10815766845 tag:CHANSEL_PXL_SOF channel:0x00 frame:16204 vi_tstamp:10815766210 data:0x00000001
     kworker/0:0-4     [000] ....   340.263561: rtcpu_vinotify_event: tstamp:10815767313 tag:ATOMP_FS channel:0x00 frame:16204 vi_tstamp:10815766214 data:0x00000000
     kworker/0:0-4     [000] ....   340.263565: rtcpu_vinotify_event: tstamp:10815783076 tag:CHANSEL_LOAD_FRAMED channel:0x10 frame:16204 vi_tstamp:10815782623 data:0x08000000
     kworker/0:0-4     [000] ....   340.263567: rtcpu_vinotify_event: tstamp:10815800639 tag:CHANSEL_PXL_EOF channel:0x00 frame:16204 vi_tstamp:10815799859 data:0x005e0002
     kworker/0:0-4     [000] ....   340.263570: rtcpu_vinotify_event: tstamp:10815800930 tag:ATOMP_FE channel:0x00 frame:16204 vi_tstamp:10815799880 data:0x00000000
     kworker/0:0-4     [000] ....   340.263580: rtos_queue_peek_from_isr_failed: tstamp:10816362735 queue:0x0b4b4500
     kworker/0:0-4     [000] ....   340.431461: rtos_queue_peek_from_isr_failed: tstamp:10821362743 queue:0x0b4b4500

I mean you have to add print message in the vi4_fops.c to trace the code flow to know it.

Yes it is also what I did. As you can see in the logs below I traced the value of ATOMP_FE threshold and no function in vi4_fops.c is setting it back to 0. It must be something else, can you please help me find out what it is ?

Logs

Could you a check tegra_channel_notify_disable() and tegra_channel_notify_enable() these two function.

I checked the threshold value before and after these functions, they don’t seem to set it back to 0 as seen in my logs. Here are the functions :

tegra_channel_notify_disable

static int tegra_channel_notify_disable(
struct tegra_channel *chan, unsigned int index)
{
int err;
int ret = 0;
struct tegra_vi4_syncpts_req req;
int threshold;

/* clear vi notify callbacks */
vi_notify_channel_set_notify_funcs(chan->vnc[index],
		NULL, NULL, NULL);

threshold = nvhost_syncpt_incr_max_ext(chan->vi->ndev,chan->syncpt[index][FE_SYNCPT_IDX], 0);
dev_info(chan->vi->dev,"%s: line %d ATOMP_FE syncpt threshold value = %d\n",__func__,__LINE__,threshold);

/* free syncpts */
nvhost_syncpt_put_ref_ext(
	chan->vi->ndev, chan->syncpt[index][SOF_SYNCPT_IDX]);
nvhost_syncpt_put_ref_ext(
	chan->vi->ndev, chan->syncpt[index][FE_SYNCPT_IDX]);

threshold = nvhost_syncpt_incr_max_ext(chan->vi->ndev,chan->syncpt[index][FE_SYNCPT_IDX], 0);
dev_info(chan->vi->dev,"%s: line %d ATOMP_FE syncpt threshold value = %d\n",__func__,__LINE__,threshold);

/* close vi-notifier */
req.syncpt_ids[0] = 0xffffffff;
req.syncpt_ids[1] = 0xffffffff;
req.syncpt_ids[2] = 0xffffffff;
req.stream = chan->port[index];
req.vc = chan->virtual_channel;
req.pad = 0;

err = vi_notify_channel_reset(
	chan->vnc_id[index], chan->vnc[index], &req);
if (err < 0) {
	dev_err(chan->vi->dev,
		"VI Notify channel reset failed, err = %d\n", err);
	if (!ret)
		ret = err;
}

err = vi_notify_channel_close(chan->vnc_id[index], chan->vnc[index]);
if (err < 0) {
	dev_err(chan->vi->dev,
		"VI Notify channel close failed, err = %d\n", err);
	if (!ret)
		ret = err;
}

return ret;

}

tegra_channel_notify_enable

static int tegra_channel_notify_enable(
struct tegra_channel *chan, unsigned int index)
{
struct tegra_vi4_syncpts_req req;
int i, err;
int threshold;

chan->vnc_id[index] = -1;
for (i = 0; i < MAX_VI_CHANNEL; i++) {
	chan->vnc[index] = vi_notify_channel_open(i);
	if (!IS_ERR(chan->vnc[index])) {
		chan->vnc_id[index] = i;
		break;
	}
}
if (chan->vnc_id[index] < 0) {
	dev_err(chan->vi->dev, "No VI channel available!\n");
	return -EFAULT;
}

vi_notify_channel_set_notify_funcs(chan->vnc[index],
		&tegra_channel_notify_status_callback,
		&tegra_channel_notify_error_callback,
		(void *)chan);

/* get PXL_SOF syncpt id */
chan->syncpt[index][SOF_SYNCPT_IDX] =
	nvhost_get_syncpt_client_managed(chan->vi->ndev, "tegra-vi4");
if (chan->syncpt[index][SOF_SYNCPT_IDX] == 0) {
	dev_err(chan->vi->dev, "Failed to get PXL_SOF syncpt!\n");
	return -EFAULT;
}

/* get ATOMP_FE syncpt id */
chan->syncpt[index][FE_SYNCPT_IDX] =
	nvhost_get_syncpt_client_managed(chan->vi->ndev, "tegra-vi4");
if (chan->syncpt[index][FE_SYNCPT_IDX] == 0) {
	dev_err(chan->vi->dev, "Failed to get ATOMP_FE syncpt!\n");
	nvhost_syncpt_put_ref_ext(
		chan->vi->ndev, chan->syncpt[index][SOF_SYNCPT_IDX]);
	return -EFAULT;
}

threshold = nvhost_syncpt_incr_max_ext(chan->vi->ndev,chan->syncpt[index][FE_SYNCPT_IDX], 0);
dev_info(chan->vi->dev,"%s: line %d ATOMP_FE syncpt threshold value = %d\n",__func__,__LINE__,threshold);

nvhost_syncpt_set_min_eq_max_ext(
	chan->vi->ndev, chan->syncpt[index][SOF_SYNCPT_IDX]);
nvhost_syncpt_set_min_eq_max_ext(
	chan->vi->ndev, chan->syncpt[index][FE_SYNCPT_IDX]);

threshold = nvhost_syncpt_incr_max_ext(chan->vi->ndev,chan->syncpt[index][FE_SYNCPT_IDX], 0);
dev_info(chan->vi->dev,"%s: line %d ATOMP_FE syncpt threshold value = %d\n",__func__,__LINE__,threshold);

/* enable VI Notify report */
req.syncpt_ids[0] = chan->syncpt[index][SOF_SYNCPT_IDX]; /* PXL_SOF */
req.syncpt_ids[1] = chan->syncpt[index][FE_SYNCPT_IDX]; /* ATOMP_FE */
req.syncpt_ids[2] = 0xffffffff;
req.stream = chan->port[index];
req.vc = chan->virtual_channel;
req.pad = 0;

err = vi_notify_channel_enable_reports(
	chan->vnc_id[index], chan->vnc[index], &req);
if (err < 0)
	dev_err(chan->vi->dev,
		"Failed to enable report for VI Notify, err = %d\n",
		err);

return err;

}

It means something else not in vi4_fops is setting the threshold back to 0. Any idea where I should look ?