System thread Affinity

Hi dear all,
Is there any way to “pin” a system thread to a specific processor ? Many
thanks

This can be done via setting thread’s processor affinity using ZwSetInformationThread.

This post will probably be useful to you: http://www.osronline.com/showThread.cfm?link=1452

Tai-Hing

Date: Sun, 6 Jun 2010 13:54:29 +0800
Subject: [ntdev] System thread Affinity
From: xxxxx@gmail.com
To: xxxxx@lists.osr.com

Hi dear all,
Is there any way to “pin” a system thread to a specific processor ? Many thanks
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3

KeSetSystemAffinityThread(Ex) is documented.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“yushang” wrote in message news:xxxxx@ntdev…
Hi dear all,
Is there any way to “pin” a system thread to a specific processor ? Many thanks

The obvious answer is yes, just look for “affinity” in the documents. However, the real question is why, since in nearly all cases the asker is simply throwing code at a bad design.

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] System thread Affinity

Hi dear all,
Is there any way to “pin” a system thread to a specific processor ? Many thanks
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Sometime I need to create threads by available processors , so , pinning
thread to specific processor will improve the performance , is it ?

2010/6/6 Gary G. Little

> The obvious answer is yes, just look for “affinity” in the documents.
> However, the real question is why, since in nearly all cases the asker is
> simply throwing code at a bad design.
>
>
>
> Gary G. Little
>
> H (952) 223-1349
>
> C (952) 454-4629
>
> xxxxx@comcast.net
>
>
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *yushang
> Sent: Sunday, June 06, 2010 12:54 AM
> To: Windows System Software Devs Interest List
>
> Subject: [ntdev] System thread Affinity
>
>
>
> Hi dear all,
>
> Is there any way to “pin” a system thread to a specific processor ? Many
> thanks
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Typically assigning affinity is a good way to HINDER system performance. But, you still didn’t answer the question; why do you think you need to do this?

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 8:28 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System thread Affinity

Sometime I need to create threads by available processors , so , pinning thread to specific processor will improve the performance , is it ?

2010/6/6 Gary G. Little

The obvious answer is yes, just look for “affinity” in the documents. However, the real question is why, since in nearly all cases the asker is simply throwing code at a bad design.

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List

Subject: [ntdev] System thread Affinity

Hi dear all,

Is there any way to “pin” a system thread to a specific processor ? Many thanks

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer



NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

That is an interesting tidbit that appears to have come from someone tries to equate the failures and limitations of some other OS to Windows. Have you ever heard of the following: “Premature optimization is the root of all evil”? It is a quote by Donald Knuth. Trying to concoct some mysterious code to improve “performance” sounds like something a P.H.B. would order.

First, write the code in a straight forward, easy to maintain and understand form. Get it working and test it with DTM and a good QA department to help find edge cases. Compare performance against other products only after it is stable. Then use a good profiler to find any bottlenecks. Consider the impact of any code necessary to eliminate those bottlenecks on maintainability and stability. Then come back with questions and provide some useful information about the real problem including the “big picture” of why it is too slow, where and why. If you need to transfer terabytes of data from or to somewhere then you might need some code changes. Don’t forget that mass storage uses ScsiPort in XP and below so the high performance model of StorPort is not available for XP. Also NDIS6 has many things that have been improved to assist in increasing throughput compared to NDIS3/4/5. It also has a throttle back mode to keep the network from interfering with multimedia throughput that is only active for consumer OS versions.

“yushang” wrote in message news:xxxxx@ntdev…
Sometime I need to create threads by available processors , so , pinning thread to specific processor will improve the performance , is it ?

2010/6/6 Gary G. Little

The obvious answer is yes, just look for “affinity” in the documents. However, the real question is why, since in nearly all cases the asker is simply throwing code at a bad design.

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List

Subject: [ntdev] System thread Affinity

Hi dear all,

Is there any way to “pin” a system thread to a specific processor ? Many thanks

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer



NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I think if threads(same priorities) no. < processors no., setting
affinitywill hurt performance , but if threads no. >= processors no.
there is no
difference . In my case , I create threads for all available processors .
They work on a global list , doing the same thing .

