From 0ddfe2d4820dfcb0c53ffab47e89203c8e651339 Mon Sep 17 00:00:00 2001 From: Pranav Sanwal Date: Thu, 2 Sep 2021 19:08:30 +0530 Subject: [PATCH] msm: camera: isp: Reduce traffic for shutter notification To reduce traffic for shutter notification, sof and boot sof timestamps are sent in a unified v4l2 event. Thereby, reducing the event notification traffic by 50%. CRs-Fixed: 3040374 Change-Id: Ib4580e0a4df7c3d1cb892fdf3254272d3134d4cb Signed-off-by: Pranav Sanwal --- drivers/cam_isp/cam_isp_context.c | 37 +++++++++++++++++++++++++ drivers/cam_isp/cam_isp_context.h | 2 ++ drivers/cam_req_mgr/cam_req_mgr_dev.c | 8 ++++++ drivers/cam_req_mgr/cam_req_mgr_dev.h | 6 ++++ include/uapi/camera/media/cam_req_mgr.h | 35 +++++++++++++++++++++++ 5 files changed, 88 insertions(+) diff --git a/drivers/cam_isp/cam_isp_context.c b/drivers/cam_isp/cam_isp_context.c index 73c5c988f7..7c0d7b1ac3 100644 --- a/drivers/cam_isp/cam_isp_context.c +++ b/drivers/cam_isp/cam_isp_context.c @@ -865,6 +865,33 @@ static void __cam_isp_ctx_send_sof_boot_timestamp( request_id); } +static void __cam_isp_ctx_send_unified_timestamp( + struct cam_isp_context *ctx_isp, uint64_t request_id) +{ + struct cam_req_mgr_message req_msg; + + req_msg.session_hdl = ctx_isp->base->session_hdl; + req_msg.u.frame_msg_v2.frame_id = ctx_isp->frame_id; + req_msg.u.frame_msg_v2.request_id = request_id; + req_msg.u.frame_msg_v2.timestamps[CAM_REQ_SOF_QTIMER_TIMESTAMP] = + (request_id == 0) ? 0 : ctx_isp->sof_timestamp_val; + req_msg.u.frame_msg_v2.timestamps[CAM_REQ_BOOT_TIMESTAMP] = ctx_isp->boot_timestamp; + req_msg.u.frame_msg_v2.link_hdl = ctx_isp->base->link_hdl; + req_msg.u.frame_msg_v2.frame_id_meta = ctx_isp->frame_id_meta; + + CAM_DBG(CAM_ISP, + "link hdl 0x%x request id:%lld frame number:%lld SOF time stamp:0x%llx ctx %d\ + boot time stamp:0x%llx", ctx_isp->base->link_hdl, request_id, + ctx_isp->frame_id, ctx_isp->sof_timestamp_val,ctx_isp->base->ctx_id, + ctx_isp->boot_timestamp); + + if (cam_req_mgr_notify_message(&req_msg, + V4L_EVENT_CAM_REQ_MGR_SOF_UNIFIED_TS, V4L_EVENT_CAM_REQ_MGR_EVENT)) + CAM_ERR(CAM_ISP, + "Error in notifying the sof and boot time for req id:%lld", + request_id); +} + static void __cam_isp_ctx_send_sof_timestamp_frame_header( struct cam_isp_context *ctx_isp, uint32_t *frame_header_cpu_addr, uint64_t request_id, uint32_t sof_event_status) @@ -907,6 +934,12 @@ static void __cam_isp_ctx_send_sof_timestamp( { struct cam_req_mgr_message req_msg; + if ((ctx_isp->v4l2_event_sub_ids & (1 << V4L_EVENT_CAM_REQ_MGR_SOF_UNIFIED_TS)) + && !ctx_isp->use_frame_header_ts) { + __cam_isp_ctx_send_unified_timestamp(ctx_isp,request_id); + return; + } + if ((ctx_isp->use_frame_header_ts) || (request_id == 0)) goto end; @@ -4785,6 +4818,7 @@ static int __cam_isp_ctx_release_dev_in_top_state(struct cam_context *ctx, ctx_isp->offline_context = false; ctx_isp->rdi_only_context = false; ctx_isp->req_info.last_bufdone_req_id = 0; + ctx_isp->v4l2_event_sub_ids = 0; atomic64_set(&ctx_isp->state_monitor_head, -1); for (i = 0; i < CAM_ISP_CTX_EVENT_MAX; i++) @@ -5101,6 +5135,8 @@ static int __cam_isp_ctx_acquire_dev_in_available(struct cam_context *ctx, cmd->session_handle, cmd->num_resources, cmd->handle_type, cmd->resource_hdl); + ctx_isp->v4l2_event_sub_ids = cam_req_mgr_get_id_subscribed(); + if (cmd->num_resources == CAM_API_COMPAT_CONSTANT) { ctx_isp->split_acquire = true; CAM_DBG(CAM_ISP, "Acquire dev handle"); @@ -6575,6 +6611,7 @@ int cam_isp_context_init(struct cam_isp_context *ctx, ctx->reported_req_id = 0; ctx->bubble_frame_cnt = 0; ctx->req_info.last_bufdone_req_id = 0; + ctx->v4l2_event_sub_ids = 0; ctx->hw_ctx = NULL; ctx->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF; diff --git a/drivers/cam_isp/cam_isp_context.h b/drivers/cam_isp/cam_isp_context.h index ae4a295e45..c3c5dbe641 100644 --- a/drivers/cam_isp/cam_isp_context.h +++ b/drivers/cam_isp/cam_isp_context.h @@ -274,6 +274,7 @@ struct cam_isp_context_event_record { * @workq: Worker thread for offline ife * @trigger_id: ID provided by CRM for each ctx on the link * @last_bufdone_err_apply_req_id: last bufdone error apply request id + * @v4l2_event_sub_ids contains individual bits representing subscribed v4l2 ids * */ struct cam_isp_context { @@ -323,6 +324,7 @@ struct cam_isp_context { struct cam_req_mgr_core_workq *workq; int32_t trigger_id; int64_t last_bufdone_err_apply_req_id; + uint32_t v4l2_event_sub_ids; }; /** diff --git a/drivers/cam_req_mgr/cam_req_mgr_dev.c b/drivers/cam_req_mgr/cam_req_mgr_dev.c index 4e52581e33..7322147117 100644 --- a/drivers/cam_req_mgr/cam_req_mgr_dev.c +++ b/drivers/cam_req_mgr/cam_req_mgr_dev.c @@ -279,13 +279,21 @@ static struct v4l2_subscribed_event_ops g_cam_v4l2_ops = { static int cam_subscribe_event(struct v4l2_fh *fh, const struct v4l2_event_subscription *sub) { + g_dev.v4l2_sub_ids |= 1 << sub->id; return v4l2_event_subscribe(fh, sub, CAM_REQ_MGR_EVENT_MAX, &g_cam_v4l2_ops); } +uint32_t cam_req_mgr_get_id_subscribed(void) +{ + return g_dev.v4l2_sub_ids; +} +EXPORT_SYMBOL(cam_req_mgr_get_id_subscribed); + static int cam_unsubscribe_event(struct v4l2_fh *fh, const struct v4l2_event_subscription *sub) { + g_dev.v4l2_sub_ids &= ~(1 << sub->id); return v4l2_event_unsubscribe(fh, sub); } diff --git a/drivers/cam_req_mgr/cam_req_mgr_dev.h b/drivers/cam_req_mgr/cam_req_mgr_dev.h index 8b8755c835..2d41ed629b 100644 --- a/drivers/cam_req_mgr/cam_req_mgr_dev.h +++ b/drivers/cam_req_mgr/cam_req_mgr_dev.h @@ -16,6 +16,7 @@ * @dev_lock: lock for the subdevice count. * @state: state of the root device. * @open_cnt: open count of subdev + * @v4l2_sub_ids: bits representing v4l2 event ids subscribed or not * @cam_lock: per file handle lock * @cam_eventq: event queue * @cam_eventq_lock: lock for event queue @@ -28,6 +29,7 @@ struct cam_req_mgr_device { struct mutex dev_lock; bool state; int32_t open_cnt; + uint32_t v4l2_sub_ids; struct mutex cam_lock; struct v4l2_fh *cam_eventq; spinlock_t cam_eventq_lock; @@ -52,4 +54,8 @@ int cam_req_mgr_init(void); */ void cam_req_mgr_exit(void); +/** + * @brief : API to get V4L2 eventIDs subscribed by UMD. + */ +uint32_t cam_req_mgr_get_id_subscribed(void); #endif /* _CAM_REQ_MGR_DEV_H_ */ diff --git a/include/uapi/camera/media/cam_req_mgr.h b/include/uapi/camera/media/cam_req_mgr.h index d088882b1b..03f086c507 100644 --- a/include/uapi/camera/media/cam_req_mgr.h +++ b/include/uapi/camera/media/cam_req_mgr.h @@ -57,6 +57,7 @@ #define V4L_EVENT_CAM_REQ_MGR_SOF_BOOT_TS 2 #define V4L_EVENT_CAM_REQ_MGR_CUSTOM_EVT 3 #define V4L_EVENT_CAM_REQ_MGR_NODE_EVENT 4 +#define V4L_EVENT_CAM_REQ_MGR_SOF_UNIFIED_TS 5 /* SOF Event status */ #define CAM_REQ_MGR_SOF_EVENT_SUCCESS 0 @@ -507,6 +508,39 @@ struct cam_req_mgr_frame_msg { __u32 reserved; }; +/** + * enum cam_req_msg_timestamp_type - Identifies index of timestamps + * + * @CAM_REQ_SOF_QTIMER_TIMESTAMP: SOF qtimer timestamp + * @CAM_REQ_BOOT_TIMESTAMP: SOF boot timestamp + * @CAM_REQ_TIMESTAMP_TYPE: Max enum index for timestamp type + * + */ +enum cam_req_msg_timestamp_type { + CAM_REQ_SOF_QTIMER_TIMESTAMP = 0, + CAM_REQ_BOOT_TIMESTAMP, + CAM_REQ_TIMESTAMP_MAX +}; + +/** + * struct cam_req_mgr_frame_msg + * @request_id: request id of the frame + * @frame_id: frame id of the frame + * @timestamps: array for all the supported timestamps + * @link_hdl: link handle associated with this message + * @frame_id_meta: refers to the meta for + * that frame in specific usecases + * @reserved: reserved for future addtions and max size for structure can be 64 bytes + */ +struct cam_req_mgr_frame_msg_v2 { + __u64 request_id; + __u64 frame_id; + __u64 timestamps[CAM_REQ_TIMESTAMP_MAX]; + __s32 link_hdl; + __u32 frame_id_meta; + __u32 reserved[4]; +}; + /** * struct cam_req_mgr_custom_msg * @custom_type: custom type @@ -573,6 +607,7 @@ struct cam_req_mgr_message { union { struct cam_req_mgr_error_msg err_msg; struct cam_req_mgr_frame_msg frame_msg; + struct cam_req_mgr_frame_msg_v2 frame_msg_v2; struct cam_req_mgr_custom_msg custom_msg; struct cam_req_mgr_node_msg node_msg; } u;