From patchwork Mon Nov 27 15:25:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119720 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp418712qgn; Mon, 27 Nov 2017 07:26:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMaZyVH6V1PW5Qc7uuEbiP+DPzhv0wFaz8vxonO/0orlyf4nKOZW5h1Ru4Jxw54pFN+0fl5b X-Received: by 10.98.253.3 with SMTP id p3mr37495930pfh.20.1511796412540; Mon, 27 Nov 2017 07:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511796412; cv=none; d=google.com; s=arc-20160816; b=jMN2qvcNSrmeX6ReBNIgamsHlaz7Ow3i9JXr5lCvmMNszBcclTq36ufi3pSh6JOA9R Du/Pn5LYUdrJBbmxuYsPC8kTxpKmcImYgO8v0HqE8J3B8P/4ULt1sMd/pcgEWHIO9CoT /Wx4eH1aefz2x0o+l3zfJiKwQK+ySEns/VE/mQalTPCgXunPTS5tY9wYadjkC8n3YmuX OMzfkU1befLWRC4SmBhYkW1yYOH8/LY7HqzMqCsxqu7lb4StDe+Plnk4xQ9HNpidmFS8 vwu1vnoAXmJvDRFH9zszWLMfu80ebrdBBZVh5yNwF0Oj3rugfrj6FHTvYg/c457WTj5+ LHEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2gx96rlaXeqXwRraXAxi+i8c3Rs0VoK81YCND8LsUxs=; b=U3ArMUnDg0kKLwbR4HLBHIeyq6FScvLZdoUVezdX28EDaFT+3Osazu5vgZkytLiQ2b 5Hr8IREypoACxN+rbh4ndhHowbdJed91lmMBAwhQHRbGTkGzQH5PvcEH6INXWPFWl3p6 +TrxiOfciDveYoh9G2ksrqn4lpmXxdnAEMdbQ0B0dJ6CqdnHaOaRIe2lMUJfEoF9WjXw L75pbggae2vQpq6J8TBxIeduIoVtcp4j/IRZzfn7YzglJeOU1R8txdklY803WbyYztOE X7Mc5sL4pcJ2Y1FugAK42b5d2OCDJX5KtCW7H00kpo1v5mvVCZYKSfGlnnPVFjiG5E0x 1H5g== 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 s64si25323493pfj.279.2017.11.27.07.26.52; Mon, 27 Nov 2017 07:26:52 -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 S1752822AbdK0P0u (ORCPT + 28 others); Mon, 27 Nov 2017 10:26:50 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:53391 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbdK0P0t (ORCPT ); Mon, 27 Nov 2017 10:26:49 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0MflE8-1eVWXN3hum-00N8Xu; Mon, 27 Nov 2017 16:26:34 +0100 From: Arnd Bergmann To: Hans Verkuil , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, Arnd Bergmann , Philipp Zabel , Vincent ABRIOU , Ingo Molnar , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] [media] vivid: use ktime_t for timestamp calculation Date: Mon, 27 Nov 2017 16:25:56 +0100 Message-Id: <20171127152624.2340381-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:t/ZcJPoPXxklJg9BBRR/AMn7JChQF0+J+WaCQ0lVyEtcxDO4wa2 KSJyb8byvyWsaNKdZMarwTT9b04hCAREy+GRrJrC0os6nrLrd7zV5YmarbQnug3v711xPMp g1B706UdpxTEhNyFX3kdS+PnU4v1SNi0EK/A7Rh33TixlzWfcvYSJoJrBkvG7lrV4PH6VQp Beq8llbs7gieCR8KBV9cg== X-UI-Out-Filterresults: notjunk:1; V01:K0:L69Q4yejSGE=:iisghhKVST1iGj42FEOi0B ZU2XKEuEunA7fU6ugZhR9BSeL0uR70Q+3/4c6v4BflE5TZivKgFWi8vi4c2RxRaVvSDCG+1OI Aiz7FDORHyrk7+n1adIaDcOozk+kKlw1cSMv5gJU73HmdDxWdlhYh/+swHMjb+E30cPToIe3q cM1cZe2xqplEpPglpHu7gKWNFPkr45AYoYeY+75NoGgQOAe74YfwENfpkPWQGBw+otEYQfFFk l1QJbnn/8pLUGTpgwJ0Ba/dbLmNeCgH+UL9FXUUBux6DaLjWUm46BIma40AwaPpCbqyqO+5qU dUqMiFiBhTXFVXIXsU9ZXNfX1nhggQsFNN4gOjTFAMEtoTyCh3p0ETKb7LfQBNy/yTAVy8egu 5o2oT9bONcXMhKsutSWDxXHYXE6Su1sZXbqx/X8zcpRDoEKnKRV5DVVvBsAXho3eledcQ1s/u EMXVphASEkFkM2lq+rtO7NrXUBZ+mCCQ96sYPQxNVOdjUFxUw7dV+rSToRibmhDzXffQ4ijsV 5b2ANia2jQA59HqIoIPAs+5h6pmDHySpLYQyyYib9btVDt7rSoeRVPhrlwmt24Iq2yPuJQvIY 6VDUbyFbuh0lKa4cnVqH2+sxPtmICscIVKW0FNXUcp124M8Ix/BXr9ASOxuVC1u9Z3NFKqNSF U2c2SKirrjuaCwXPmU9WyjtEPWm1T1auCnF3R3zxFA0kCffuSu0668NxDDVS/MDLAOi36BWey y3iOdDuZ46Y7SlXTp8R94HurGmVBF9c40gPMHA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Tested-by: Hans Verkuil Signed-off-by: Arnd Bergmann --- v2: fix a small mistake in the use_alternates computation --- 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(-) -- 2.9.0 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..35fbff490535 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) & 1; + 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];