2010/6/7 Gary G. Little

> Typically assigning affinity is a good way to HINDER system performance.
> But, you still didn’t answer the question; why do you think you need to do
> this?
>
>
>
> Gary G. Little
>
> H (952) 223-1349
>
> C (952) 454-4629
>
> xxxxx@comcast.net
>
>
>
>
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *yushang
> Sent: Sunday, June 06, 2010 8:28 PM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] System thread Affinity
>
>
>
> Sometime I need to create threads by available processors , so , pinning
> thread to specific processor will improve the performance , is it ?
>
> 2010/6/6 Gary G. Little
>
> The obvious answer is yes, just look for “affinity” in the documents.
> However, the real question is why, since in nearly all cases the asker is
> simply throwing code at a bad design.
>
>
>
> Gary G. Little
>
> H (952) 223-1349
>
> C (952) 454-4629
>
> xxxxx@comcast.net
>
>
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *yushang
> Sent: Sunday, June 06, 2010 12:54 AM
> To: Windows System Software Devs Interest List
>
>
> Subject: [ntdev] System thread Affinity
>
>
>
> Hi dear all,
>
>
> Is there any way to “pin” a system thread to a specific processor ? Many
> thanks
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
>
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Have you confirmed that this is a problem? Reference my prior message.
Windows will schedule them where it needs. Why do you think you can do
better? Why do you think the user will not get upset with an unresponsive
keyboard, mouse and video? Windows, excluding servers, is a consumer OS and
being responsive to the user is a major priority as it should be. Most
newsgroups prefer pain text and not HTML.

“yushang” wrote in message news:xxxxx@ntdev…
>I think if threads(same priorities) no. < processors no., setting affinity
>will hurt performance , but if threads no. >= processors no. there is no
>difference . In my case , I create threads for all available processors .
>They work on a global list , doing the same thing .

>2010/6/7 Gary G. Little

>Typically assigning affinity is a good way to HINDER system performance.
>But, you still didn’t answer the question; why do you think you need to do
>this?

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 8:28 PM

To: Windows System Software Devs Interest List

Subject: Re: [ntdev] System thread Affinity

Sometime I need to create threads by available processors , so , pinning
thread to specific processor will improve the performance , is it ?
2010/6/6 Gary G. Little
The obvious answer is yes, just look for “affinity” in the documents.
However, the real question is why, since in nearly all cases the asker is
simply throwing code at a bad design.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List

Subject: [ntdev] System thread Affinity

Hi dear all,

Is there any way to “pin” a system thread to a specific processor ? Many
thanks
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

OK . I think I got what you mean but on a Windows server , the
discussion makes sense , right ?

2010/6/7 David Craig :
> Have you confirmed that this is a problem? Reference my prior message.
> Windows will schedule them where it needs. Why do you think you can do
> better? Why do you think the user will not get upset with an unresponsive
> keyboard, mouse and video? Windows, excluding servers, is a consumer OS and
> being responsive to the user is a major priority as it should be. Most
> newsgroups prefer pain text and not HTML.
>
>
>> “yushang” wrote in message news:xxxxx@ntdev…
>> I think if threads(same priorities) no. < processors no., setting affinity
>> will hurt performance , but if threads no. >= processors no. there is no
>> difference . In my case , I create threads for all available processors .
>> They work on a global list , doing the same thing .
>
>
>> 2010/6/7 Gary G. Little
>
>> Typically assigning affinity is a good way to HINDER system performance.
>> But, you still didn’t answer the question; why do you think you need to do
>> this?
>
> Gary G. Little
> H (952) 223-1349
> C (952) 454-4629
> xxxxx@comcast.net
>
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
> Sent: Sunday, June 06, 2010 8:28 PM
>
> To: Windows System Software Devs Interest List
>
> Subject: Re: [ntdev] System thread Affinity
>
> Sometime I need to create threads by available processors , so , pinning
> thread to specific processor will improve the performance , is it ?
> 2010/6/6 Gary G. Little
> The obvious answer is yes, just look for “affinity” in the documents.
> However, the real question is why, since in nearly all cases the asker is
> simply throwing code at a bad design.
>
> Gary G. Little
> H (952) 223-1349
> C (952) 454-4629
> xxxxx@comcast.net
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
> Sent: Sunday, June 06, 2010 12:54 AM
> To: Windows System Software Devs Interest List
>
> Subject: [ntdev] System thread Affinity
>
> Hi dear all,
>
> Is there any way to “pin” a system thread to a specific processor ? Many
> thanks
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> — NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> — NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

