Intel IA-32 Computer Accessories User Manual


 
IA-32 Intel® Architecture Optimization
7-54
Example 7-12 Assembling a Look up Table to Manage Affinity Masks and
Schedule Threads to Each Core First
AFFINITYMASK LuT[64]; // A Lookup table to retrieve the affinity
// mask we want to use from the thread
// scheduling sequence index.
int index =0; // Index to scheduling sequence.
j = 0;
/ Assemble the sequence for first LP consecutively to different core.
while (j < NumStartedLPs) {
// Determine the first LP in each core.
if( ! apic_conf [j ].smt) { // This is the first LP in a core
// supporting HT.
LuT[index++] = apic_conf[j].affinitymask;
}
j++;
}
/// Now the we have assigned each core to consecutive indices,
// we can finish the table to use the rest of the
// LPs in each core.
nThreadsPerCore = MaxLPPerPackage()/MaxCoresPerPackage();
for (i = 0 ; i < nThreadsPerCore; i ++) {
for (j = 0 ; j < NumStartedLPs; j += nThreadsPerCore) {
// Set the affinity binding for another logical
// processor in each core.
if( apic_conf[ i+j ].SMT) {
LuT[ index++] = apic_id[ i+j ].affinitymask;
}
}
}
}