Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.arch / Re: Precision timers

SubjectAuthor
* Precision timersrobf...@gmail.com
+- Re: Precision timersTerje Mathisen
+* Re: Precision timersMitchAlsup
|`- Re: Precision timersEricP
+* Re: Precision timersEricP
|+* Re: Precision timersrobf...@gmail.com
||+- Re: Precision timersMitchAlsup
||`- Re: Precision timersEricP
|`- Re: Precision timersMichael S
`* Re: Precision timersStephen Fuld
 `* Re: Precision timersMitchAlsup
  `* Re: Precision timersrobf...@gmail.com
   `* Re: Precision timersThomas Koenig
    `* Re: Precision timersEricP
     `* Re: Precision timersMitchAlsup
      +* Re: Precision timersEricP
      |`* Re: Precision timersMitchAlsup
      | `- Re: Precision timersEricP
      `* Re: Precision timersTerje Mathisen
       +* Re: Precision timersStephen Fuld
       |`- Re: Precision timersTerje Mathisen
       +* Re: Precision timersrobf...@gmail.com
       |+- Re: Precision timersStephen Fuld
       |+- Re: Precision timersEricP
       |`- Re: Precision timersTerje Mathisen
       `* Re: Precision timersEricP
        +* Re: Precision timersStefan Monnier
        |`- Re: Precision timersMitchAlsup
        +* Re: Precision timersMitchAlsup
        |`- Re: Precision timersMichael S
        `* Re: Precision timersTerje Mathisen
         `* Re: Precision timersMichael S
          +* Re: Precision timersTerje Mathisen
          |`* Re: Precision timersMichael S
          | `- Re: Precision timersTerje Mathisen
          `* Re: Precision timersMitchAlsup
           `* Re: Precision timersrobf...@gmail.com
            +- Re: Precision timersMitchAlsup
            `* Re: Precision timersScott Lurndal
             `* Re: Precision timersrobf...@gmail.com
              `- Re: Precision timersrobf...@gmail.com

Pages:12
Precision timers

<b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27229&group=comp.arch#27229

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a0c:f5d2:0:b0:475:825:757f with SMTP id q18-20020a0cf5d2000000b004750825757fmr2123577qvm.36.1660284457299;
Thu, 11 Aug 2022 23:07:37 -0700 (PDT)
X-Received: by 2002:a37:952:0:b0:6ba:37c6:12ec with SMTP id
79-20020a370952000000b006ba37c612ecmr1874179qkj.331.1660284457107; Thu, 11
Aug 2022 23:07:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 11 Aug 2022 23:07:36 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=99.251.79.92; posting-account=QId4bgoAAABV4s50talpu-qMcPp519Eb
NNTP-Posting-Host: 99.251.79.92
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
Subject: Precision timers
From: robfi...@gmail.com (robf...@gmail.com)
Injection-Date: Fri, 12 Aug 2022 06:07:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 17
 by: robf...@gmail.com - Fri, 12 Aug 2022 06:07 UTC

I have been studying HPET and wondering why they used the approach they did.. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.

HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.

My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.

Re: Precision timers

<td5ehe$1343$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27232&group=comp.arch#27232

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!10O9MudpjwoXIahOJRbDvA.user.46.165.242.91.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Fri, 12 Aug 2022 13:45:56 +0200
Organization: Aioe.org NNTP Server
Message-ID: <td5ehe$1343$1@gioia.aioe.org>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="35971"; posting-host="10O9MudpjwoXIahOJRbDvA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.13
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Fri, 12 Aug 2022 11:45 UTC

robf...@gmail.com wrote:
> I have been studying HPET and wondering why they used the approach they did. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
>
> HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
>
> My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
>

Obviously, a single down counter will be enough if you have a supervisor
that gathers all counting requests:

When a new request comes in, it is compared with the current counter
value and if less, is placed at the front of the queue with the counter
set to this value. At the same time the previous front is decremented by
the new top priority count.

In this way, each event just contains the delta from the previous event,
the only real issue is when things occur so quickly or close together
that you have problems updating the queue, but you can fix this byusing
the free-running counter to measure hw long it took you to update the
down counter. :-)

If you instead have a single free-running counter and a single
comparator the world becomes simpler since you just have to iterate over
queue entries until you find the next which has a deadline which hasn't
already passed while you were processing the previous entry.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Precision timers

<de07c74a-0d4d-435e-9b57-4e8b198d45a3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27234&group=comp.arch#27234

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:d82:b0:477:3d7c:1081 with SMTP id e2-20020a0562140d8200b004773d7c1081mr4378656qve.28.1660324147929;
Fri, 12 Aug 2022 10:09:07 -0700 (PDT)
X-Received: by 2002:a05:620a:78c:b0:6b4:7012:97bd with SMTP id
12-20020a05620a078c00b006b4701297bdmr3573693qka.135.1660324147787; Fri, 12
Aug 2022 10:09:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Fri, 12 Aug 2022 10:09:07 -0700 (PDT)
In-Reply-To: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:ec1a:8176:6d09:2264;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:ec1a:8176:6d09:2264
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <de07c74a-0d4d-435e-9b57-4e8b198d45a3n@googlegroups.com>
Subject: Re: Precision timers
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Fri, 12 Aug 2022 17:09:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1468
 by: MitchAlsup - Fri, 12 Aug 2022 17:09 UTC

On Friday, August 12, 2022 at 1:07:38 AM UTC-5, robf...@gmail.com wrote:
> I have been studying HPET and wondering why they used the approach they did.
<
A single constantly incrementing counter is always true to itself.
A single constantly incrementing counter cannot drift with respect to other
counters.

Re: Precision timers

<mEwJK.87380$BZ1.53986@fx03.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27236&group=comp.arch#27236

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx03.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <de07c74a-0d4d-435e-9b57-4e8b198d45a3n@googlegroups.com>
In-Reply-To: <de07c74a-0d4d-435e-9b57-4e8b198d45a3n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 37
Message-ID: <mEwJK.87380$BZ1.53986@fx03.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Fri, 12 Aug 2022 18:06:10 UTC
Date: Fri, 12 Aug 2022 14:05:23 -0400
X-Received-Bytes: 2410
 by: EricP - Fri, 12 Aug 2022 18:05 UTC

MitchAlsup wrote:
> On Friday, August 12, 2022 at 1:07:38 AM UTC-5, robf...@gmail.com wrote:
>> I have been studying HPET and wondering why they used the approach they did.
> <
> A single constantly incrementing counter is always true to itself.
> A single constantly incrementing counter cannot drift with respect to other
> counters.

It cannot drift WRT other counters driven by the same clock signal.
It certainly can drift WRT external clocks like wall clocks.

Crystals have an inherent inaccuracy which manufacturers binning
(sorting parts into accuracy bins to sell at different prices)
skews results for, plus temperature and aging variations.

The counter bit precision and its increment amount decides your
ability to compensate for the above inaccuracies. How long you
expect a system to run between time adjustments comes into play.

Also, depending on the software design, a multi-shot timer can introduce
drift in the delay between when a timer fires and when it is requeued.
Short duration multi-shot timers can miss a firing deadline if timer
processing gets far enough behind, say because of other interrupts.

You can minimize software drift by having an absolute time counter
and having multi-shot timers automatically requeue themselves for
the next absolute deadline until explicitly stopped.
When the absolute clock >= the oldest timer queue entry, pop/requeue
one or more entries and dispatch each timers' callback routine,
until timer entry deadline is > current clock.

If it is an SMP system you can have a bunch of race conditions
to deal with, as timers can be triggering on one cpu while a
different cpu is trying to cancel that timer.

Re: Precision timers

<R_QJK.656175$70j.546485@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27243&group=comp.arch#27243

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
In-Reply-To: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 68
Message-ID: <R_QJK.656175$70j.546485@fx16.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Sat, 13 Aug 2022 17:15:29 UTC
Date: Sat, 13 Aug 2022 13:13:57 -0400
X-Received-Bytes: 4568
 by: EricP - Sat, 13 Aug 2022 17:13 UTC

robf...@gmail.com wrote:
> I have been studying HPET and wondering why they used the approach they did.. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
>
> HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
>
> My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
>

By the way, if you are referring to the High Precision Event Timer HPET
as specified by Intel then a quicky search finds lots of complaints
from both OS implementers and end users, and I see many people looking
for ways to disable it because it has a large jitter
(variable trigger latency) that interferes with games.

Its spec says clock is >= 10 MHz and drift for intervals >= 1 millisecond
is +- 500 ppm. Note that is 500 pmm is 1/2 the millisecond time interval
which, if my calculation is correct, is +- 43.2 seconds per day.

IA-PC HPET (High Precision Event Timers) Specification, 2004
http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf

"The timers are implemented as a single up-counter with a set of
comparators. The counter increases monotonically. When software does
two consecutive reads of the counter, the second read will never return
a value that is less than the first read unless the counter has actually
rolled over. Each timer includes a match register and a comparator.
Each individual timer can generate an interrupt when the value in its
match register equals the value of the free-running counter.
Some of the timers can be enabled to generate a periodic interrupt."

The see a number of problems:

- the compare register can be either 32 or 64 bits.
This was obviously done so it works with x86 and x64.

However if a 32 bit compare then software has to deal with partial
matches and wraps, and this interacts (badly) with issues below.

It would not have been difficult to have all compare values
be 64-bits and just have x86 write two values, low and high,
with compare disabled on the low write and re-enabled on high write.

- the compare function is == NOT >=
Since it triggers on == you can miss trigger.

At 10 MHz a 64-bit >= compare should not be a problem even for FPGA.
A high performance >= is an XOR with a find-last-set which is a
log_4 parallel prefix NAND, so say 4 or 5 gate delays.

- there is a unknown latency between read of current counter and when
it replies, and a possibly different latency on trigger writes.

That is why the compare == is a problem because OS software
has to correct for all of this, which introduces more jitter.

- even though the internal counters can be up to femtosecond (10^-15 s)
resolution, the timer increment value appears to be read-only so there
is no way to adjust this to compensate for hardware variations.

The specified drift makes this completely unusable as a system clock
base which means a separate hardware and software system for regular
OS timers and "HPET" ones. Which is a good thing as the requirements
for each could be different but thats a different set of API's.

