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);