You wrote:

Sometime I need to create threads by available processors , so , pinning
thread to specific processor will improve the performance , is it ?

No, quite the contrary. ALL you would be doing is LIMITING your performance. The Windows scheduler knows much more than you do about how to handle the processing load. Now, if you want to create one thread per processor, that’s a sensible strategy used by many programs. But when you do so, don’t set the affinity. Let Windows assign the threads to processors as the load demands. That’s a much better plan.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

OK. Thanks . Then what is the use case of setting affinity if there is
no performance gain ?

2010/6/7 Tim Roberts :
> You wrote:
>>
>>Sometime I need to create threads by available processors , so , pinning
>>thread to specific processor will improve the performance , is it ?
>
> No, quite the contrary. ALL you would be doing is LIMITING your performance. The Windows scheduler knows much more than you do about how to handle the processing load. Now, if you want to create one thread per processor, that’s a sensible strategy used by many programs. But when you do so, don’t set the affinity. Let Windows assign the threads to processors as the load demands. That’s a much better plan.
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

> In my case , I create threads for all available processors . They work on a global list , doing the same thing .

“Doing the same thing”, indeed, justifies parallel processing, particularly if each execution unit operates on its own data set so that very little contention between these units takes place. However, your statement that “they work on a global list” suggests exactly the opposite. Therefore, depending on how much contention for the shared resources the whole thing involves there is a good chance that, unless you are desperate to
hurt overall performance, you don’t need even creating multiple threads here, let alone binding each thread to a particular CPU…

Anton Bassov

In fact my thread dequeue(ExInterlockedRemoveHeadList) an item from
the list and process it . Processing is time consuming. That’s why I
need more threads to do such thing.

2010/6/7 :
>> In my case , I create threads for all available processors . They work on a global list , doing the same thing .
>
> “Doing the same thing”, indeed, justifies parallel processing, particularly if each execution unit operates on its own data set so that very little contention between these units takes place. However, your statement that “they work on a global list” suggests exactly the opposite. Therefore, depending on how much contention for the shared resources the whole thing involves there is a good chance that, unless you are desperate to
> hurt overall performance, you don’t need even creating multiple threads here, let alone binding each thread to a particular CPU…
>
>
> Anton Bassov
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

>Sometime I need to create threads by available processors , so , pinning thread to specific processor

will improve the performance , is it ?

Sometimes, yes.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Actually, depending on what your model and environment is if the number of
threads is greater than or equal the number of processors I have seen no
better way to slow things down. Take your driver without affinity and
run kernrate on it with verbose output. See what the loading of the
various processors is, you will probably find that you have misconceptions
of how scheduling is impacting you.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

From: yushang [mailto:xxxxx@gmail.com]
Posted At: Monday, June 07, 2010 12:03 AM
Posted To: ntdev
Conversation: System thread Affinity
Subject: Re: System thread Affinity

I think if threads(same priorities) no. < processors no., setting affinity
will hurt performance , but if threads no. >= processors no. there is no
difference . In my case , I create threads for all available processors .
They work on a global list , doing the same thing .
2010/6/7 Gary G. Little
Typically assigning affinity is a good way to HINDER system performance.
But, you still didn’t answer the question; why do you think you need to do
this?

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 8:28 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System thread Affinity

Sometime I need to create threads by available processors , so , pinning
thread to specific processor will improve the performance , is it ?
2010/6/6 Gary G. Little
The obvious answer is yes, just look for “affinity” in the documents.
However, the real question is why, since in nearly all cases the asker is
simply throwing code at a bad design.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List

Subject: [ntdev] System thread Affinity