Re: Precision timers

<a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27251&group=comp.arch#27251

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:622a:178e:b0:344:56a8:25da with SMTP id s14-20020a05622a178e00b0034456a825damr522749qtk.375.1660430770554;
Sat, 13 Aug 2022 15:46:10 -0700 (PDT)
X-Received: by 2002:a05:620a:4399:b0:6b9:c355:3a72 with SMTP id
a25-20020a05620a439900b006b9c3553a72mr7319011qkp.151.1660430770336; Sat, 13
Aug 2022 15:46:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sat, 13 Aug 2022 15:46:10 -0700 (PDT)
In-Reply-To: <R_QJK.656175$70j.546485@fx16.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=99.251.79.92; posting-account=QId4bgoAAABV4s50talpu-qMcPp519Eb
NNTP-Posting-Host: 99.251.79.92
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <R_QJK.656175$70j.546485@fx16.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>
Subject: Re: Precision timers
From: robfi...@gmail.com (robf...@gmail.com)
Injection-Date: Sat, 13 Aug 2022 22:46:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 117
 by: robf...@gmail.com - Sat, 13 Aug 2022 22:46 UTC

On Saturday, August 13, 2022 at 1:15:33 PM UTC-4, EricP wrote:
> robf...@gmail.com wrote:
> > I have been studying HPET and wondering why they used the approach they did.. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
> >
> > HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed.. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
> >
> > My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
> >
> By the way, if you are referring to the High Precision Event Timer HPET
> as specified by Intel then a quicky search finds lots of complaints
> from both OS implementers and end users, and I see many people looking
> for ways to disable it because it has a large jitter
> (variable trigger latency) that interferes with games.
>
> Its spec says clock is >= 10 MHz and drift for intervals >= 1 millisecond
> is +- 500 ppm. Note that is 500 pmm is 1/2 the millisecond time interval
> which, if my calculation is correct, is +- 43.2 seconds per day.

Yeah, I saw all the posts too, people asking how to disable the timers.
Got the impression they are not well liked.

> IA-PC HPET (High Precision Event Timers) Specification, 2004
> http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf
>
> "The timers are implemented as a single up-counter with a set of
> comparators. The counter increases monotonically. When software does
> two consecutive reads of the counter, the second read will never return
> a value that is less than the first read unless the counter has actually
> rolled over. Each timer includes a match register and a comparator.
> Each individual timer can generate an interrupt when the value in its
> match register equals the value of the free-running counter.
> Some of the timers can be enabled to generate a periodic interrupt."
>
> The see a number of problems:
>
> - the compare register can be either 32 or 64 bits.
> This was obviously done so it works with x86 and x64.
>
> However if a 32 bit compare then software has to deal with partial
> matches and wraps, and this interacts (badly) with issues below.
>
> It would not have been difficult to have all compare values
> be 64-bits and just have x86 write two values, low and high,
> with compare disabled on the low write and re-enabled on high write.
>
> - the compare function is == NOT >=
> Since it triggers on == you can miss trigger.
>
> At 10 MHz a 64-bit >= compare should not be a problem even for FPGA.
> A high performance >= is an XOR with a find-last-set which is a
> log_4 parallel prefix NAND, so say 4 or 5 gate delays.

So, the comparators should ideally compare ‘>=’? Or possibly an option
for either.

The HPET may use either level or edge sensitive outputs. I wonder if
the ‘==’ comparators are so that the edge outputs are not continuously
triggering. It is just a little bit more logic to track if and edge occurred already.

> - there is a unknown latency between read of current counter and when
> it replies, and a possibly different latency on trigger writes.
>
> That is why the compare == is a problem because OS software
> has to correct for all of this, which introduces more jitter.
>
> - even though the internal counters can be up to femtosecond (10^-15 s)
> resolution, the timer increment value appears to be read-only so there
> is no way to adjust this to compensate for hardware variations.

I do not think it is an increment value in terms of being added to the
counter. The counter just increments by one all the time. The counter
would have to be counting at a THz rate to be adjustable.
I think the idea is the counter will be hard-wired for a fixed oscillator and
its necessary to know the frequency or period. If vendor A uses a 10 Mhz
clock and vendor B uses a 15 MHz one there must be a way to track how
much the counter increments by in terms of femtoseconds. So that the
compare values can be adjusted for the clock frequency.

I found the timer increment value confusing. It shows it as read-only but
later in the document it shows it as read/write and says to be careful
updating it.

> The specified drift makes this completely unusable as a system clock
> base which means a separate hardware and software system for regular
> OS timers and "HPET" ones. Which is a good thing as the requirements
> for each could be different but thats a different set of API's.

I have written my own PET core that uses a single up counter now. I have
the luxury of not worrying about backwards compatibility. It is strictly 64-bit,
but I use just a 48-bit counter and comparators for now to try and conserve
some hardware in the FPGA which is running low on resources. That is still
enough to time events almost a year in duration at 10 MHz. Decided not to
provide FSB interrupt messaging as that would add to the size of the core.

Re: Precision timers

<adda8bfc-0fa6-4ba7-b6c9-d7bcf279abd2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27252&group=comp.arch#27252

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:ecb:b0:6b9:787b:ec13 with SMTP id x11-20020a05620a0ecb00b006b9787bec13mr6993221qkm.55.1660431352396;
Sat, 13 Aug 2022 15:55:52 -0700 (PDT)
X-Received: by 2002:a05:6214:1c48:b0:479:71ce:1498 with SMTP id
if8-20020a0562141c4800b0047971ce1498mr8684007qvb.112.1660431352260; Sat, 13
Aug 2022 15:55:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sat, 13 Aug 2022 15:55:52 -0700 (PDT)
In-Reply-To: <a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:d4fa:9459:c187:7734;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:d4fa:9459:c187:7734
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<R_QJK.656175$70j.546485@fx16.iad> <a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <adda8bfc-0fa6-4ba7-b6c9-d7bcf279abd2n@googlegroups.com>
Subject: Re: Precision timers
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sat, 13 Aug 2022 22:55:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2216
 by: MitchAlsup - Sat, 13 Aug 2022 22:55 UTC

On Saturday, August 13, 2022 at 5:46:11 PM UTC-5, robf...@gmail.com wrote:
> On Saturday, August 13, 2022 at 1:15:33 PM UTC-4, EricP wrote:
> > robf...@gmail.com wrote:

> > - the compare function is == NOT >=
> > Since it triggers on == you can miss trigger.
> >
> > At 10 MHz a 64-bit >= compare should not be a problem even for FPGA.
> > A high performance >= is an XOR with a find-last-set which is a
> > log_4 parallel prefix NAND, so say 4 or 5 gate delays.
<
> So, the comparators should ideally compare ‘>=’? Or possibly an option
> for either.
<
The OS sets the time of the <next> trigger. OS is in charge of the >= part.
<
When the trigger goes off, OS takes everybody off the wait queues
that want to run before the next timer tick. Then schedules the cores
based on priority and affinity of all the runnable threads.

Re: Precision timers

<473868dd-7955-47de-92e0-83b1be120252n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27253&group=comp.arch#27253

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:2889:b0:6b6:5410:b2c7 with SMTP id j9-20020a05620a288900b006b65410b2c7mr8622931qkp.697.1660486285328;
Sun, 14 Aug 2022 07:11:25 -0700 (PDT)
X-Received: by 2002:ac8:5b4d:0:b0:33b:858a:5c40 with SMTP id
n13-20020ac85b4d000000b0033b858a5c40mr10562524qtw.563.1660486285191; Sun, 14
Aug 2022 07:11:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sun, 14 Aug 2022 07:11:25 -0700 (PDT)
In-Reply-To: <R_QJK.656175$70j.546485@fx16.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <R_QJK.656175$70j.546485@fx16.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <473868dd-7955-47de-92e0-83b1be120252n@googlegroups.com>
Subject: Re: Precision timers
From: already5...@yahoo.com (Michael S)
Injection-Date: Sun, 14 Aug 2022 14:11:25 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2254
 by: Michael S - Sun, 14 Aug 2022 14:11 UTC

On Saturday, August 13, 2022 at 8:15:33 PM UTC+3, EricP wrote:
>
> Its spec says clock is >= 10 MHz and drift for intervals >= 1 millisecond
> is +- 500 ppm. Note that is 500 pmm is 1/2 the millisecond time interval
> which, if my calculation is correct, is +- 43.2 seconds per day.
>

You'll have hard time buying 500ppm oscillator. They don't appear to be
available at standard places.
You can buy 200ppm or 150ppm oscillator, but it is not clear to me why
would you want to. This low-stability parts are exotic and as such are much
more expensive than "normal" 20 to 100ppm oscillator.

Among "normal" 14.318 MHz, 15pF, CMOS output oscillators there is little
difference in price, at least for moderate quantities. I don't know what
happens when you buy 1M, but for lot of 3000 the common part (25 ppm) appears
to be the cheapest - 0.56 USD on Mouser.

If you want better than 20 ppm then you'd have to pay more, but not a lot more.
10 ppm MEMS oscillators are available in lots of 3000 for 0.98 USD with somewhat
inconvenient 40 pF load capacitance and for 2.16 USD with standard 15 pF capacitance.

Re: Precision timers

<KTaKK.102089$Eh2.28423@fx41.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27261&group=comp.arch#27261

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <R_QJK.656175$70j.546485@fx16.iad> <a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>
In-Reply-To: <a7b493ff-769d-4036-907a-510c47428009n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 157
Message-ID: <KTaKK.102089$Eh2.28423@fx41.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Sun, 14 Aug 2022 18:09:46 UTC
Date: Sun, 14 Aug 2022 14:08:55 -0400
X-Received-Bytes: 9536
 by: EricP - Sun, 14 Aug 2022 18:08 UTC

