/* * Send an interprocessor interrupt. */ void mips64_send_ipi(unsigned int cpuid, unsigned int ipimask) { #ifdef DEBUG if (cpuid >= CPU_MAXID || get_cpu_info(cpuid) == NULL) panic("mips_send_ipi: bogus cpu_id"); if (!cpuset_isset(&cpus_running, get_cpu_info(cpuid))) panic("mips_send_ipi: CPU %ld not running", cpuid); #endif atomic_setbits_int(&ipi_mailbox[cpuid], ipimask); hw_ipi_intr_set(cpuid); }
/* * Send an IPI to all in the list but ourselves. */ void mips64_multicast_ipi(unsigned int cpumask, unsigned int ipimask) { struct cpu_info *ci; CPU_INFO_ITERATOR cii; cpumask &= ~(1 << cpu_number()); CPU_INFO_FOREACH(cii, ci) { if (!(cpumask & (1UL << ci->ci_cpuid)) || !cpuset_isset(&cpus_running, ci)) continue; mips64_send_ipi(ci->ci_cpuid, ipimask); } }
static void hwloc_netbsd_bsd2hwloc(hwloc_bitmap_t hwloc_cpuset, const cpuset_t *cpuset) { unsigned cpu, cpulimit; int found = 0; hwloc_bitmap_zero(hwloc_cpuset); cpulimit = cpuset_size(cpuset) * CHAR_BIT; for (cpu = 0; cpu < cpulimit; cpu++) if (cpuset_isset(cpu, cpuset)) { hwloc_bitmap_set(hwloc_cpuset, cpu); found++; } /* when never bound, it returns an empty set, fill it instead */ if (!found) hwloc_bitmap_fill(hwloc_cpuset); }
/* Return the number of processors available to the current process, based on a modern system call that returns the "affinity" between the current process and each CPU. Return 0 if unknown or if such a system call does not exist. */ static unsigned long num_processors_via_affinity_mask (void) { /* glibc >= 2.3.3 with NPTL and NetBSD 5 have pthread_getaffinity_np, but with different APIs. Also it requires linking with -lpthread. Therefore this code is not enabled. glibc >= 2.3.4 has sched_getaffinity whereas NetBSD 5 has sched_getaffinity_np. */ #if HAVE_PTHREAD_GETAFFINITY_NP && defined __GLIBC__ && 0 { cpu_set_t set; if (pthread_getaffinity_np (pthread_self (), sizeof (set), &set) == 0) { unsigned long count; # ifdef CPU_COUNT /* glibc >= 2.6 has the CPU_COUNT macro. */ count = CPU_COUNT (&set); # else size_t i; count = 0; for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET (i, &set)) count++; # endif if (count > 0) return count; } } #elif HAVE_PTHREAD_GETAFFINITY_NP && defined __NetBSD__ && 0 { cpuset_t *set; set = cpuset_create (); if (set != NULL) { unsigned long count = 0; if (pthread_getaffinity_np (pthread_self (), cpuset_size (set), set) == 0) { cpuid_t i; for (i = 0;; i++) { int ret = cpuset_isset (i, set); if (ret < 0) break; if (ret > 0) count++; } } cpuset_destroy (set); if (count > 0) return count; } } #elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */ { cpu_set_t set; if (sched_getaffinity (0, sizeof (set), &set) == 0) { unsigned long count; # ifdef CPU_COUNT /* glibc >= 2.6 has the CPU_COUNT macro. */ count = CPU_COUNT (&set); # else size_t i; count = 0; for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET (i, &set)) count++; # endif if (count > 0) return count; } } #elif HAVE_SCHED_GETAFFINITY_NP /* NetBSD >= 5 */ { cpuset_t *set; set = cpuset_create (); if (set != NULL) { unsigned long count = 0; if (sched_getaffinity_np (getpid (), cpuset_size (set), set) == 0) { cpuid_t i; for (i = 0;; i++) { int ret = cpuset_isset (i, set); if (ret < 0) break; if (ret > 0) count++; } } cpuset_destroy (set); if (count > 0) return count; } } #endif #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ { /* This works on native Windows platforms. */ DWORD_PTR process_mask; DWORD_PTR system_mask; if (GetProcessAffinityMask (GetCurrentProcess (), &process_mask, &system_mask)) { DWORD_PTR mask = process_mask; unsigned long count = 0; for (; mask != 0; mask = mask >> 1) if (mask & 1) count++; if (count > 0) return count; } }