affinity

Cannot allocate exclusively a CPU for my process

给你一囗甜甜゛ 提交于 2019-12-12 03:05:53
问题 I have a simple mono-threaded application that does almost pure processing It uses two int buffers of the same size It reads one-by-one all the values of the first buffer each value is a random index in the second buffer It reads the value at the index in the second buffer It sums all the values taken from the second buffer It does all the previous steps for bigger and bigger At the end, I print the number of voluntary and involuntary CPU context switches If the size of the buffers become

Set processor affinity for current thread on Mono (Linux)

泪湿孤枕 提交于 2019-12-10 20:12:59
问题 I'm writing a custom task scheduler, and I would like to know if there is any way of setting the processor affinity for the current thread on Mono (running on Linux). For the .NET runtime running on Windows, I've managed to get this to work by following Lenard Gunda's Running .NET threads on selected processor cores article; however, his approach fails on Mono (and Linux) because: It requires a P/Invoke call to GetCurrentThreadId in the Kernel32.dll library. The Process.Threads property

Is there a way to set thread affinity to a processor core with the boost thread library?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 16:49:39
问题 And would it be a good idea to do so if I needed the processor cores running on 100% for a dozen seconds or would I get better performance if I let the system decide how to handle the threads? What I need is fast execution and I'm worried the system might spend a few seconds before using all the cores, but I haven't found any way of doing this with boost thread. 回答1: You'll first need to call the get_native_handle member function then pass the obtained handle to a platform specific function

setting cpu affinity for linux kernel, not process [closed]

守給你的承諾、 提交于 2019-12-09 10:32:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . I am having a hard time finding information about how to set cpu affinity for linux kernel (with all of its loaded modules), NOT for a specific process. This is because I want the kernel to run on CPU 0 all the time to handle I/O stuff, and not do any switches to run on other 3 CPUs because it may pollute L1 and

线程绑定CPU核

喜欢而已 提交于 2019-12-07 21:36:57
简单地说, CPU 亲和性(affinity) 就是进程要在某个给定的 CPU 上尽量长时间地运行而不被迁移到其他处理器的倾向性。Linux 内核进程调度器天生就具有被称为 软 CPU 亲和性(affinity) 的特性,这意味着进程通常不会在处理器之间频繁迁移。这种状态正是我们希望的,因为进程迁移的频率小就意味着产生的负载小。 2.6 版本的 Linux 内核还包含了一种机制,它让开发人员可以编程实现 硬 CPU 亲和性(affinity) 。这意味着应用程序可以显式地指定进程在哪个(或哪些)处理器上运行。 1 概念 什么是 CPU Affinity ? Affinity 是进程的一个属性,这个属性指明了进程调度器能够把这个进程调度到哪些 CPU 上。 在 Linux 中,我们可以利用 CPU affinity 把一个或多个进程绑定到一个或多个 CPU 上。 CPU Affinity 分为 2 种, soft affinity 和 hard affinity 。 soft affinity 仅是一个建议,如果不可避免,调度器还是会把进程调度到其它的 CPU 上。 hard affinity 是调度器必须遵守的规则。 为什么需要 CPU 绑定? ●增加 CPU 缓存的命中率 CPU 之间是不共享缓存的,如果进程频繁的在各个 CPU 间进行切换,需要不断的使旧 CPU 的 cache

How can I ensure that a process runs in a specific physical CPU core and thread?

谁说我不能喝 提交于 2019-12-07 16:53:58
问题 This question asks about ensuring two processes run on the same CPU. Using sched_setaffinity I can limit a process to a number of logical CPUs, but how can I ensure that these are mapped to specific physical CPUs and threads? I expect that the mapping would be: 0 - CPU 0 thread 0 1 - CPU 0 thread 1 2 - CPU 1 thread 0 3 - CPU 1 thread 1 etc... where the number on the left is the relevant CPU used in sched_setaffinity . However, when I tried to test this, it appeared that this is not

Set cpu affinity on a loadable linux kernel module

帅比萌擦擦* 提交于 2019-12-07 09:46:30
问题 I need to create a kernel module that enables ARM PMU counters on every core in the computer. I have trouble setting the cpu affinity. Ive tried sched_get_affinity , but apparently, it only works for user space processes. My code is below. Any ideas? #define _GNU_SOURCE #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void){ unsigned reg; /* enable user-mode access to the performance counters*/ asm volatile("MRC p15, 0,

These days, what are good reasons for setting thread affinity rather than leaving it to the OS?

喜欢而已 提交于 2019-12-06 11:11:20
Searching answers here for "thread affinity", I see a lot of interest in doing it but little justification for it save possibly getting stable QueryPerformanceTimer results. Assuming a modern OS and a modern 2-4 socket workstation/server class machine with modern 4-6 core CPUs, what good reasons would anyone have for thinking they know better than their OS's scheduler ? Are there any real world situations where taking more control of thead affinity is the right thing to do ? What sort of performance benefits can be demonstrated ? The last time I saw a really good case for setting thread

Is it possible to set pthread CPU affinity in OS X?

早过忘川 提交于 2019-12-06 06:18:29
问题 In Linux there is a sched_setaffinity() function defined in sched.h , but I can't seem to find anything like that in Mac OS X 10.6 pthreads implementation... If it is not possible to set affinity, what is the default policy in OS X ? 回答1: Mac OS X has Thread Affinity API and you can use it with pthread ID as thread_policy_set(pthread_mach_thread_np(pthreadId), but, as far as I know, there are no APIs like sched_setaffinity. 来源: https://stackoverflow.com/questions/6183888/is-it-possible-to-set

How to start a thread on a specific core?

放肆的年华 提交于 2019-12-06 04:17:14
问题 I have a quad core CPU, and lets say I always want to start a Thread on the second core. Is that possible in C#? 回答1: Yes. Check out ProcessorAffinity for Windows or SetProcessorAffinity for XBox XNA. This is also discussed on another Stackoverflow question. 回答2: Yes, take a look at the ProcessorAffinity property for the thread. 回答3: Set ProcessorAffinity of the process: 0x0001 = 0000 0001 - run on 1st core ↑ 0x0002 = 0000 0010 - run on 2nd core ↑ 0x0003 = 0000 0011 - run on 1st and 2nd core