robf...@gmail.com wrote:
> On Saturday, August 13, 2022 at 1:15:33 PM UTC-4, EricP wrote:
>> robf...@gmail.com wrote:
>>> I have been studying HPET and wondering why they used the approach they did.. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
>>>
>>> HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed.. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
>>>
>>> My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
>>>
>> By the way, if you are referring to the High Precision Event Timer HPET
>> as specified by Intel then a quicky search finds lots of complaints
>> from both OS implementers and end users, and I see many people looking
>> for ways to disable it because it has a large jitter
>> (variable trigger latency) that interferes with games.
>>
>> Its spec says clock is >= 10 MHz and drift for intervals >= 1 millisecond
>> is +- 500 ppm. Note that is 500 pmm is 1/2 the millisecond time interval
>> which, if my calculation is correct, is +- 43.2 seconds per day.
>
> Yeah, I saw all the posts too, people asking how to disable the timers.
> Got the impression they are not well liked.
>
>> IA-PC HPET (High Precision Event Timers) Specification, 2004
>> http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf
>>
>> "The timers are implemented as a single up-counter with a set of
>> comparators. The counter increases monotonically. When software does
>> two consecutive reads of the counter, the second read will never return
>> a value that is less than the first read unless the counter has actually
>> rolled over. Each timer includes a match register and a comparator.
>> Each individual timer can generate an interrupt when the value in its
>> match register equals the value of the free-running counter.
>> Some of the timers can be enabled to generate a periodic interrupt."
>>
>> The see a number of problems:
>>
>> - the compare register can be either 32 or 64 bits.
>> This was obviously done so it works with x86 and x64.
>>
>> However if a 32 bit compare then software has to deal with partial
>> matches and wraps, and this interacts (badly) with issues below.
>>
>> It would not have been difficult to have all compare values
>> be 64-bits and just have x86 write two values, low and high,
>> with compare disabled on the low write and re-enabled on high write.
>>
>> - the compare function is == NOT >=
>> Since it triggers on == you can miss trigger.
>>
>> At 10 MHz a 64-bit >= compare should not be a problem even for FPGA.
>> A high performance >= is an XOR with a find-last-set which is a
>> log_4 parallel prefix NAND, so say 4 or 5 gate delays.
>
> So, the comparators should ideally compare ‘>=’? Or possibly an option
> for either.

Yes >=, or decrement the trigger value before storing it and use > as it
is slightly faster (it doesn't need to NOR with the XOR values).

An == would only be need if you wanted compatibility with that spec.

The problem with == is you don't know when the next clock is.
There can be arbitrary delay between read of current timer counter
and write of the trigger due to other interrupts or cache misses.
A short duration could miss its trigger value and then it would wait
until the counter to wrap around. This is not what was wanted
so software has to correct for this, adding more jitter.

The document warns of this:
"WARNING: Software developers must be careful when programming the
comparator registers. If the value written to the register is not
sufficiently set far enough ahead of the current register value,
then the counter may pass the value before it reaches the register
and the interrupt will be missed."

A 64-bit compare > does not have this problem.

> The HPET may use either level or edge sensitive outputs. I wonder if
> the ‘==’ comparators are so that the edge outputs are not continuously
> triggering. It is just a little bit more logic to track if and edge occurred already.

Yes, that is my guess too, they chose == so they can do 32 bit compares
on the low order counter and trigger values, as a compare > on just the
low order 32 bits would incur repeated false triggering.

The correct solution is to require 64 bit compares,
not to do == compares on the low order 32 bits and
then throw software at it to fix the inevitable issues.

There is also a warning that a 64-bit read of the time counter
on a 64-bit cpu might be turned into two 32 bit reads internally
by the HPET hardware and therefore miss a carry-out from low order
to high order 32-bits. This forces software to always read the
counter in a loop until it gets the same value twice.

The correct solution is to require 64 bit reads on 64 bit cpus,
not to maybe allow value tearing along 32 bit boundaries and
expect software to patch it up.

>> - there is a unknown latency between read of current counter and when
>> it replies, and a possibly different latency on trigger writes.
>>
>> That is why the compare == is a problem because OS software
>> has to correct for all of this, which introduces more jitter.
>>
>> - even though the internal counters can be up to femtosecond (10^-15 s)
>> resolution, the timer increment value appears to be read-only so there
>> is no way to adjust this to compensate for hardware variations.
>
> I do not think it is an increment value in terms of being added to the
> counter. The counter just increments by one all the time. The counter
> would have to be counting at a THz rate to be adjustable.
> I think the idea is the counter will be hard-wired for a fixed oscillator and
> its necessary to know the frequency or period. If vendor A uses a 10 Mhz
> clock and vendor B uses a 15 MHz one there must be a way to track how
> much the counter increments by in terms of femtoseconds. So that the
> compare values can be adjusted for the clock frequency.

There looks to be a read-only register COUNTER_CLK_PERIOD that contains
the tick size in femtoseconds. Software would scale delay durations
with that value to get a tick count and then wait for that many ticks.

> I found the timer increment value confusing. It shows it as read-only but
> later in the document it shows it as read/write and says to be careful
> updating it.

I didn't see the read-write value for COUNTER_CLK_PERIOD.

>> The specified drift makes this completely unusable as a system clock
>> base which means a separate hardware and software system for regular
>> OS timers and "HPET" ones. Which is a good thing as the requirements
>> for each could be different but thats a different set of API's.
>
> I have written my own PET core that uses a single up counter now. I have
> the luxury of not worrying about backwards compatibility. It is strictly 64-bit,
> but I use just a 48-bit counter and comparators for now to try and conserve
> some hardware in the FPGA which is running low on resources. That is still
> enough to time events almost a year in duration at 10 MHz. Decided not to
> provide FSB interrupt messaging as that would add to the size of the core.

48 bits is enough for 345 days of 100 nsec ticks before wrap around.
That 48 bit value could be OR'ed with a 16-bit high order value
in memory to produce the full 64 bit counter for software to use.
It might be handy if the timer unit generated a specific interrupt on
carry out from the up counter so it can increment the 16-bit high order
value so software doesn't always have to check for overflow.

The spec is over 20 years old but there is no reason for something
like this to be complicated or inefficient if one considers both
the HW and SW implications during its design.

For example, I haven't looked at how this interacts with the interrupt
subsystem but it should be possible for almost all of the timer register
manipulations to be done without disabling and enabling interrupts,
even on 32-bit cpus.

Re: Precision timers

<tdf5jh$3lo8i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27295&group=comp.arch#27295

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Mon, 15 Aug 2022 21:14:41 -0700
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <tdf5jh$3lo8i$1@dont-email.me>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 16 Aug 2022 04:14:41 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="46670e5a6221064e240b8771aab97cd1";
logging-data="3858706"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9j/zkAU43/pNv+YXkAnnffII+ggERV8E="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Cancel-Lock: sha1:2zdlr2epFsw+7uigftPOD72R+Nk=
Content-Language: en-US
In-Reply-To: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
 by: Stephen Fuld - Tue, 16 Aug 2022 04:14 UTC

On 8/11/2022 11:07 PM, robf...@gmail.com wrote:
> I have been studying HPET and wondering why they used the approach they did. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
>
> HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
>
> My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
>

It could be that they were trying to provide the capability to read the
timer, do something, then read it again in order to tell the elapsed
time to do that thing. From what I understand, your implementation
doesn't provide that capability. Is it needed? It depends.

So that brings up a question relevant for comp.arch. What are the
requirements for a timer in a clean sheet design?

Some questions:

I assume the "timing an event" functionality is required, as well as the
"interrupt at a specified time in the future" functionality.

What is the required time granularity?

For the interrupt at a specified time function, how many comparitors are
required. Is one enough? I can see an argument for two, one self
resetting, one not. I don't see much need for more than that.

Should the implementation allow multiple reads of the timer to return
the same value?

How closely should the timer be synched to external time?

How long should it be before the timer rolls over?

Other issues. Discuss. :-)

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Precision timers

<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27302&group=comp.arch#27302

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:622a:1453:b0:344:5909:ba44 with SMTP id v19-20020a05622a145300b003445909ba44mr9535741qtx.132.1660665660167;
Tue, 16 Aug 2022 09:01:00 -0700 (PDT)
X-Received: by 2002:ad4:5946:0:b0:477:42fd:6492 with SMTP id
eo6-20020ad45946000000b0047742fd6492mr18525566qvb.88.1660665659778; Tue, 16
Aug 2022 09:00:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Tue, 16 Aug 2022 09:00:59 -0700 (PDT)
In-Reply-To: <tdf5jh$3lo8i$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:c894:1a68:cad4:f08b;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:c894:1a68:cad4:f08b
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
Subject: Re: Precision timers
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Tue, 16 Aug 2022 16:01:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 67
 by: MitchAlsup - Tue, 16 Aug 2022 16:00 UTC

On Monday, August 15, 2022 at 11:14:50 PM UTC-5, Stephen Fuld wrote:
> On 8/11/2022 11:07 PM, robf...@gmail.com wrote:
> > I have been studying HPET and wondering why they used the approach they did. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
> >
> > HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed.. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
> >
> > My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
> >
> It could be that they were trying to provide the capability to read the
> timer, do something, then read it again in order to tell the elapsed
> time to do that thing. From what I understand, your implementation
> doesn't provide that capability. Is it needed? It depends.
>
> So that brings up a question relevant for comp.arch. What are the
> requirements for a timer in a clean sheet design?
>
> Some questions:
>
> I assume the "timing an event" functionality is required, as well as the
> "interrupt at a specified time in the future" functionality.
>
> What is the required time granularity?
<
No worse than 1ns.
>
> For the interrupt at a specified time function, how many comparitors are
> required. Is one enough? I can see an argument for two, one self
> resetting, one not. I don't see much need for more than that.
<
1 comparator on machines with 10 cycle context switching.
>
> Should the implementation allow multiple reads of the timer to return
> the same value?
<
This defeats the ability to use the timer to sort conflicts.
>
> How closely should the timer be synched to external time?
<
1ns
>
> How long should it be before the timer rolls over?
<
at least a month.
>
> Other issues. Discuss. :-)
>
Constant access time delay.
>
>
>
> --
> - Stephen Fuld
> (e-mail address disguised to prevent spam)

Re: Precision timers

