From patchwork Mon Nov 27 13:19:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10076905 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 9B19A602BC for ; Mon, 27 Nov 2017 13:23:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B81E28E4E for ; Mon, 27 Nov 2017 13:23:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 804E128E50; Mon, 27 Nov 2017 13:23: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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2504928E4F for ; Mon, 27 Nov 2017 13:23:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752221AbdK0NXb (ORCPT ); Mon, 27 Nov 2017 08:23:31 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:59183 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdK0NXa (ORCPT ); Mon, 27 Nov 2017 08:23:30 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0LheU5-1exKyM22iH-00mw6q; Mon, 27 Nov 2017 14:23:19 +0100 From: Arnd Bergmann To: Hans Verkuil , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , Javier Martinez Canillas , Vincent ABRIOU , Ingo Molnar , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] [media] vivid: use ktime_t for timestamp calculation Date: Mon, 27 Nov 2017 14:19:58 +0100 Message-Id: <20171127132027.1734806-6-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:GHlXyGTjdicJWWDTNEZbl32dMyoaroPzvS+ZxYj2b/0aAGX58dM XvqnRWi4wKuYStqo38Aydu9P1MIlC5it33+t7ql1qUreWYYon4BJpBUz7X/bCWWeeeOMICt +KOITwMurcwIIdgKX21ccP9MTPtumAvbQJDmKDpSZompoMlEDWGNnNePnOEBg5AL+qwWSLW AOqgTvQH9dFcTsHttEj9A== X-UI-Out-Filterresults: notjunk:1; V01:K0:PLIH6uVECzU=:XW2pEimbeyw2mdo/EsQ8Ml QK0gh5G3TPLh5Yq3jzqkXlPE+TZkMTY+Bg1ypgvcZviZsjvqdviOLl+XcFS9XpSOMDLOpRWL1 XeLJVbCqfPyqnq+s7xS/e4qs2i3O7BmL1e0i8ie/9zs9q7TnZa+JDnZSE2Vwag1leqzAqzePZ JR1SN0+y11liSdtPPXO2IPcONmBV5sqbe3WQvZSrPXpR5vsEREHR1l+ZphAIy/0wkiYAfDY1b w44fIeCgNxgl/4iSp4f42ZNVGVG927B+JCA2ZjRREyRrVDtNg9FqtaocPMBlqAvGoLfaY2Tb5 roB4zMCexF+saXVE1/jhtIwC9XhxpouU3np0gSrcy+iVWOnG9en0X5xZ0CdWqh96Bqc4+3G+k urS2zIEcynDDNFBl+nITJdE6xBdvwgAmHf0uy8yirDcpHvw38lKI1g+tBV3WKZHqx7PcRicaU FNPjE8UXeRKT0EcrIaYGFV0gFzjv9drILR7XysHL3jqGwe8TLe4EHe+P03l38fjfFqs1Oy91j DDqogBqcPypDN8Xiu82kF1Tg2xcATZKHD3LgsBsY06hQ8v7HUXNp4HlrKpz9KgYHCaOm0DkpW U9W6WKIqTinLKKDL/E3ypr40DsXw1sFxC6ITbWwGkSpHKOi7CROxr4Lb7cLf40eUU4gqXD4G9 VAGIkefYnOxQ1c0J9gVcqBegx41eurmwCprsBl1MS/NaLXi/NlE7UTpkL/VKNi178aLpAckBn 4Rpf+ta9kHfiUE1j3wcaeF12oAjrxV4gPgB0qg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP timespec is generally deprecated because of the y2038 overflow. In vivid, the usage is fine, since we are dealing with monotonic timestamps, but we can also simplify the code by going to ktime_t. Using ktime_divns() should be roughly as efficient as the old code, since the constant 64-bit division gets turned into a multiplication on modern platforms, and we save multiple 32-bit divisions that can be expensive e.g. on ARMv7. Signed-off-by: Arnd Bergmann Tested-by: Hans Verkuil --- I hope I understood the VIVID_RDS_GEN_BLOCKS calculation right, please review carefully. --- drivers/media/platform/vivid/vivid-core.c | 2 +- drivers/media/platform/vivid/vivid-core.h | 2 +- drivers/media/platform/vivid/vivid-radio-rx.c | 11 +++++------ drivers/media/platform/vivid/vivid-radio-tx.c | 8 +++----- drivers/media/platform/vivid/vivid-rds-gen.h | 1 + 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c index 5f316a5e38db..a091cfd93164 100644 --- a/drivers/media/platform/vivid/vivid-core.c +++ b/drivers/media/platform/vivid/vivid-core.c @@ -995,7 +995,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) dev->edid_max_blocks = dev->edid_blocks = 2; memcpy(dev->edid, vivid_hdmi_edid, sizeof(vivid_hdmi_edid)); - ktime_get_ts(&dev->radio_rds_init_ts); + dev->radio_rds_init_time = ktime_get(); /* create all controls */ ret = vivid_create_controls(dev, ccs_cap == -1, ccs_out == -1, no_error_inj, diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h index 5cdf95bdc4d1..d8bff4dcefb7 100644 --- a/drivers/media/platform/vivid/vivid-core.h +++ b/drivers/media/platform/vivid/vivid-core.h @@ -510,7 +510,7 @@ struct vivid_dev { /* Shared between radio receiver and transmitter */ bool radio_rds_loop; - struct timespec radio_rds_init_ts; + ktime_t radio_rds_init_time; /* CEC */ struct cec_adapter *cec_rx_adap; diff --git a/drivers/media/platform/vivid/vivid-radio-rx.c b/drivers/media/platform/vivid/vivid-radio-rx.c index 47c36c26096b..1b96cbd7f2ea 100644 --- a/drivers/media/platform/vivid/vivid-radio-rx.c +++ b/drivers/media/platform/vivid/vivid-radio-rx.c @@ -38,9 +38,9 @@ ssize_t vivid_radio_rx_read(struct file *file, char __user *buf, size_t size, loff_t *offset) { struct vivid_dev *dev = video_drvdata(file); - struct timespec ts; struct v4l2_rds_data *data = dev->rds_gen.data; bool use_alternates; + ktime_t timestamp; unsigned blk; int perc; int i; @@ -64,17 +64,16 @@ ssize_t vivid_radio_rx_read(struct file *file, char __user *buf, } retry: - ktime_get_ts(&ts); - use_alternates = ts.tv_sec % 10 >= 5; + timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time); + blk = ktime_divns(timestamp, VIVID_RDS_NSEC_PER_BLK); + use_alternates = blk % VIVID_RDS_GEN_BLOCKS; + if (dev->radio_rx_rds_last_block == 0 || dev->radio_rx_rds_use_alternates != use_alternates) { dev->radio_rx_rds_use_alternates = use_alternates; /* Re-init the RDS generator */ vivid_radio_rds_init(dev); } - ts = timespec_sub(ts, dev->radio_rds_init_ts); - blk = ts.tv_sec * 100 + ts.tv_nsec / 10000000; - blk = (blk * VIVID_RDS_GEN_BLOCKS) / 500; if (blk >= dev->radio_rx_rds_last_block + VIVID_RDS_GEN_BLOCKS) dev->radio_rx_rds_last_block = blk - VIVID_RDS_GEN_BLOCKS + 1; diff --git a/drivers/media/platform/vivid/vivid-radio-tx.c b/drivers/media/platform/vivid/vivid-radio-tx.c index 0e8025b7b4dd..897b56195ca7 100644 --- a/drivers/media/platform/vivid/vivid-radio-tx.c +++ b/drivers/media/platform/vivid/vivid-radio-tx.c @@ -37,7 +37,7 @@ ssize_t vivid_radio_tx_write(struct file *file, const char __user *buf, { struct vivid_dev *dev = video_drvdata(file); struct v4l2_rds_data *data = dev->rds_gen.data; - struct timespec ts; + ktime_t timestamp; unsigned blk; int i; @@ -58,10 +58,8 @@ ssize_t vivid_radio_tx_write(struct file *file, const char __user *buf, dev->radio_tx_rds_owner = file->private_data; retry: - ktime_get_ts(&ts); - ts = timespec_sub(ts, dev->radio_rds_init_ts); - blk = ts.tv_sec * 100 + ts.tv_nsec / 10000000; - blk = (blk * VIVID_RDS_GEN_BLOCKS) / 500; + timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time); + blk = ktime_divns(timestamp, VIVID_RDS_NSEC_PER_BLK); if (blk - VIVID_RDS_GEN_BLOCKS >= dev->radio_tx_rds_last_block) dev->radio_tx_rds_last_block = blk - VIVID_RDS_GEN_BLOCKS + 1; diff --git a/drivers/media/platform/vivid/vivid-rds-gen.h b/drivers/media/platform/vivid/vivid-rds-gen.h index eff4bf552ed3..e55e3b22b7ca 100644 --- a/drivers/media/platform/vivid/vivid-rds-gen.h +++ b/drivers/media/platform/vivid/vivid-rds-gen.h @@ -29,6 +29,7 @@ #define VIVID_RDS_GEN_GROUPS 57 #define VIVID_RDS_GEN_BLKS_PER_GRP 4 #define VIVID_RDS_GEN_BLOCKS (VIVID_RDS_GEN_BLKS_PER_GRP * VIVID_RDS_GEN_GROUPS) +#define VIVID_RDS_NSEC_PER_BLK (u32)(5ull * NSEC_PER_SEC / VIVID_RDS_GEN_BLOCKS) struct vivid_rds_gen { struct v4l2_rds_data data[VIVID_RDS_GEN_BLOCKS];