I have an application that processes a lot of data.
When the working set exceeds the L2(L3) cache performance falls dramatically.
I want to fix part of that using prefetching of data.
I want to take advantage of the fact that multithreaded code that runs on a hyper-threaded CPU shares a core and and cache.
The first thread (A) is the worker thread.
The second thread (B) prefetches data.
If I can force both threads to execute on the same core I can have thread (B) run ahead and fetch data.
Here's how it would look in pseudo code.
procedure TWorkerThread.Execute;
begin
Node:= WalkTheDataTree.GetNode;
Dowork(Node.MyData);
SyncWithThreadB;
end;
procedure TFetchThread.Execute;
begin
WaitForThreadA;
Node:= WalkTheDataTree_5_nodes_Ahead_of_A.GetNode; //Prefetch data.
end;
Both threads execute in lockstep, with the worker thread running at full speed and the fetch thread waiting for a signal.
Is there a way to force two threads to run in the same core on a HyperThreaded CPU?
I'm using Delphi XE2.
P.S. I know how to detect if the CPU supports hyperthreading using the CPUID instruction.