<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27325&group=comp.arch#27325

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:1a16:b0:6b8:7789:8ca4 with SMTP id bk22-20020a05620a1a1600b006b877898ca4mr16976680qkb.292.1660722484721;
Wed, 17 Aug 2022 00:48:04 -0700 (PDT)
X-Received: by 2002:a05:6214:d88:b0:46e:64aa:842a with SMTP id
e8-20020a0562140d8800b0046e64aa842amr20700529qve.101.1660722484536; Wed, 17
Aug 2022 00:48:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Wed, 17 Aug 2022 00:48:04 -0700 (PDT)
In-Reply-To: <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fea8:1dde:6a00:f139:3a43:fb66:2744;
posting-account=QId4bgoAAABV4s50talpu-qMcPp519Eb
NNTP-Posting-Host: 2607:fea8:1dde:6a00:f139:3a43:fb66:2744
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
Subject: Re: Precision timers
From: robfi...@gmail.com (robf...@gmail.com)
Injection-Date: Wed, 17 Aug 2022 07:48:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4643
 by: robf...@gmail.com - Wed, 17 Aug 2022 07:48 UTC

On Tuesday, August 16, 2022 at 12:01:01 PM UTC-4, MitchAlsup wrote:
> On Monday, August 15, 2022 at 11:14:50 PM UTC-5, Stephen Fuld wrote:
> > On 8/11/2022 11:07 PM, robf...@gmail.com wrote:
> > > I have been studying HPET and wondering why they used the approach they did. Is there some value to using just a single counter? The only thing I could think of was power consumption. I may switch my somewhat naïve timer implementation if there is good cause.
> > >
> > > HPET uses a single up counter and comparators and adders to trigger periodic or non-periodic events. It seems to me to be more complex than needed. To determine when the next non-periodic event occurs the current counter value must be added onto then the comparator updated. For periodic events the comparator is automatically increased by the last amount written to the comparator register.
> > >
> > > My timer system is organized more like a classic 8254 or 6840 timer. I used down counters and pre-sets for each timer. The comparator is a compare to zero count to trigger events. The counters can be auto pre-set to get periodic events. There are multiple counters but I think this is no worse than having adders for each timer. It amounts to the same resource usage.
> > >
> > It could be that they were trying to provide the capability to read the
> > timer, do something, then read it again in order to tell the elapsed
> > time to do that thing. From what I understand, your implementation
> > doesn't provide that capability. Is it needed? It depends.
> >
> > So that brings up a question relevant for comp.arch. What are the
> > requirements for a timer in a clean sheet design?
> >
> > Some questions:
> >
> > I assume the "timing an event" functionality is required, as well as the
> > "interrupt at a specified time in the future" functionality.
> >
> > What is the required time granularity?
> <
10 ns or 100 ns, easily achievable in a PLD.

> >
> > For the interrupt at a specified time function, how many comparitors are
> > required. Is one enough? I can see an argument for two, one self
> > resetting, one not. I don't see much need for more than that.
> <

30+ comparators per core (300 comparators?) might allow every
process to have its own comparator. Which would not need to be
managed by the OS.

> >
> > Should the implementation allow multiple reads of the timer to return
> > the same value?
> <
Yes. The software could just loop until it gets the next value if unique values
are needed. If the timer is close to the processor speed, it is not going to
loop very many times. Might be handy to have hardware assistance for this.
Sync to port value change instruction.

> >
> > How closely should the timer be synched to external time?
> <
Should be able to sync to the minimum increment.

> >
> > How long should it be before the timer rolls over?
> <
A year or more. There is lots of work done on weekly or monthly basis.
Some work is done on quarterly or yearly basis - seasonal.

> > Other issues. Discuss. :-)
> >
> >
> >
> > --
> > - Stephen Fuld
> > (e-mail address disguised to prevent spam)

Re: Precision timers

<tdifiv$tkh$3@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27332&group=comp.arch#27332

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2a0a-a540-1faa-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Wed, 17 Aug 2022 10:23:27 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <tdifiv$tkh$3@newsreader4.netcologne.de>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me>
<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
Injection-Date: Wed, 17 Aug 2022 10:23:27 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2a0a-a540-1faa-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2a0a:a540:1faa:0:7285:c2ff:fe6c:992d";
logging-data="30353"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Wed, 17 Aug 2022 10:23 UTC

robf...@gmail.com <robfi680@gmail.com> schrieb:

> 30+ comparators per core (300 comparators?) might allow every
> process to have its own comparator. Which would not need to be
> managed by the OS.

Hmm... do you want to restrict the core to 300 processes? Hard
limits have a habit of coming around and biting the user when it
least expected (for example when an attacker or a buggy process
does a few forks() and uses up all of them).

And you would need the OS anyway to schedule access to them so
so it is guaranteed that no two processes use the same timer.

Re: Precision timers

<wJ6LK.734298$5fVf.97913@fx09.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27343&group=comp.arch#27343

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com> <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de>
In-Reply-To: <tdifiv$tkh$3@newsreader4.netcologne.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 37
Message-ID: <wJ6LK.734298$5fVf.97913@fx09.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Wed, 17 Aug 2022 14:14:52 UTC
Date: Wed, 17 Aug 2022 10:14:36 -0400
X-Received-Bytes: 2462
 by: EricP - Wed, 17 Aug 2022 14:14 UTC

Thomas Koenig wrote:
> robf...@gmail.com <robfi680@gmail.com> schrieb:
>
>> 30+ comparators per core (300 comparators?) might allow every
>> process to have its own comparator. Which would not need to be
>> managed by the OS.
>
> Hmm... do you want to restrict the core to 300 processes? Hard
> limits have a habit of coming around and biting the user when it
> least expected (for example when an attacker or a buggy process
> does a few forks() and uses up all of them).
>
> And you would need the OS anyway to schedule access to them so
> so it is guaranteed that no two processes use the same timer.

You don't need to dedicate a high resolution timer to a process.
That wouldn't do much good as processes can have many timers
and software within a single process won't know about other timers.

Each one-shot HW hr-comparator manages a queue of requests.
The queue can be a linked list or binary tree in ascending order
of absolute timeout hr-tick time. The earliest timeout timestamp
is written into the trigger register, or 0 to disable the trigger
if the queue is empty.

If there are multiple hr-comparators then there are multiple queues.
The OS could distribute new timer inserts across queues.
That allows inserts to do less work as they have to touch
fewer other timer objects in each queue (less cache misses).

I don't see much advantage in allowing a process or thread or
device driver to reserve a timer queue to itself.
And all such software would have to deal with the possibility
that the timer queue reservation request was denied.
This adds complexity without adding value.

Re: Precision timers

<54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27353&group=comp.arch#27353

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:400e:b0:6ba:fcb6:3641 with SMTP id h14-20020a05620a400e00b006bafcb63641mr13780574qko.375.1660748906781;
Wed, 17 Aug 2022 08:08:26 -0700 (PDT)
X-Received: by 2002:a05:622a:1388:b0:344:4ff1:dd66 with SMTP id
o8-20020a05622a138800b003444ff1dd66mr17406244qtk.135.1660748906535; Wed, 17
Aug 2022 08:08:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Wed, 17 Aug 2022 08:08:26 -0700 (PDT)
In-Reply-To: <wJ6LK.734298$5fVf.97913@fx09.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:5879:d7aa:3989:85e9;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:5879:d7aa:3989:85e9
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de>
<wJ6LK.734298$5fVf.97913@fx09.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
Subject: Re: Precision timers
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Wed, 17 Aug 2022 15:08:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3420
 by: MitchAlsup - Wed, 17 Aug 2022 15:08 UTC

On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
> Thomas Koenig wrote:
> > robf...@gmail.com <robf...@gmail.com> schrieb:
> >
> >> 30+ comparators per core (300 comparators?) might allow every
> >> process to have its own comparator. Which would not need to be
> >> managed by the OS.
> >
> > Hmm... do you want to restrict the core to 300 processes? Hard
> > limits have a habit of coming around and biting the user when it
> > least expected (for example when an attacker or a buggy process
> > does a few forks() and uses up all of them).
> >
> > And you would need the OS anyway to schedule access to them so
> > so it is guaranteed that no two processes use the same timer.
<
> You don't need to dedicate a high resolution timer to a process.
> That wouldn't do much good as processes can have many timers
> and software within a single process won't know about other timers.
>
> Each one-shot HW hr-comparator manages a queue of requests.
<
Yes, obviously...
<
> The queue can be a linked list or binary tree in ascending order
> of absolute timeout hr-tick time. The earliest timeout timestamp
> is written into the trigger register, or 0 to disable the trigger
> if the queue is empty.
<
What does SW do in managing this list of event-times when one
event fires, and the next event is 1 tick farther down in time ?
It seems to me that the only way for SW to manage such a queue
would be to have large timer-quanta.
<
>
> If there are multiple hr-comparators then there are multiple queues.
> The OS could distribute new timer inserts across queues.
> That allows inserts to do less work as they have to touch
> fewer other timer objects in each queue (less cache misses).
>
> I don't see much advantage in allowing a process or thread or
> device driver to reserve a timer queue to itself.
> And all such software would have to deal with the possibility
> that the timer queue reservation request was denied.
> This adds complexity without adding value.

Re: Precision timers

<Ka9LK.793786$J0r9.236469@fx11.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27363&group=comp.arch#27363

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com> <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
In-Reply-To: <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 85
Message-ID: <Ka9LK.793786$J0r9.236469@fx11.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Wed, 17 Aug 2022 17:02:34 UTC
Date: Wed, 17 Aug 2022 13:01:17 -0400
X-Received-Bytes: 4722
 by: EricP - Wed, 17 Aug 2022 17:01 UTC

MitchAlsup wrote:
> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>> Thomas Koenig wrote:
>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>
>>>> 30+ comparators per core (300 comparators?) might allow every
>>>> process to have its own comparator. Which would not need to be
>>>> managed by the OS.
>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>> limits have a habit of coming around and biting the user when it
>>> least expected (for example when an attacker or a buggy process
>>> does a few forks() and uses up all of them).
>>>
>>> And you would need the OS anyway to schedule access to them so
>>> so it is guaranteed that no two processes use the same timer.
> <
>> You don't need to dedicate a high resolution timer to a process.
>> That wouldn't do much good as processes can have many timers
>> and software within a single process won't know about other timers.
>>
>> Each one-shot HW hr-comparator manages a queue of requests.
> <
> Yes, obviously...

Just making sure everyone is sync'ed on this...

