Changeset 20829
- Timestamp:
- 09/19/07 20:09:57 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp
r20822 r20829 405 405 ); 406 406 } 407 #elif defined(VPR_OS_Linux) && defined(CPU_SET)407 #elif defined(VPR_OS_Linux) 408 408 if ( sysconf(_SC_NPROCESSORS_CONF) > cpu ) 409 409 { 410 cpu_set_t cpu_mask; 411 CPU_ZERO(&cpu_mask); 412 CPU_SET(cpu, &cpu_mask); 413 const int result = sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask); 414 415 if ( result != 0 ) 410 const pid_t thread_id(syscall(__NR_gettid)); 411 412 if ( thread_id ) 416 413 { 417 std::ostringstream msg_stream; 418 msg_stream << "Failed to set CPU affinity: " 419 << vpr::Error::getCurrentErrorMsg(); 420 throw vpr::Exception(msg_stream.str(), VPR_LOCATION); 414 cpu_set_t cpu_mask; 415 CPU_ZERO(&cpu_mask); 416 CPU_SET(cpu, &cpu_mask); 417 const int result = sched_setaffinity(thread_id, sizeof(cpu_mask), 418 &cpu_mask); 419 420 if ( result != 0 ) 421 { 422 std::ostringstream msg_stream; 423 msg_stream << "Failed to set CPU affinity: " 424 << vpr::Error::getCurrentErrorMsg(); 425 throw vpr::Exception(msg_stream.str(), VPR_LOCATION); 426 } 421 427 } 422 428 } … … 465 471 } 466 472 #elif defined(VPR_OS_Linux) 467 c pu_set_t cpu_mask;468 CPU_ZERO(&cpu_mask); 469 const int result = sched_getaffinity(0, sizeof(cpu_mask), &cpu_mask);470 471 if ( result == 0 )472 {473 const long cpu_count(sysconf(_SC_NPROCESSORS_CONF));474 cpus.reserve(cpu_count);475 476 for ( int i = 0; i < cpu_count; ++i)473 const pid_t thread_id(syscall(__NR_gettid)); 474 475 if ( thread_id ) 476 { 477 cpu_set_t cpu_mask; 478 CPU_ZERO(&cpu_mask); 479 const int result = sched_getaffinity(thread_id, sizeof(cpu_mask), 480 &cpu_mask); 481 482 if ( result == 0 ) 477 483 { 478 if ( CPU_ISSET(i, &cpu_mask) ) 484 const long cpu_count(sysconf(_SC_NPROCESSORS_CONF)); 485 cpus.reserve(cpu_count); 486 487 for ( int i = 0; i < cpu_count; ++i ) 479 488 { 480 cpus.push_back(i); 489 if ( CPU_ISSET(i, &cpu_mask) ) 490 { 491 cpus.push_back(i); 492 } 481 493 } 482 494 } 483 }484 else485 {486 std::ostringstream msg_stream;487 msg_stream << "Failed to query CPU affinity: "488 << Error::getCurrentErrorMsg();489 throw vpr::Exception(msg_stream.str(), VPR_LOCATION);495 else 496 { 497 std::ostringstream msg_stream; 498 msg_stream << "Failed to query CPU affinity: " 499 << Error::getCurrentErrorMsg(); 500 throw vpr::Exception(msg_stream.str(), VPR_LOCATION); 501 } 490 502 } 491 503 #else
