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;