> <
>> The queue can be a linked list or binary tree in ascending order
>> of absolute timeout hr-tick time. The earliest timeout timestamp
>> is written into the trigger register, or 0 to disable the trigger
>> if the queue is empty.
> <
> What does SW do in managing this list of event-times when one
> event fires, and the next event is 1 tick farther down in time ?

Its not just 1 tick as servicing the timers has some latency.
So it a window of N ticks, where N varies depending on cpu load.
That is one of the problems that compare == has,
which is why > or >= should be the trigger compares.
Requeue of periodic timers could encounter this for each trigger.

Periodic timers also have the possibility of multiple timeouts at once.
The timer service routine should loop adding timer duration to the
prior trigger time and counting the number of intervals added,
until the next timeout is in the future.
When the callback routine is called, one of the parameters should
be how many timeouts periods have expired since the last callback.

So to answer your question, it would add 1 or more ticks to the
prior timeout trigger and set that as next future deadline,
which might trigger immediately if the time counter has incremented.
Then call the callback passing (timerPtr, trigCount, arg1, arg2, arg3).

An OS would likely impose a lower limit on the duration of
periodic timers to prevent them taking over the cpu.

Some SMP related software issues:
(a) Can the timer queue(s) be serviced on multiple cpus at once,
or should there be a cpu dedicated to servicing timers?
There is something to be said for each approach.

(b) Can a single timer fire twice in short succession on different
cpus at once, such that you wind up with the same callback routine
for the same timer executing concurrently on multiple cpus?
It is possible to write the timer dispatch software either way.

Timer using software would probably prefer to NOT have to deal with
multiple concurrent timeout firings for the same timer.

> It seems to me that the only way for SW to manage such a queue
> would be to have large timer-quanta.

This is one difference between high resolution timers and
system timers. For system timers a tick size might be 100 ns
but the quanta is defined by OS, such as 1 ms, or 10 ms.

For HR timers the tick size is the quanta defined by the hardware.
Having the model dependent tick size in femtoseconds stored
in a read-only HW register is as good as any method.

Software converts duration specified in, say, nanoseconds to
HR tick counts for that model and waits > that many ticks.

Re: Precision timers

<df63f07d-e665-4427-b6e0-ca70e3d34892n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27367&group=comp.arch#27367

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:d0b:b0:47b:4d2b:fa53 with SMTP id 11-20020a0562140d0b00b0047b4d2bfa53mr22936209qvh.13.1660762523926;
Wed, 17 Aug 2022 11:55:23 -0700 (PDT)
X-Received: by 2002:a05:620a:2728:b0:6ba:e857:9375 with SMTP id
b40-20020a05620a272800b006bae8579375mr16263691qkp.728.1660762523774; Wed, 17
Aug 2022 11:55:23 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Wed, 17 Aug 2022 11:55:23 -0700 (PDT)
In-Reply-To: <Ka9LK.793786$J0r9.236469@fx11.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:f1c3:96e3:f4f1:d944;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:f1c3:96e3:f4f1:d944
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de>
<wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
<Ka9LK.793786$J0r9.236469@fx11.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <df63f07d-e665-4427-b6e0-ca70e3d34892n@googlegroups.com>
Subject: Re: Precision timers
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Wed, 17 Aug 2022 18:55:23 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 7153
 by: MitchAlsup - Wed, 17 Aug 2022 18:55 UTC

On Wednesday, August 17, 2022 at 12:02:37 PM UTC-5, EricP wrote:
> MitchAlsup wrote:
> > On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
> >> Thomas Koenig wrote:
> >>> robf...@gmail.com <robf...@gmail.com> schrieb:
> >>>
> >>>> 30+ comparators per core (300 comparators?) might allow every
> >>>> process to have its own comparator. Which would not need to be
> >>>> managed by the OS.
> >>> Hmm... do you want to restrict the core to 300 processes? Hard
> >>> limits have a habit of coming around and biting the user when it
> >>> least expected (for example when an attacker or a buggy process
> >>> does a few forks() and uses up all of them).
> >>>
> >>> And you would need the OS anyway to schedule access to them so
> >>> so it is guaranteed that no two processes use the same timer.
> > <
> >> You don't need to dedicate a high resolution timer to a process.
> >> That wouldn't do much good as processes can have many timers
> >> and software within a single process won't know about other timers.
> >>
> >> Each one-shot HW hr-comparator manages a queue of requests.
> > <
> > Yes, obviously...
> Just making sure everyone is sync'ed on this...
> > <
> >> The queue can be a linked list or binary tree in ascending order
> >> of absolute timeout hr-tick time. The earliest timeout timestamp
> >> is written into the trigger register, or 0 to disable the trigger
> >> if the queue is empty.
> > <
> > What does SW do in managing this list of event-times when one
> > event fires, and the next event is 1 tick farther down in time ?
<
> Its not just 1 tick as servicing the timers has some latency.
> So it a window of N ticks, where N varies depending on cpu load.
<
And how much cache+memory interference is present.
<
> That is one of the problems that compare == has,
> which is why > or >= should be the trigger compares.
<
>= is the only thing that makes sense.
<
> Requeue of periodic timers could encounter this for each trigger.
<
With SW in control of queueing and dequeueing, I would have thought
the CPU/core would have an indication of how big N is so that SW
leaves the earliest 'event' in the timer, and everyone between that and
that+N would be dequeued in order of oldness before the SW thinks
the timer event is 'satisfied'.
>
> Periodic timers also have the possibility of multiple timeouts at once.
> The timer service routine should loop adding timer duration to the
> prior trigger time and counting the number of intervals added,
> until the next timeout is in the future.
> When the callback routine is called, one of the parameters should
> be how many timeouts periods have expired since the last callback.
<
This feature should be a part of EVERY asynchronous wakeup system.
"how many of your things happened" before control could be transferred
to you.
>
> So to answer your question, it would add 1 or more ticks to the
> prior timeout trigger and set that as next future deadline,
> which might trigger immediately if the time counter has incremented.
> Then call the callback passing (timerPtr, trigCount, arg1, arg2, arg3).
>
> An OS would likely impose a lower limit on the duration of
> periodic timers to prevent them taking over the cpu.
>
> Some SMP related software issues:
> (a) Can the timer queue(s) be serviced on multiple cpus at once,
> or should there be a cpu dedicated to servicing timers?
> There is something to be said for each approach.
<
I prefer that HW receives the events, and schedules the service routines.
This way, one can service a timer event every 5 CPU cycles (or so);
SW can never be in such a position--and this gets rid of the need for
synchronization, and interrupt latency.
>
> (b) Can a single timer fire twice in short succession on different
> cpus at once, such that you wind up with the same callback routine
> for the same timer executing concurrently on multiple cpus?
<
This question becomes moot if something other than a CPU receives
and processes the event to the point of the context switch(s).
<
> It is possible to write the timer dispatch software either way.
>
> Timer using software would probably prefer to NOT have to deal with
> multiple concurrent timeout firings for the same timer.
<
A single timer "going off" in Sun 10K system was one of the worst possible
things that could happen. Consider: timer goes off, timer dispatcher wakes
up 100+ jobs, IPIs are sent to every CPU, every CPU attempts to dequeue
the front of the highest priority run queue. There were up to 64 CPUs, and
every piece of interference caused N-1 CPUs to have to retry.
<
Nick McLaren said that sometimes it might take a whole second (note not
millisecond or microsecond--a real wall clock second) for all the CPUs to
be running their appointed thread.
<
> > It seems to me that the only way for SW to manage such a queue
> > would be to have large timer-quanta.
> This is one difference between high resolution timers and
> system timers. For system timers a tick size might be 100 ns
> but the quanta is defined by OS, such as 1 ms, or 10 ms.
<
Good point.
>
> For HR timers the tick size is the quanta defined by the hardware.
> Having the model dependent tick size in femtoseconds stored
> in a read-only HW register is as good as any method.
<
Aren't HRTs used more as nanosecond clocks than for scheduling
timer events--that is time measurement rather than scheduling of
events.
>
> Software converts duration specified in, say, nanoseconds to
> HR tick counts for that model and waits > that many ticks.

Re: Precision timers

<tdkp46$104a$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27382&group=comp.arch#27382

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!10O9MudpjwoXIahOJRbDvA.user.46.165.242.91.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Thu, 18 Aug 2022 09:18:31 +0200
Organization: Aioe.org NNTP Server
Message-ID: <tdkp46$104a$1@gioia.aioe.org>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me>
<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
<tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad>
<54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="32906"; posting-host="10O9MudpjwoXIahOJRbDvA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Firefox/68.0 SeaMonkey/2.53.13
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Thu, 18 Aug 2022 07:18 UTC

MitchAlsup wrote:
> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>> Thomas Koenig wrote:
>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>
>>>> 30+ comparators per core (300 comparators?) might allow every
>>>> process to have its own comparator. Which would not need to be
>>>> managed by the OS.
>>>
>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>> limits have a habit of coming around and biting the user when it
>>> least expected (for example when an attacker or a buggy process
>>> does a few forks() and uses up all of them).
>>>
>>> And you would need the OS anyway to schedule access to them so
>>> so it is guaranteed that no two processes use the same timer.
> <
>> You don't need to dedicate a high resolution timer to a process.
>> That wouldn't do much good as processes can have many timers
>> and software within a single process won't know about other timers.
>>
>> Each one-shot HW hr-comparator manages a queue of requests.
> <
> Yes, obviously...
> <
>> The queue can be a linked list or binary tree in ascending order
>> of absolute timeout hr-tick time. The earliest timeout timestamp
>> is written into the trigger register, or 0 to disable the trigger
>> if the queue is empty.
> <
> What does SW do in managing this list of event-times when one
> event fires, and the next event is 1 tick farther down in time ?
> It seems to me that the only way for SW to manage such a queue
> would be to have large timer-quanta.

I think that there are only two ways it can work:

a) Make the comparator >= so that when the next value is written, it
immediately causes a timeout since the tick count has passed. This does
require that comparator to separate between a recent rollower and a long
time to go, typically using 2^63 as the boundary:

diff = next_event_count - current_tick_count;
if ((signed) diff <= 0) fire();

b) Do the same in SW with a polled approach:

