how to declare per-processor variables?

As we know, Linux can declare per-CPU variables.
I have found "per-processor " data structures mentioned in some MS white papers.
The per-processor variables is similar with the per-CPU varialbes of Linux?
How can I declare and use such variables?

thanks!!

Therr is way to declare per thread variables in user mode (it has limitations) , but in kernel mode no such support exists.

d

debt from my phone

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Tuesday, August 16, 2011 7:16 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] how to declare per-processor variables?

As we know, Linux can declare per-CPU variables.
I have found "per-processor " data structures mentioned in some MS white papers.
The per-processor variables is similar with the per-CPU varialbes of Linux?
How can I declare and use such variables?

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

Hi,

adding this link to Doron’s post and as he said User Mode only:

http://msdn.microsoft.com/en-us/library/ms686749(v=vs.85).aspx

Have a look at the mechanism behind,…

best

K.

thanks everyone.

O, My God, it is regretful that I can’t use per-processor varialbles in kernel mode!!

You can call KeGetCurrentProcessorNumberEx which gives you a current
processor index, which you can then use to index into an array of
structures/pointers for per processor data. To prevent the processor index
from instantly becoming invalid due to thread scheduling, you will need to
be running at IRQL_DISPATCH or higher. You also have to deal with any
dynamic changes to the processor configuration.

Some kinds of hardware/drivers can improve their SMP performance by using
per processor hardware command queues, avoiding having to take a lock on a
single command queue. An optimized NDIS 6.x NIC driver should be able to do
this, as NDIS 6.x has a well-defined state machine for running and paused
device states. Your hardware has to be designed to support lockless SMP
optimized drivers.

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-470700-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, August 16, 2011 7:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] how to declare per-processor variables?

As we know, Linux can declare per-CPU variables.
I have found "per-processor " data structures mentioned in some MS white
papers.
The per-processor variables is similar with the per-CPU varialbes of
Linux?
How can I declare and use such variables?

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

A crude approach would be to have a global array of your per-processor
variables. Index by current CPU.

Would have to do some magic when CPUs are added/removed at runtime.

Not the “processor local storage” solution you are probably hoping for,
however…

Not my area of expertise, though. Just a WAG.

Thomas F. Divine
http://www.pcausa.com


From:
Sent: Tuesday, August 16, 2011 10:53 PM
To: “Windows System Software Devs Interest List”
Subject: RE:[ntdev] how to declare per-processor variables?

> thanks everyone.
>
> O, My God, it is regretful that I can’t use per-processor varialbles in
> kernel mode!!
>
> —
> 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

OP: if you take this approach, you will also want to split that array based
on NUMA nodes into locally allocated segments. Also note that unless you
have a special purpose device, there are few situations where the use of
per-processor variables is a good idea because it requires (assumes) you are
in a context that is either not premptable or afinitized to a single CPU.
In either case you can badly affect overall system performance by doing too
much work and so the uses of any variables are naturally limited.

“Jan Bottorff” wrote in message news:xxxxx@ntdev…

You can call KeGetCurrentProcessorNumberEx which gives you a current
processor index, which you can then use to index into an array of
structures/pointers for per processor data. To prevent the processor index
from instantly becoming invalid due to thread scheduling, you will need to
be running at IRQL_DISPATCH or higher. You also have to deal with any
dynamic changes to the processor configuration.

Some kinds of hardware/drivers can improve their SMP performance by using
per processor hardware command queues, avoiding having to take a lock on a
single command queue. An optimized NDIS 6.x NIC driver should be able to do
this, as NDIS 6.x has a well-defined state machine for running and paused
device states. Your hardware has to be designed to support lockless SMP
optimized drivers.

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-470700-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, August 16, 2011 7:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] how to declare per-processor variables?

As we know, Linux can declare per-CPU variables.
I have found "per-processor " data structures mentioned in some MS white
papers.
The per-processor variables is similar with the per-CPU varialbes of
Linux?
How can I declare and use such variables?

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