Hi dear all,

Is there any way to “pin” a system thread to a specific processor ? Many
thanks
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Information from ESET Smart Security, version of virus
signature database 5178 (20100607)


The message was checked by ESET Smart Security.

http://www.eset.com

Wow… tough crowd.

Creating your own pool of worker threads and pinning them to individual processors can be a good thing or a bad thing in terms of performance. A lot has to do with the architecture of the machine (are we talking NUMA here?), the version of Windows, and the work the threads are doing.

It’s been my observation (and obviously that of several other folks who’ve voiced their opinions here) that, in general, pinning threads to specific processors doesn’t HELP performance. In a lot of cases, it seems like it probably WOULD… but when you sit down with a beer, a pencil, and a cocktail napkin and start to think through all the ramifications of your design… pinning the threads is rarely a win.

The Windows scheduler changes rather dramatically from release to release. In more recent OS releases, it’s aware of, and able to optimize based on, things like which CPU cores are physically separate processors and which are “cores” on multi-threaded CPUs, NUMA architecture, and a ton of other stuff that you probably wouldn’t think of. In other words, it’s probably smarter than you are.

So, like it is to all good engineering questions, the answer to “Is pinning a thread to a specific processor likely to make things faster” is IT DEPENDS. But, in absence of a solid architectural reason or measured performance analysis, I have to agree with Mr. Little (and the others) that this idea sounds a lot like premature optimization. And, as Mr. Burn said, it is entirely possible that your scheme will slow things down considerably.

Peter
OSR

Uh … the system I’m writing this on is brand new using an Intel CORE i7, with 4 processors. When I look at task manager I see enough processes running that I have to scroll up. Yeah I’ve got a Visual Studio session running as well as Messenger and Outlook. But if I shut all of them down I still have more than a dozen processes running, so how do you come up with the number of threads EVER being less than the number of processors in a normally functioning Windows system unless you are trying to be brilliant in the middle of a boot?

You still have not answered the quest: What are you trying to do? Why do you think you need to control what process runs on what processor?

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 11:03 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] System thread Affinity

I think if threads(same priorities) no. < processors no., setting affinity will hurt performance , but if threads no. >= processors no. there is no difference . In my case , I create threads for all available processors . They work on a global list , doing the same thing .

2010/6/7 Gary G. Little

Typically assigning affinity is a good way to HINDER system performance. But, you still didn’t answer the question; why do you think you need to do this?

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 8:28 PM

To: Windows System Software Devs Interest List

Subject: Re: [ntdev] System thread Affinity

Sometime I need to create threads by available processors , so , pinning thread to specific processor will improve the performance , is it ?

2010/6/6 Gary G. Little

The obvious answer is yes, just look for “affinity” in the documents. However, the real question is why, since in nearly all cases the asker is simply throwing code at a bad design.

Gary G. Little

H (952) 223-1349

C (952) 454-4629

xxxxx@comcast.net

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of yushang
Sent: Sunday, June 06, 2010 12:54 AM
To: Windows System Software Devs Interest List

Subject: [ntdev] System thread Affinity

Hi dear all,

Is there any way to “pin” a system thread to a specific processor ? Many thanks

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer



NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

It seems, unless I missed it, that the OP’s original question has not been answered; rather there’s this whole discussion about why the OP wants to pin the thread to a processor in the first place.

@“Peter_Viscarola_(OSR)” said:
Creating your own pool of worker threads and pinning them to individual processors can be a good thing or a bad thing in terms of performance. A lot has to do with the architecture of the machine (are we talking NUMA here?), the version of Windows, and the work the threads are doing.
This is as close an answer as I found above. But Peter doesn’t say how you create a pool of worker threads and pin them to individual processors.
The NT Insider article here shows creating the threads with PsCreateSystemThread but does not show anything to set their affinity.

I’m confused…The first two answers to the OP give you the APIs. Google also found the right API with “windows kernel thread affinity”. Pretty straightforward, but if you’re still confused please start a new thread instead of resurrecting a 9 year old one.

(And I can’t wait until we can automatically lock old posts…)