When a event count triggers, the handler dispatches it, then grabs the
next count in the queue and inserts it before immediately reading the
current count to check if the time has already passed, if so, handle it
and repeat. The big problem here is of course that there will always be
a tiny window between writing the next comparator value and reading the
current count to check for an overrun. Fixing that adds a lot of hair,
you either need the (HW) ability to get the current count at the same
time as you write the comparator, or some kind of status register to
report on any currently pending timeout.

It is very easy to see why the hw people would prefer a plain ==
comparator, but it does lead to even more issues in software. :-(

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Precision timers

<tdlmtf$1347f$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27383&group=comp.arch#27383

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Thu, 18 Aug 2022 08:46:55 -0700
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <tdlmtf$1347f$1@dont-email.me>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me>
<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
<tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad>
<54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
<tdkp46$104a$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 Aug 2022 15:46:56 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e436c90cb68dd97fdb8817815b8b8349";
logging-data="1151215"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NivsUtQolYYsHqXxu5R/sBDeknI562iQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Cancel-Lock: sha1:pD82Ke4MAFVBvDS8W/EZqeO4diY=
In-Reply-To: <tdkp46$104a$1@gioia.aioe.org>
Content-Language: en-US
 by: Stephen Fuld - Thu, 18 Aug 2022 15:46 UTC

On 8/18/2022 12:18 AM, Terje Mathisen wrote:
> MitchAlsup wrote:
>> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>>> Thomas Koenig wrote:
>>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>>
>>>>> 30+ comparators per core (300 comparators?) might allow every
>>>>> process to have its own comparator. Which would not need to be
>>>>> managed by the OS.
>>>>
>>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>>> limits have a habit of coming around and biting the user when it
>>>> least expected (for example when an attacker or a buggy process
>>>> does a few forks() and uses up all of them).
>>>>
>>>> And you would need the OS anyway to schedule access to them so
>>>> so it is guaranteed that no two processes use the same timer.
>> <
>>> You don't need to dedicate a high resolution timer to a process.
>>> That wouldn't do much good as processes can have many timers
>>> and software within a single process won't know about other timers.
>>>
>>> Each one-shot HW hr-comparator manages a queue of requests.
>> <
>> Yes, obviously...
>> <
>>> The queue can be a linked list or binary tree in ascending order
>>> of absolute timeout hr-tick time. The earliest timeout timestamp
>>> is written into the trigger register, or 0 to disable the trigger
>>> if the queue is empty.
>> <
>> What does SW do in managing this list of event-times when one
>> event fires, and the next event is 1 tick farther down in time ?
>> It seems to me that the only way for SW to manage such a queue
>> would be to have large timer-quanta.
>
> I think that there are only two ways it can work:
>
> a) Make the comparator >= so that when the next value is written, it
> immediately causes a timeout since the tick count has passed. This does
> require that comparator to separate between a recent rollower and a long
> time to go, typically using 2^63 as the boundary:
>
>   diff = next_event_count - current_tick_count;
>   if ((signed) diff <= 0) fire();
>
> b) Do the same in SW with a polled approach:
>
> When a event count triggers, the handler dispatches it, then grabs the
> next count in the queue and inserts it before immediately reading the
> current count to check if the time has already passed, if so, handle it
> and repeat. The big problem here is of course that there will always be
> a tiny window between writing the next comparator value and reading the
> current count to check for an overrun. Fixing that adds a lot of hair,
> you either need the (HW) ability to get the current count at the same
> time as you write the comparator, or some kind of status register to
> report on any currently pending timeout.
>
> It is very easy to see why the hw people would prefer a plain ==
> comparator, but it does lead to even more issues in software. :-(

I have seen timers that append a few bit field to the timer. This field
is returned as the low end of the value when one reads the timer. The
contents of this field are incremented each time the timer is read, and
reset to zero each time the timer ticks. The result guarantees a unique
value returned, but does give a value where the bits below the specified
minimum accuracy of the timer may not be accurate.

For example, suppose you have a timer granularity of 1ns, and four bits
in the new field. Someone reading the timer would see a value specified
in 16ths of a ns, but only the bits at or above 1 ns would be accurate.
Thus someone reading the counter will usually get an accurate value (the
extra bits zero), but occasionally it will be off by a small number of
16ths of a nanosecond.

I thought this was an interesting tradeoff.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Precision timers

<5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27384&group=comp.arch#27384

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:1ccc:b0:496:ab0a:896a with SMTP id g12-20020a0562141ccc00b00496ab0a896amr3204337qvd.36.1660837704991;
Thu, 18 Aug 2022 08:48:24 -0700 (PDT)
X-Received: by 2002:a05:620a:2181:b0:6bb:50a1:222e with SMTP id
g1-20020a05620a218100b006bb50a1222emr2582997qka.151.1660837704747; Thu, 18
Aug 2022 08:48:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 18 Aug 2022 08:48:24 -0700 (PDT)
In-Reply-To: <tdkp46$104a$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fea8:1dde:6a00:411a:681d:c98f:4315;
posting-account=QId4bgoAAABV4s50talpu-qMcPp519Eb
NNTP-Posting-Host: 2607:fea8:1dde:6a00:411a:681d:c98f:4315
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de>
<wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
<tdkp46$104a$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>
Subject: Re: Precision timers
From: robfi...@gmail.com (robf...@gmail.com)
Injection-Date: Thu, 18 Aug 2022 15:48:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 5366
 by: robf...@gmail.com - Thu, 18 Aug 2022 15:48 UTC

On Thursday, August 18, 2022 at 3:18:32 AM UTC-4, Terje Mathisen wrote:
> MitchAlsup wrote:
> > On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
> >> Thomas Koenig wrote:
> >>> robf...@gmail.com <robf...@gmail.com> schrieb:
> >>>
> >>>> 30+ comparators per core (300 comparators?) might allow every
> >>>> process to have its own comparator. Which would not need to be
> >>>> managed by the OS.
> >>>
> >>> Hmm... do you want to restrict the core to 300 processes? Hard
> >>> limits have a habit of coming around and biting the user when it
> >>> least expected (for example when an attacker or a buggy process
> >>> does a few forks() and uses up all of them).
> >>>
> >>> And you would need the OS anyway to schedule access to them so
> >>> so it is guaranteed that no two processes use the same timer.

With enough timers the process ID could be used to determine which
timer to use, so the OS does not need to schedule one. There are only
about 250 process running on my Windows machine (3,000 threads).
I think a timer component is not very large so there could be a lot of
them.

> > <
> >> You don't need to dedicate a high resolution timer to a process.
> >> That wouldn't do much good as processes can have many timers
> >> and software within a single process won't know about other timers.
> >>
> >> Each one-shot HW hr-comparator manages a queue of requests.
> > <
> > Yes, obviously...
> > <
> >> The queue can be a linked list or binary tree in ascending order
> >> of absolute timeout hr-tick time. The earliest timeout timestamp
> >> is written into the trigger register, or 0 to disable the trigger
> >> if the queue is empty.
> > <
> > What does SW do in managing this list of event-times when one
> > event fires, and the next event is 1 tick farther down in time ?
> > It seems to me that the only way for SW to manage such a queue
> > would be to have large timer-quanta.
> I think that there are only two ways it can work:
>
> a) Make the comparator >= so that when the next value is written, it
> immediately causes a timeout since the tick count has passed. This does
> require that comparator to separate between a recent rollower and a long
> time to go, typically using 2^63 as the boundary:
>
> diff = next_event_count - current_tick_count;
> if ((signed) diff <= 0) fire();
>
> b) Do the same in SW with a polled approach:
>
> When a event count triggers, the handler dispatches it, then grabs the
> next count in the queue and inserts it before immediately reading the
> current count to check if the time has already passed, if so, handle it
> and repeat. The big problem here is of course that there will always be
> a tiny window between writing the next comparator value and reading the
> current count to check for an overrun. Fixing that adds a lot of hair,
> you either need the (HW) ability to get the current count at the same
> time as you write the comparator, or some kind of status register to
> report on any currently pending timeout.
>
> It is very easy to see why the hw people would prefer a plain ==
> comparator, but it does lead to even more issues in software. :-(
> Terje
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

How about writing the increment amount to the comparator instead
of the absolute value? The current compare value would not need to be
read then. The store operation would just automatically add to the current
count.

What about having two comparator types, one for high precision timing
that works down to ns range and a second type that works on the range
shifted over a number of bits, eight for example, to give a range of value
that can be used to time events into the years? And then use a 72-bit
counter.

Re: Precision timers

<tdlqe4$1347f$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27385&group=comp.arch#27385

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Thu, 18 Aug 2022 09:47:00 -0700
Organization: A noiseless patient Spider
Lines: 103
Message-ID: <tdlqe4$1347f$2@dont-email.me>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me>
<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
<tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad>
<54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
<tdkp46$104a$1@gioia.aioe.org>
<5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 18 Aug 2022 16:47:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e436c90cb68dd97fdb8817815b8b8349";
logging-data="1151215"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FBDZyJsr/HvQKxJB+9iDGATwX35TWl5U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Cancel-Lock: sha1:5uRVIoVO+tq5hw2a5QvwNsikcZc=
In-Reply-To: <5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>
Content-Language: en-US
 by: Stephen Fuld - Thu, 18 Aug 2022 16:47 UTC

On 8/18/2022 8:48 AM, robf...@gmail.com wrote:
> On Thursday, August 18, 2022 at 3:18:32 AM UTC-4, Terje Mathisen wrote:
>> MitchAlsup wrote:
>>> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>>>> Thomas Koenig wrote:
>>>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>>>
>>>>>> 30+ comparators per core (300 comparators?) might allow every
>>>>>> process to have its own comparator. Which would not need to be
>>>>>> managed by the OS.
>>>>>
>>>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>>>> limits have a habit of coming around and biting the user when it
>>>>> least expected (for example when an attacker or a buggy process
>>>>> does a few forks() and uses up all of them).
>>>>>
>>>>> And you would need the OS anyway to schedule access to them so
>>>>> so it is guaranteed that no two processes use the same timer.
>
> With enough timers the process ID could be used to determine which
> timer to use, so the OS does not need to schedule one. There are only
> about 250 process running on my Windows machine (3,000 threads).
> I think a timer component is not very large so there could be a lot of
> them.
>
>>> <
>>>> You don't need to dedicate a high resolution timer to a process.
>>>> That wouldn't do much good as processes can have many timers
>>>> and software within a single process won't know about other timers.
>>>>
>>>> Each one-shot HW hr-comparator manages a queue of requests.
>>> <
>>> Yes, obviously...
>>> <
>>>> The queue can be a linked list or binary tree in ascending order
>>>> of absolute timeout hr-tick time. The earliest timeout timestamp
>>>> is written into the trigger register, or 0 to disable the trigger
>>>> if the queue is empty.
>>> <
>>> What does SW do in managing this list of event-times when one
>>> event fires, and the next event is 1 tick farther down in time ?
>>> It seems to me that the only way for SW to manage such a queue
>>> would be to have large timer-quanta.
>> I think that there are only two ways it can work:
>>
>> a) Make the comparator >= so that when the next value is written, it
>> immediately causes a timeout since the tick count has passed. This does
>> require that comparator to separate between a recent rollower and a long
>> time to go, typically using 2^63 as the boundary:
>>
>> diff = next_event_count - current_tick_count;
>> if ((signed) diff <= 0) fire();
>>
>> b) Do the same in SW with a polled approach:
>>
>> When a event count triggers, the handler dispatches it, then grabs the
>> next count in the queue and inserts it before immediately reading the
>> current count to check if the time has already passed, if so, handle it
>> and repeat. The big problem here is of course that there will always be
>> a tiny window between writing the next comparator value and reading the
>> current count to check for an overrun. Fixing that adds a lot of hair,
>> you either need the (HW) ability to get the current count at the same
>> time as you write the comparator, or some kind of status register to
>> report on any currently pending timeout.
>>
>> It is very easy to see why the hw people would prefer a plain ==
>> comparator, but it does lead to even more issues in software. :-(
>> Terje
>>
>> --
>> - <Terje.Mathisen at tmsw.no>
>> "almost all programming can be viewed as an exercise in caching"
>
> How about writing the increment amount to the comparator instead
> of the absolute value? The current compare value would not need to be
> read then. The store operation would just automatically add to the current
> count.

If you write the increment to the "comparator", you could eliminate the
compare to the clock, by having the hardware decrement the value in the
comparator each time it increments the clock. When the value in the
comparitor hits zero, it "fires".

> What about having two comparator types, one for high precision timing
> that works down to ns range and a second type that works on the range
> shifted over a number of bits, eight for example, to give a range of value
> that can be used to time events into the years? And then use a 72-bit
> counter.

The Unisys 2200 series has a system request that returns the number of
ns since 00:00 Dec 31, 1899, in 72 bits. Of course 72 bits is a lot
easier to handle in a 36 bit word machine. :-) Note: I vaguely recall
it used the trick I mentioned in a previous post such that the accuracy
wasn't 1 ns.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Precision timers

