1. thread switching time? (Krassimir Slavchev)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

1. thread switching time? (Krassimir Slavchev)

Sam Xia

hi krassi,

 what kind of hardware are you using?  Actually because of process/thread
scheduling mechanism, timing granulariy is coarse in FreeBSD(more than 10
ms)
 
S.X
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: Thursday, October 30, 2008 8:00 PM
> To: [hidden email]
> Subject: freebsd-performance Digest, Vol 68, Issue 4

>
> Message: 1
> Date: Wed, 29 Oct 2008 17:28:36 +0200
> From: Krassimir Slavchev <[hidden email]>
> Subject: thread switching time?
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello All,
>
> I am using FreeBSD 7 and would like to decrease the time of
> switching between threads. This time seems to be 1ms and it
> is impossible to make lower delays inside a thread, at least
> using nanosleep().
>
> Is it possible to decrease this time to 1us?
>
>
> Best Regards
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (FreeBSD)
>
> iD8DBQFJCIEkxJBWvpalMpkRAmKUAKCehUxakt83IvQ/QhW2n0BicWaQbQCeJW9z
> twONH5Eb9fA4JoQaYVk69os=
> =6xti
> -----END PGP SIGNATURE-----
>
>
> **************************************************
>

_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: 1. thread switching time? (Krassimir Slavchev)

Krassimir Slavchev
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,


Sam Xia wrote:
> hi krassi,
>
>  what kind of hardware are you using?  Actually because of process/thread
> scheduling mechanism, timing granulariy is coarse in FreeBSD(more than 10
> ms)

dmesg:
...
CPU: Intel(R) Core(TM)2 CPU         E8400  @ 3.00GHz (3005.25-MHz
686-class CPU)
...
Timecounter "ACPI-fast" frequency 3579545 Hz quality 1000
acpi_timer0: <24-bit timer at 3.579545MHz> port 0x408-0x40b on acpi0
acpi_hpet0: <High Precision Event Timer> iomem 0xfed00000-0xfed003ff on
acpi0
Timecounter "HPET" frequency 14318180 Hz quality 900
...

The hardware is fast enough!

Also, I am able to set HZ=100000 but the thread switching time is still
~1ms.


Best Regards

>  
> S.X
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of
>> [hidden email]
>> Sent: Thursday, October 30, 2008 8:00 PM
>> To: [hidden email]
>> Subject: freebsd-performance Digest, Vol 68, Issue 4
>
>> Message: 1
>> Date: Wed, 29 Oct 2008 17:28:36 +0200
>> From: Krassimir Slavchev <[hidden email]>
>> Subject: thread switching time?
>> To: [hidden email]
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
> Hello All,
>
> I am using FreeBSD 7 and would like to decrease the time of
> switching between threads. This time seems to be 1ms and it
> is impossible to make lower delays inside a thread, at least
> using nanosleep().
>
> Is it possible to decrease this time to 1us?
>
>
> Best Regards
>>
>>
**************************************************
>>

> _______________________________________________
> [hidden email] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-performance
> To unsubscribe, send any mail to "[hidden email]"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFJCrR3xJBWvpalMpkRAq8aAJ9F/n9mX94h46Rb4kHOBo9kDMUjzQCgmcZQ
Yuum1rMnhaKICE+FKC6n294=
=y2hp
-----END PGP SIGNATURE-----
_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: 1. thread switching time? (Krassimir Slavchev)

Julian Elischer
Krassimir Slavchev wrote:

>
> Also, I am able to set HZ=100000 but the thread switching time is still
> ~1ms.

You must be talking about the time that a thread can run before it is
pushed out by other threads?  I know I've seem many x 10,000 context
switches in some cases, i.e. look at very high interrupt rates
etc. so I guess I'm not sure what you are measuring..

at one time the scheduling quantum was independent of Hz.
I am not sure how true that is now..


_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: 1. thread switching time? (Krassimir Slavchev)

Krassimir Slavchev
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Julian,

Julian Elischer wrote:

> Krassimir Slavchev wrote:
>
>>
>> Also, I am able to set HZ=100000 but the thread switching time is still
>> ~1ms.
>
> You must be talking about the time that a thread can run before it is
> pushed out by other threads?  I know I've seem many x 10,000 context
> switches in some cases, i.e. look at very high interrupt rates
> etc. so I guess I'm not sure what you are measuring..

Okay, I have a thread with:

while(1) {
        clock_gettime(CLOCK_REALTIME, &tv);
        nanosleep(&delay, NULL);
        clock_gettime(CLOCK_REALTIME, &tv2);
        timespecsub(&tv2, &tv);
}

