< prev index next >

src/hotspot/os/solaris/os_solaris.cpp

Print this page

 437   //                subsequent distributions don't all start at board 0.
 438   static uint board = 0;
 439   uint assigned = 0;
 440   // Until we've found enough processors ....
 441   while (assigned < distribution_length) {
 442     // ... find the next available processor in the board.
 443     for (uint slot = 0; slot < processors_per_board; slot += 1) {
 444       uint try_id = board * processors_per_board + slot;
 445       if ((try_id < limit_id) && (available_id[try_id] == true)) {
 446         distribution[assigned] = try_id;
 447         available_id[try_id] = false;
 448         assigned += 1;
 449         break;
 450       }
 451     }
 452     board += 1;
 453     if (board * processors_per_board + 0 >= limit_id) {
 454       board = 0;
 455     }
 456   }
 457   if (available_id != NULL) {
 458     FREE_C_HEAP_ARRAY(bool, available_id);
 459   }
 460   return true;
 461 }
 462 
 463 void os::set_native_thread_name(const char *name) {
 464   if (Solaris::_pthread_setname_np != NULL) {
 465     // Only the first 31 bytes of 'name' are processed by pthread_setname_np
 466     // but we explicitly copy into a size-limited buffer to avoid any
 467     // possible overflow.
 468     char buf[32];
 469     snprintf(buf, sizeof(buf), "%s", name);
 470     buf[sizeof(buf) - 1] = '\0';
 471     Solaris::_pthread_setname_np(pthread_self(), buf);
 472   }
 473 }
 474 
 475 bool os::distribute_processes(uint length, uint* distribution) {
 476   bool result = false;
 477   // Find the processor id's of all the available CPUs.
 478   processorid_t* id_array  = NULL;
 479   uint           id_length = 0;

 476   bool result = false;
 477   // Find the processor id's of all the available CPUs.
 478   processorid_t* id_array  = NULL;
 479   uint           id_length = 0;
 480   // There are some races between querying information and using it,
 481   // since processor sets can change dynamically.
 482   psetid_t pset = PS_NONE;
 483   // Are we running in a processor set?
 484   if ((pset_bind(PS_QUERY, P_PID, P_MYID, &pset) == 0) && pset != PS_NONE) {
 485     result = find_processors_in_pset(pset, &id_array, &id_length);
 486   } else {
 487     result = find_processors_online(&id_array, &id_length);
 488   }
 489   if (result == true) {
 490     if (id_length >= length) {
 491       result = assign_distribution(id_array, id_length, distribution, length);
 492     } else {
 493       result = false;
 494     }
 495   }
 496   if (id_array != NULL) {
 497     FREE_C_HEAP_ARRAY(processorid_t, id_array);
 498   }
 499   return result;
 500 }
 501 
 502 bool os::bind_to_processor(uint processor_id) {
 503   // We assume that a processorid_t can be stored in a uint.
 504   assert(sizeof(uint) == sizeof(processorid_t),
 505          "can't convert uint to processorid_t");
 506   int bind_result =
 507     processor_bind(P_LWPID,                       // bind LWP.
 508                    P_MYID,                        // bind current LWP.
 509                    (processorid_t) processor_id,  // id.
 510                    NULL);                         // don't return old binding.
 511   return (bind_result == 0);
 512 }
 513 
 514 // Return true if user is running as root.
 515 
 516 bool os::have_special_privileges() {
 517   static bool init = false;
 518   static bool privileges = false;

 437   //                subsequent distributions don't all start at board 0.
 438   static uint board = 0;
 439   uint assigned = 0;
 440   // Until we've found enough processors ....
 441   while (assigned < distribution_length) {
 442     // ... find the next available processor in the board.
 443     for (uint slot = 0; slot < processors_per_board; slot += 1) {
 444       uint try_id = board * processors_per_board + slot;
 445       if ((try_id < limit_id) && (available_id[try_id] == true)) {
 446         distribution[assigned] = try_id;
 447         available_id[try_id] = false;
 448         assigned += 1;
 449         break;
 450       }
 451     }
 452     board += 1;
 453     if (board * processors_per_board + 0 >= limit_id) {
 454       board = 0;
 455     }
 456   }
 457   FREE_C_HEAP_ARRAY(bool, available_id);


 458   return true;
 459 }
 460 
 461 void os::set_native_thread_name(const char *name) {
 462   if (Solaris::_pthread_setname_np != NULL) {
 463     // Only the first 31 bytes of 'name' are processed by pthread_setname_np
 464     // but we explicitly copy into a size-limited buffer to avoid any
 465     // possible overflow.
 466     char buf[32];
 467     snprintf(buf, sizeof(buf), "%s", name);
 468     buf[sizeof(buf) - 1] = '\0';
 469     Solaris::_pthread_setname_np(pthread_self(), buf);
 470   }
 471 }
 472 
 473 bool os::distribute_processes(uint length, uint* distribution) {
 474   bool result = false;
 475   // Find the processor id's of all the available CPUs.
 476   processorid_t* id_array  = NULL;
 477   uint           id_length = 0;

 474   bool result = false;
 475   // Find the processor id's of all the available CPUs.
 476   processorid_t* id_array  = NULL;
 477   uint           id_length = 0;
 478   // There are some races between querying information and using it,
 479   // since processor sets can change dynamically.
 480   psetid_t pset = PS_NONE;
 481   // Are we running in a processor set?
 482   if ((pset_bind(PS_QUERY, P_PID, P_MYID, &pset) == 0) && pset != PS_NONE) {
 483     result = find_processors_in_pset(pset, &id_array, &id_length);
 484   } else {
 485     result = find_processors_online(&id_array, &id_length);
 486   }
 487   if (result == true) {
 488     if (id_length >= length) {
 489       result = assign_distribution(id_array, id_length, distribution, length);
 490     } else {
 491       result = false;
 492     }
 493   }
 494   FREE_C_HEAP_ARRAY(processorid_t, id_array);


 495   return result;
 496 }
 497 
 498 bool os::bind_to_processor(uint processor_id) {
 499   // We assume that a processorid_t can be stored in a uint.
 500   assert(sizeof(uint) == sizeof(processorid_t),
 501          "can't convert uint to processorid_t");
 502   int bind_result =
 503     processor_bind(P_LWPID,                       // bind LWP.
 504                    P_MYID,                        // bind current LWP.
 505                    (processorid_t) processor_id,  // id.
 506                    NULL);                         // don't return old binding.
 507   return (bind_result == 0);
 508 }
 509 
 510 // Return true if user is running as root.
 511 
 512 bool os::have_special_privileges() {
 513   static bool init = false;
 514   static bool privileges = false;
< prev index next >