<TQvLK.163391$%i2.78442@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27387&group=comp.arch#27387

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com> <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com> <Ka9LK.793786$J0r9.236469@fx11.iad> <df63f07d-e665-4427-b6e0-ca70e3d34892n@googlegroups.com>
In-Reply-To: <df63f07d-e665-4427-b6e0-ca70e3d34892n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 178
Message-ID: <TQvLK.163391$%i2.78442@fx48.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Thu, 18 Aug 2022 18:49:23 UTC
Date: Thu, 18 Aug 2022 14:28:24 -0400
X-Received-Bytes: 9244
 by: EricP - Thu, 18 Aug 2022 18:28 UTC

MitchAlsup wrote:
> On Wednesday, August 17, 2022 at 12:02:37 PM UTC-5, EricP wrote:
>> MitchAlsup wrote:
>>> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>>>> Thomas Koenig wrote:
>>>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>>>
>>>>>> 30+ comparators per core (300 comparators?) might allow every
>>>>>> process to have its own comparator. Which would not need to be
>>>>>> managed by the OS.
>>>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>>>> limits have a habit of coming around and biting the user when it
>>>>> least expected (for example when an attacker or a buggy process
>>>>> does a few forks() and uses up all of them).
>>>>>
>>>>> And you would need the OS anyway to schedule access to them so
>>>>> so it is guaranteed that no two processes use the same timer.
>>> <
>>>> You don't need to dedicate a high resolution timer to a process.
>>>> That wouldn't do much good as processes can have many timers
>>>> and software within a single process won't know about other timers.
>>>>
>>>> Each one-shot HW hr-comparator manages a queue of requests.
>>> <
>>> Yes, obviously...
>> Just making sure everyone is sync'ed on this...
>>> <
>>>> The queue can be a linked list or binary tree in ascending order
>>>> of absolute timeout hr-tick time. The earliest timeout timestamp
>>>> is written into the trigger register, or 0 to disable the trigger
>>>> if the queue is empty.
>>> <
>>> What does SW do in managing this list of event-times when one
>>> event fires, and the next event is 1 tick farther down in time ?
> <
>> Its not just 1 tick as servicing the timers has some latency.
>> So it a window of N ticks, where N varies depending on cpu load.
> <
> And how much cache+memory interference is present.

Yes that affects the actual timer routine performance
but it is independent of the hr timer design.
The design should be such that it is not a bottleneck.

> <
>> That is one of the problems that compare == has,
>> which is why > or >= should be the trigger compares.
> <
> >= is the only thing that makes sense.
> <
>> Requeue of periodic timers could encounter this for each trigger.
> <
> With SW in control of queueing and dequeueing, I would have thought
> the CPU/core would have an indication of how big N is so that SW
> leaves the earliest 'event' in the timer, and everyone between that and
> that+N would be dequeued in order of oldness before the SW thinks
> the timer event is 'satisfied'.

Yes but (a) there is a latency before the timer loop starts and
(b) time continues to pass while the loop is running.
If the clock increment quantum is 1 ms you can ignore these effects but
if it is 1 ns then it can increment before and during timeouts.

The timer queue is guarded by a spinlock which you don't want to hold.
So I would lock queue, read counter, dequeue/requeue one timer at
head of list, release lock, call callback.
Loop doing the above until head of timer queue is > current counter.

If counter increments before, during, or after either the loop will
catch those new expires or it will immediately interrupt again when
a new trigger is set.

>> Periodic timers also have the possibility of multiple timeouts at once.
>> The timer service routine should loop adding timer duration to the
>> prior trigger time and counting the number of intervals added,
>> until the next timeout is in the future.
>> When the callback routine is called, one of the parameters should
>> be how many timeouts periods have expired since the last callback.
> <
> This feature should be a part of EVERY asynchronous wakeup system.
> "how many of your things happened" before control could be transferred
> to you.

It depends on whose code is responsible for requeuing periodic timers.
If auto-requeue is a "feature" of the OS kernel then yes it should.
However it can also be left to individual drivers or apps to requeue
so only those that care would be responsible counting expired intervals.

>> So to answer your question, it would add 1 or more ticks to the
>> prior timeout trigger and set that as next future deadline,
>> which might trigger immediately if the time counter has incremented.
>> Then call the callback passing (timerPtr, trigCount, arg1, arg2, arg3).
>>
>> An OS would likely impose a lower limit on the duration of
>> periodic timers to prevent them taking over the cpu.
>>
>> Some SMP related software issues:
>> (a) Can the timer queue(s) be serviced on multiple cpus at once,
>> or should there be a cpu dedicated to servicing timers?
>> There is something to be said for each approach.
> <
> I prefer that HW receives the events, and schedules the service routines.
> This way, one can service a timer event every 5 CPU cycles (or so);
> SW can never be in such a position--and this gets rid of the need for
> synchronization, and interrupt latency.

On a general purpose cpu I'd just assign one cpu to handle all timers.

But if one has hardware threads then there are multiple ways
timeout events can bind to service threads. There could be:
(a) a single thread triggered by the all timeouts that runs
all timer routines, consecutively.
(b) each timer object is a separate thread that is triggered
to run by its timeout, concurrent by timer request object.
(c) concurrent by individual timeout instance

>> (b) Can a single timer fire twice in short succession on different
>> cpus at once, such that you wind up with the same callback routine
>> for the same timer executing concurrently on multiple cpus?
> <
> This question becomes moot if something other than a CPU receives
> and processes the event to the point of the context switch(s).

These questions are all about when a timeout routine binds to a
HW thread to execute it.

> <
>> It is possible to write the timer dispatch software either way.
>>
>> Timer using software would probably prefer to NOT have to deal with
>> multiple concurrent timeout firings for the same timer.
> <
> A single timer "going off" in Sun 10K system was one of the worst possible
> things that could happen. Consider: timer goes off, timer dispatcher wakes
> up 100+ jobs, IPIs are sent to every CPU, every CPU attempts to dequeue
> the front of the highest priority run queue. There were up to 64 CPUs, and
> every piece of interference caused N-1 CPUs to have to retry.

My impression is that this kind of thing happens for
non-blocking IO polling loops common with sockets.
The solution is for the application to use async IO.

Also for highly contended shared resources like scheduler queues a kernel
should use spin-queues instead of spin-locks to eliminate O(N^2) retries.

> <
> Nick McLaren said that sometimes it might take a whole second (note not
> millisecond or microsecond--a real wall clock second) for all the CPUs to
> be running their appointed thread.
> <
>>> It seems to me that the only way for SW to manage such a queue
>>> would be to have large timer-quanta.
>> This is one difference between high resolution timers and
>> system timers. For system timers a tick size might be 100 ns
>> but the quanta is defined by OS, such as 1 ms, or 10 ms.
> <
> Good point.
>> For HR timers the tick size is the quanta defined by the hardware.
>> Having the model dependent tick size in femtoseconds stored
>> in a read-only HW register is as good as any method.
> <
> Aren't HRTs used more as nanosecond clocks than for scheduling
> timer events--that is time measurement rather than scheduling of
> events.

For general purpose cpus and OS I don't see how anyone could depend on
nanosecond resolution deadlines as there so much variation introduced
by other sources that you will never achieve that actual timing.

By making the hr timer 1 ns or better we ensure that the timer
mechanism is not the performance bottleneck.

On a real-time system where one can lock down cache and one has total
control over all threads and their priorities, maybe those could
nanosecond resolution deadlines could be achieved.

