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
}


}
4-09 16:10:48 -0400'>2024-04-09.guix-authorizations: Remove Raghav Gururajan due to inactivity....* .guix-authorizations: Remove raghavgururajan. Change-Id: Iec45c971c4ec4cd1721d9b6299dc44bc7bb1a94e Leo Famulari 2024-01-09Authorize Oleg (Sharlatan)'s key....* .guix-authorizations (sharlatan): Register PGP key fingerprint. Change-Id: I0d20e50a37971237721964852a404c5cf136f0be Maxim Cournoyer 2023-07-23.guix-authorizations: Update lfam's key....* .guix-authorizations: Update lfam's signing key fingerprint. Change-Id: Ic34f364dfc46e403e1d431e5860a63b36143b6f3 Leo Famulari 2023-08-13.guix-authorizations: Authorise Hilton Chain....* .guix-authorizations (hako): Add OpenPGP key fingerprint. Tobias Geerinckx-Rice 2023-06-14.guix-authorizations: Remove Lars-Dominik Braun’s professional key....* .guix-authorizations: Remove from lbraun (professional). Lars-Dominik Braun 2023-05-15.guix-authorizations: Authorize Jorge Gomez....* .guix-authorizations (jgart): Add OpenPGP key fingerprint. Maxim Cournoyer 2023-05-11.guix-authorizations: Authorize Josselin Poiret....* .guix-authorizations (jpoiret): Add OpenPGP key fingerprint. Maxim Cournoyer 2023-05-11.guix-authorizations: Authorize Simon Tournier....* .guix-authorizations (zimoun): Add OpenPGP key fingerprint. Maxim Cournoyer 2023-03-24.guix-authorizations: Remove Paul Garlick due to inactivity....* .guix-authorizations: Remove from pgarlick. Leo Famulari 2023-03-24.guix-authorizations: Remove Jakub Kądziołka due to inactivity....* .guix-authorizations: Remove niedzejkob. Leo Famulari 2023-03-24.guix-authorizations: Remove Chris Marusich due to inactivity....* .guix-authorizations: Remove marusich. Leo Famulari 2023-03-24.guix-authorizations: Remove Brice Waegeneire due to inactivity....* .guix-authorizations: Remove bricewge. Leo Famulari 2023-03-24.guix-authorizations: Remove Alex Kost due to inactivity....* .guix-authorizations: Remove alezost. Leo Famulari