Re: Selecting target CPU for thread
On Jan 29, 12:22 pm, Patricia Shanahan <p...@acm.org> wrote:
Kenneth P. Turvey wrote:
On Mon, 28 Jan 2008 15:59:50 -0800, Todd wrote:
On Jan 28, 1:55 pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
[Snip]
I am sorry that I was unclear - is there any way using Java to get the
cpu id for the current thread? if the answer is yes, how is it done?
The answer is no, not without native code. But the real answer is that
you don't need it. You should probably be using the id of the thread, not
the CPU. This you can get.
I don't agree with "you don't need it".
Consider the following basic question: "Are threads moving around too
much?". There is a non-zero cost to moving a thread, because each
processor accumulates cache contents and other history for the threads
it is running. Excessive thread movement is a possible hypothesis if a
thread has an unexpectedly large cache miss rate. On the other hand, it
is also undesirable to leave an imbalance too long.
How would one investigate this sort of question without asking about
mappings between threads and processors?
Patricia
The only real way to handle that would be to ask the OS to keep track
of when it "moves" threads.
You can't do it *in* thread because you might have this happen:
Thread 1 start on CPU A: What CPU am I on? -> A
Thread 1 moves to CPU B: Do stuff important now
Thread 1 moves to CPU A: What CPU am I on? -> A
Basically, having a *thread* know about which CPU it "was" on is not
important, because its unreliable information. Have an outside
process give you the information is more useful, because that outside
process can do analysis.
On the other hand, the OS should know best on how to schedule
threads. Let your program's business be business logic.