Analytical Modeling and Optimization for Affinity Based Thread Scheduling on Multicore Systems