Re: Precision timers

<TQvLK.163392$%i2.22546@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27388&group=comp.arch#27388

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com> <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com> <tdkp46$104a$1@gioia.aioe.org>
In-Reply-To: <tdkp46$104a$1@gioia.aioe.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 88
Message-ID: <TQvLK.163392$%i2.22546@fx48.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Thu, 18 Aug 2022 18:49:23 UTC
Date: Thu, 18 Aug 2022 14:48:43 -0400
X-Received-Bytes: 4959
 by: EricP - Thu, 18 Aug 2022 18:48 UTC

Terje Mathisen wrote:
> MitchAlsup wrote:
>> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>>> Thomas Koenig wrote:
>>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>>
>>>>> 30+ comparators per core (300 comparators?) might allow every
>>>>> process to have its own comparator. Which would not need to be
>>>>> managed by the OS.
>>>>
>>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>>> limits have a habit of coming around and biting the user when it
>>>> least expected (for example when an attacker or a buggy process
>>>> does a few forks() and uses up all of them).
>>>>
>>>> And you would need the OS anyway to schedule access to them so
>>>> so it is guaranteed that no two processes use the same timer.
>> <
>>> You don't need to dedicate a high resolution timer to a process.
>>> That wouldn't do much good as processes can have many timers
>>> and software within a single process won't know about other timers.
>>>
>>> Each one-shot HW hr-comparator manages a queue of requests.
>> <
>> Yes, obviously...
>> <
>>> The queue can be a linked list or binary tree in ascending order
>>> of absolute timeout hr-tick time. The earliest timeout timestamp
>>> is written into the trigger register, or 0 to disable the trigger
>>> if the queue is empty.
>> <
>> What does SW do in managing this list of event-times when one
>> event fires, and the next event is 1 tick farther down in time ?
>> It seems to me that the only way for SW to manage such a queue
>> would be to have large timer-quanta.
>
> I think that there are only two ways it can work:
>
> a) Make the comparator >= so that when the next value is written, it
> immediately causes a timeout since the tick count has passed. This does
> require that comparator to separate between a recent rollower and a long
> time to go, typically using 2^63 as the boundary:
>
> diff = next_event_count - current_tick_count;
> if ((signed) diff <= 0) fire();

Unlike the system clock, the period counter resets to zero at boot.
With a 1 ns tick a 64 bit counter wraps after 584 years of
continuous up-time so it wouldn't need any extra handling.

However if the counter or trigger is smaller, say 32 or 48 bits,
or the ticks smaller, say 1 ps, then the counter wrap generates
an interrupt that increments an epoch number in memory.

The trigger register for the youngest timer at the head of the queue
is only set when the current epoch number >= that timers' epoch.
Otherwise the trigger is disabled.

> b) Do the same in SW with a polled approach:
>
> When a event count triggers, the handler dispatches it, then grabs the
> next count in the queue and inserts it before immediately reading the
> current count to check if the time has already passed, if so, handle it
> and repeat. The big problem here is of course that there will always be
> a tiny window between writing the next comparator value and reading the
> current count to check for an overrun. Fixing that adds a lot of hair,
> you either need the (HW) ability to get the current count at the same
> time as you write the comparator, or some kind of status register to
> report on any currently pending timeout.
>
> It is very easy to see why the hw people would prefer a plain ==
> comparator, but it does lead to even more issues in software. :-(
>
> Terje
>

The original spec also had design options like whether the counter
or comparators were 32 or 64 bits, and if 64 bits are they read and
written atomically or as two separate 32 bit values.
Software had to take all these variations into account.

One of the interactions the Linux folks seemed concerned
about is that an interrupt is generated when the counter wraps,
and this can interact with power state management.
A 32 bit counter with 1 ns resolution tick would overflow every
4 seconds and wake up the processor out of power down.
Another reason to require 64 bit timer components.

Re: Precision timers

<LewLK.82656$mY1.375@fx01.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27389&group=comp.arch#27389

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx01.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Precision timers
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com> <tdf5jh$3lo8i$1@dont-email.me> <253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com> <09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com> <tdifiv$tkh$3@newsreader4.netcologne.de> <wJ6LK.734298$5fVf.97913@fx09.iad> <54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com> <tdkp46$104a$1@gioia.aioe.org> <5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>
In-Reply-To: <5a63de4b-cb56-4646-a26f-23283f690b9bn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 94
Message-ID: <LewLK.82656$mY1.375@fx01.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Thu, 18 Aug 2022 19:16:59 UTC
Date: Thu, 18 Aug 2022 15:16:42 -0400
X-Received-Bytes: 5514
 by: EricP - Thu, 18 Aug 2022 19:16 UTC

robf...@gmail.com wrote:
> On Thursday, August 18, 2022 at 3:18:32 AM UTC-4, Terje Mathisen wrote:
>> MitchAlsup wrote:
>>> On Wednesday, August 17, 2022 at 9:14:55 AM UTC-5, EricP wrote:
>>>> Thomas Koenig wrote:
>>>>> robf...@gmail.com <robf...@gmail.com> schrieb:
>>>>>
>>>>>> 30+ comparators per core (300 comparators?) might allow every
>>>>>> process to have its own comparator. Which would not need to be
>>>>>> managed by the OS.
>>>>> Hmm... do you want to restrict the core to 300 processes? Hard
>>>>> limits have a habit of coming around and biting the user when it
>>>>> least expected (for example when an attacker or a buggy process
>>>>> does a few forks() and uses up all of them).
>>>>>
>>>>> And you would need the OS anyway to schedule access to them so
>>>>> so it is guaranteed that no two processes use the same timer.
>
> With enough timers the process ID could be used to determine which
> timer to use, so the OS does not need to schedule one. There are only
> about 250 process running on my Windows machine (3,000 threads).
> I think a timer component is not very large so there could be a lot of
> them.
>
>>> <
>>>> You don't need to dedicate a high resolution timer to a process.
>>>> That wouldn't do much good as processes can have many timers
>>>> and software within a single process won't know about other timers.
>>>>
>>>> Each one-shot HW hr-comparator manages a queue of requests.
>>> <
>>> Yes, obviously...
>>> <
>>>> The queue can be a linked list or binary tree in ascending order
>>>> of absolute timeout hr-tick time. The earliest timeout timestamp
>>>> is written into the trigger register, or 0 to disable the trigger
>>>> if the queue is empty.
>>> <
>>> What does SW do in managing this list of event-times when one
>>> event fires, and the next event is 1 tick farther down in time ?
>>> It seems to me that the only way for SW to manage such a queue
>>> would be to have large timer-quanta.
>> I think that there are only two ways it can work:
>>
>> a) Make the comparator >= so that when the next value is written, it
>> immediately causes a timeout since the tick count has passed. This does
>> require that comparator to separate between a recent rollower and a long
>> time to go, typically using 2^63 as the boundary:
>>
>> diff = next_event_count - current_tick_count;
>> if ((signed) diff <= 0) fire();
>>
>> b) Do the same in SW with a polled approach:
>>
>> When a event count triggers, the handler dispatches it, then grabs the
>> next count in the queue and inserts it before immediately reading the
>> current count to check if the time has already passed, if so, handle it
>> and repeat. The big problem here is of course that there will always be
>> a tiny window between writing the next comparator value and reading the
>> current count to check for an overrun. Fixing that adds a lot of hair,
>> you either need the (HW) ability to get the current count at the same
>> time as you write the comparator, or some kind of status register to
>> report on any currently pending timeout.
>>
>> It is very easy to see why the hw people would prefer a plain ==
>> comparator, but it does lead to even more issues in software. :-(
>> Terje
>>
>> --
>> - <Terje.Mathisen at tmsw.no>
>> "almost all programming can be viewed as an exercise in caching"
>
> How about writing the increment amount to the comparator instead
> of the absolute value? The current compare value would not need to be
> read then. The store operation would just automatically add to the current
> count.

You would also have to reset the counter to zero.
Remember you also have multiple items in the queue with their
own durations relative to *when they were enqueued/requeued*.

If you work through the software in detail I think you will find
they can accomplish the same but using the offset duration is more work.

> What about having two comparator types, one for high precision timing
> that works down to ns range and a second type that works on the range
> shifted over a number of bits, eight for example, to give a range of value
> that can be used to time events into the years? And then use a 72-bit
> counter.

That is what PC's currently have. The system clock which interrupts
approx 1 to 10 milliseconds and the OS uses that to adjust OS time.
The high resolution timers are in addition to the system clock.

Re: Precision timers

<jwva6815pjl.fsf-monnier+comp.arch@gnu.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27391&group=comp.arch#27391

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: monn...@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.arch
Subject: Re: Precision timers
Date: Thu, 18 Aug 2022 15:19:09 -0400
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <jwva6815pjl.fsf-monnier+comp.arch@gnu.org>
References: <b3662ae3-4e78-4af8-adb3-d397954e7bacn@googlegroups.com>
<tdf5jh$3lo8i$1@dont-email.me>
<253fa161-fdae-4312-a8de-a93891166dafn@googlegroups.com>
<09a5763e-38c2-439e-9cec-810c0d150ca1n@googlegroups.com>
<tdifiv$tkh$3@newsreader4.netcologne.de>
<wJ6LK.734298$5fVf.97913@fx09.iad>
<54940761-07c4-4b54-bdf4-4fbaf7d073ccn@googlegroups.com>
<tdkp46$104a$1@gioia.aioe.org> <TQvLK.163392$%i2.22546@fx48.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="e4fe124e885f72e5b85e8e9ffb13afeb";
logging-data="1213190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fjoGLRGl5+c/vt0To3kCN"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:76NOJN4T8YETUkzbv79DeYHOS7w=
sha1:TyTo9oyL20iRLpJbTVrylJx1+Wc=
 by: Stefan Monnier - Thu, 18 Aug 2022 19:19 UTC

> However if the counter or trigger is smaller, say 32 or 48 bits,
> or the ticks smaller, say 1 ps, then the counter wrap generates
> an interrupt that increments an epoch number in memory.

You'll want to make sure this epoch-interrupt is triggered often enough
to be tested sufficiently to be reliable.

Stefan


devel / comp.arch / Re: Precision timers

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor