public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Functions to consume CPU time in x86
@ 2001-03-28 10:26 Cristiano Ligieri Pereira
       [not found] ` <Pine.SOL.4.20.0103281120510.11565-100000@washoe.ics.uci.ed>
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Cristiano Ligieri Pereira @ 2001-03-28 10:26 UTC (permalink / raw)
  To: ecos-discuss

Hi all,

I need to implement some functions to keep the CPU busy for some amounts
of time. I know that one way to do that is to build loops that do nothing
other than keep the CPU busy. I would like to have functions to consume
hundreds or thousands of nanoseconds of CPU time in x86 platform. Has
anyone done this before? If so, would you be up to provide me such
functions?

Thanks a lot,

Cristiano.

------------------------------------------------------------
Cristiano Ligieri Pereira - http://www.ics.uci.edu/~cpereira


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 10:26 [ECOS] Functions to consume CPU time in x86 Cristiano Ligieri Pereira
       [not found] ` <Pine.SOL.4.20.0103281120510.11565-100000@washoe.ics.uci.ed>
@ 2001-03-28 11:26 ` Cristiano Ligieri Pereira
  2001-03-28 12:08   ` Lewin A.R.W. Edwards
  2001-03-29 11:50   ` Nick Garnett
  2001-03-29 11:50 ` Hugo Tyson
  2 siblings, 2 replies; 8+ messages in thread
From: Cristiano Ligieri Pereira @ 2001-03-28 11:26 UTC (permalink / raw)
  To: ecos-discuss

And of course I want to be able to specify that I want to keep the CPU
busy for specific X (mili/nano)seconds and not only keep it busy for some
randon amount of time.

I looking for functions like this.

consume10ns() or consume1ns()

or consume1ms() or consume10ms()

Thanks again,

Cristiano.

------------------------------------------------------------
Cristiano Ligieri Pereira - http://www.ics.uci.edu/~cpereira

On Wed, 28 Mar 2001, Cristiano Ligieri Pereira wrote:

> 
> Hi all,
> 
> I need to implement some functions to keep the CPU busy for some amounts
> of time. I know that one way to do that is to build loops that do nothing
> other than keep the CPU busy. I would like to have functions to consume
> hundreds or thousands of nanoseconds of CPU time in x86 platform. Has
> anyone done this before? If so, would you be up to provide me such
> functions?
> 
> Thanks a lot,
> 
> Cristiano.
> 
> ------------------------------------------------------------
> Cristiano Ligieri Pereira - http://www.ics.uci.edu/~cpereira
> 
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 11:26 ` Cristiano Ligieri Pereira
@ 2001-03-28 12:08   ` Lewin A.R.W. Edwards
  2001-03-28 12:17     ` Grant Edwards
  2001-03-29 11:50   ` Nick Garnett
  1 sibling, 1 reply; 8+ messages in thread
From: Lewin A.R.W. Edwards @ 2001-03-28 12:08 UTC (permalink / raw)
  To: Cristiano Ligieri Pereira, ecos-discuss

>And of course I want to be able to specify that I want to keep the CPU
>busy for specific X (mili/nano)seconds and not only keep it busy for some
>randon amount of time.

This is going to be close to impossible to achieve. The exact amount of 
time will depend on:

* clock speed
* exact CPU vendor and model (and maybe microcode revision)
* L1 and L2 cache state
* alignment of code
* MMU state
* (potentially) other hardware tying up buses

You'll need to examine the instruction timing for your particular specific 
hardware and write functions of your own methinks.

=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/

"Und setzet ihr nicht das Leben ein,
Nie wird euch das Leben gewonnen sein."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 12:08   ` Lewin A.R.W. Edwards
@ 2001-03-28 12:17     ` Grant Edwards
  2001-03-28 12:31       ` Lewin A.R.W. Edwards
  0 siblings, 1 reply; 8+ messages in thread
From: Grant Edwards @ 2001-03-28 12:17 UTC (permalink / raw)
  To: Lewin A.R.W. Edwards; +Cc: Cristiano Ligieri Pereira, ecos-discuss

On Wed, Mar 28, 2001 at 03:07:50PM -0500, Lewin A.R.W. Edwards wrote:

> >And of course I want to be able to specify that I want to keep the CPU
> >busy for specific X (mili/nano)seconds and not only keep it busy for some
> >randon amount of time.
> 
> This is going to be close to impossible to achieve. The exact amount of 
> time will depend on:
> 
> * clock speed
> * exact CPU vendor and model (and maybe microcode revision)
> * L1 and L2 cache state
> * alignment of code
> * MMU state
> * (potentially) other hardware tying up buses
> 
> You'll need to examine the instruction timing for your particular specific 
> hardware and write functions of your own methinks.

The classic way of doing delays on x86 is to do a string of
some sort of I/O access cycles (e.g. inw/outw) that took a
relatively long (and fixed) amount of time compared to the loop
overhead. That way you can minimize the effects of cache and
MMU state.

It still requires hand tuning for each platform.

Unless you've got access to a hardware counter (with a known
clock rate), you're going to have to tune a delay loop for your
platform.

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 12:17     ` Grant Edwards
@ 2001-03-28 12:31       ` Lewin A.R.W. Edwards
  2001-03-28 12:35         ` Grant Edwards
  0 siblings, 1 reply; 8+ messages in thread
From: Lewin A.R.W. Edwards @ 2001-03-28 12:31 UTC (permalink / raw)
  To: Grant Edwards; +Cc: Cristiano Ligieri Pereira, ecos-discuss

> > >And of course I want to be able to specify that I want to keep the CPU
> > >busy for specific X (mili/nano)seconds and not only keep it busy for some
> > >randon amount of time.
>
>Unless you've got access to a hardware counter (with a known
>clock rate), you're going to have to tune a delay loop for your

Oh, one silly thing I forgot - On Pentium and higher x86 CPUs, you have the 
TSC MSR which is incremented every CPU clock cycle. You can use this to 
measure elapsed time. For very small values this will obviously not be an 
accurate technique for yielding delays, though.

=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/

"Und setzet ihr nicht das Leben ein,
Nie wird euch das Leben gewonnen sein."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 12:31       ` Lewin A.R.W. Edwards
@ 2001-03-28 12:35         ` Grant Edwards
  0 siblings, 0 replies; 8+ messages in thread
From: Grant Edwards @ 2001-03-28 12:35 UTC (permalink / raw)
  To: Lewin A.R.W. Edwards; +Cc: Cristiano Ligieri Pereira, ecos-discuss

On Wed, Mar 28, 2001 at 03:30:33PM -0500, Lewin A.R.W. Edwards wrote:

> > > >And of course I want to be able to specify that I want to keep
> > > >the CPU busy for specific X (mili/nano)seconds and not only
> > > >keep it busy for some randon amount of time.
> >
> >Unless you've got access to a hardware counter (with a known
> >clock rate), you're going to have to tune a delay loop for your
> 
> Oh, one silly thing I forgot - On Pentium and higher x86 CPUs,
> you have the TSC MSR which is incremented every CPU clock
> cycle. You can use this to measure elapsed time. For very small
> values this will obviously not be an accurate technique for
> yielding delays, though.

The problem with fancy processors these days (w/ cache, MMU) is
that the call/return overhead is not fixed the way it was in
the "good old days".  If it is, then you can calibrate it out
by shortening the delay routines "internal" delay by the same
amount as the call/return overhead.

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 10:26 [ECOS] Functions to consume CPU time in x86 Cristiano Ligieri Pereira
       [not found] ` <Pine.SOL.4.20.0103281120510.11565-100000@washoe.ics.uci.ed>
  2001-03-28 11:26 ` Cristiano Ligieri Pereira
@ 2001-03-29 11:50 ` Hugo Tyson
  2 siblings, 0 replies; 8+ messages in thread
From: Hugo Tyson @ 2001-03-29 11:50 UTC (permalink / raw)
  To: ecos-discuss


Cristiano Ligieri Pereira <cpereira@ics.uci.edu> writes:

> I need to implement some functions to keep the CPU busy for some amounts
> of time. I know that one way to do that is to build loops that do nothing
> other than keep the CPU busy. I would like to have functions to consume
> hundreds or thousands of nanoseconds of CPU time in x86 platform. Has
> anyone done this before? If so, would you be up to provide me such
> functions?

There is something in the net tests, in net/tcpip/VERSION/tests/tcp_echo.c
that keeps the CPU busy a certain *percentage* of its capability.

Not what you asked for, but you might find it of interest - especially the
way it calibrates itself for differing platforms, which might be useful to
you in this?

Doesn't hal_delay_us(int) AKA CYGACC_CALL_IF_DELAY_US(_u_) via virtual
vectors do almost what you want?  It's defined to be a busy wait.  It's in
uS not nS, but it should be another place to start.

	- Huge

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Functions to consume CPU time in x86
  2001-03-28 11:26 ` Cristiano Ligieri Pereira
  2001-03-28 12:08   ` Lewin A.R.W. Edwards
@ 2001-03-29 11:50   ` Nick Garnett
  1 sibling, 0 replies; 8+ messages in thread
From: Nick Garnett @ 2001-03-29 11:50 UTC (permalink / raw)
  To: ecos-discuss

Cristiano Ligieri Pereira <cpereira@ics.uci.edu> writes:

> And of course I want to be able to specify that I want to keep the CPU
> busy for specific X (mili/nano)seconds and not only keep it busy for some
> randon amount of time.
> 
> I looking for functions like this.
> 
> consume10ns() or consume1ns()
> 
> or consume1ms() or consume10ms()
> 
> Thanks again,
> 

Nanosecond delays are a bit difficult since you have to do it with
calibrated loops or use CPU specific cycle counters. Microsecond
delays are easier since you can use the timer. Here is some code that
does that:

void 
hal_delay_us(int us)
{
    while( us > 0 )
    {
        cyg_uint32 us1 = us;
        cyg_int32 ticks;
        cyg_uint32 cval1, cval2;

        // Wait in bursts of 1s to avoid overflow problems with the
        // multiply by 1000 below.
        
        if( us1 > 1000000 )
            us1 = 1000000;

        us -= us1;
        
        // The PC clock ticks at 838ns per tick. So we convert the us
        // value we were given to clock ticks and wait for that many
        // to pass.

        ticks = (us1 * 1000UL) / 838UL;

        HAL_CLOCK_READ( &cval1 );

        // We just loop, waiting for clock ticks to happen,
        // and subtracting them from ticks when they do.
        
        while( ticks > 0 )
        {
            cyg_int32 diff;
            HAL_CLOCK_READ( &cval2 );

            diff = cval2 - cval1;

            // Cope with counter wrap-around.
            if( diff < 0 )
                diff += CYGNUM_HAL_RTC_PERIOD;

            ticks -= diff;
            cval1 = cval2;

        }
    }
}


-- 
Nick Garnett, eCos Kernel Architect
Red Hat, Cambridge, UK

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-03-29 11:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-28 10:26 [ECOS] Functions to consume CPU time in x86 Cristiano Ligieri Pereira
     [not found] ` <Pine.SOL.4.20.0103281120510.11565-100000@washoe.ics.uci.ed>
2001-03-28 11:26 ` Cristiano Ligieri Pereira
2001-03-28 12:08   ` Lewin A.R.W. Edwards
2001-03-28 12:17     ` Grant Edwards
2001-03-28 12:31       ` Lewin A.R.W. Edwards
2001-03-28 12:35         ` Grant Edwards
2001-03-29 11:50   ` Nick Garnett
2001-03-29 11:50 ` Hugo Tyson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).