This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1705 from nemanja-boric-sociomantic/addsched
Add Linux-specific sched_setaffinity and sched_getaffinity
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/******************************************************************************* | ||
D binding for Linux specific scheduler control methods. | ||
Defines functions sched_setaffinity and sched_getaffinity and the data | ||
types they operate on. | ||
Copyright: Copyright (c) 2016 Sociomantic Labs. All rights reserved. | ||
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0). | ||
Authors: Nemanja Boric | ||
*******************************************************************************/ | ||
|
||
|
||
module core.sys.linux.sched; | ||
|
||
import core.sys.posix.sched; | ||
import core.sys.posix.config; | ||
import core.sys.posix.sys.types; | ||
|
||
version (Linux): | ||
extern (C): | ||
@nogc: | ||
nothrow: | ||
|
||
|
||
private // helpers | ||
{ | ||
|
||
/* Size definition for CPU sets. */ | ||
enum | ||
{ | ||
__CPU_SETSIZE = 1024, | ||
__NCPUBITS = 8 * cpu_mask.sizeof, | ||
} | ||
|
||
/* Macros */ | ||
|
||
/* Basic access functions. */ | ||
size_t __CPUELT(size_t cpu) pure | ||
{ | ||
return cpu / __NCPUBITS; | ||
} | ||
cpu_mask __CPUMASK(size_t cpu) pure | ||
{ | ||
return 1UL << (cpu % __NCPUBITS); | ||
} | ||
|
||
cpu_mask __CPU_SET_S(size_t cpu, size_t setsize, cpu_set_t* cpusetp) pure | ||
{ | ||
if (cpu < 8 * setsize) | ||
{ | ||
cpusetp.__bits[__CPUELT(cpu)] |= __CPUMASK(cpu); | ||
return __CPUMASK(cpu); | ||
} | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
/// Type for array elements in 'cpu_set_t'. | ||
alias c_ulong cpu_mask; | ||
|
||
/// Data structure to describe CPU mask. | ||
struct cpu_set_t | ||
{ | ||
cpu_mask[__CPU_SETSIZE / __NCPUBITS] __bits; | ||
} | ||
|
||
/// Access macros for `cpu_set' (missing a lot of them) | ||
|
||
cpu_mask CPU_SET(size_t cpu, cpu_set_t* cpusetp) pure | ||
{ | ||
return __CPU_SET_S(cpu, cpu_set_t.sizeof, cpusetp); | ||
} | ||
|
||
/* Functions */ | ||
int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask); | ||
int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters