From patchwork Thu Nov 2 11:43: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: 10038587 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 BDCA6603B5 for ; Thu, 2 Nov 2017 11:44:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B051D28F0D for ; Thu, 2 Nov 2017 11:44:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A489628F12; Thu, 2 Nov 2017 11:44:28 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 3B06E28F0D for ; Thu, 2 Nov 2017 11:44:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 925636E1F6; Thu, 2 Nov 2017 11:44:26 +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.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D30E6E1F6 for ; Thu, 2 Nov 2017 11:44:25 +0000 (UTC) Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0Mhgu7-1dnUGY0D0V-00Mq4R; Thu, 02 Nov 2017 12:44:17 +0100 From: Arnd Bergmann To: Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , David Airlie Subject: [PATCH] exynos: drm: use monotonic timestamps Date: Thu, 2 Nov 2017 12:43:54 +0100 Message-Id: <20171102114415.1811842-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:Nld9XDwIVvQqHygjDOfA3X2tH2dwyzzAL4Ed0iuurCSs+TqAVxU T1XxJXyDJG/dAKmjZKIM4SWXp2goAGMOyZMeEVgYfJFYRxwGLvLSYb+jhsSlhbi+QAKzDF7 dVhWDLsYvceLD72y9EWmICIeQ5j2Lb96n9cxrokBBhTropEDU1VjwPvjBQF0m9taWFwGUGp H1Lg2yoVbbO6KdzdM7fnQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:giwR0uM0Ug8=:B6KcINhGYLYwV4+GUaTW7J uBjqTTE0/j8ONydhWCRFVN/NRx0UNHbeIyNOtr/5XWsJFaYrjA2mm/Z4m54wpX98ipCnlnxNk IIMVCBVNOvv5RhyCUJrSO3JjOTTyIemlq5sWCwlWhulwXDiv5/qtxbDa2WY+pixfV+Ykwqq/J E7A0DI2pSjhxwdRuzIgr5yH3XlySi7aMhxsIfZkPi7PmDt+g+wXIAeQRs0JaNGSPJo8tDr7H7 kohjQAESem5YeXlL/YMjiBHw4nK2jH8hkIPoK/eeqJ3BWCiTGNrcIe4eA81XAzHk0LeQoNqDr dMqgjNmuGQqyV4uIcyfEK5Ttn87W4/LrqAcu/PfDwm35uH1XOrVNT5kDQs9Y1mNBXOxRfprNW ODvp4JlzkonAEfLr8RZgqQR8j9TiRCTHSU6kFhJysFM1wx4qQ6Qcxi/IzulmrRr9p36mXvEJp ukEUl2QUGG6wnMD9AGLW266/bqeO7V7gSR5+mYLVI1xGjLK3eHb6QIwPBkX89091O7OfWp+20 Hgqo3ZwpoBCqMIOTEgixr8ydqTbUVysXHr/oHkp/XNFnQU8KzzogbprCFh4OduF+w22X1XFrc EC0STFeA0YGoqVvnYZHeWPaRoQ5I9OtqxheuQmdUbH4p/XP5z3NQuDisihYaI4VK5++0e2/gI L+bMmdJMPmFFKqiK59rMee0Rmd9LEO2YDaFN/MGOpvb70u1OuW2+K9AdknDIHJnx2f0acOV2V OAhhutYdPLsv3UWqkNIhJl4cL0i3PiEcoQBHow== Cc: linux-samsung-soc@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tobias Jakobi , Kukjin Kim , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org 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 The exynos DRM driver uses real-time 'struct timeval' values for exporting its timestamps to user space. This has multiple problems: 1. signed seconds overflow in y2038 2. the 'struct timeval' definition is deprecated in the kernel 3. time may jump or go backwards after a 'settimeofday()' syscall 4. other DRM timestamps are in CLOCK_MONOTONIC domain, so they can't be compared 5. exporting microseconds requires a division by 1000, which may be slow on some architectures. Ideally timestamps should just use 64-bit nanoseconds instead, but of course we can't change that now. Instead, this tries to address the first four points above by using monotonic 'timespec' values. The downside is that there is a small risk of breaking user space if that expects the absolute timestamp numbers to relate to the result of 'gettimeofday()'. Please review the user space driver before applying this patch to ensure this works. Signed-off-by: Arnd Bergmann --- drivers/gpu/drm/exynos/exynos_drm_g2d.c | 6 +++--- drivers/gpu/drm/exynos/exynos_drm_ipp.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index 2b8bf2dd6387..9effe40f5fa5 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -926,7 +926,7 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 cmdlist_no) struct drm_device *drm_dev = g2d->subdrv.drm_dev; struct g2d_runqueue_node *runqueue_node = g2d->runqueue_node; struct drm_exynos_pending_g2d_event *e; - struct timeval now; + struct timespec64 now; if (list_empty(&runqueue_node->event_list)) return; @@ -934,9 +934,9 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 cmdlist_no) e = list_first_entry(&runqueue_node->event_list, struct drm_exynos_pending_g2d_event, base.link); - do_gettimeofday(&now); + ktime_get_ts64(&now); e->event.tv_sec = now.tv_sec; - e->event.tv_usec = now.tv_usec; + e->event.tv_usec = now.tv_nsec / NSEC_PER_USEC; e->event.cmdlist_no = cmdlist_no; drm_send_event(drm_dev, &e->base); diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c index 3edda18cc2d2..3f9d8d79bbde 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c +++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c @@ -1406,7 +1406,7 @@ static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv, struct drm_exynos_ipp_queue_buf qbuf; struct drm_exynos_ipp_send_event *e; struct list_head *head; - struct timeval now; + struct timespec64 now; u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, }; int ret, i; @@ -1509,10 +1509,10 @@ static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv, e = list_first_entry(&c_node->event_list, struct drm_exynos_ipp_send_event, base.link); - do_gettimeofday(&now); - DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec); + ktime_get_ts64(&now); + DRM_DEBUG_KMS("tv_sec[%lld]tv_nsec[%ld]\n", (s64)now.tv_sec, now.tv_nsec); e->event.tv_sec = now.tv_sec; - e->event.tv_usec = now.tv_usec; + e->event.tv_usec = now.tv_nsec / NSEC_PER_USEC; e->event.prop_id = property->prop_id; /* set buffer id about source destination */