Is it possible to create threads without system calls in Linux x86 GAS assembly?

前端 未结 7 682
轮回少年
轮回少年 2020-12-07 12:30

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. The

相关标签:
7条回答
  • 2020-12-07 13:07

    If you want to gain performance, you'll have to leverage kernel threads. Only the kernel can help you get code running simultaneously on more than one CPU core. Unless your program is I/O bound (or performing other blocking operations), performing user-mode cooperative multithreading (also known as fibers) is not going to gain you any performance. You'll just be performing extra context switches, but the one CPU that your real thread is running will still be running at 100% either way.

    System calls have gotten faster. Modern CPUs have support for the sysenter instruction, which is significantly faster than the old int instruction. See also this article for how Linux does system calls in the fastest way possible.

    Make sure that the automatically-generated multithreading has the threads run for long enough that you gain performance. Don't try to parallelize short pieces of code, you'll just waste time spawning and joining threads. Also be wary of memory effects (although these are harder to measure and predict) -- if multiple threads are accessing independent data sets, they will run much faster than if they were accessing the same data repeatedly due to the cache coherency problem.

    0 讨论(0)
提交回复
热议问题