/* reset scheduler from real-time to normal scheduling */ void reset_scheduler(void) { #ifdef _AIX_ #if HAVE_THREAD_SETSCHED struct thrdentry64 te; tid64_t ti; ti = 0ULL; if (getthrds64(getpid(), &te, sizeof(te), &ti, 1) != 1) { DEBUG(DEBUG_ERR, ("Unable to get thread information\n")); } if (thread_setsched(te.ti_tid, 0, SCHED_OTHER) == -1) { DEBUG(DEBUG_ERR, ("Unable to set scheduler to SCHED_OTHER\n")); } #endif #else /* no AIX */ #if HAVE_SCHED_SETSCHEDULER #ifndef SCHED_RESET_ON_FORK struct sched_param p; p.sched_priority = 0; if (sched_setscheduler(0, SCHED_OTHER, &p) == -1) { DEBUG(DEBUG_ERR, ("Unable to set scheduler to SCHED_OTHER\n")); } #endif #endif #endif }
/* if possible, make this task real time */ bool set_scheduler(void) { #ifdef _AIX_ #if HAVE_THREAD_SETSCHED struct thrdentry64 te; tid64_t ti; ti = 0ULL; if (getthrds64(getpid(), &te, sizeof(te), &ti, 1) != 1) { DEBUG(DEBUG_ERR, ("Unable to get thread information\n")); return false; } if (thread_setsched(te.ti_tid, 0, SCHED_RR) == -1) { DEBUG(DEBUG_ERR, ("Unable to set scheduler to SCHED_RR (%s)\n", strerror(errno))); return false; } else { return true; } #endif #else /* no AIX */ #if HAVE_SCHED_SETSCHEDULER struct sched_param p; int policy = SCHED_FIFO; p.sched_priority = 1; #ifdef SCHED_RESET_ON_FORK policy |= SCHED_RESET_ON_FORK; #endif if (sched_setscheduler(0, policy, &p) == -1) { DEBUG(DEBUG_CRIT,("Unable to set scheduler to SCHED_FIFO (%s)\n", strerror(errno))); return false; } else { return true; } #endif #endif DEBUG(DEBUG_CRIT,("No way to set real-time priority.\n")); return false; }
static int hwloc_aix_get_pid_getthrds_cpubind(hwloc_topology_t topology __hwloc_attribute_unused, pid_t pid, hwloc_bitmap_t hwloc_set, int flags __hwloc_attribute_unused) { #if HWLOC_BITS_PER_LONG == 64 struct thrdentry64 thread_info; tid64_t next_thread; #else struct thrdsinfo thread_info; tid_t next_thread; #endif next_thread = 0; /* TODO: get multiple at once */ #if HWLOC_BITS_PER_LONG == 64 while (getthrds64 (pid, &thread_info, sizeof (thread_info), &next_thread, 1) == 1) { #else while (getthrds (pid, &thread_info, sizeof (thread_info), &next_thread, 1) == 1) { #endif if (PROCESSOR_CLASS_ANY != thread_info.ti_cpuid) hwloc_bitmap_set(hwloc_set, thread_info.ti_cpuid); else hwloc_bitmap_fill(hwloc_set); } /* TODO: what if the thread list changes and we get nothing? */ return 0; } static int hwloc_aix_get_tid_getthrds_cpubind(hwloc_topology_t topology __hwloc_attribute_unused, tid_t tid, hwloc_bitmap_t hwloc_set, int flags __hwloc_attribute_unused) { #if HWLOC_BITS_PER_LONG == 64 struct thrdentry64 thread_info; tid64_t next_thread; #else struct thrdsinfo thread_info; tid_t next_thread; #endif pid_t pid = getpid(); next_thread = 0; /* TODO: get multiple at once */ #if HWLOC_BITS_PER_LONG == 64 while (getthrds64 (pid, &thread_info, sizeof (thread_info), &next_thread, 1) == 1) { #else while (getthrds (pid, &thread_info, sizeof (thread_info), &next_thread, 1) == 1) { #endif if (thread_info.ti_tid == tid) { if (PROCESSOR_CLASS_ANY != thread_info.ti_cpuid) hwloc_bitmap_set(hwloc_set, thread_info.ti_cpuid); else hwloc_bitmap_fill(hwloc_set); break; } } /* TODO: what if the thread goes away in the meantime? */ return 0; } static int hwloc_aix_set_thisproc_cpubind(hwloc_topology_t topology, hwloc_const_bitmap_t hwloc_set, int flags) { rsid_t who; who.at_pid = getpid(); return hwloc_aix_set_sth_cpubind(topology, R_PROCESS, who, who.at_pid, hwloc_set, flags); } static int hwloc_aix_get_thisproc_cpubind(hwloc_topology_t topology, hwloc_bitmap_t hwloc_set, int flags) { int ret, bound; rsid_t who; who.at_pid = getpid(); ret = hwloc_aix_get_sth_rset_cpubind(topology, R_PROCESS, who, hwloc_set, flags, &bound); if (!ret && !bound) { hwloc_bitmap_zero(hwloc_set); ret = hwloc_aix_get_pid_getthrds_cpubind(topology, who.at_pid, hwloc_set, flags); } return ret; }