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
}


}
itle='2018-09-05 20:56:55 +0800'>2018-09-05gnu: packages: mp3: Use HTTPS where possible....Alex Vong 2018-09-05gnu: eyed3: Update home page....Alex Vong 2018-08-15gnu: eyeD3: Update to 0.8.7....Leo Famulari 2018-04-21Merge branch 'master' into core-updatesMark H Weaver 2018-04-18gnu: mpg123: Update to 1.25.10....Leo Famulari 2018-04-10Merge branch 'master' into core-updatesMark H Weaver 2018-04-09gnu: chromaprint: Fix typo....Leo Famulari 2018-04-09gnu: eyeD3: Update to 0.8.5....Leo Famulari 2018-04-04gnu: chromaprint: Build 'fpcalc'....Pierre Neidhardt 2018-03-16gnu: All snippets report errors using exceptions, else return #t....Mark H Weaver 2018-02-19gnu: chromaprint: Update to 1.4.3....Tobias Geerinckx-Rice 2018-01-16gnu: mpg123: Use HTTPS for home page....Tobias Geerinckx-Rice 2018-01-16gnu: mpg123: Update to 1.25.8....Tobias Geerinckx-Rice 2018-01-08gnu: lame: Remove obsolete workaround....Marius Bakke 2017-11-21gnu: taglib: Update to 1.11.1 and fix home page....Pierre Langlois 2017-11-09gnu: chromaprint: Update to 1.4.2....Leo Famulari 2017-10-22gnu: lame: Update to 3.100....Marius Bakke 2017-10-11gnu: mpg123: Update to 1.25.7....Leo Famulari 2017-09-24gnu: Fix syntax errors introduced by dc1d3cdef70f0e3c047c229c2a0e56....Marius Bakke 2017-09-20gnu: Use 'modify-phases' syntax....Kei Kebreau 2017-09-11gnu: mpg123: Update to 1.25.6 [fixes CVE-2017-12797]....Leo Famulari