Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7171877imu; Mon, 3 Dec 2018 08:45:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/W5mZrQmbLNYTIUP/Mf2tOSdp9P8EJP42faREKsYwyjZrxepFoetdmO+evQUz7t9oXdJzy5 X-Received: by 2002:a62:8f8c:: with SMTP id n134mr16869579pfd.137.1543855500934; Mon, 03 Dec 2018 08:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543855500; cv=none; d=google.com; s=arc-20160816; b=svUULluP9VjyRpJnr0JSbsoTDBXimchSBpEgxSuLuDeIJpWU2cCvQw0MAUq2B8O8u4 G2QC44/c/HvIftE8XVvG/8R3pv0i3rmUgukgmpNBqJ+GkbxwLbM50LZhMXKQduXiqXbI jJWc7M1ZxGbSh4P2yZZecYTA/fpkXalJtp7Wie3TVyC97N2y5rJZZ/j4RcY+vwnfgF6/ DeceI47bEleaR7TlfXOlNW222g76G/57zHxOsXaUdC5uS7Xx4Wqdcmnu3Xtt/sKOL/fd tgG3SfUx8iYHAV7blDWhDRhETemWz7sksQhdXspctYL0XysiwYffza7qBhMGOm75tk/K Z8pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=aHGO8hd8XcJOmBaPhU6GLIJfHmo66om3Ci7ukHhGM+E=; b=zr+C9KdE24AL3YnC254H43F/Kuu8OEsX53JHv5TrBvLWc1/p8jFAeCKBQiM+8VBJx5 X47iEDVSlc6GO0TW7I1ebNd6PTip3Q8wR8oMaDejD++MUqK76kLxmNWRMFOYiSxVDlFW jMlJEKeCHOLH4V6OCwUrgqtNAdt4r0leM6g8Pc/aL5UIjqGxUSj5R+MHwVRQMNLzWZKV DVYU4823bWKGx1ZrGxZ/dKq1f25ANF3UNTKmBrA755F2IQPh/BAfUs0hZnM8mt2kllvb ZYvh87T8TiUBH63yfIhiJ1CWwLcssxtp56qAcTP+S7rdp+4DF9n7fncIyKeIHyJ2DLsh Lg4g== 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 t20si13758721ply.359.2018.12.03.08.44.38; Mon, 03 Dec 2018 08:45:00 -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 S1726832AbeLCQmD (ORCPT + 99 others); Mon, 3 Dec 2018 11:42:03 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:44805 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeLCQmD (ORCPT ); Mon, 3 Dec 2018 11:42:03 -0500 Received: by mail-qt1-f196.google.com with SMTP id n32so14458850qte.11; Mon, 03 Dec 2018 08:41:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aHGO8hd8XcJOmBaPhU6GLIJfHmo66om3Ci7ukHhGM+E=; b=g4B/bWvQFTGdxwGEtriBd+TPCuH/KGo3s3pIBCeLbRCLU/w0OvKG5Dg5N4cbAXZs/0 +TS7j3+B0RpPFm41tyhO+91eA0G5H/ukw/sZ+BZkbNGif6CM4MRM9oJ5GQpuiarsGJfu M6+wQtlDssQJsxXnNTW/55goOVu4TSMPlKgyfZL8nqCLJ5zN5DcsmPd+e/fFjLefcWzB kIK30VnrzQwuC8AyqZ2CCWLMUYHyRq/CaiKwNXOW6aaRY16yrfKF7wp7Qu+jAW/g09dB oWMHxCd8PAXz31wFIfiKil5GM5oY8I7Ff8/6faSUS38QbIy3i+CC723KxdzEy/ygb8Tf mm0Q== X-Gm-Message-State: AA+aEWaIRnTgJWgq8OTKWmlwkwe4rgBANjs4QUdPEuXOS43ATROM8j3v U04HZse+aDJ2KHzDGs3VcUCdFMRAFFUKI8lqNpGc0S98 X-Received: by 2002:a0c:e202:: with SMTP id q2mr15984333qvl.180.1543855317239; Mon, 03 Dec 2018 08:41:57 -0800 (PST) MIME-Version: 1.0 References: <20181202134538.GA18886@gfm-note> In-Reply-To: From: Arnd Bergmann Date: Mon, 3 Dec 2018 17:41:40 +0100 Message-ID: Subject: Re: [PATCH v4] media: vivid: Improve timestamping To: Hans Verkuil Cc: gfmandaji@gmail.com, Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , lkcamp@lists.libreplanetbr.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 3, 2018 at 10:15 AM Hans Verkuil wrote: > > On 12/02/2018 09:43 PM, Arnd Bergmann wrote: > > On Sun, Dec 2, 2018 at 2:47 PM Gabriel Francisco Mandaji > > wrote: > > > >> @@ -667,10 +653,28 @@ static void vivid_overlay(struct vivid_dev *dev, struct vivid_buffer *buf) > >> } > >> } > >> > >> +static void vivid_cap_update_frame_period(struct vivid_dev *dev) > >> +{ > >> + u64 f_period; > >> + > >> + f_period = (u64)dev->timeperframe_vid_cap.numerator * 1000000000; > >> + do_div(f_period, dev->timeperframe_vid_cap.denominator); > >> + if (dev->field_cap == V4L2_FIELD_ALTERNATE) > >> + do_div(f_period, 2); > >> + /* > >> + * If "End of Frame", then offset the exposure time by 0.9 > >> + * of the frame period. > >> + */ > >> + dev->cap_frame_eof_offset = f_period * 9; > >> + do_div(dev->cap_frame_eof_offset, 10); > >> + dev->cap_frame_period = f_period; > >> +} > > > > Doing two or three do_div() operations is going to make this rather > > expensive on 32-bit architectures, and it looks like this happens for > > each frame? > > > > Since each one is a multiplication followed by a division, could this > > be changed to using a different factor followed by a bit shift? > > The division by 2 can obviously be replaced by a shift, and the > 'End of Frame' calculation can be simplified as well by multiplying by > 7 and dividing by 8 (again a simple shift): this equals 0.875 which is > close enough to 0.9 (so update the comment as well). The first division f_period = (u64)dev->timeperframe_vid_cap.numerator * 1000000000; do_div(f_period, dev->timeperframe_vid_cap.denominator); looks like it could be replaced with a fixed multiplication with a precomputed 'u64 factor = div_u64(numerator * 100000000, denominator) > It's all a bit overkill since this function isn't called very often, > but these are easy changes to make. Ah, I assumed it was called once per frame or more. If this is only done during initalization, it doesn't matter. Arnd