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: 117803 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2055244qgn; Thu, 2 Nov 2017 04:44:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SwElz02rLVhx5djNilD4dslqOyckULNbNGVc7N40YT6OWXtU0VNibKd2EDv3FBQarYj01q X-Received: by 10.159.253.147 with SMTP id q19mr2948961pls.54.1509623068652; Thu, 02 Nov 2017 04:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509623068; cv=none; d=google.com; s=arc-20160816; b=ew9xdmrV4UQTHNoXKXav6nGWr+ghIQeQeGft6iFXTB4tIHdhHrhUOyopQkKueDCc3/ XgeFKyLY1epjAw0duqHOZieaADt6Tsx9W7VSW1W2JYvKOX9UjWXlgp/2/+Ztg2Ntm+v1 qXaZqUth0YC9m7JAKjiTZE/b2C0+eBhiqAfkndjW02TqoIt18ChsiyXRav9JyVqHpYlQ 1s3lojDNQKUfttj/dNesWjhgg538AuSfGegcziUuMtXSkiuejnWVY0OPPCi/jxrAvL8w 51+Q79zdrUXdVvzCnUAVUmuXTjDC3ekfqGqrxBN3HuZmxmrAob5ykkLzYI+Yzna52Z9s eA7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:message-id:date:subject:to:from:delivered-to :arc-authentication-results; bh=O/fcvITojSXEmdgGKC/oU7TmNNVDEsxFT2d4q+1Y3HU=; b=hPesODiXqUsgUAt86Nz/gFUjlo7qkIHeKm5Yr7CrRx7yoHLYiy6MRgqYYOvujCh0Pi m6aQgDgzAmxq4YiMqftkU1CoPmr8ljsqj/3PpI0wrbAcjS6pd6kP+lye0SE6JxP8Av/2 RJ00bFsU4bBiFoElUSLVLOlf+ReuK2be0SxwBjDj1k8i41yvRd9C2E25DsBRBkd9jHPQ CC6JAXyk7S98pNunJDnA6SuA0Yc3NzQLHksdVbT3h1UDyIHdBSwl9tXNd6B3JP3eylef 4Fmo8DGN0BrArRnhwrAC0cPNAEbd64cX9hx0VBJjXFsi/KfGjn9Vb3taG4rQjoXpa6Cj zFPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id d2si3211212pgp.817.2017.11.02.04.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 04:44:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org 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" 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 */