aboutsummaryrefslogtreecommitdiff
#include "types.hh"
#include "util.hh"
#include "affinity.hh"

#if HAVE_SCHED_H
#include <sched.h>
#endif

namespace nix {


#if HAVE_SCHED_SETAFFINITY
static bool didSaveAffinity = false;
static cpu_set_t savedAffinity;
#endif


void setAffinityTo(int cpu)
{
#if HAVE_SCHED_SETAFFINITY
    if (sched_getaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1) return;
    didSaveAffinity = true;
    printMsg(lvlDebug, format("locking this thread to CPU %1%") % cpu);
    cpu_set_t newAffinity;
    CPU_ZERO(&newAffinity);
    CPU_SET(cpu, &newAffinity);
    if (sched_setaffinity(0, sizeof(cpu_set_t), &newAffinity) == -1)
        printMsg(lvlError, format("failed to lock thread to CPU %1%") % cpu);
#endif
}


int lockToCurrentCPU()
{
#if HAVE_SCHED_SETAFFINITY
    int cpu = sched_getcpu();
    if (cpu != -1) setAffinityTo(cpu);
    return cpu;
#else
    return -1;
#endif
}


void restoreAffinity()
{
#if HAVE_SCHED_SETAFFINITY
    if (!didSaveAffinity) return;
    if (sched_setaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1)
        printMsg(lvlError, "failed to restore affinity %1%");
#endif
}


}
'equal?' in Guile 2.2.1....Ludovic Courtès 2017-06-30build: Remove check for broken (srfi srfi-37)....Ludovic Courtès 2017-02-20gnu: Add bootstrap-binaries for 'aarch64-linux'....Efraim Flashner 2016-11-25offload: Use Guile-SSH instead of GNU lsh....Ludovic Courtès 2016-08-10build: Correctly determine the system type for GNU/Hurd systems....Manolis Ragkousis 2016-07-20Merge branch 'master' into core-updatesLudovic Courtès 2016-07-19Add (guix zlib)....Ludovic Courtès 2016-06-23build: Remove unneeded conditionals for (guix build syscalls)....Manolis Ragkousis 2016-03-19build: Protect against misconfiguration of localstatedir....Ludovic Courtès 2016-01-13build: Use 127 as the Linux hash-bang limit....Ludovic Courtès 2016-01-12build: 'make check' errors out if file name limits would be hit....Ludovic Courtès 2016-01-12build: Warn against long hash bang lines for tests....Ludovic Courtès 2015-12-01build: Fix detection of ARM systems....Ludovic Courtès 2015-11-25build: Reject ARMv6 systems....Ludovic Courtès 2015-10-09build: Fix libgcrypt detection on FHS systems....Ludovic Courtès 2015-10-06build: Automatically determine libgcrypt's file name....Ludovic Courtès 2015-08-27build: Do not build (guix build syscalls) if 'mount' is missing from libc....Ludovic Courtès 2015-05-19build: Make sure $CXX supports C++11....Ludovic Courtès 2015-02-24build: Reject or warn against file name length limit overruns....Ludovic Courtès 2015-01-07gnu: Add bootstrap binaries for 'armhf-linux'....Mark H Weaver 2014-01-24Add 'guix offload' as a daemon build hook....Ludovic Courtès 2013-11-03Add mips64el-linux to the list of supported systems....Mark H Weaver 2013-07-17build: Provide a replacement (srfi srfi-37) when the user's one is broken....Ludovic Courtès 2013-07-05build: Bail out on unsupported platforms; add `--with-courage'....Ludovic Courtès 2013-07-05build: Correctly determine the system type for non-Linux systems....Ludovic Courtès 2013-05-10build: Make sure the user's Guile has all the required features....Ludovic Courtès 2013-01-10build: Print the Guix system type....Ludovic Courtès 2013-01-06Update a few more license headers....Ludovic Courtès 2012-12-06build: Capture configure-time settings in (guix config)....Ludovic Courtès 2012-12-03build: Include a copy of Nix's libstore and daemon; build it....Ludovic Courtès 2012-11-03build: Require GNU libgcrypt....Ludovic Courtès