aboutsummaryrefslogtreecommitdiff
path: root/nix/libutil/affinity.cc
blob: 3e21f43a2e9d1b23e40a7f524a514730981bdbfc (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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
}


}
113f3de857bb8'>gnu: aws-c-sdkutils: Update to 0.1.19....* gnu/packages/c.scm (aws-c-sdkutils): Update to 0.1.19. Change-Id: I7c6ee085cafdd0f0d8df125f2f602b14b073bb81 Greg Hogan 2024-09-28gnu: aws-c-event-stream: Update to 0.4.3....* gnu/packages/c.scm (aws-c-event-stream): Update to 0.4.3. Change-Id: Iae87c5793b1a886fefcf0597ff6254e172869159 Greg Hogan 2024-09-28gnu: aws-c-io: Update to 0.14.18....* gnu/packages/c.scm (aws-c-io): Update to 0.14.18. Change-Id: I2013a9c2f173898e2c48c05824da0044885166e1 Greg Hogan 2024-09-28gnu: aws-c-cal: Update to 0.7.4....* gnu/packages/c.scm (aws-c-cal): Update to 0.7.4. [propagated-inputs]: Add s2n. [inputs]: Remove openssl and openssl:static. Change-Id: I211a3d96ec984ab870b6e1621756ad6463f27a8b Greg Hogan 2024-09-28gnu: aws-checksums: Update to 0.1.18....* gnu/packages/c.scm (aws-checksums): Update to 0.1.18. Change-Id: Iaed4161d8f2ba568e4aaae45a07e707d6a1b42bc Greg Hogan 2024-09-28gnu: aws-c-common: Update to 0.9.27....* gnu/packages/c.scm (aws-c-common): Update to 0.9.27. [arguments]: Disable parallel tests. [supported-systems]: Add armhf-linux and aarch64-linux. Change-Id: I66ddf9ed03f8ead70aa1c86792dd4aa8782ac59e Greg Hogan 2024-08-31gnu: Add c-template-sort....* gnu/packages/c.scm (c-template-sort): New variable. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Adam Faiz 2024-08-02gnu: Add libcsptr....* gnu/packages/c.scm (libcsptr): New variable. Change-Id: I47e34191047df0a171a78a11f9ba2ebef4a8c37a Liliana Marie Prikler 2024-07-30gnu: aml: Update to 0.3.0....* gnu/packages/c.scm (aml): Update to 0.3.0. Change-Id: I2bb2c44650485538eaf4dd174cbbc6e697d00e69 Zheng Junjie 2024-07-30gnu: Add aml....* gnu/packages/c.scm (aml): New variable. Change-Id: I271be102bfa1f2e529d70f1e0029263d624821b8 kitzman 2024-05-13gnu: Add sfsexp....* gnu/packages/c.scm (sfsexp): New variable. Change-Id: Iabfbe10b4ad6134ae886a3d26487f881107b559c Signed-off-by: Christopher Baines <mail@cbaines.net> Fabio Natali 2024-04-30gnu: tomlc99: Install pkg-config file....* gnu/packages/c.scm (tomlc99) <arguments>: Add phase to install pkg-config file. Change-Id: Id09f22912fe7e4dcac6a0377e4a78d3d34346106 Signed-off-by: Christopher Baines <mail@cbaines.net> Jean-Pierre De Jesus DIAZ 2024-04-30gnu: tomlc99: Update to 1.0-1.5221b3d....* gnu/packages/c.scm (tomlc99): Update to 1.0-1.5221b3d. Change-Id: Icb9c736fb7d49a097fe6db6451031637b7a01492 Signed-off-by: Christopher Baines <mail@cbaines.net> Jean-Pierre De Jesus DIAZ 2024-03-10gnu: qbe: Update to 1.2....* gnu/packages/c.scm (qbe): Update to 1.2. Change-Id: I0fc2039b416026dc0563b9ead967713e594446bc Signed-off-by: 宋文武 <iyzsong@member.fsf.org> Nguyễn Gia Phong 2024-02-13gnu: tinydir: Update to 1.2.6....* gnu/packages/c.scm (tinydir): Update to 1.2.6. * gnu/packages/patches/tinydir-fix-cbehave-test.patch: Adjust patch. Signed-off-by: Christopher Baines <mail@cbaines.net> David Elsing 2024-01-24gnu: libdispatch: Update to 5.9.2....* gnu/packages/c.scm (libdispatch): Update to 5.9.2. Change-Id: I119d1de974673aa2c08eb51a7bcaa7ce24aeb0b2 Efraim Flashner 2023-12-02gnu: Add pcg-c....* gnu/packages/c.scm (pcg-c): New variable. Signed-off-by: Ludovic Courtès <ludo@gnu.org> David Elsing 2023-11-15gnu: mimalloc: Update to 2.1.2....* gnu/packages/c.scm (mimalloc): Update to 2.1.2. Change-Id: I20ff922250f57beabb427d72e82579e0059fd4f2 Efraim Flashner 2023-11-15gnu: mimalloc: Fix building on powerpc-linux....* gnu/packages/c.scm (mimalloc)[arguments]: When building for powerpc-linux add a configure-flag to use libatomic. Change-Id: I41062686186640bc4c685a0ee5de1e613040dfb9 Efraim Flashner