the thread context switch time

Hi All,

How much time does it take to switch between threads in different
processes
assuming PASSIIVE_LEVEL and the same priority?

Another words is it a very bad/good idea to have the working thread to
simplify life?

TIA

Andrew

Andrew,

Hi All,

How much time does it take to switch between threads in different
processes
assuming PASSIIVE_LEVEL and the same priority?

How long is a piece of string?

There are many factors to influence this:
Procesor speed & number of processors.
Memory timing parameters
Cache contents
Page table contents and related TLB misses.

We have a thread library inside our chip simulator (that we use to develop a
driver before we have hardware), and it’s got it’s own thread switching, as
switching threads via the OS inside a driver is too expensive. We use
threads to simulate parallel execution in the silicon when several units are
clocked by the same clock, and it makes life a lot easier to do things with
threads than to achieve this in any other way.

We recently simplified the thread library, and it made an overall
improvement of about 15-20% in the test-cases that I tried out. This is with
about 50 threads running in “parallel”. (Note: we do not support
multiprocessor threads, in the case of a multiprocessor system, the “other”
processor will just sit idle).

This thread library switches in a few tens of nanoseconds (about 30 ns on a
2.533GHz P4 and slightly faster on the Athlon MP 2100+), but you can surely
count on MS having to spend a few hundred nanoseconds in the same scenario.

I’m by no means recommending that anyone goes out and writes their own
thread switching just because it’s 10 times faster than MS’s version. We did
this for a particular, very isolated. purpose, and these threads have
absolutely no communication with anything outside the simulator itself, so
there’s no need to sync them to each other, etc, etc.

Another words is it a very bad/good idea to have the working thread to
simplify life?

The key questions are:

  1. Is the work that you’re planning to perform in the worker thread long
    enough to make, let’s say, half a microsecond insignificant?

  2. Is this a performance critical part of the driver, or just something that
    has to be done every now and again?

  3. What are the benefits from a coding perspective of using threads vs.
    single threaded?

  4. Will life get more complicated due to synchronisation between the worker
    thread and main thread (particularly in MP/HyperThreading cases)?

Only you (may) know the answers to those questions.


Mats

TIA

Andrew


Thank you very much, Mats, for the informative answer

From: Mats Petersson
>Reply-To: “Windows System Software Devs Interest List”
>
>To: “Windows System Software Devs Interest List”
>Subject: [ntdev] RE: the thread context switch time
>Date: Tue, 9 Dec 2003 16:45:08 -0000
>
>Andrew,
> > Hi All,
> >
> > How much time does it take to switch between threads in different
> > processes
> > assuming PASSIIVE_LEVEL and the same priority?
>
>How long is a piece of string?
>
>There are many factors to influence this:
>Procesor speed & number of processors.
>Memory timing parameters
>Cache contents
>Page table contents and related TLB misses.
>
>We have a thread library inside our chip simulator (that we use to develop
>a
>driver before we have hardware), and it’s got it’s own thread switching, as
>switching threads via the OS inside a driver is too expensive. We use
>threads to simulate parallel execution in the silicon when several units
>are
>clocked by the same clock, and it makes life a lot easier to do things with
>threads than to achieve this in any other way.
>
>We recently simplified the thread library, and it made an overall
>improvement of about 15-20% in the test-cases that I tried out. This is
>with
>about 50 threads running in “parallel”. (Note: we do not support
>multiprocessor threads, in the case of a multiprocessor system, the “other”
>processor will just sit idle).
>
>This thread library switches in a few tens of nanoseconds (about 30 ns on a
>2.533GHz P4 and slightly faster on the Athlon MP 2100+), but you can surely
>count on MS having to spend a few hundred nanoseconds in the same scenario.
>
>
>I’m by no means recommending that anyone goes out and writes their own
>thread switching just because it’s 10 times faster than MS’s version. We
>did
>this for a particular, very isolated. purpose, and these threads have
>absolutely no communication with anything outside the simulator itself, so
>there’s no need to sync them to each other, etc, etc.
>
> >
> > Another words is it a very bad/good idea to have the working thread to
> > simplify life?
>
>The key questions are:
>1. Is the work that you’re planning to perform in the worker thread long
>enough to make, let’s say, half a microsecond insignificant?
>
>2. Is this a performance critical part of the driver, or just something
>that
>has to be done every now and again?
>
>3. What are the benefits from a coding perspective of using threads vs.
>single threaded?
>
>4. Will life get more complicated due to synchronisation between the worker
>thread and main thread (particularly in MP/HyperThreading cases)?
>
>Only you (may) know the answers to those questions.
>
>–
>Mats
> >
> > TIA
> >
> > Andrew
> >
> > —
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

_________________________________________________________________
Tired of slow downloads and busy signals? Get a high-speed Internet
connection! Comparison-shop your local high-speed providers here.
https://broadband.msn.com

Here are the results from my old benchmark program for thread and process
switching times on Pentium III, 1 GHz, Windows 2000, user mode.
System is just running this benchmark.

switches/sec

num threads processes
1 862362 858334 // basically just the scheduling
syscall overhead
2 637922 529250
3 632763 527519
4 631797 501361

1024 143656 88209

Kernel mode times would be slightly (10%-20%?) faster.

Dmitriy Budko VMware

-----Original Message-----
From: Andrew [mailto:xxxxx@hotmail.com]
Sent: Tuesday, December 09, 2003 8:19 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] the thread context switch time

Hi All,

How much time does it take to switch between threads in different
processes
assuming PASSIIVE_LEVEL and the same priority?

numbers at last

thank you Dmitriy ( db13 ?)