From patchwork Mon Nov 27 13:19:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119703 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp258116qgn; Mon, 27 Nov 2017 05:20:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMY4Zya/+89+C+NCrZJiVLqS7QkDlUiVa5aQPdLOX+E3qspcKJjmK+7qM+zBre5mIBr0SAlN X-Received: by 10.99.177.75 with SMTP id g11mr37000467pgp.268.1511788857022; Mon, 27 Nov 2017 05:20:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511788857; cv=none; d=google.com; s=arc-20160816; b=NOblLTEzeDZBLWPyIdkK5rxv98c7VUTMRe5QpvhH5Z1vqW8zgZDJ1xHmrVb8wskS/Y b+Ep1BTKv1Zg24gee6jqpv8nQWsuMRkc3HYWVXSloGD4dASQ8ih8YBZ02y3yoT4Nf99T 1akUOXlgqSZ2TGm1icDYm19wuynsK8kp1JE6rOJjKKbM/b7S6jdDngPREdTop+uuVrHH qo2nu36iw72nouLo8JMVQU0VTS8VKL+EKMb/QkHX1NfniwZC7G7U8ww2S5DfXMy7dq3i /J6Ub0eG+W95kPrZBdT8w5fMTOLBuOK5uk4DXC1ZyMVQni+cAmgIRephGCSFGmmEMlOZ cKNg== 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=HwazMe7LoyNZPYxRmmBBsXkxI5SaK/9EGKHG1TcB7pA=; b=WLIzHwyjPRavbo5A30O3r+4cO7e2y7fOErRUn4t2L1Ai+xx5RDP4ekYWu6aeMbaBfp 8bZ53e4CeG5Zbi3IvtT7elGtv20i/PaJ2xzs9NcVxorNlaiMY6wKc6cZwiCiWaRdb1s5 0TCVS8pgmNDG8U7PAiUump12GMhollMYIk5W25S91gRJPaIWLrStOurbbV+Vh2LtwwIJ OKVcigigGugZoI1+TfKTiz6vNr1M4ochzC58EFGum4BDXKioLWDsJ9VPBAlM4hqQYc6e yYv/r8owPDqH1UckbiNwUcbHf5QED2ksWtA/XLY5oKk9bmZEsP2VB/XNkROZ/9h0x4F0 mWgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 h1si17356278pld.629.2017.11.27.05.20.56; Mon, 27 Nov 2017 05:20:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752419AbdK0NUy (ORCPT + 28 others); Mon, 27 Nov 2017 08:20:54 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:63751 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752363AbdK0NUv (ORCPT ); Mon, 27 Nov 2017 08:20:51 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MOAxo-1eDnZ215jY-005aU9; Mon, 27 Nov 2017 14:20:44 +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 2/8] [media] uvc_video: use ktime_t for timestamps Date: Mon, 27 Nov 2017 14:19:54 +0100 Message-Id: <20171127132027.1734806-2-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:wMKmB2nuJSUj0y4O/3KMzYCdEqNAQ78ywLbUlOUbOwpHLO/KpJl tm77/fFfgVqESl5UFzhplSnMLI1SwYNBCr3QMnLgKAk/Rfcinur+oX1BRYpAMOPwKBIZbqp vnShC0kln80Lq0Z10WZwQ6Yo/4LnjSo5dspFZcPGGJHhuc5xGMe2ABb8WTF7DwYaXEjYsRW St/JI+Mbgw5lHFI7RzBvA== X-UI-Out-Filterresults: notjunk:1; V01:K0:vVCfj/y8OVo=:peqndEu39Of23LhWuuVGwO Qw4klqZ5aXOnKwzdaES46St9cy22mHlvYZJyzRTm2wMe1M0XLA3Km4u7bO8Lyt8CFUvFvfY7o 47me3PL12AOL0JrfzXLYjb7TNKeC68pGAQ9nk1jPU1ce3pQzDtnj8jCjYX2hPtsljQD5WhH+X gecWBmbhOCHpKMuHS/RHpZOhepM54N9QqsHYcurIk3jZ/OJCIwhdBYqzUNpc/sPcROF0l2vhG ghSI9FEv5m4DGpCwriTLG8by8F1fU8YCZrvfyZBFT1pucA/iK3O2TB5+a0iAJu+3oyKA+XPcb C+tofCMIvMhx8jFZi3TAgWHtWse6at8JsLG0D4Oalf52GDgAj78Y9qu0CkbUNgyFCQEApPDRa YFJE1IjXPRONkju8BA7DB6RRAGjYBpz9Pp93mLJLAA8up4kMi6gbzC5LqZ7QXPJpOuxshVQ6a 8CGJLICyTJ0Wisel5tuHKz/k+VW8KSrzR1DC2Y0eZUJV/h1jVAYn6dJvBTbM+TfC8COAjfe4X QOpa4aChY7QzIJtIThuLWcxtxKcrTxlAizbwDNzqM1Ve5t8mAXD87Datm1iU7dc7TYy6JLPz2 6hrHvqorRMTaDkvw2uFvQR3bFY9xV6er9Z11tSofgJTK2e3swYlMPiY1b+xVHPibNj8D9ah25 az3uXh0JsgUXvOZTC3RERwcHWh9OfCKzJnXssTW8GHNmXg95C+l9QQf+ZBrbjWI/WXgPaPdPz DEW00QAupjGN/u4z8iJInSnDQB4ThoJc3dowIA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org uvc_video_get_ts() returns a 'struct timespec', but all its users really want a nanoseconds variable anyway. Changing the deprecated ktime_get_ts/ktime_get_real_ts to ktime_get and ktime_get_real simplifies the code noticeably, while keeping the resulting numbers unchanged. Signed-off-by: Arnd Bergmann --- drivers/media/usb/uvc/uvc_video.c | 37 ++++++++++++------------------------- drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 13 insertions(+), 26 deletions(-) -- 2.9.0 Reviewed-by: Laurent Pinchart diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index d6bee37cd1b8..f7a919490b2b 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -369,12 +369,12 @@ static int uvc_commit_video(struct uvc_streaming *stream, * Clocks and timestamps */ -static inline void uvc_video_get_ts(struct timespec *ts) +static inline ktime_t uvc_video_get_time(void) { if (uvc_clock_param == CLOCK_MONOTONIC) - ktime_get_ts(ts); + return ktime_get(); else - ktime_get_real_ts(ts); + return ktime_get_real(); } static void @@ -386,7 +386,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, bool has_pts = false; bool has_scr = false; unsigned long flags; - struct timespec ts; + ktime_t time; u16 host_sof; u16 dev_sof; @@ -436,7 +436,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, stream->clock.last_sof = dev_sof; host_sof = usb_get_current_frame_number(stream->dev->udev); - uvc_video_get_ts(&ts); + time = uvc_video_get_time(); /* The UVC specification allows device implementations that can't obtain * the USB frame number to keep their own frame counters as long as they @@ -473,7 +473,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, sample->dev_stc = get_unaligned_le32(&data[header_size - 6]); sample->dev_sof = dev_sof; sample->host_sof = host_sof; - sample->host_ts = ts; + sample->host_time = time; /* Update the sliding window head and count. */ stream->clock.head = (stream->clock.head + 1) % stream->clock.size; @@ -613,14 +613,12 @@ void uvc_video_clock_update(struct uvc_streaming *stream, struct uvc_clock_sample *first; struct uvc_clock_sample *last; unsigned long flags; - struct timespec ts; + u64 timestamp; u32 delta_stc; u32 y1, y2; u32 x1, x2; u32 mean; u32 sof; - u32 div; - u32 rem; u64 y; if (!uvc_hw_timestamps_param) @@ -667,9 +665,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream, if (x1 == x2) goto done; - ts = timespec_sub(last->host_ts, first->host_ts); y1 = NSEC_PER_SEC; - y2 = (ts.tv_sec + 1) * NSEC_PER_SEC + ts.tv_nsec; + y2 = (u32)ktime_to_ns(ktime_sub(last->host_time, first->host_time)) + y1; /* Interpolated and host SOF timestamps can wrap around at slightly * different times. Handle this by adding or removing 2048 to or from @@ -686,24 +683,18 @@ void uvc_video_clock_update(struct uvc_streaming *stream, - (u64)y2 * (u64)x1; y = div_u64(y, x2 - x1); - div = div_u64_rem(y, NSEC_PER_SEC, &rem); - ts.tv_sec = first->host_ts.tv_sec - 1 + div; - ts.tv_nsec = first->host_ts.tv_nsec + rem; - if (ts.tv_nsec >= NSEC_PER_SEC) { - ts.tv_sec++; - ts.tv_nsec -= NSEC_PER_SEC; - } + timestamp = ktime_to_ns(first->host_time) + y - y1; uvc_trace(UVC_TRACE_CLOCK, "%s: SOF %u.%06llu y %llu ts %llu " "buf ts %llu (x1 %u/%u/%u x2 %u/%u/%u y1 %u y2 %u)\n", stream->dev->name, sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536), - y, timespec_to_ns(&ts), vbuf->vb2_buf.timestamp, + y, timestamp, vbuf->vb2_buf.timestamp, x1, first->host_sof, first->dev_sof, x2, last->host_sof, last->dev_sof, y1, y2); /* Update the V4L2 buffer. */ - vbuf->vb2_buf.timestamp = timespec_to_ns(&ts); + vbuf->vb2_buf.timestamp = timestamp; done: spin_unlock_irqrestore(&clock->lock, flags); @@ -1007,8 +998,6 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, * when the EOF bit is set to force synchronisation on the next packet. */ if (buf->state != UVC_BUF_STATE_ACTIVE) { - struct timespec ts; - if (fid == stream->last_fid) { uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " "sync).\n"); @@ -1018,11 +1007,9 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, return -ENODATA; } - uvc_video_get_ts(&ts); - buf->buf.field = V4L2_FIELD_NONE; buf->buf.sequence = stream->sequence; - buf->buf.vb2_buf.timestamp = timespec_to_ns(&ts); + buf->buf.vb2_buf.timestamp = uvc_video_get_time(); /* TODO: Handle PTS and SCR. */ buf->state = UVC_BUF_STATE_ACTIVE; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a2c190937067..d7797dfb6468 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -536,8 +536,8 @@ struct uvc_streaming { struct uvc_clock_sample { u32 dev_stc; u16 dev_sof; - struct timespec host_ts; u16 host_sof; + ktime_t host_time; } *samples; unsigned int head; From patchwork Mon Nov 27 13:19:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119704 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp258293qgn; Mon, 27 Nov 2017 05:21:04 -0800 (PST) X-Google-Smtp-Source: AGs4zMZN5hmfKxaobxSUAkAUsPxxHJKVnIGhHXXKCuHQP0w68Wi9sFV32pGv2c8hKK6A48sAK5fJ X-Received: by 10.98.99.68 with SMTP id x65mr19758372pfb.56.1511788864769; Mon, 27 Nov 2017 05:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511788864; cv=none; d=google.com; s=arc-20160816; b=KIbgQudaIsNZzbSjAte06A0scpFaocuUpDP6WW5U0DDWNSZBYPC0H06BPBXNIbnV9g 9aslDu7TVaK0YjgNtdUr4YL4/HUV8XAPnk4tyftaOP3Ipv7DRcngLZbEpHNaQ+Vpe7Lo BqshVGcvHE9PaXMxxVIXpcScD4/G0IXqURd0OLIXKNKL2R9M0UM+omQP6Wx7OBzSv5+f eOYAxJZ7vJsVOGHBJfmtQ6+lwWQWRcpKNTIrGJPPvOBvG0bE4I/5Od8cz32Bylay9mWg PdZtx99T13ugoDugAZcmpYNK7yb1tHYIK7NOw5rxG8wUB83ks+g8m/Cez6vsrZG0ePZy dP6Q== 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=3zirZbU7cbDEYVgySSOwfDDa2FBl7t+5W+i+3uyMLQ4=; b=nEzmB6OUrvJdrpbFC1mF/hziXlsKogUrDcpweWMV3VoyYGnfaabfS7v2N+K8xru0FD CtcsyETrba77u7Mei/sG333TAS5Z6t9jPu3EpI2OypIpu5/qoMMbtrFUqVqOpwL6UriT HeEromAfTEMjBjrIS/Q4vuMZh11jJhLorElGYdWp/x4LCT28Dec1DWkTk2ytBDCdK2l9 uxNSHYka1tmxoBHO/pkFfH9yzCHBDthkXxZurK48yIXoQKOnfR3u5vffO2Y0kiYyA20T bKo202Lb4dZpHH9GXDPZzrgPPZ3OgHZd19VvFr7seZVwvrQzxY11AhnJJWBAd2lO2+9w Ml/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 h1si17356278pld.629.2017.11.27.05.21.04; Mon, 27 Nov 2017 05:21:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752470AbdK0NVC (ORCPT + 28 others); Mon, 27 Nov 2017 08:21:02 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:64383 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751570AbdK0NVA (ORCPT ); Mon, 27 Nov 2017 08:21:00 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MC1MO-1eS91r1qDo-008uOH; Mon, 27 Nov 2017 14:20:55 +0100 From: Arnd Bergmann To: Bluecherry Maintainers , Anton Sviridenko , Andrey Utkin , Ismael Luceno , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] [media] solo6x10: use ktime_get_ts64() for time sync Date: Mon, 27 Nov 2017 14:19:55 +0100 Message-Id: <20171127132027.1734806-3-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:FbTw/8Y9brlcBCI1tpM56+AGBf2vaLj19c24OzcxKAi/ImSqk5H EgrkiIWtuwATl2NplOaNQ4s+UCAEQNFpAfDOUG3CFFxE+5CNAHMg09VKvntiCTsOaEjPsbN ngBES4n6S3nPyIH5tB82lk7Zyjo+o0Z/RzrAAhnCYc/d4isX/c/IlMO7lpbSCuTR9s1zgb1 6ohMlb94Cxbimskgd4g/g== X-UI-Out-Filterresults: notjunk:1; V01:K0:AN3otbxvyvo=:8chms7JmlGDs04j7uUlts/ zDasdAoEIBxWQfh3b83bELpqBaZen4f7GWIG5lodo5jCb7FA4utBwAtljorf9WSgvC21bjEdC BvqHfV5aDm3tipoK2aPlzC8kEkp6NIU5pBG/OfmfmhFOhAxyUb3woo35o7ggXAh0HY7KxSTO1 /zS/xDcYBcxgilQE+T/eX+3ze8Ej/VY8ZNdnm8+/RdyyQLfhpNTV/KoewIjj5Du1sMg+9msoL 5xNenZkQg+tciKkOtQQ0EZ+Iwv+yIxJAVg8WvBrs1JYSM66iWlclq1sqIsYYKecOkhpoBMHZU S8MhVv4NU/9+WO2sdBvCf2JyQcc8+CoES/Q4sOCjFsyZFjvli5Gr5TbH6ZUYn4UdumBaJhp5A BcuyUt4pGrHEEouZAmz2MsihxSLfV57z8F3QK3BACQ3X8H+eK7/z/utFaGKjn5JE1qNg2hrpT fNm2UcbKGHkn5vvQ/Sm2Ok3ZtgrposfWpy5J6P2XOOC8PZlLyOZCRnV5BwIkStPJBki1QSp6p GXWYhn4aHNuxDvNE1uhlEIGOWir+50VV9Mcm5sQ2YIVg5kb7A5vdoYpQsKcA0OJw9ZptJKk4A obORgYSQybG/rA28lUkVbDjA8dNOlU9I89QY6C5ex3pad8uAcQD8phAdpl5eF4HcONcn05H14 2hQ3S+TVVF1xXSJO8l4mTUGrCQK0gD8l+t0eg2SyRYbjbTLG78vplvcJuHZOydiuff/OWRTrY v8hGB6nDlp/AYGx9xhIlWGvp/vYyi5xCuvL8Ng== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org solo6x10 correctly deals with time stamps and will never suffer from overflows, but it uses the deprecated 'struct timespec' type and 'ktime_get_ts()' interface to read the monotonic clock. This changes it to use ktime_get_ts64() instead, so we can eventually remove ktime_get_ts(). Signed-off-by: Arnd Bergmann --- drivers/media/pci/solo6x10/solo6x10-core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.9.0 Signed-off-by: Ismael Luceno diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c index ca0873e47bea..19ffd2ed3cc7 100644 --- a/drivers/media/pci/solo6x10/solo6x10-core.c +++ b/drivers/media/pci/solo6x10/solo6x10-core.c @@ -47,18 +47,19 @@ MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)"); static void solo_set_time(struct solo_dev *solo_dev) { - struct timespec ts; + struct timespec64 ts; - ktime_get_ts(&ts); + ktime_get_ts64(&ts); - solo_reg_write(solo_dev, SOLO_TIMER_SEC, ts.tv_sec); - solo_reg_write(solo_dev, SOLO_TIMER_USEC, ts.tv_nsec / NSEC_PER_USEC); + /* no overflow because we use monotonic timestamps */ + solo_reg_write(solo_dev, SOLO_TIMER_SEC, (u32)ts.tv_sec); + solo_reg_write(solo_dev, SOLO_TIMER_USEC, (u32)ts.tv_nsec / NSEC_PER_USEC); } static void solo_timer_sync(struct solo_dev *solo_dev) { u32 sec, usec; - struct timespec ts; + struct timespec64 ts; long diff; if (solo_dev->type != SOLO_DEV_6110) @@ -72,11 +73,11 @@ static void solo_timer_sync(struct solo_dev *solo_dev) sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC); usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC); - ktime_get_ts(&ts); + ktime_get_ts64(&ts); - diff = (long)ts.tv_sec - (long)sec; + diff = (s32)ts.tv_sec - (s32)sec; diff = (diff * 1000000) - + ((long)(ts.tv_nsec / NSEC_PER_USEC) - (long)usec); + + ((s32)(ts.tv_nsec / NSEC_PER_USEC) - (s32)usec); if (diff > 1000 || diff < -1000) { solo_set_time(solo_dev); From patchwork Mon Nov 27 13:19:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119705 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp260197qgn; Mon, 27 Nov 2017 05:22:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMY2sfSESQnReugb6pHPLYjiEHSdnYu1gT5LpQsIBVNyap8xbecfYyYMMOFQm7WXuH68vH2k X-Received: by 10.98.249.5 with SMTP id o5mr36907682pfh.54.1511788949447; Mon, 27 Nov 2017 05:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511788949; cv=none; d=google.com; s=arc-20160816; b=C4HNKJTBKHUnPYOHiy03pzbeWs1Q+H/iE2l8GYN/jq9qn1WBAlYOnkmQukih2+rNhj 3O2M2DfIOFsJi++e7XVRR12KnZGN3SYlIkAXy7bMw3yAcdhvM0Dit/KNc0YxLjLLGtf0 Fci2gVQ53Poe5NvmaYebMKc0j1esUuvP8VgR3cLfezZ01nPSoBBYDDcJGPTJmUlSTse7 IMdYVDfTfeY9fNP02jPk98msmFxscN9gzhZpnOScjQ7XeT658zNFdmRzm4Nfb6fPnIkg npIiv7yxD6Mt3uenVPtWVC9OYOPT38F+cwBG6U6EfVJTgeSispUabGuOE+ZQgqilJ350 rQ1w== 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=tmKkbGKa43/ULzh3rpb17oXuAS/1fjkbkjo3hI795mY=; b=vV16kFlE2IPh7Cgtre15p2k4ZVMFsfaQDu57R4sc5z/AGzFaWqsfzHZ4qS0BA9BwRy 2dbGg9khVI/bAiin3d55+XfIZYJ9bQlWtRz17/mf1NRk67r6HKl/JtTf869UgboGyYz5 I8khzsL+9N29u3Fqg3+Pux0guF8KZmaEYPUYHd8iUyDnawR7VkoQzT58/XfTaEPzDodv TPyKcfS89EK5/RyHJdssNvyW/VUmpcjQq0LtVY+UmQtj289Cmw9GEeRsP0LJIWTM7lfB 9zNIIouzj5n61so9SRepgcT2IvNxBsDmOEMcwFUztiKY679MhV4nWQYNDGfwlvhQ1iIt t1kA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 k21si7814671pfb.44.2017.11.27.05.22.29; Mon, 27 Nov 2017 05:22:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752409AbdK0NW1 (ORCPT + 28 others); Mon, 27 Nov 2017 08:22:27 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:62821 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752083AbdK0NWZ (ORCPT ); Mon, 27 Nov 2017 08:22:25 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MJTL9-1eHwhx2RRb-0036i2; Mon, 27 Nov 2017 14:21:50 +0100 From: Arnd Bergmann To: Eric Anholt , Stefan Wahren , Greg Kroah-Hartman , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com Cc: y2038@lists.linaro.org, Arnd Bergmann , Narcisa Ana Maria Vasile , Michael Zoran , Aishwarya Pant , Derek Robson , linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] [media] staging: bcm2835-camera use ktime_t for timestamps Date: Mon, 27 Nov 2017 14:19:56 +0100 Message-Id: <20171127132027.1734806-4-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:MVl04qGSRhXhkCMD9+Gi42dvUTcVZ9FC4uN2YpDCwZOkrZKv3Ce BlPC4UlSDWzLQQalaVUuoH5iQFmrYgY5/cwadlHSQZXZY+LNFhnpxSfdbIcGycVi0YEPro8 9QJOqtqkahATzMgSYNY4IZgSodBC4zMQgf8HcLWZ62P8sST52qB4I6I9O1oBjO5ZtBR4rvn weS6N49yzhl/+e5k07fBA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Igjie9rb1Lw=:7etzPtGzjSgbWHFNTzaLow Zmxr9+R4dj/lzo+1EOKpVGKwH8mYFJJWBQwUn0W7i8UQyaw4S3xOgXPA6QPP6W1Ya3UDTO/8T CzTJiAEOHwBwAKRon8BXlgq/6JdYJ6WXb7Mv3yoO1Goze9fyUXKXiwHR9sW+CpEQT8YSDEHcY KY1Ar3+wJIRxZhGN56QiS+p+sjeE2gFTR4UXSK9wmD+BXeqKX9ibv+y+3GFgRhQRAnhrlFzqS yabfdULyPKD2hqEOOki8Oey6n3wGswzrlAu87NHfetqSV2xhZQj0WDgb+Ii5c5QX3lELsUSVD aH5drHvtcKbm77pJemr5jVvcL5pZ8uK0alWLU1esYpIlaz/l+saY+7EYtwafmkPcfkdPCHgh8 CYL6klUCUYCfc1m08S7MEoFt9tJoVYjIRFBMIiUDev1I0Jq+oafKw4yK4H/fesuQDEggBmbuQ woRZvMBsbCmlmoQU5PTP/4bpM0grVpeoL/420i5DzapvPDMgjW7q1yB06gbs24uy4AOCduzPD GrliXiIQHXZdYBKEHKlkM6N/qo3czdwVWj/A06Q65CuV10I6tKUWiG0VMBx13gr5RYR80HTcN 8iDiOUNvKyWeEIvdADTT2b+jmiABefl3js48h5meRRhhNjQp5lHjEtPfkYn7i1wTziRpe3L0z +zWTsyMgK+YmwF93Lb02xgeziwARO/Za7Sn7BSF7RCSfTO8X57tcV1ZH7IYrc2RZPitlMAgcu TeiWzJPKMjwNruJWXaQUNzOCvL9jSUEPuyXpkw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct timeval is deprecated for in-kernel use, and converting this function to use ktime_t makes it simpler as well. Signed-off-by: Arnd Bergmann --- .../vc04_services/bcm2835-camera/bcm2835-camera.c | 37 ++++++---------------- .../vc04_services/bcm2835-camera/bcm2835-camera.h | 2 +- 2 files changed, 10 insertions(+), 29 deletions(-) -- 2.9.0 diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c index be936b8fe317..d8766b166675 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c @@ -343,37 +343,18 @@ static void buffer_cb(struct vchiq_mmal_instance *instance, if (dev->capture.frame_count) { if (dev->capture.vc_start_timestamp != -1 && pts != 0) { - struct timeval timestamp; + ktime_t timestamp; s64 runtime_us = pts - dev->capture.vc_start_timestamp; - u32 div = 0; - u32 rem = 0; - - div = - div_u64_rem(runtime_us, USEC_PER_SEC, &rem); - timestamp.tv_sec = - dev->capture.kernel_start_ts.tv_sec + div; - timestamp.tv_usec = - dev->capture.kernel_start_ts.tv_usec + rem; - - if (timestamp.tv_usec >= - USEC_PER_SEC) { - timestamp.tv_sec++; - timestamp.tv_usec -= - USEC_PER_SEC; - } + timestamp = ktime_add_us(dev->capture.kernel_start_ts, + runtime_us); v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, - "Convert start time %d.%06d and %llu " - "with offset %llu to %d.%06d\n", - (int)dev->capture.kernel_start_ts. - tv_sec, - (int)dev->capture.kernel_start_ts. - tv_usec, + "Convert start time %llu and %llu " + "with offset %llu to %llu\n", + ktime_to_ns(dev->capture.kernel_start_ts), dev->capture.vc_start_timestamp, pts, - (int)timestamp.tv_sec, - (int)timestamp.tv_usec); - buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL + - timestamp.tv_usec * 1000ULL; + ktime_to_ns(timestamp)); + buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp); } else { buf->vb.vb2_buf.timestamp = ktime_get_ns(); } @@ -547,7 +528,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count) "Start time %lld size %d\n", dev->capture.vc_start_timestamp, parameter_size); - v4l2_get_timestamp(&dev->capture.kernel_start_ts); + dev->capture.kernel_start_ts = ktime_get(); /* enable the camera port */ dev->capture.port->cb_ctx = dev; diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h index 404037476bc5..83920683a448 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h @@ -92,7 +92,7 @@ struct bm2835_mmal_dev { /* VC start timestamp for streaming */ s64 vc_start_timestamp; /* Kernel start timestamp for streaming */ - struct timeval kernel_start_ts; + ktime_t kernel_start_ts; struct vchiq_mmal_port *port; /* port being used for capture */ /* camera port being used for capture */ From patchwork Mon Nov 27 13:19:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119706 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp260542qgn; Mon, 27 Nov 2017 05:22:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMacVv5kBWUbetZLRK7SGSGL4xZravR00pRcFUiW/uvRCg+zd9xKh76OVSrp76xAn4yHV1Ya X-Received: by 10.99.124.75 with SMTP id l11mr37946086pgn.453.1511788967556; Mon, 27 Nov 2017 05:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511788967; cv=none; d=google.com; s=arc-20160816; b=A+IWvNo0nVBDZDyztuIoUDeBS3Mv8+J6yxeOwh4x/b5Y8pGi9qn6hGxje9fjjhGw9A cgZv0SjTF0hSM+3qcOMtO+YyNOBv34n1WkjRX4JFjjcv6Pj4RwaQJztPiBdKtYI0/4Kf R4lVBDZ/g07KQErsc7zDqyZ7H2v1+RJMzJT6+YUHR1sl59rLNKuSCcdIx6Krt2ClbjWZ usJOrw2lD/VaU8zyfSgqXLE9L3jGH9GD93QFQOOREOtoenQ8Vq8h380OvWNi8E59d8mH L5D+Sz2zA2x73SydERmekXmk8ly4biRJLgHwiWcsYnd1E8cU11tlLEYn4AkELpNUipqk ee1Q== 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=lSVfjEHJc6GB2oEbjlwE9dnQ6mzAgETc7S7c9BRwsls=; b=IPZYFf0seFCdsDi15fd3wA+UpwpGJDguIcEdBo9giAY2TGecH7aVi8LMY2K6uMoT7z TjDUzaPVAAQjeLZ7mYtjcPQuZJanMhvPpZtXxA3iBHFPhnAIvONUNgxw+bnwOrlj2DjY Nw6x0y/1jvJ8iHANPInWMqPhQXQxdruvE3iU5NnyfGYtl8Nk4WY1hNMVGm2PJmtmza9S GeSFpXobsXOfSvYgphc0gcgu2L0Z+Xch9TAyt90FgktDSPdRwTDyFqWc+bKdJDNBMqOo ciKyudA7YRXE4Y69XqTO1G4Fcj7ZJCPQzMvjiUpvNLH4+ybPJJcIQRtI80cuW0hK0ziS 3ALA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 o185si1046772pga.27.2017.11.27.05.22.47; Mon, 27 Nov 2017 05:22:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752542AbdK0NWp (ORCPT + 28 others); Mon, 27 Nov 2017 08:22:45 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:60076 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752094AbdK0NWm (ORCPT ); Mon, 27 Nov 2017 08:22:42 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MYNYv-1effbw21Mf-00V8F6; Mon, 27 Nov 2017 14:22:37 +0100 From: Arnd Bergmann To: Laurent Pinchart , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] [media] omap3isp: support 64-bit version of omap3isp_stat_data Date: Mon, 27 Nov 2017 14:19:57 +0100 Message-Id: <20171127132027.1734806-5-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:IrYHyXSYeJ3hu3oPd7MR9vcQyr4byNSb/Up5tklqa6gqpBAMz7v hhNOYuLssgbTtQZpBt28PeEk1nWNwAMeMgq8gWpUoxaLh9HqnZjC59n/hoKvXTFLMXX/IBp o0Istf4pLSgNahzJkrY2HTTVbXchEhFIMLjwJk3N+v1mzZiwnm0BJAOUeyaZHKCX1leSqWp f6gf/0NVg7aEAgGoEXRgg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Kqwv/1wrXHM=:WSpEb071gwrI2g76xmdBsJ 5g5848+/VYUOwe/PEIxwZNCbqmrtycc4SejK/SuSyvW6ALhdaIIl3JOfG/NVX38q1TNw0Y48n pCeK+hyJdPunqHO1Y/mrghR+4RwQflXHlXHgHahscpVPns2qIPgUUULE3/927Rlm5/aiSmNVR bgl+74BxJaKefZdSEAJCeq9z287Mr/rdcjEgD3MKrLhcEyI13lIA59KK/0h8J61zbeYb/4D/4 Htt7CZUrTxf1gdR6maVa9Jt6LDhlpN4ly3olyAvvVZ19XXA86uf6kNqJfffI96H6+F3adYAdx /43guigijSbq8NwSc0SOL4dyeKh96PxFDB1lqCTUBLpfWpbZqsueaoJDbSQ8PtRGMm+7LJLB/ 4YfstLALZwchwnnqyg2JPUZM/KMjtauVu5U4ik11+CJryqYLN1I9fZbPbAI0mYyw00t8YHeks Wr1M7lfYUs3s/0P/sAHxYVccdaLLSELewxUe3lV5MGP2FZ9pP6wd72z/W2H/ZqVTZv+rjJ9t2 sBn+hUjCeKjR0FhQAQt/8lJjER6H2+dLcGsqdIbyeczCCnVs1uUZRV53yOaXCFEx5BkCVVTiY sOzbe9Pt3OZGHfrM2J6wyfDWOqtH2nkeb7JFF8am+Hr48ZFsgcGYsuUek5oUUe837Q7NCUzCY O86EUMCbrhPO9LaeTpicR9sgGfChxL/zy+9uWDId0a3hKpeKvWadnBzKFXqDUQih+1R1M0UTI 9e23Ieqt+6U6P5mXwoZbe7oj/R9LRWZLyhFJRg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org C libraries with 64-bit time_t use an incompatible format for struct omap3isp_stat_data. This changes the kernel code to support either version, by moving over the normal handling to the 64-bit variant, and adding compatiblity code to handle the old binary format with the existing ioctl command code. Fortunately, the command code includes the size of the structure, so the difference gets handled automatically. In the process of eliminating the references to 'struct timeval' from the kernel, I also change the way the timestamp is generated internally, basically by open-coding the v4l2_get_timestamp() call. Signed-off-by: Arnd Bergmann --- drivers/media/platform/omap3isp/isph3a_aewb.c | 2 ++ drivers/media/platform/omap3isp/isph3a_af.c | 2 ++ drivers/media/platform/omap3isp/isphist.c | 2 ++ drivers/media/platform/omap3isp/ispstat.c | 21 +++++++++++++++++++-- drivers/media/platform/omap3isp/ispstat.h | 4 +++- include/uapi/linux/omap3isp.h | 22 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 3 deletions(-) -- 2.9.0 diff --git a/drivers/media/platform/omap3isp/isph3a_aewb.c b/drivers/media/platform/omap3isp/isph3a_aewb.c index d44626f20ac6..3c82dea4d375 100644 --- a/drivers/media/platform/omap3isp/isph3a_aewb.c +++ b/drivers/media/platform/omap3isp/isph3a_aewb.c @@ -250,6 +250,8 @@ static long h3a_aewb_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { unsigned long *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/isph3a_af.c b/drivers/media/platform/omap3isp/isph3a_af.c index 99bd6cc21d86..4da25c84f0c6 100644 --- a/drivers/media/platform/omap3isp/isph3a_af.c +++ b/drivers/media/platform/omap3isp/isph3a_af.c @@ -314,6 +314,8 @@ static long h3a_af_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { int *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/isphist.c b/drivers/media/platform/omap3isp/isphist.c index a4ed5d140d48..d4be3d0e06f9 100644 --- a/drivers/media/platform/omap3isp/isphist.c +++ b/drivers/media/platform/omap3isp/isphist.c @@ -435,6 +435,8 @@ static long hist_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { int *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index 47cbc7e3d825..5967dfd0a9f7 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "isp.h" @@ -237,7 +238,7 @@ static int isp_stat_buf_queue(struct ispstat *stat) if (!stat->active_buf) return STAT_NO_BUF; - v4l2_get_timestamp(&stat->active_buf->ts); + ktime_get_ts64(&stat->active_buf->ts); stat->active_buf->buf_size = stat->buf_size; if (isp_stat_buf_check_magic(stat, stat->active_buf)) { @@ -500,7 +501,8 @@ int omap3isp_stat_request_statistics(struct ispstat *stat, return PTR_ERR(buf); } - data->ts = buf->ts; + data->ts.tv_sec = buf->ts.tv_sec; + data->ts.tv_usec = buf->ts.tv_nsec / NSEC_PER_USEC; data->config_counter = buf->config_counter; data->frame_number = buf->frame_number; data->buf_size = buf->buf_size; @@ -512,6 +514,21 @@ int omap3isp_stat_request_statistics(struct ispstat *stat, return 0; } +int omap3isp_stat_request_statistics_time32(struct ispstat *stat, + struct omap3isp_stat_data_time32 *data) +{ + struct omap3isp_stat_data data64; + int ret; + + ret = omap3isp_stat_request_statistics(stat, &data64); + + data->ts.tv_sec = data64.ts.tv_sec; + data->ts.tv_usec = data64.ts.tv_usec; + memcpy(&data->buf, &data64.buf, sizeof(*data) - sizeof(data->ts)); + + return ret; +} + /* * omap3isp_stat_config - Receives new statistic engine configuration. * @new_conf: Pointer to config structure. diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index 6d9b0244f320..923b38cfc682 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h @@ -39,7 +39,7 @@ struct ispstat_buffer { struct sg_table sgt; void *virt_addr; dma_addr_t dma_addr; - struct timeval ts; + struct timespec64 ts; u32 buf_size; u32 frame_number; u16 config_counter; @@ -130,6 +130,8 @@ struct ispstat_generic_config { int omap3isp_stat_config(struct ispstat *stat, void *new_conf); int omap3isp_stat_request_statistics(struct ispstat *stat, struct omap3isp_stat_data *data); +int omap3isp_stat_request_statistics_time32(struct ispstat *stat, + struct omap3isp_stat_data_time32 *data); int omap3isp_stat_init(struct ispstat *stat, const char *name, const struct v4l2_subdev_ops *sd_ops); void omap3isp_stat_cleanup(struct ispstat *stat); diff --git a/include/uapi/linux/omap3isp.h b/include/uapi/linux/omap3isp.h index 1a920145db04..87b55755f4ff 100644 --- a/include/uapi/linux/omap3isp.h +++ b/include/uapi/linux/omap3isp.h @@ -55,6 +55,8 @@ _IOWR('V', BASE_VIDIOC_PRIVATE + 5, struct omap3isp_h3a_af_config) #define VIDIOC_OMAP3ISP_STAT_REQ \ _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data) +#define VIDIOC_OMAP3ISP_STAT_REQ_TIME32 \ + _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data_time32) #define VIDIOC_OMAP3ISP_STAT_EN \ _IOWR('V', BASE_VIDIOC_PRIVATE + 7, unsigned long) @@ -165,7 +167,14 @@ struct omap3isp_h3a_aewb_config { * @config_counter: Number of the configuration associated with the data. */ struct omap3isp_stat_data { +#ifdef __KERNEL__ + struct { + __s64 tv_sec; + __s64 tv_usec; + } ts; +#else struct timeval ts; +#endif void __user *buf; __u32 buf_size; __u16 frame_number; @@ -173,6 +182,19 @@ struct omap3isp_stat_data { __u16 config_counter; }; +#ifdef __KERNEL__ +struct omap3isp_stat_data_time32 { + struct { + __s32 tv_sec; + __s32 tv_usec; + } ts; + __u32 buf; + __u32 buf_size; + __u16 frame_number; + __u16 cur_frame; + __u16 config_counter; +}; +#endif /* Histogram related structs */ From patchwork Mon Nov 27 13:19:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119707 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp261555qgn; Mon, 27 Nov 2017 05:23:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMZJVEiGpF/tv8WeLHmEtCsxSeW1bubgKqBtd1fw+8NNHjxkj46AJB8lnU3NqGBY3xBSikUj X-Received: by 10.98.213.71 with SMTP id d68mr34976340pfg.171.1511789013853; Mon, 27 Nov 2017 05:23:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511789013; cv=none; d=google.com; s=arc-20160816; b=XPDbeWuZDtpCdH6cGBE5fK2vzq2fC7nQbe+WMlqHItSsaltWS8a7ORTolBwuigWANm uesWJlofCVW2BZExecqAs0N307jxCm2MARk7yGrinvFkzarFanRB2GaWJxKLrI8hWoYx qC0A0JWR6V9PNjhDaeXFwbSXofpHSheoTz0M5guZvojJ+QtBQDMfvrecpyYWz3aWLmnh E36VAIZzHmW1f9bp6lZvN7H+Aw5wdw++tr7dzQ+OGn1swjo/zuKxjvwZskjbrU2yHGI/ mppYGs2LV8Z+6mNxrsK6WrjZTnGTKPb13GKEOqqnskUiDse+Alv4VD42GxPkqz1qem0q fOFg== 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=l5gpWwgLhMqEwZ8SSMG9p+TP2cH+jLcEi7fiaueUsBU=; b=LNbp7xwSCgbgXQpy/vdKjwqJwgJLpg3IeUKV29ijq9vu+N2NZ6Ky0F+Qa6O/++ylLS aa8E0CnPZV5gfnfmSO5NWvMg8+x+CnnEF47ZmtsvZIWmMLy66jP2CnCtew6ociTRx8p3 5+mdis+ppTBansD4iZISvBbe0GKpVy9CdJN95RTgAUrM9xc07K83juXWar5ePKGIqrA2 lyL5z5EtVRNIBnrlAq8nd0SyTzrY5nyNy5vXN0554HR3JUGfHf7nhinQ/zzu7ijZuUQ5 qnoYl2bd+B2ZJTsFRs+0mBEtnA1vmoXaPNl2xGe99NPJGLro2aKWvD3PWqG7w6qUDqge Vogg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 f15si23102028pga.543.2017.11.27.05.23.33; Mon, 27 Nov 2017 05:23:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752551AbdK0NXc (ORCPT + 28 others); Mon, 27 Nov 2017 08:23:32 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:59183 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdK0NXa (ORCPT ); Mon, 27 Nov 2017 08:23:30 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0LheU5-1exKyM22iH-00mw6q; Mon, 27 Nov 2017 14:23:19 +0100 From: Arnd Bergmann To: Hans Verkuil , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , Javier Martinez Canillas , Vincent ABRIOU , Ingo Molnar , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] [media] vivid: use ktime_t for timestamp calculation Date: Mon, 27 Nov 2017 14:19:58 +0100 Message-Id: <20171127132027.1734806-6-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:GHlXyGTjdicJWWDTNEZbl32dMyoaroPzvS+ZxYj2b/0aAGX58dM XvqnRWi4wKuYStqo38Aydu9P1MIlC5it33+t7ql1qUreWYYon4BJpBUz7X/bCWWeeeOMICt +KOITwMurcwIIdgKX21ccP9MTPtumAvbQJDmKDpSZompoMlEDWGNnNePnOEBg5AL+qwWSLW AOqgTvQH9dFcTsHttEj9A== X-UI-Out-Filterresults: notjunk:1; V01:K0:PLIH6uVECzU=:XW2pEimbeyw2mdo/EsQ8Ml QK0gh5G3TPLh5Yq3jzqkXlPE+TZkMTY+Bg1ypgvcZviZsjvqdviOLl+XcFS9XpSOMDLOpRWL1 XeLJVbCqfPyqnq+s7xS/e4qs2i3O7BmL1e0i8ie/9zs9q7TnZa+JDnZSE2Vwag1leqzAqzePZ JR1SN0+y11liSdtPPXO2IPcONmBV5sqbe3WQvZSrPXpR5vsEREHR1l+ZphAIy/0wkiYAfDY1b w44fIeCgNxgl/4iSp4f42ZNVGVG927B+JCA2ZjRREyRrVDtNg9FqtaocPMBlqAvGoLfaY2Tb5 roB4zMCexF+saXVE1/jhtIwC9XhxpouU3np0gSrcy+iVWOnG9en0X5xZ0CdWqh96Bqc4+3G+k urS2zIEcynDDNFBl+nITJdE6xBdvwgAmHf0uy8yirDcpHvw38lKI1g+tBV3WKZHqx7PcRicaU FNPjE8UXeRKT0EcrIaYGFV0gFzjv9drILR7XysHL3jqGwe8TLe4EHe+P03l38fjfFqs1Oy91j DDqogBqcPypDN8Xiu82kF1Tg2xcATZKHD3LgsBsY06hQ8v7HUXNp4HlrKpz9KgYHCaOm0DkpW U9W6WKIqTinLKKDL/E3ypr40DsXw1sFxC6ITbWwGkSpHKOi7CROxr4Lb7cLf40eUU4gqXD4G9 VAGIkefYnOxQ1c0J9gVcqBegx41eurmwCprsBl1MS/NaLXi/NlE7UTpkL/VKNi178aLpAckBn 4Rpf+ta9kHfiUE1j3wcaeF12oAjrxV4gPgB0qg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org timespec is generally deprecated because of the y2038 overflow. In vivid, the usage is fine, since we are dealing with monotonic timestamps, but we can also simplify the code by going to ktime_t. Using ktime_divns() should be roughly as efficient as the old code, since the constant 64-bit division gets turned into a multiplication on modern platforms, and we save multiple 32-bit divisions that can be expensive e.g. on ARMv7. Signed-off-by: Arnd Bergmann --- I hope I understood the VIVID_RDS_GEN_BLOCKS calculation right, please review carefully. --- drivers/media/platform/vivid/vivid-core.c | 2 +- drivers/media/platform/vivid/vivid-core.h | 2 +- drivers/media/platform/vivid/vivid-radio-rx.c | 11 +++++------ drivers/media/platform/vivid/vivid-radio-tx.c | 8 +++----- drivers/media/platform/vivid/vivid-rds-gen.h | 1 + 5 files changed, 11 insertions(+), 13 deletions(-) -- 2.9.0 Tested-by: Hans Verkuil diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c index 5f316a5e38db..a091cfd93164 100644 --- a/drivers/media/platform/vivid/vivid-core.c +++ b/drivers/media/platform/vivid/vivid-core.c @@ -995,7 +995,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) dev->edid_max_blocks = dev->edid_blocks = 2; memcpy(dev->edid, vivid_hdmi_edid, sizeof(vivid_hdmi_edid)); - ktime_get_ts(&dev->radio_rds_init_ts); + dev->radio_rds_init_time = ktime_get(); /* create all controls */ ret = vivid_create_controls(dev, ccs_cap == -1, ccs_out == -1, no_error_inj, diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h index 5cdf95bdc4d1..d8bff4dcefb7 100644 --- a/drivers/media/platform/vivid/vivid-core.h +++ b/drivers/media/platform/vivid/vivid-core.h @@ -510,7 +510,7 @@ struct vivid_dev { /* Shared between radio receiver and transmitter */ bool radio_rds_loop; - struct timespec radio_rds_init_ts; + ktime_t radio_rds_init_time; /* CEC */ struct cec_adapter *cec_rx_adap; diff --git a/drivers/media/platform/vivid/vivid-radio-rx.c b/drivers/media/platform/vivid/vivid-radio-rx.c index 47c36c26096b..1b96cbd7f2ea 100644 --- a/drivers/media/platform/vivid/vivid-radio-rx.c +++ b/drivers/media/platform/vivid/vivid-radio-rx.c @@ -38,9 +38,9 @@ ssize_t vivid_radio_rx_read(struct file *file, char __user *buf, size_t size, loff_t *offset) { struct vivid_dev *dev = video_drvdata(file); - struct timespec ts; struct v4l2_rds_data *data = dev->rds_gen.data; bool use_alternates; + ktime_t timestamp; unsigned blk; int perc; int i; @@ -64,17 +64,16 @@ ssize_t vivid_radio_rx_read(struct file *file, char __user *buf, } retry: - ktime_get_ts(&ts); - use_alternates = ts.tv_sec % 10 >= 5; + timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time); + blk = ktime_divns(timestamp, VIVID_RDS_NSEC_PER_BLK); + use_alternates = blk % VIVID_RDS_GEN_BLOCKS; + if (dev->radio_rx_rds_last_block == 0 || dev->radio_rx_rds_use_alternates != use_alternates) { dev->radio_rx_rds_use_alternates = use_alternates; /* Re-init the RDS generator */ vivid_radio_rds_init(dev); } - ts = timespec_sub(ts, dev->radio_rds_init_ts); - blk = ts.tv_sec * 100 + ts.tv_nsec / 10000000; - blk = (blk * VIVID_RDS_GEN_BLOCKS) / 500; if (blk >= dev->radio_rx_rds_last_block + VIVID_RDS_GEN_BLOCKS) dev->radio_rx_rds_last_block = blk - VIVID_RDS_GEN_BLOCKS + 1; diff --git a/drivers/media/platform/vivid/vivid-radio-tx.c b/drivers/media/platform/vivid/vivid-radio-tx.c index 0e8025b7b4dd..897b56195ca7 100644 --- a/drivers/media/platform/vivid/vivid-radio-tx.c +++ b/drivers/media/platform/vivid/vivid-radio-tx.c @@ -37,7 +37,7 @@ ssize_t vivid_radio_tx_write(struct file *file, const char __user *buf, { struct vivid_dev *dev = video_drvdata(file); struct v4l2_rds_data *data = dev->rds_gen.data; - struct timespec ts; + ktime_t timestamp; unsigned blk; int i; @@ -58,10 +58,8 @@ ssize_t vivid_radio_tx_write(struct file *file, const char __user *buf, dev->radio_tx_rds_owner = file->private_data; retry: - ktime_get_ts(&ts); - ts = timespec_sub(ts, dev->radio_rds_init_ts); - blk = ts.tv_sec * 100 + ts.tv_nsec / 10000000; - blk = (blk * VIVID_RDS_GEN_BLOCKS) / 500; + timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time); + blk = ktime_divns(timestamp, VIVID_RDS_NSEC_PER_BLK); if (blk - VIVID_RDS_GEN_BLOCKS >= dev->radio_tx_rds_last_block) dev->radio_tx_rds_last_block = blk - VIVID_RDS_GEN_BLOCKS + 1; diff --git a/drivers/media/platform/vivid/vivid-rds-gen.h b/drivers/media/platform/vivid/vivid-rds-gen.h index eff4bf552ed3..e55e3b22b7ca 100644 --- a/drivers/media/platform/vivid/vivid-rds-gen.h +++ b/drivers/media/platform/vivid/vivid-rds-gen.h @@ -29,6 +29,7 @@ #define VIVID_RDS_GEN_GROUPS 57 #define VIVID_RDS_GEN_BLKS_PER_GRP 4 #define VIVID_RDS_GEN_BLOCKS (VIVID_RDS_GEN_BLKS_PER_GRP * VIVID_RDS_GEN_GROUPS) +#define VIVID_RDS_NSEC_PER_BLK (u32)(5ull * NSEC_PER_SEC / VIVID_RDS_GEN_BLOCKS) struct vivid_rds_gen { struct v4l2_rds_data data[VIVID_RDS_GEN_BLOCKS]; From patchwork Mon Nov 27 13:20:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119709 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp264635qgn; Mon, 27 Nov 2017 05:25:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMbHJHx+OYR7QqgtqnZKJn/0gZXwNM0e1Dmw4+LvyqKHpCeOSczfLnq33Yhu7Ri5pm7gLa2h X-Received: by 10.101.82.1 with SMTP id o1mr36089288pgp.261.1511789158590; Mon, 27 Nov 2017 05:25:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511789158; cv=none; d=google.com; s=arc-20160816; b=oDaYVKRalNf65wTPrbl77l36/SCSRpZszIOdUH/7B8TemOvBe+ETcoVo74ovJaVCg1 sURWaDjaq8JI0/96b0iJnaaZewqdkMt6fQ5nApxA/zbNaeNbePMi1oYHI50WjI9RG2bM jMK2szTO1DLweR/my43EZBtECdLOJR65qB0igOY+p4HDdYUPoC+ZuLmxL1D59zvN1/Ac sAauCiy0i9iUBrrKP4D56fH1YiHIM9gE7Zx0KSzuYGfZj3ojjaGA3+mDuTjzP6sQeDel vq3oCkrYHMSxgJeqyzFIQpi1SeapvXA+NISgkhUJmFL7VG5XHCzr0lpvqjs0LvBIMgwW Qkzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LqXGq6fvH/JynUoFzfYJeHKPy5qC9/4sz8uYlGHQ+uM=; b=ipZBvA1qkXkghKzwK4y3th6wRMKKLUGipNWmZ4JVD0V17nTDOFwR46tZ7PADvHdpRi SR/N2ljGwYGvONigJEe2YX9OleeDTi7IN53n3Swu5+JXoK7yNwy/OtOfdQY/RmicCGWH 6wKsdRMNe0nqFx82Xc6IzqpsdAJhk8LnCI1c4oBnU+6bUSW9JcRGTPU8nnOXGVviJYwV Xwh4143btT7OjvvrkL91OeUTnbt0g/2ffHv0hg6ohe/kZI9f7GSxLsTgKWJO+F7c6IvO bFwK1MdZ1+22r/5FUcOAx9PD+ctuhGLPs4yyR3tEWAaU2eFddIBG9RhV0r9RALTsZ24O EJGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 o5si7989942pgs.191.2017.11.27.05.25.58; Mon, 27 Nov 2017 05:25:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752369AbdK0NZ4 (ORCPT + 28 others); Mon, 27 Nov 2017 08:25:56 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:59062 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdK0NZy (ORCPT ); Mon, 27 Nov 2017 08:25:54 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0LuMJr-1fIsSq2jPr-011h2M; Mon, 27 Nov 2017 14:25:39 +0100 From: Arnd Bergmann To: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: y2038@lists.linaro.org, Arnd Bergmann , Hans Verkuil , Russell King , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] [media] staging: imx: use ktime_t for timestamps Date: Mon, 27 Nov 2017 14:20:00 +0100 Message-Id: <20171127132027.1734806-8-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> MIME-Version: 1.0 X-Provags-ID: V03:K0:Bqes2hr45fYHxusjH6qXmS7UsXbLnp8/AjwHUn0p+4E8ved7i73 sbxf0nWzeCUOkxxyyZtRlV6Bm8GCg6FYAmhnXJmFisV2mml8b430ChPchI+mRIONAA950c1 TQOqQ/R6luCAWd1erqKPl0N1kkrA3AhPGdcWbw5NOAZ3kZHV5YH494V0cdu/edfLb2MS0Q8 d4+Ntla9U7LmD0t17um/w== X-UI-Out-Filterresults: notjunk:1; V01:K0:jOkh0FTUkZM=:P1DyrVpYyz3ppQLMNRh2iH 8RBXszTmq5e0NZL0jC1lvviQlQDO6zwy2pXwaMU0OQgLuicAdi98BrR32g9fchhXURituewXK 07wKVPG3o1CE5k7Xp79Tyrdp+shnyOosvnrb7rwOGvoQI5dryJ2TVzjkI9e7oo/6XrhGTqrlP QOfwgiAMsrBIs8W/Nd2wsKfWt+n/TRH/CnjdS7t34Jrl2+x54ljIzFD/brrU6osjq1PnFWPkE CMQ2OJ046U96QpNuyUjI2jOnkFnpro0xGI1NUT9/g1lrCIItNj6kCmb3M4UO6k98oHEqhwLN2 F7cC+RuPKPPcE/cip1ik5GPayX5QhEfKZgEnacdXeonraEPTEnu9c/cO+ZuEOQDN/SOKThI3o OETynXXIw4T9fuHSTsHJKZbWF3B2BtLgeuTqySVtLS3l/KCBqVX/LR8kTkwCIJUA5OjN3w2RL h0p9PtVz5TVSgY8VNHdK4ZjELMly/JHqPKERyKPtuzWM8Cr9zz16UQhoX17O1zjJ3sePM2tup lq9WT6LS35zcoUuzPZ9SYtMA4eE0xt6xk8bXrMl7QQD9KCw/EptgTbOsX2uJ0QjbLh22XPISd Y9Gf4uMW6y/9lFWewDrYZOV54Da/elJYnuMuT5wbJ6zXw+lI+Ie/XB2F2/kgKAxhjbK3IfiDp uKoLAnxTbZJ1+UDX35utpZ5OwAXuP/BNz2XcWNQTekVwWbMkEv0mGUlV9jF/XnKOo4+odYEmk ZcfJErrkgic57K8QI03TrwCHkx9LYwoGL99j9C38fCIiEbiWqgATsxGLb7w= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The imx media driver passes around monotonic timestamps in the deprecated 'timespec' format. This is not a problem for the driver, as they won't overflow, but moving to either timespec64 or ktime_t is preferred. I'm picking ktime_t for simplicity here. frame_interval_monitor() is the main function that changes, as it tries to compare a time interval in microseconds. The algorithm slightly changes here, to avoid 64-bit division. The code previously assumed that the error was at most 32-bit worth of microseconds here, so I'm making the same assumption but add an explicit test for it. Signed-off-by: Arnd Bergmann --- drivers/staging/media/imx/imx-media-csi.c | 8 ++------ drivers/staging/media/imx/imx-media-fim.c | 30 +++++++++++++++++------------- drivers/staging/media/imx/imx-media.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) -- 2.9.0 diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index bb1d6dafca83..26994b429cf2 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -207,13 +207,9 @@ static irqreturn_t csi_idmac_eof_interrupt(int irq, void *dev_id) goto unlock; } - if (priv->fim) { - struct timespec cur_ts; - - ktime_get_ts(&cur_ts); + if (priv->fim) /* call frame interval monitor */ - imx_media_fim_eof_monitor(priv->fim, &cur_ts); - } + imx_media_fim_eof_monitor(priv->fim, ktime_get()); csi_vb2_buf_done(priv); diff --git a/drivers/staging/media/imx/imx-media-fim.c b/drivers/staging/media/imx/imx-media-fim.c index 47275ef803f3..6df189135db8 100644 --- a/drivers/staging/media/imx/imx-media-fim.c +++ b/drivers/staging/media/imx/imx-media-fim.c @@ -66,7 +66,7 @@ struct imx_media_fim { int icap_flags; int counter; - struct timespec last_ts; + ktime_t last_ts; unsigned long sum; /* usec */ unsigned long nominal; /* usec */ @@ -147,22 +147,26 @@ static void send_fim_event(struct imx_media_fim *fim, unsigned long error) * (presumably random) interrupt latency. */ static void frame_interval_monitor(struct imx_media_fim *fim, - struct timespec *ts) + ktime_t timestamp) { - unsigned long interval, error, error_avg; + long long interval, error; + unsigned long error_avg; bool send_event = false; - struct timespec diff; if (!fim->enabled || ++fim->counter <= 0) goto out_update_ts; - diff = timespec_sub(*ts, fim->last_ts); - interval = diff.tv_sec * 1000 * 1000 + diff.tv_nsec / 1000; - error = abs(interval - fim->nominal); + /* max error is less than l00µs, so use 32-bit division or fail */ + interval = ktime_to_ns(ktime_sub(timestamp, fim->last_ts)); + error = abs(interval - NSEC_PER_USEC * (u64)fim->nominal); + if (error > U32_MAX) + error = U32_MAX; + else + error = abs((u32)error / NSEC_PER_USEC); if (fim->tolerance_max && error >= fim->tolerance_max) { dev_dbg(fim->sd->dev, - "FIM: %lu ignored, out of tolerance bounds\n", + "FIM: %llu ignored, out of tolerance bounds\n", error); fim->counter--; goto out_update_ts; @@ -184,7 +188,7 @@ static void frame_interval_monitor(struct imx_media_fim *fim, } out_update_ts: - fim->last_ts = *ts; + fim->last_ts = timestamp; if (send_event) send_fim_event(fim, error_avg); } @@ -195,14 +199,14 @@ static void frame_interval_monitor(struct imx_media_fim *fim, * to interrupt latency. */ static void fim_input_capture_handler(int channel, void *dev_id, - struct timespec *ts) + ktime_t timestamp) { struct imx_media_fim *fim = dev_id; unsigned long flags; spin_lock_irqsave(&fim->lock, flags); - frame_interval_monitor(fim, ts); + frame_interval_monitor(fim, timestamp); if (!completion_done(&fim->icap_first_event)) complete(&fim->icap_first_event); @@ -405,14 +409,14 @@ static int init_fim_controls(struct imx_media_fim *fim) * the frame_interval_monitor() is called by the input capture event * callback handler in that case. */ -void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts) +void imx_media_fim_eof_monitor(struct imx_media_fim *fim, ktime_t timestamp) { unsigned long flags; spin_lock_irqsave(&fim->lock, flags); if (!icap_enabled(fim)) - frame_interval_monitor(fim, ts); + frame_interval_monitor(fim, timestamp); spin_unlock_irqrestore(&fim->lock, flags); } diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index d409170632bd..ac3ab115394f 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -280,7 +280,7 @@ int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd, /* imx-media-fim.c */ struct imx_media_fim; -void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts); +void imx_media_fim_eof_monitor(struct imx_media_fim *fim, ktime_t timestamp); int imx_media_fim_set_stream(struct imx_media_fim *fim, const struct v4l2_fract *frame_interval, bool on);