Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Sagar Arun Kamble <sagar.a.kamble@intel.com>,
	Richard Cochran <richardcochran@gmail.com>
Cc: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>,
	linux-kernel@vger.kernel.org, Vinod Koul <vinod.koul@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
Date: Fri, 5 Jan 2018 09:43:12 -0600	[thread overview]
Message-ID: <8c4dbc50-3e59-e860-6131-99fa10a8313f@linux.intel.com> (raw)
In-Reply-To: <d3e83230-dc06-fc2b-b507-723d4863fb4e@intel.com>

On 1/5/18 4:06 AM, Sagar Arun Kamble wrote:
> 
> 
> On 1/3/2018 1:23 AM, Pierre-Louis Bossart wrote:
>> On 1/2/18 12:21 PM, Richard Cochran wrote:
>>> On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
>>>> I wrote the code for HDaudio and I remember wasting time trying to 
>>>> figure
>>>> out the gory details of the cycle counter stuff when all I wanted was a
>>>> conversion from a 24MHz counter to ns values using a 125/3 operation 
>>>> in the
>>>> right order - as explained in the comments
>>>
>>> Would using clocks_calc_mult_shift() work for you?
>>
>> In theory yes, but I'd need to re-check what the results would be.
>> I remember applying the 1/3 factor separately to avoid wrap-around 
>> after 4 hours [1], but I can't remember the details on the analysis. I 
>> can't figure out what the 'maxsec' argument should be either.
>>
> I am not sure if I understood the wrap-around correctly. Is 
> AZX_REG_WALL_CLK 64bit or 32bit and in the comments which 20 bits are 
> being referred.

it's a 32-bit counter.
off the top of my head, the idea was that the integer arithmetic should 
not degrade the precision (42ns) and that means you need to be careful 
with the fractional part, especially if the errors with the fractional 
part accumulate over time (I think this was the case when I looked 
several years ago). That's the main reason why I did the division by 3 
last, after the read, so that the precision is not impacted by the 
interval between two reads.

You also need to be careful with the multiplication factor otherwise you 
will exceed the 64-bit resolution. For example with the 14400 factor, 
you cannot handle a counter larger than 2^64/14400, which gives you 
14826 hours or 1.69 years. It's one of those 'nobody will ever need more 
than 640KB' value. The 125 factor gives you 195 years without saturating.

> 
> Keeping maxsec at lower value will ensure good precision but the mult 
> factor derived then might lead to overflow if the interval of counter 
> read is big.
> Keeping maxsec high will reduce the mult factor and will marginally 
> impact the precision (of the order of 6 decimal places of fraction nano 
> second).
> 
> For 24mhz clock I am getting following scale factors at different maxsec 
> values. I think these are as good as 125/3
> 125/3 gives scale factor of 41.666666666666666666666666666667
> 
> maxsec, mult, shift, scale factor (mult/(2^shift))
> 0, 2796202667, 26,     41.66666667163372039794921875
> 3600, 87381333, 21,   41.666666507720947265625
> 14400, 21845333, 19, 41.6666660308837890625
> 
> I see sound driver uses only timecounter_read so conversions should be 
> fine.
> If there are usages of timecounter_cyc2time then we will have to take 
> care of updating the timecounter often as
> timecounter API internally counts time backwards if counter is spaced 
> more than 1/2 the range.
> 
> Thanks
> Sagar
>> [1] 
>> http://elixir.free-electrons.com/linux/latest/source/sound/hda/hdac_stream.c#L486 
>>
> 

  reply	other threads:[~2018-01-05 15:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com>
2017-12-15  7:38 ` [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct Sagar Arun Kamble
     [not found]   ` <1513323522-15021-2-git-send-email-sagar.a.kamble-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-01-08 22:20     ` [Intel-wired-lan] " Brown, Aaron F
2018-01-09  9:01       ` Sagar Arun Kamble
2017-12-15  7:38 ` [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface Sagar Arun Kamble
2017-12-15 11:10   ` [alsa-devel] " Takashi Iwai
2017-12-15 16:51     ` Richard Cochran
2017-12-15 17:10       ` [alsa-devel] " Takashi Iwai
2017-12-26  7:37         ` Sagar Arun Kamble
2017-12-28 16:49           ` [alsa-devel] " Richard Cochran
2018-01-02  6:03             ` Sagar Arun Kamble
2018-01-02 17:15               ` Pierre-Louis Bossart
2018-01-02 18:21                 ` Richard Cochran
2018-01-02 19:53                   ` Pierre-Louis Bossart
2018-01-05 10:06                     ` [alsa-devel] " Sagar Arun Kamble
2018-01-05 15:43                       ` Pierre-Louis Bossart [this message]
2018-01-09 10:09                         ` Sagar Arun Kamble

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=8c4dbc50-3e59-e860-6131-99fa10a8313f@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=sagar.a.kamble@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /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