If the delay is configured to be 0 < delay < 1ms I always get ~1ms delay.
Since nanosleep() is a cancellation point this means that the scheduler
will switch to another thread.
If the delay = 0 I get ~1600ns delay.

Yes. You are right. This is "the time that a thread can run before it is
pushed out by other threads".

Is there a way to decrease this time?

>
> at one time the scheduling quantum was independent of Hz.
> I am not sure how true that is now..
>

It seems to be independent of HZ.


Best Regards

>
> _______________________________________________
> [hidden email] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-performance
> To unsubscribe, send any mail to
> "[hidden email]"
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFJCsoDxJBWvpalMpkRAteuAJ9Jd8ICvPSiWB/4eGquUunoclpeXgCgjqyE
vBXA0vGoRgsQ9eHZ/YwR/lw=
=AjjC
-----END PGP SIGNATURE-----
_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

RE: 1. thread switching time? (Krassimir Slavchev)

Sam Xia
hi Krassimir,

The smallest time quatum moving a thread from sleep queue to ready queue is
equal to one tick(about 1 ms). This is dependent of os scheduling mechanism.
Even the delay of nanosleep is less than 1 ms, actually 1 ms is the smallest
unit.

I guess you should modify the kernel and add clock intr frequency.

BR, Sam.Xia

> -----Original Message-----
> From: Krassimir Slavchev [mailto:[hidden email]]
> Sent: Friday, October 31, 2008 5:04 PM
> To: Julian Elischer
> Cc: [hidden email]; Sam Xia
> Subject: Re: 1. thread switching time? (Krassimir Slavchev)
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello Julian,
>
> Julian Elischer wrote:
> > Krassimir Slavchev wrote:
> >
> >>
> >> Also, I am able to set HZ=100000 but the thread switching time is
> >> still ~1ms.
> >
> > You must be talking about the time that a thread can run
> before it is
> > pushed out by other threads?  I know I've seem many x
> 10,000 context
> > switches in some cases, i.e. look at very high interrupt
> rates etc. so
> > I guess I'm not sure what you are measuring..
>
> Okay, I have a thread with:
>
> while(1) {
> clock_gettime(CLOCK_REALTIME, &tv);
> nanosleep(&delay, NULL);
> clock_gettime(CLOCK_REALTIME, &tv2);
> timespecsub(&tv2, &tv);
> }
>
> If the delay is configured to be 0 < delay < 1ms I always get
> ~1ms delay.
> Since nanosleep() is a cancellation point this means that the
> scheduler will switch to another thread.
> If the delay = 0 I get ~1600ns delay.
>
> Yes. You are right. This is "the time that a thread can run
> before it is pushed out by other threads".
>
> Is there a way to decrease this time?
>
> >
> > at one time the scheduling quantum was independent of Hz.
> > I am not sure how true that is now..
> >
>
> It seems to be independent of HZ.
>
>
> Best Regards
>
> >
> > _______________________________________________
> > [hidden email] mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-performance
> > To unsubscribe, send any mail to
> > "[hidden email]"
> >
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (FreeBSD)
>
> iD8DBQFJCsoDxJBWvpalMpkRAteuAJ9Jd8ICvPSiWB/4eGquUunoclpeXgCgjqyE
> vBXA0vGoRgsQ9eHZ/YwR/lw=
> =AjjC
> -----END PGP SIGNATURE-----
>

_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: 1. thread switching time? (Krassimir Slavchev)

Krassimir Slavchev
In reply to this post by Julian Elischer
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Julian Elischer wrote:

> Krassimir Slavchev wrote:
>
>>
>> Also, I am able to set HZ=100000 but the thread switching time is still
>> ~1ms.
>
> You must be talking about the time that a thread can run before it is
> pushed out by other threads?  I know I've seem many x 10,000 context
> switches in some cases, i.e. look at very high interrupt rates
> etc. so I guess I'm not sure what you are measuring..
>
> at one time the scheduling quantum was independent of Hz.
> I am not sure how true that is now..
>

The scheduling quantum is independent of Hz for Hz > 1000.

usr/src/sys/kern_tc.c:
...
        if (hz > 1000)
                tc_tick = (hz + 500) / 1000;
        else
                tc_tick = 1;
...

I am not sure whether setting Hz > 1000 impact on performance or not,
e.g using polling(4).
Removing this limitation and setting kern.hz=10000 give 100usec quantum.

Thanks for the point.

Best Regards
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFJDt1JxJBWvpalMpkRAnWCAJ9z5Z7JYDC/3AdsJe+Cn7+dg6y3HwCdHPZA
6sK5dec43n41/QcbiluJoeA=
=8u2E
-----END PGP SIGNATURE-----
_______________________________________________
[hidden email] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-performance
To unsubscribe, send any mail to "[hidden email]"