From 1fb0c720fed4e93f6cfd6cf709a7d7028c3f2836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 13 Jun 2021 11:29:39 +0200 Subject: Enable affinity support for non-Linux sched_getaffinity() and sched_setaffinity() are also available on BSDs. Remove the Linux restraint. --- .github/workflows/ci.yml | 8 +++--- Action.c | 11 ++++--- Affinity.c | 4 +-- Affinity.h | 10 +++---- README | 8 +++--- configure.ac | 74 ++++++++++++++++++++++++------------------------ 6 files changed, 59 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c597627c..617ed305 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity --disable-unicode --disable-sensors + run: ./configure --enable-werror --enable-affinity --disable-unicode --disable-sensors - name: Enable compatibility modes run: | sed -i 's/#define HAVE_FSTATAT 1/#undef HAVE_FSTATAT/g' config.h @@ -26,7 +26,7 @@ jobs: - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-unicode --disable-sensors" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-affinity --disable-unicode --disable-sensors" build-ubuntu-latest-minimal-clang: runs-on: ubuntu-latest @@ -44,11 +44,11 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity --disable-unicode --disable-sensors + run: ./configure --enable-werror --enable-affinity --disable-unicode --disable-sensors - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-unicode --disable-sensors" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-affinity --disable-unicode --disable-sensors" build-ubuntu-latest-full-featured-gcc: runs-on: ubuntu-latest diff --git a/Action.c b/Action.c index 86468635..62cb4525 100644 --- a/Action.c +++ b/Action.c @@ -34,7 +34,7 @@ in the source distribution for its full text. #include "Vector.h" #include "XUtils.h" -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) #include "Affinity.h" #include "AffinityPanel.h" #endif @@ -305,7 +305,7 @@ static Htop_Reaction actionSetAffinity(State* st) { if (st->pl->activeCPUs == 1) return HTOP_OK; -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) const Process* p = (const Process*) Panel_getSelected((Panel*)st->mainPanel); if (!p) return HTOP_OK; @@ -328,8 +328,11 @@ static Htop_Reaction actionSetAffinity(State* st) { Affinity_delete(affinity2); } Object_delete(affinityPanel); -#endif return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; +#else + return HTOP_OK; +#endif + } static Htop_Reaction actionKill(State* st) { @@ -484,7 +487,7 @@ static const struct { { .key = " F9 k: ", .roInactive = true, .info = "kill process/tagged processes" }, { .key = " F7 ]: ", .roInactive = true, .info = "higher priority (root only)" }, { .key = " F8 [: ", .roInactive = false, .info = "lower priority (+ nice)" }, -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) { .key = " a: ", .roInactive = true, .info = "set CPU affinity" }, #endif { .key = " e: ", .roInactive = false, .info = "show process environment" }, diff --git a/Affinity.c b/Affinity.c index d48fc9bf..13f5547c 100644 --- a/Affinity.c +++ b/Affinity.c @@ -22,7 +22,7 @@ in the source distribution for its full text. #else #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS #endif -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) #include #endif @@ -84,7 +84,7 @@ bool Affinity_set(Process* proc, Arg arg) { return ok; } -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) Affinity* Affinity_get(const Process* proc, ProcessList* pl) { cpu_set_t cpuset; diff --git a/Affinity.h b/Affinity.h index d28e848b..cf08cce7 100644 --- a/Affinity.h +++ b/Affinity.h @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "ProcessList.h" -#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY) +#if defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY) #include #include "Object.h" @@ -20,8 +20,8 @@ in the source distribution for its full text. #endif -#if defined(HAVE_LIBHWLOC) && defined(HAVE_LINUX_AFFINITY) -#error hwloc and linux affinity are mutual exclusive. +#if defined(HAVE_LIBHWLOC) && defined(HAVE_AFFINITY) +#error hwloc and affinity support are mutual exclusive. #endif @@ -38,12 +38,12 @@ void Affinity_delete(Affinity* this); void Affinity_add(Affinity* this, unsigned int id); -#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY) +#if defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY) Affinity* Affinity_get(const Process* proc, ProcessList* pl); bool Affinity_set(Process* proc, Arg arg); -#endif /* HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY */ +#endif /* HAVE_LIBHWLOC || HAVE_AFFINITY */ #endif diff --git a/README b/README index c38818ab..121ef964 100644 --- a/README +++ b/README @@ -80,8 +80,11 @@ To install on the local system run `make install`. By default `make install` ins enable Performance Co-Pilot support via a new pcp-htop utility dependency: *libpcp* default: *no* + * `--enable-affinity`: + enable `sched_setaffinity(2)` and `sched_getaffinity(2)` for affinity support; conflicts with hwloc + default: *check* * `--enable-hwloc`: - enable hwloc support for CPU affinity; disables Linux affinity + enable hwloc support for CPU affinity; disables affinity support dependency: *libhwloc* default: *no* * `--enable-static`: @@ -113,9 +116,6 @@ To install on the local system run `make install`. By default `make install` ins * `--enable-ancient-vserver`: enable ancient VServer support (implies `--enable-vserver`) default: *no* - * `--enable-linux-affinity`: - enable Linux `sched_setaffinity(2)` and `sched_getaffinity(2)` for affinity support; conflicts with hwloc - default: *check* * `--enable-delayacct`: enable Linux delay accounting support dependencies: *pkg-config*(build-time), *libnl-3* and *libnl-genl-3* diff --git a/configure.ac b/configure.ac index be40187a..1c83c28e 100644 --- a/configure.ac +++ b/configure.ac @@ -355,9 +355,44 @@ AC_CHECK_FUNCS( [set_escdelay] ) AC_CHECK_FUNCS( [getmouse] ) +AC_ARG_ENABLE([affinity], + [AS_HELP_STRING([--enable-affinity], + [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])], + [], + [enable_affinity=check]) +if test "x$enable_affinity" = xcheck; then + if test "x$enable_hwloc" = xyes; then + enable_affinity=no + else + AC_MSG_CHECKING([for usable sched_setaffinity]) + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ + #include + #include + static cpu_set_t cpuset; + ]], [[ + CPU_ZERO(&cpuset); + sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); + if (errno == ENOSYS) return 1; + ]])], + [enable_affinity=yes + AC_MSG_RESULT([yes])], + [enable_affinity=no + AC_MSG_RESULT([no])], + [AC_MSG_RESULT([yes (assumed while cross compiling)])]) + fi +fi +if test "x$enable_affinity" = xyes; then + if test "x$enable_hwloc" = xyes; then + AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.]) + fi + AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.]) +fi + + AC_ARG_ENABLE([hwloc], [AS_HELP_STRING([--enable-hwloc], - [enable hwloc support for CPU affinity; disables Linux affinity; requires libhwloc @<:@default=no@:>@])], + [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])], [], [enable_hwloc=no]) case "$enable_hwloc" in @@ -433,41 +468,6 @@ if test "x$enable_ancient_vserver" = xyes; then fi -AC_ARG_ENABLE([linux_affinity], - [AS_HELP_STRING([--enable-linux-affinity], - [enable Linux sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])], - [], - [enable_linux_affinity=check]) -if test "x$enable_linux_affinity" = xcheck; then - if test "x$enable_hwloc" = xyes; then - enable_linux_affinity=no - else - AC_MSG_CHECKING([for usable sched_setaffinity]) - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[ - #include - #include - static cpu_set_t cpuset; - ]], [[ - CPU_ZERO(&cpuset); - sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); - if (errno == ENOSYS) return 1; - ]])], - [enable_linux_affinity=yes - AC_MSG_RESULT([yes])], - [enable_linux_affinity=no - AC_MSG_RESULT([no])], - [AC_MSG_RESULT([yes (assumed while cross compiling)])]) - fi -fi -if test "x$enable_linux_affinity" = xyes; then - if test "x$enable_hwloc" = xyes; then - AC_MSG_ERROR([--enable-hwloc and --enable-linux-affinity are mutual exclusive. Specify at most one of them.]) - fi - AC_DEFINE([HAVE_LINUX_AFFINITY], [1], [Define if Linux sched_setaffinity and sched_getaffinity are to be used.]) -fi - - AC_ARG_ENABLE([capabilities], [AS_HELP_STRING([--enable-capabilities], [enable Linux capabilities support; requires libcap @<:@default=check@:>@])], @@ -688,11 +688,11 @@ AC_MSG_RESULT([ (Linux) openvz: $enable_openvz (Linux) vserver: $enable_vserver (Linux) ancient vserver: $enable_ancient_vserver - (Linux) affinity: $enable_linux_affinity (Linux) delay accounting: $enable_delayacct (Linux) sensors: $enable_sensors (Linux) capabilities: $enable_capabilities unicode: $enable_unicode + affinity: $enable_affinity hwloc: $enable_hwloc debug: $enable_debug static: $enable_static -- cgit v1.2.3