是否有可能创建没有在Linux x86上GAS总成系统调用线程?

是否有可能创建没有在Linux x86上GAS总成系统调用线程?

问题描述:

虽然学习汇编语言(在Linux上使用GNU汇编器一个x86架构),美国心脏协会的时刻之一是使用的系统调用。这些系统调用起来非常方便,而且有时甚至是必要的,因为你的程序运行在用户空间结果
然而,因为它们需要一个中断(当然系统调用),这意味着一个上下文切换,必须从当前的活动程序在用户空间进行到在内核空间中运行的系统的系统调用是在性能方面相当昂贵。

Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using system calls. These system calls come in very handy and are sometimes even necessary as your program runs in user-space.
However system calls are rather expensive in terms of performance as they require an interrupt (and of course a system call) which means that a context switch must be made from your current active program in user-space to the system running in kernel-space.

我想说明的一点是:我目前正在实施一个编译器(对于一个大学项目)和额外的功能,我想添加一个多线程code的支持,以增强已编译的程序的性能。由于一些多线程code会被编译器本身可以自动生成,这几乎保证会有多线程code真的很小位它。为了获得性能上的胜利,我必须确保使用线程会做到这一点。

The point I want to make is this: I'm currently implementing a compiler (for a university project) and one of the extra features I wanted to add is the support for multi-threaded code in order to enhance the performance of the compiled program. Because some of the multi-threaded code will be automatically generated by the compiler itself, this will almost guarantee that there will be really tiny bits of multi-threaded code in it as well. In order to gain a performance win, I must be sure that using threads will make this happen.

我担心的是但是,为了使用线程,我的必须的使用系统调用和必要的中断。的微小的(自动生成的)线程因此将高度影响才能使这些系统调用的时刻,这甚至可能导致性能损失...

My fear however is that, in order to use threading, I must make system calls and the necessary interrupts. The tiny little (auto-generated) threads will therefore be highly affected by the time it takes to make these system calls, which could even lead to a performance loss...

所以我的问题是双重的(与它下面的一个额外的奖金问题):


  • 是否有可能写汇编
    code,可以运行多个线程
    同时上多个内核
    一次,的没有的需要制度
    电话?

  • 我会得到的性能增益,如果我真的有微小的线程(微作为线程的总执行时间),业绩亏损,或者是不是值得所有的付出?

我的猜测是,多线程汇编code是的的可能没有系统调用。即使是这种情况,你有一个建议(甚至更好:一些真正的code)?执行线程尽可能高效

My guess is that multithreaded assembler code is not possible without system calls. Even if this is the case, do you have a suggestion (or even better: some real code) for implementing threads as efficient as possible?

简短的回答是,你不能。当你编写汇编code它有且只有一个逻辑(即硬件)线程运行顺序(或分支机构)。如果你想要一些code来执行的其他逻辑线程(无论是在相同的核心,就在同一个CPU,甚至在不同的CPU不同内核),你需要有OS安装的其他线程的指令指针( CS:EIP )以指向你想要运行的code。这意味着,使用系统调用来获得操作系统做你想做的。

The short answer is that you can't. When you write assembly code it runs sequentially (or with branches) on one and only one logical (i.e. hardware) thread. If you want some of the code to execute on another logical thread (whether on the same core, on a different core on the same CPU or even on a different CPU), you need to have the OS set up the other thread's instruction pointer (CS:EIP) to point to the code you want to run. This implies using system calls to get the OS to do what you want.

这是你想要的,因为他们都在相同的硬件线程中运行的用户线程不会给你的线程支持。

User threads won't give you the threading support that you want, because they all run on the same hardware thread.

编辑:结合艾拉巴克斯特的回答与 Parlanse 的。如果你确保你的程序在每个逻辑线程一个线程运行,首先,那么你可以建立自己的调度程序,而无需依赖操作系统上。无论哪种方式,你需要一个调度程序来处理跳频从一个线程到另一个。呼叫调度之间,没有特殊的汇编指令来处理多线程。调度本身不能依赖于任何特殊的组装,而是在每个线程调度器部分之间的约定。

Incorporating Ira Baxter's answer with Parlanse. If you ensure that your program has a thread running in each logical thread to begin with, then you can build your own scheduler without relying on the OS. Either way, you need a scheduler to handle hopping from one thread to another. Between calls to the scheduler, there are no special assembly instructions to handle multi-threading. The scheduler itself can't rely on any special assembly, but rather on conventions between parts of the scheduler in each thread.

无论哪种方式,您是否使用的操作系统,你还是要依靠一些调度,以处理跨线程执行。

Either way, whether or not you use the OS, you still have to rely on some scheduler to handle cross-thread execution.