如何禁止在任何应用程序的所有线程的特定CPU核上运行,除非我指定的线程? [英] How to forbid run on specific CPU-cores for all threads of any application, unless the thread specified by me?

查看:147
本文介绍了如何禁止在任何应用程序的所有线程的特定CPU核上运行,除非我指定的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁止在任何应用程序的所有线程的特定CPU核上运行,除非我指定的线程(在Win / nix中)?

How to forbid run on specific CPU-cores for all threads of any application, unless the thread specified by me (in Win/nix)?

线程或进程到特定的CPU核心,我们可以在POSIX中使用OS-API函数:sched_setaffinity(),在WINAPI中使用SetProcessAffinityMask(),SetThreadAffinityMask()。

To bind the threads or processes to specific CPUs cores, we can use the OS-API-functions: sched_setaffinity() in POSIX and SetProcessAffinityMask(), SetThreadAffinityMask() in WINAPI.

如果我们想要的话,在这些核上,不会启动许多第三方应用程序的任何其他线程,目前在操作系统上运行,如何做?

But if we want, that on these nuclei will not be started any other threads of many third-party applications, which currently running on the operating system, how to do it?

UPDATE :需要实时系统 - 必须指定线程从未发生过上下文切换或暂停。

UPDATE: Need a real-time system - necessary to have specified by me threads never happened context switching, or the temporary suspension.

可能的解决方案:


  • 使用实时操作系统,例如QNX

  • 除了绑定到处理器核心,设置实时优先级

  • 使用XEN虚拟化跨操作系统分配处理器核心

使用固定内存很容易解决页错误:(POSIX)mlock()或(WINAPI)VirtualLock()

A page fault is easily solved using a pinned memory: (POSIX) mlock() or (WINAPI) VirtualLock()

推荐答案

如果你将你的进程和线程设置为实时优先级,他们会把所有的东西推开。使用 SetPriorityClass 设置流程优先级和 SetThreadPriority ,如下:

If you set your process and threads to real-time priority, and they'll shove everything else out the way. Use SetPriorityClass to set the process priority and SetThreadPriority for the threads, like this:

SetPriorityClass(HProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(HThread, THREAD_PRIORITY_TIME_CRITICAL);

这篇关于如何禁止在任何应用程序的所有线程的特定CPU核上运行,除非我指定的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