From patchwork Mon Nov 27 13:19:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119702 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp257667qgn; Mon, 27 Nov 2017 05:20:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMbC9YjE3vekUNzpyhLlzSTZv3qUgwAUnNZplOA8OK3gSraTspQ4+Y0Ru67shdoo8DP7nMdz X-Received: by 10.98.163.73 with SMTP id s70mr36198894pfe.64.1511788839111; Mon, 27 Nov 2017 05:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511788839; cv=none; d=google.com; s=arc-20160816; b=cQTrXo+0x89Hyu7OlIc+rsk9giMaSjs61B8SN1vg31pGz4enrS3dxRtvAWrIYuh2Fw FON/3HqHNYjGYt6k68xzuyAcfldOFwYxQnK75wgCjyxltFsaV/oiwZxwB6O6b4ZL2vcD lq3TXfyHsaOo0+8KTVVNLlcKA/+vtBKa4d3xltBFNFlJPVPFnM5Bk0NF1ALNhaOHu39Y F0V9I7GSvox8RPtF+LLqUqUuUnwXRu6x8GtdnxzD5pKpE1Ph1ICV+Vm2RHOKdPGCVm0/ 9dDxQNOtFF6+doByc2LSfQXi6wbKnm87dikmCRqv79DDKscF+PQaMmpviBKP/BzrrqAp nTUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jUz3DkOjE43gYJlqCxhafCsC/V3bDbiJv8qev0S1hfw=; b=YjQ8S3UrtIzswLULswaQeCiXWbkaQEp156iPetXBipLM53M1mMm+2MYwC0bGaJ/sMB ppNemLDum157sOD/U/vFRCpEXqaKYP6aACww3Wj/i6l1oc/okh71S3lvJ2UDbeA39+bE gTARxs+Tr/OUWCYIvAU7r6kWTupV4RVi5EhVdPgCyM3ZLzUq+iAFPi8gh+yuIqilpA+k SnBeQoAWpXCMIsAS/aq83YEaO0ZzBC5Xq4T0gF1fpD3QbkhNqWxcnFDrRZalPfddG9Qu IHlvxwsXv3uLam5jP1tACmm8/cgiFHgZhnJAhk/RcT2ggtmB0mcCsFgBG2n+As3lq9F3 xaHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si22998688plz.394.2017.11.27.05.20.38; Mon, 27 Nov 2017 05:20:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752215AbdK0NUi (ORCPT + 4 others); Mon, 27 Nov 2017 08:20:38 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:55950 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752083AbdK0NUh (ORCPT ); Mon, 27 Nov 2017 08:20:37 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MduOr-1eTY5B36YX-00PbPY; Mon, 27 Nov 2017 14:20:28 +0100 From: Arnd Bergmann To: Laurent Pinchart , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , Kieran Bingham , Guennadi Liakhovetski , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] [media] uvc_video: use ktime_t for stats Date: Mon, 27 Nov 2017 14:19:53 +0100 Message-Id: <20171127132027.1734806-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:cYz7XyslFcyisyesdMZLDqD82b+IQ0U5MRriYwn2qXYFGJ012o5 sed48L9dSKObQ/C9SLSuYp6Nc12EykuL6GmooDB2qC1QR425uRPFUh5tSs+sS3Umkkxfcs0 nc16eaByvpiJQOiKIbSH1YW2TqQIRTNhe+kQUrLOqw0xSOFYhMH0Y6kqdPaMmwSusKHOd8d uD8J+uiIn+oOHBCtQH8iw== X-UI-Out-Filterresults: notjunk:1; V01:K0:GHDkNlDZSmo=:Zax3Rjzq6HtRfRC5gK0si6 aWzjqwDuUVf31TyUa3NaVMsfcqoDOKUcgYKspRCqkn9VqufCrne2fYFDMKRoHI3HNJee6ivmY pi7pHElepk6HE3Fej5lgT6IlgpUclZ+AkRNBSEWfxDTAaehvkw3cHYNNF80IbL1DvEcmL3nou Fg1CoJ2jXMXxUY0yPPbS4gUeuGIgeXLaqhuYeHwsvKR0jneIOtN6HxO/TXjPiFL0tkLUWc294 Bs7tnmVXiKTi4WfCZsgkAfLZ3GqP19/mmFc7t46iM0MefS0APB4Hfph0Txmdf3FVL3QExV/XT naKpQWCGicWpzQwH4z/qxh+UEclMWdb9gASBH3Aq8pW9GSxnuOLzULkaheXlmP4Pem3K5uZk0 Cw1Z96vFgBQ/e87sIdOjsCklUxdmbmoRitwgHMNGDAAN1cukVfHq74ZyMrL0+3og+2iumvIUy MTXodPxKTKPX+FnftiSDZC4C+8d+9opyKyBn/FSybSdOiVELtl3JhVpqNnVuqCZTdDehGjOer j5Qg9pSMjvmMJm6YyxA0lLWH30fxktWkJaToolrYiqt9pBTDJAneVFxnMD2+RsQEwUMwuzXkQ P+BCev7y+0Sk9jPzj/x6hCictbnHUp5eZqs3X54P/YAX0NwNHQMMoLQ+0gDKVRSc/cCYWjdlT afUt3nXy9kMPwUxGcL/QvxV/RVUK0vANDcj4jNppL65xhSNFBzNfoFPq8OcDx2enuswHsxDer 3jQJTYnuCbE7653inbIzXKzL8vY95nsTGoyPhw== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 'struct timespec' works fine here, but we try to migrate away from it in favor of ktime_t or timespec64. In this case, using ktime_t produces the simplest code. Signed-off-by: Arnd Bergmann --- drivers/media/usb/uvc/uvc_video.c | 11 ++++------- drivers/media/usb/uvc/uvcvideo.h | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) -- 2.9.0 diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index fb86d6af398d..d6bee37cd1b8 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -725,7 +725,7 @@ static void uvc_video_stats_decode(struct uvc_streaming *stream, if (stream->stats.stream.nb_frames == 0 && stream->stats.frame.nb_packets == 0) - ktime_get_ts(&stream->stats.stream.start_ts); + stream->stats.stream.start_ts = ktime_get(); switch (data[1] & (UVC_STREAM_PTS | UVC_STREAM_SCR)) { case UVC_STREAM_PTS | UVC_STREAM_SCR: @@ -865,16 +865,13 @@ size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, { unsigned int scr_sof_freq; unsigned int duration; - struct timespec ts; size_t count = 0; - ts = timespec_sub(stream->stats.stream.stop_ts, - stream->stats.stream.start_ts); - /* Compute the SCR.SOF frequency estimate. At the nominal 1kHz SOF * frequency this will not overflow before more than 1h. */ - duration = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + duration = ktime_ms_delta(stream->stats.stream.stop_ts, + stream->stats.stream.start_ts); if (duration != 0) scr_sof_freq = stream->stats.stream.scr_sof_count * 1000 / duration; @@ -915,7 +912,7 @@ static void uvc_video_stats_start(struct uvc_streaming *stream) static void uvc_video_stats_stop(struct uvc_streaming *stream) { - ktime_get_ts(&stream->stats.stream.stop_ts); + stream->stats.stream.stop_ts = ktime_get(); } /* ------------------------------------------------------------------------ diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 05398784d1c8..a2c190937067 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -452,8 +452,8 @@ struct uvc_stats_frame { }; struct uvc_stats_stream { - struct timespec start_ts; /* Stream start timestamp */ - struct timespec stop_ts; /* Stream stop timestamp */ + ktime_t start_ts; /* Stream start timestamp */ + ktime_t stop_ts; /* Stream stop timestamp */ unsigned int nb_frames; /* Number of frames */ From patchwork Mon Nov 27 13:19:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119708 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp263326qgn; Mon, 27 Nov 2017 05:24:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMbzPhEby4UUVX9ryXfc5UfPcvQE9pA5lATP2vSu97ZTaO1xZjYPUJfVGt74XQVy36nUMCfl X-Received: by 10.101.70.11 with SMTP id v11mr36484985pgq.306.1511789097427; Mon, 27 Nov 2017 05:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511789097; cv=none; d=google.com; s=arc-20160816; b=RCnN2Uh5jMdPyIUgh3YM1yR37M7ORv50RLzoi67auV3hCdcc5QdLO1H9zYg/iUeY4b X9sqUge08AYQoL61pUnV+Ky/PG6KzjkksePiBgHt9wvfn0ecRCso/QVWRiro+BS0YrFv x0v1k8mStOKvO+CiWGBsgbmemw9NayN/pL5Lg9ezD7sTehNX+j+tbCnE4J5KB3Bz2RTO OQiWbpudsaqyvwsoUG42OgtqYVc+K6Ma2P1QGUbUUnCFW6B5eU+Kz0tqtIgXXJheEDrt dTfxUqkjfRaa8nKfDvuutzk4mSUko1h6wcOQkHCZvLDYgqcobjOKYBT4ocyrxzqdPv6m Hh1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=KoyzF7Ry3Ys+VTKVzHk552hzK7Wl/EBgiS+wr7LsYf4=; b=FBlr7FpK1PFCbyi1Duj/AgW0IPwuBc9ZGfwi2/0u3YrKBzLoFx2FCbTqHaPAppReMH DzGdtltg5PnfHZiUS2DOEjPkyJkHRx6/YcLsCn/px15cxqvGplY0+J4oz2XkEtnfose2 ppx4fVsNsNqx7gglCe60By1Rz3gne5uMKwP/cv9A3oP1QGYJbBYkwiEFsXbHOdMRiL9B biAtvtfQfh7HwQZUZ0DRxoyq/E/S4sjRILrCBZbikvinhXh3rz2Sc5l/pJNe3FnVSLOK acpA9ufyV5EDGze9rWHVcmAMqfVHMAC8qFYT1fl2CbPyyPJV65CYDJKo0wXZTy674SBM xZNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y21si15412116pgc.766.2017.11.27.05.24.57; Mon, 27 Nov 2017 05:24:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752182AbdK0NY4 (ORCPT + 4 others); Mon, 27 Nov 2017 08:24:56 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:64621 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbdK0NYz (ORCPT ); Mon, 27 Nov 2017 08:24:55 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0LlnLU-1eseDb3rNo-00ZPSD; Mon, 27 Nov 2017 14:24:44 +0100 From: Arnd Bergmann To: Alan Cox , Sakari Ailus , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: y2038@lists.linaro.org, Arnd Bergmann , Andy Shevchenko , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] [media] staging: atomisp: convert timestamps to ktime_t Date: Mon, 27 Nov 2017 14:19:59 +0100 Message-Id: <20171127132027.1734806-7-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171127132027.1734806-1-arnd@arndb.de> References: <20171127132027.1734806-1-arnd@arndb.de> X-Provags-ID: V03:K0:/+7j1r9EDm5UfyVnGclpfGsQKRTPgB0y2Hku+zqqUO4dHUdmLnv eAQcEbN4tEqMbst/3wuokUI803TngqtSxoXrdF07q/ftQv7grLf4L5b5amKxP+PM+djRk40 cqg4IwcMD0ZZ4aS17DRkGOylJWxHPfyOK/MvSpS9lwVCMSM+5hHL87PJ1vVYcWc+rbuOWxu tnsffaTs+eiRB7OrQziFw== X-UI-Out-Filterresults: notjunk:1; V01:K0:wyQtjaMmdJ4=:ysE8tUvkAKMr2/eei/LXcC boABwV0Dg0jBFj3Qhj+yzLT9GZ3EOAqPMHML3t+8Opi+nQcrTTylvsqReD5E67PcumbMYXJbr nYj8kDEXS3YZ/9L4JzKkleR4rb4Qg1hk5zRx1KwyL9ryH3n10VSIo6BwDHwTSiS1kezLVFWRj wsuY1xm2p+WaB4r7tqy+xv4xkR1LCsfjcyDCdCsAOl0MzfRwfznXJF+GBfTDJlFdygnuEiHdT qW13KbhWQlTjxBy0DOJKFdn5V76+T8ObVKq7d8cet+mXfzBISudjM7RIDROdsDR4IH+y14PuL ZsXssbuCLALKrxMUbgWUAjS3aMRlzozHT86PXGcr9QuekUS8QpqmI0PCPDv1KiS+7C5hk5mB7 fnvq9kNdsh0nJEiO2Za2meOwsJ4HM5Yt/XulUldaTemwok0KFTR7EgVO6YJ8SE8GpB/27NA9G SK1jQIhpa17vU1SqvvsuAbPLH01lLiZniSpt0RTb0T7eoxT1CK0/oAajxUgbxHcgt+XDGDS5a oc8OjaIGjEdG2xg57LjjBZoqh+zvY0vuD5gSFKDiS3lk+0O3MO0KYeFGjgXSB2izSYX1F9pU1 On45Z31rq50iGt0OLBICw2y4jS43oP0cy64hXdFjHp3pYdYGuqObI5JiTtDIHHj1rMT1xWLnm 1/stEXBrjBjnq/CsBEFehTDFvBdCev1RyvZPqJSQmaJCYNNFagWZweTVIRXOfko/eOn0peV6Y F4RF1GJxcQIU1vnBBHcNfvfbXNxSYiNyW6BqHQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org timespec overflows in 2038 on 32-bit architectures, and the getnstimeofday() suffers from possible time jumps, so the timestamps here are better done using ktime_get(), which has neither of those problems. In case of ov2680, we don't seem to use the timestamp at all, so I just remove it. Signed-off-by: Arnd Bergmann --- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 15 ++++++--------- drivers/staging/media/atomisp/i2c/ov5693/ov5693.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) -- 2.9.0 diff --git a/drivers/staging/media/atomisp/i2c/ov2680.h b/drivers/staging/media/atomisp/i2c/ov2680.h index bf4897347df7..03f75dd80f87 100644 --- a/drivers/staging/media/atomisp/i2c/ov2680.h +++ b/drivers/staging/media/atomisp/i2c/ov2680.h @@ -174,7 +174,6 @@ struct ov2680_format { struct mutex input_lock; struct v4l2_ctrl_handler ctrl_handler; struct camera_sensor_platform_data *platform_data; - struct timespec timestamp_t_focus_abs; int vt_pix_clk_freq_mhz; int fmt_idx; int run_mode; diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index 3e7c3851280f..a715ea0e4230 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -973,7 +973,7 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value) if (ret == 0) { dev->number_of_steps = value - dev->focus; dev->focus = value; - getnstimeofday(&(dev->timestamp_t_focus_abs)); + dev->timestamp_t_focus_abs = ktime_get(); } else dev_err(&client->dev, "%s: i2c failed. ret %d\n", __func__, ret); @@ -993,16 +993,13 @@ static int ov5693_q_focus_status(struct v4l2_subdev *sd, s32 *value) { u32 status = 0; struct ov5693_device *dev = to_ov5693_sensor(sd); - struct timespec temptime; - const struct timespec timedelay = { - 0, + ktime_t temptime; + ktime_t timedelay = ns_to_ktime( min((u32)abs(dev->number_of_steps) * DELAY_PER_STEP_NS, - (u32)DELAY_MAX_PER_STEP_NS), - }; + (u32)DELAY_MAX_PER_STEP_NS)); - getnstimeofday(&temptime); - temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs)); - if (timespec_compare(&temptime, &timedelay) <= 0) { + temptime = ktime_sub(ktime_get(), (dev->timestamp_t_focus_abs)); + if (ktime_compare(temptime, timedelay) <= 0) { status |= ATOMISP_FOCUS_STATUS_MOVING; status |= ATOMISP_FOCUS_HP_IN_PROGRESS; } else { diff --git a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h index 2ea63807c56d..68cfcb4a6c3c 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h +++ b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h @@ -221,7 +221,7 @@ struct ov5693_device { struct v4l2_ctrl_handler ctrl_handler; struct camera_sensor_platform_data *platform_data; - struct timespec timestamp_t_focus_abs; + ktime_t timestamp_t_focus_abs; int vt_pix_clk_freq_mhz; int fmt_idx; int run_mode;