linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: gfmandaji@gmail.com, Mauro Carvalho Chehab <mchehab@kernel.org>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	lkcamp@lists.libreplanetbr.org
Subject: Re: [PATCH v4] media: vivid: Improve timestamping
Date: Mon, 3 Dec 2018 17:41:40 +0100	[thread overview]
Message-ID: <CAK8P3a3uLxxTkTxvSZ8wqwRD5EKVWdimDuH8X6cHoWXdAGDJ+w@mail.gmail.com> (raw)
In-Reply-To: <c3d75256-bfdc-6f36-1e6e-ad4e5cd9b855@xs4all.nl>

On Mon, Dec 3, 2018 at 10:15 AM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> On 12/02/2018 09:43 PM, Arnd Bergmann wrote:
> > On Sun, Dec 2, 2018 at 2:47 PM Gabriel Francisco Mandaji
> > <gfmandaji@gmail.com> 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

  reply	other threads:[~2018-12-03 16:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 13:45 [PATCH v4] media: vivid: Improve timestamping Gabriel Francisco Mandaji
2018-12-02 20:43 ` Arnd Bergmann
2018-12-03  9:15   ` Hans Verkuil
2018-12-03 16:41     ` Arnd Bergmann [this message]
2018-12-07 10:44 ` Hans Verkuil
2018-12-08 13:11   ` Gabriel Francisco Mandaji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK8P3a3uLxxTkTxvSZ8wqwRD5EKVWdimDuH8X6cHoWXdAGDJ+w@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=gfmandaji@gmail.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lkcamp@lists.libreplanetbr.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).