Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results
The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
Upcoming OSR Seminars | ||
---|---|---|
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead! | ||
Kernel Debugging | 13-17 May 2024 | Live, Online |
Developing Minifilters | 1-5 Apr 2024 | Live, Online |
Internals & Software Drivers | 11-15 Mar 2024 | Live, Online |
Writing WDF Drivers | 26 Feb - 1 Mar 2024 | Live, Online |
Comments
The affinity mask ought to be a ULONG, but it appears to be undocumented in
the DDK. Each bit corresponds to the processor to which you want this thread
bound. You can set more than one bit. Who knows what happens if you set only
bits for processors that don't exist. There is most likely some Nt
equivalent that you could look up in Undocumented Windows NT to confirm the
Zw parameters. Thereis probably a Win32 equivalent too.
That's hard affinity. Soft affinity as far as I know is not programmable. It
is a function of the run time behavior of the thread and some screwball
algorithm in the dispatcher. It should be ignored.
Mark Roddy
Windows 2000/NT Consultant
Hollis Technology Solutions
www.hollistech.com
following lines of code in a device driver to set the thread affinity:
KAFFINITY threadAffinityMask;
threadAffinityMask = KeNumberProcessors & ( 1<< TargetProcessorNumber)
; // TargetProcessorNumber is a zero based number
status = ZwSetInformationThread((HANDLE)-2, //current thread handle
ThreadAffinityMask,
&threadAffinityMask,
sizeof(KAFFINITY));
-Eliyas
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, April 19, 2000 7:00 PM
To: NT Developers Interest List
Subject: [ntdev] Soft Affinity of Thread
Hello,
How can one set the soft-affinity (and hard-affinity) of a Driver-created
thread to a particular processor ?
Thank you for your help!
Puja
---
You are currently subscribed to ntdev as: [email protected]
To unsubscribe send a blank email to $subst('Email.Unsub')
Maybe I'm missing something really big here, but I donot understand the
code snippet:
1. Shouldn't threadAffinityMask = (1 << TargetProcessorNumber) instead of
threadAffinityMask = KeNumberProcessors & (1 << TargetProcessorNumber) ??
[By my calculation, threadAffinityMask is always 0 if I use the code
snippet given here]
2. Even if we were to use KeNumberProcessors, isn't it a pointer (we will
need to dereference it, won't we) ?
Appreciate the clarification.
Thanks
Puja
==
Hello,
Maybe I'm missing something really big here, but I donot understand the
code snippet in the post below:
1. Shouldn't threadAffinityMask = (1 << TargetProcessorNumber) instead of
threadAffinityMask = KeNumberProcessors & (1 << TargetProcessorNumber) ??
[By my calculation, threadAffinityMask is always 0 if I use the code
snippet given here]
2. Even if we were to use KeNumberProcessors, isn't it a pointer (we will
need to dereference it, won't we) ?
Appreciate the clarification.
Thanks
Puja
On 04/21/00, "Eliyas Yakub <[email protected]>" wrote:
> The function ZwSetInformationThread is partially documented. You can use the
> following lines of code in a device driver to set the thread affinity:
>
> KAFFINITY threadAffinityMask;
> threadAffinityMask = KeNumberProcessors & ( 1<< TargetProcessorNumber)
> ; // TargetProcessorNumber is a zero based number
> status = ZwSetInformationThread((HANDLE)-2, //current thread handle
> ThreadAffinityMask,
> &threadAffinityMask,
> sizeof(KAFFINITY));
>
> -Eliyas
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Wednesday, April 19, 2000 7:00 PM
> To: NT Developers Interest List
> Subject: [ntdev] Soft Affinity of Thread
>
>
> Hello,
>
> How can one set the soft-affinity (and hard-affinity) of a Driver-created
> thread to a particular processor ?
>
> Thank you for your help!
> Puja
>
> ---
> You are currently subscribed to ntdev as: [email protected]
> To unsubscribe send a blank email to $subst('Email.Unsub')
KeSetAffinityThread (
IN PKTHREAD Thread,
IN KAFFINITY Affinity
)
> That's hard affinity. Soft affinity as far as I know is not programmable.
It
CCHAR
KeSetIdealProcessorThread (
IN PKTHREAD Thread,
IN CCHAR Processor
)
- this is the soft affinity.
Max