mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-14 02:58:08 +00:00
Porting cpu affinity to DragonFly.
Thanks their API is very similar in this area.
This commit is contained in:
@ -72,18 +72,21 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
|
||||||
defined(__NetBSD__)
|
defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif /* __APPLE__ || __FreeBSD__ || __OpenBSD__ */
|
#endif /* __APPLE__ || __FreeBSD__ || __OpenBSD__ */
|
||||||
|
|
||||||
/* For systems that have sched_setaffinity; right now just Linux, but one
|
/* For systems that have sched_setaffinity; right now just Linux, but one
|
||||||
can hope... */
|
can hope... */
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
|
||||||
|
defined(__DragonFly__)
|
||||||
#define HAVE_AFFINITY 1
|
#define HAVE_AFFINITY 1
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/cpuset.h>
|
#include <sys/cpuset.h>
|
||||||
|
#endif
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
void bind_to_free_cpu(void) {
|
void bind_to_free_cpu(void) {
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
cpu_set_t c;
|
cpu_set_t c;
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
cpuset_t* c;
|
cpuset_t* c;
|
||||||
@ -117,7 +117,7 @@ void bind_to_free_cpu(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
struct kinfo_proc* procs;
|
struct kinfo_proc* procs;
|
||||||
size_t nprocs;
|
size_t nprocs;
|
||||||
size_t proccount;
|
size_t proccount;
|
||||||
@ -138,8 +138,13 @@ void bind_to_free_cpu(void) {
|
|||||||
|
|
||||||
for (i = 0; i < proccount; i++) {
|
for (i = 0; i < proccount; i++) {
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
if (procs[i].ki_oncpu < sizeof(cpu_used) && procs[i].ki_pctcpu > 2)
|
if (procs[i].ki_oncpu < sizeof(cpu_used) && procs[i].ki_pctcpu > 2)
|
||||||
cpu_used[procs[i].ki_oncpu] = 1;
|
cpu_used[procs[i].ki_oncpu] = 1;
|
||||||
|
#elif defined(__DragonFly__)
|
||||||
|
if (procs[i].kp_lwp.kl_cpuid < sizeof(cpu_used) && procs[i].kp_lwp.kl_pctcpu > 2)
|
||||||
|
cpu_used[procs[i].kp_lwp.kl_cpuid] = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +205,7 @@ void bind_to_free_cpu(void) {
|
|||||||
|
|
||||||
cpu_aff = i;
|
cpu_aff = i;
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
CPU_ZERO(&c);
|
CPU_ZERO(&c);
|
||||||
CPU_SET(i, &c);
|
CPU_SET(i, &c);
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
@ -212,7 +217,7 @@ void bind_to_free_cpu(void) {
|
|||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
if (sched_setaffinity(0, sizeof(c), &c)) PFATAL("sched_setaffinity failed");
|
if (sched_setaffinity(0, sizeof(c), &c)) PFATAL("sched_setaffinity failed");
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
|
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
|
||||||
PFATAL("pthread_setaffinity failed");
|
PFATAL("pthread_setaffinity failed");
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
@ -871,7 +876,7 @@ double get_runnable_processes(void) {
|
|||||||
static double res;
|
static double res;
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
|
||||||
defined(__NetBSD__)
|
defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
|
|
||||||
/* I don't see any portable sysctl or so that would quickly give us the
|
/* I don't see any portable sysctl or so that would quickly give us the
|
||||||
number of runnable processes; the 1-minute load average can be a
|
number of runnable processes; the 1-minute load average can be a
|
||||||
@ -1605,7 +1610,7 @@ void check_cpu_governor(void) {
|
|||||||
|
|
||||||
void get_core_count(void) {
|
void get_core_count(void) {
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
||||||
|
|
||||||
size_t s = sizeof(cpu_core_count);
|
size_t s = sizeof(cpu_core_count);
|
||||||
|
|
||||||
@ -1651,7 +1656,7 @@ void get_core_count(void) {
|
|||||||
|
|
||||||
cur_runnable = (u32)get_runnable_processes();
|
cur_runnable = (u32)get_runnable_processes();
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
||||||
|
|
||||||
/* Add ourselves, since the 1-minute average doesn't include that yet. */
|
/* Add ourselves, since the 1-minute average doesn't include that yet. */
|
||||||
|
|
||||||
|
@ -52,12 +52,14 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__DragonFly__)
|
||||||
#define HAVE_AFFINITY 1
|
#define HAVE_AFFINITY 1
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/cpuset.h>
|
#include <sys/cpuset.h>
|
||||||
|
#endif
|
||||||
#define cpu_set_t cpuset_t
|
#define cpu_set_t cpuset_t
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -168,7 +170,7 @@ int main(int argc, char** argv) {
|
|||||||
if (!fr) {
|
if (!fr) {
|
||||||
|
|
||||||
u32 util_perc;
|
u32 util_perc;
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
cpu_set_t c;
|
cpu_set_t c;
|
||||||
|
|
||||||
CPU_ZERO(&c);
|
CPU_ZERO(&c);
|
||||||
@ -188,7 +190,7 @@ int main(int argc, char** argv) {
|
|||||||
PFATAL("thread_policy_set failed");
|
PFATAL("thread_policy_set failed");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
|
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
|
||||||
PFATAL("pthread_setaffinity_np failed");
|
PFATAL("pthread_setaffinity_np failed");
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user