From patchwork Sat Nov 4 21:20:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10041791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6E62C60567 for ; Sat, 4 Nov 2017 21:21:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 714C62963B for ; Sat, 4 Nov 2017 21:21:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64302296EA; Sat, 4 Nov 2017 21:21:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B3DCE2963B for ; Sat, 4 Nov 2017 21:21:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77ABF6E04E; Sat, 4 Nov 2017 21:21:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by gabe.freedesktop.org (Postfix) with ESMTPS id 54F8F6E04E for ; Sat, 4 Nov 2017 21:21:41 +0000 (UTC) Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0MVYxn-1dckwy3tNf-00Yzz4; Sat, 04 Nov 2017 22:21:36 +0100 From: Arnd Bergmann To: David Airlie Subject: [PATCH] drm: via: use ktime_get() instead of do_gettimeofday Date: Sat, 4 Nov 2017 22:20:08 +0100 Message-Id: <20171104212131.2939989-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:rCkUDX9BzDV9OAKTwZSFK8XlRlvoRASJ8hjmqH/K0RDduY7DQNS oYL0CDO0VlBu83DCuX5Se0Ad5sc8wa19+X1yBnG9bxCYqMYhut7JtmdQnAiUGsl5iv3NtKd MAzEsO+kchkFwasgmL/WQ2sj9Dp8+FE7ebRNX5RPyAHtbtVaaAMTu0OQCrVCTUr3ssfKfoA 9AAQbAqj9Fcvj0RXIW2Cw== X-UI-Out-Filterresults: notjunk:1; V01:K0:2zGAaa10PVo=:2N+sIL63fh3GMoCkLFFOMJ Aw18q1MJspMSioiBsxSME3rpOfabDWKNWKd/EVwgROUESUh/6DTMHWi5YEpms1A1877gaPYrk seo1wUczuaOXwtbDNv+CCxPUk3ln54BgOd12czrKOI9lCrttxEti+AVnwZuTsg1T2qFC2cOge B0jhmRD9TvXI6vQAsnvTLn4pW8mW5bkWIu2+A2zHB9ykenpBcsxjG1TZiRUyAbz3ewjTigu+4 efU4CnctpItZHV9ORXVaqfdIOgJeBBX//R612B0YCDFZJRtVgRGqkFvYMtdc3BiTpoElfJg8o BYDD5eCUwoxcGbH5tVzWp4YetNlpV0SFr0RqqtdT9Ppo5on7SMZR7AuxSHF9YvvVt26ffFuC+ T5petaXvsbuCsAlMZcTtV5pBi9hxnKYOZHenOxZ9N5rf7+SHuUWstGb9kX9zV+8jC+rNc66Dg Uh4yhKsRhQ6B3g2EJ72hyQ6xA9FjIxBvkJ7S8lEiHH8TqYLuThiVDmNlhiUy4Uzwussio97sM PbyKIyP6HI4GT5lHoMeGX51yB0iqft5GZ3srVjGzyccghqSoMy+urVvLeeZuJVueER47xcGos jlVC6ycQTCaFXfjfxYe5Jl7FkNYF1RKUX2AbUjzzoG8uztXQvLOurpQlV2xKh1w8i+6PUMtDE KptAJGJdGKpweSP3E8Pj6a7uawdgggfOvdCg7NYIa/k5H2F4L9xMV75sLw1Bptn+Y1Kje+I9F fNL3DCOAq49dASROH8ZF+059H6kFbD13WRQdZA== Cc: Arnd Bergmann , y2038@lists.linaro.org, Daniel Vetter , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Gabriel Krisman Bertazi X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We want to remove uses of do_gettimeofday() from the kernel since the resulting timeval structure overflows in 2038. This is not a problem for this particular use, but do_gettimeofday() is also not an appropriate method for measuring time intervals, since it requires a conversion into microseconds and is complicated to work with. ktime_get() is a better replacement, as it works with the monontonic kernel timebase and requires a minimum of computation. I'm slightly changing the output from microseconds to nanoseconds here, to avoid introducing a new division operation. This should be fine since the value is only used for debugging. Signed-off-by: Arnd Bergmann --- drivers/gpu/drm/via/via_drv.h | 4 ++-- drivers/gpu/drm/via/via_irq.c | 21 +++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h index 9873942ca8f4..6d1ae834484c 100644 --- a/drivers/gpu/drm/via/via_drv.h +++ b/drivers/gpu/drm/via/via_drv.h @@ -74,9 +74,9 @@ typedef struct drm_via_private { volatile uint32_t *last_pause_ptr; volatile uint32_t *hw_addr_ptr; drm_via_ring_buffer_t ring; - struct timeval last_vblank; + ktime_t last_vblank; int last_vblank_valid; - unsigned usec_per_vblank; + ktime_t nsec_per_vblank; atomic_t vbl_received; drm_via_state_t hc_state; char pci_buf[VIA_PCI_BUF_SIZE]; diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c index ea8172c747a2..24e71578af4d 100644 --- a/drivers/gpu/drm/via/via_irq.c +++ b/drivers/gpu/drm/via/via_irq.c @@ -88,13 +88,6 @@ static int via_num_unichrome = ARRAY_SIZE(via_unichrome_irqs); static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1}; -static unsigned time_diff(struct timeval *now, struct timeval *then) -{ - return (now->tv_usec >= then->tv_usec) ? - now->tv_usec - then->tv_usec : - 1000000 - (then->tv_usec - now->tv_usec); -} - u32 via_get_vblank_counter(struct drm_device *dev, unsigned int pipe) { drm_via_private_t *dev_priv = dev->dev_private; @@ -111,7 +104,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg) drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; u32 status; int handled = 0; - struct timeval cur_vblank; + ktime_t cur_vblank; drm_via_irq_t *cur_irq = dev_priv->via_irqs; int i; @@ -119,18 +112,18 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg) if (status & VIA_IRQ_VBLANK_PENDING) { atomic_inc(&dev_priv->vbl_received); if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) { - do_gettimeofday(&cur_vblank); + cur_vblank = ktime_get(); if (dev_priv->last_vblank_valid) { - dev_priv->usec_per_vblank = - time_diff(&cur_vblank, - &dev_priv->last_vblank) >> 4; + dev_priv->nsec_per_vblank = + ktime_sub(cur_vblank, + dev_priv->last_vblank) >> 4; } dev_priv->last_vblank = cur_vblank; dev_priv->last_vblank_valid = 1; } if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) { - DRM_DEBUG("US per vblank is: %u\n", - dev_priv->usec_per_vblank); + DRM_DEBUG("nsec per vblank is: %llu\n", + ktime_to_ns(dev_priv->nsec_per_vblank)); } drm_handle_vblank(dev, 0); handled = 1;