如何强制两种工艺在同一CPU上运行? [英] How to force two process to run on the same CPU?

查看:167
本文介绍了如何强制两种工艺在同一CPU上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我编程,由多个进程的一个软件系统。在C编程++ Linux下。而他们之间的沟通他们使用Linux共享内存。

I'm programming a software system that consists of multiple processes. It is programmed in C++ under Linux. and they communicate among them using Linux shared memory.

一般情况下,在软件开发,是在最后阶段的性能优化时作出。在这里,我来到了一个大问题。该软件具有高性能的要求,但在与4个或8个CPU核心(通常使用多个CPU)上,这是只能够使用3个核心,因此浪费CPU的功率的25%,在第一批,而超过在第二组的60%。
很多研究,有丢弃的互斥和锁争后,我发现时间被浪费在shmdt /调用的shmat(分离和附加到共享内存段)。一些研究之后,我发现,这些CPU,这通常是AMD Opteron和Intel Xeon处理器,使用名为NUMA内存系统,这基本上意味着,每个处理器都有快,本地存储,并访问存储从其它CPU是昂贵。

Usually, in software development, is in the final stage when the performance optimization is made. Here I came to a big problem. The software has high performance requirements, but in machines with 4 or 8 CPU cores (usually with more than one CPU), it was only able to use 3 cores, thus wasting 25% of the CPU power in the first ones, and more than 60% in the second ones. After many research, and having discarded mutex and lock contention, I found out that the time was being wasted on shmdt/shmat calls (detach and attach to shared memory segments). After some more research, I found out that these CPUs, which usually are AMD Opteron and Intel Xeon, use a memory system called NUMA, which basically means that each processor has its fast, "local memory", and accessing memory from other CPUs is expensive.

做一些试验之后,这个问题似乎是,该软件被设计成使得,基本上,任何方法可以通过共享存储器段的任何其他方法,并在其中任何线程。这似乎杀性能,工艺不断从其他进程访问内存。

After doing some tests, the problem seems to be that the software is designed so that, basically, any process can pass shared memory segments to any other process, and to any thread in them. This seems to kill performance, as process are constantly accessing memory from other processes.

问:

现在的问题是,有没有办法迫使对流程相同的CPU中执行?我不是说要强迫他们在同一个处理器始终执行的,因为我不关心你,其中一个,他们被执行,altough,会做这项工作。理想情况下,会有办法告诉内核:如果您在一个处理器安排此过程中,还必须安排这兄弟的过程(这是与它通过共享内存通信的过程),在相同的处理器,从而使性能不会受到惩罚。

Now, the question is, is there any way to force pairs of processes to execute in the same CPU?. I don't mean to force them to execute always in the same processor, as I don't care in which one they are executed, altough that would do the job. Ideally, there would be a way to tell the kernel: If you schedule this process in one processor, you must also schedule this "brother" process (which is the process with which it communicates through shared memory) in that same processor, so that performance is not penalized.

推荐答案

我想你可以开始与这些手册页:

I think you may be able to start with these manual pages:

$ apropos affinity
sched_getaffinity (2) - set and get a process's CPU affinity mask
sched_setaffinity (2) - set and get a process's CPU affinity mask
taskset (1)          - retrieve or set a process's CPU affinity
$

这取决于您是否想这样做,从源头code或外壳。 pthread库也有一定的作用。

depending on whether you want to do that from the source code or the shell. The pthread library also has some function.

这篇关于如何强制两种工艺在同一CPU上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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