Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

AFFINITY plugin

May
12,949
172
When I write plugins, I speed-test those things I want to be fast. Ever since I got my current computer (quad-core) it has been difficult to reproduce speed-test results. They'd be reproducible in one instance of TCC but (reproducibly) different in another. Occasionally I'd get lucky and see results 10% faster than others and then not be able to reproduce them in another shell.

So (after getting the idea) I wrote a plugin, AFFINITY, to investigate the processors. AFFINITY lets the user see the system "affinity mask" (_SYSAFFIN, a bitmap of the processors available to the system) and the process affinity mask (_AFFINITY). It also lets the user recommend a processor for the current thread (with IDEAL) and demand a processor (or a collection of them) for the thread or process by specifying a new thread or process affinity mask (with AFFINITY). [More details below]

Results like these are reproducible.

Code:
v:\> for %j in (1 2 4 8) (affinity /t %j & echo ^r^nAffinity mask: %j (was %_?)& for /L %k in (1,1,3) (timer /q & for /l %i in (1,1,1000) (lc hammer.txt > nul) & timer))

Affinity mask: 1 (was 15)
Timer 1 off: 22:28:57  Elapsed: 0:00:00.97
Timer 1 off: 22:28:58  Elapsed: 0:00:00.97
Timer 1 off: 22:28:59  Elapsed: 0:00:00.97

Affinity mask: 2 (was 1)
Timer 1 off: 22:29:00  Elapsed: 0:00:01.11
Timer 1 off: 22:29:01  Elapsed: 0:00:01.09
Timer 1 off: 22:29:02  Elapsed: 0:00:01.09

Affinity mask: 4 (was 2)
Timer 1 off: 22:29:03  Elapsed: 0:00:01.03
Timer 1 off: 22:29:04  Elapsed: 0:00:01.04
Timer 1 off: 22:29:05  Elapsed: 0:00:01.03

Affinity mask: 8 (was 4)
Timer 1 off: 22:29:06  Elapsed: 0:00:01.03
Timer 1 off: 22:29:07  Elapsed: 0:00:01.05
Timer 1 off: 22:29:08  Elapsed: 0:00:01.03
They show I have one processor which is detectably faster than the others and one which is detectable slower. Why? I don't know. It could be hardware; it could be how the system process makes use of them.

I've done a lot of horsing around and had no ill effects (but no promises). I doubt AFFINITY will be of much practical value. But if you have a multi-processor machine it could provide a few minutes of recreation. I have no idea if non-admins can use it (and less of an idea than that of how it will fare on Vista or Win7). I put affinity.zip (32-bit only for now) on lucky.syr.edu and barnyard.syr.edu (FTP).

More details:

Code:
v:\> affinity /?
AFFINITY /T(hread) | /P(rocess)  N - set affinity mask to N (_? = old mask)
The process mask must be a subset of the system mask (_SYSAFFIN)
The thread mask must be a subset of the process mask (_AFFINITY)
Affinity masks are bitmaps; bit n corresponds to processor n (n = 0 to 31)
On a quad-core, for example, the mask 15 means any processor
and the masks for the individual processors are 1, 2, 4 and 8

v:\> ideal
IDEAL N - recommend a processor for this thread; N = 0 to 3
 

Similar threads

Back
Top