为通用 x86/64 编译的 linux 内核与 Xeon 或其他内核之间有什么区别

What are differences between linux kernel compiled for generic x86/64 vs Xeon or others

在 linux 内核配置中有更改 CPU 系列的选项,大多数预编译内核是 generic x86/64.

我有一个 Xeon E3 CPU 所以我想知道如果我在那里选择 Core duo/Newer Xeon 会发生什么。

这里到底有什么区别?为我的 CPU 系列而不是通用内核编译内核有什么意义吗?针对 Xeon 优化的内核甚至可以在非 Xeon CPU 上运行吗?有人测量过性能等方面的差异吗?

它将select对应的配置选项(来自arch/x86/Kconfig.cpu):

config MCORE2
     bool "Core 2/newer Xeon"

一般来说,CONFIG_MCORE2 将在 32 位构建和 -march=core2 上启用编译器选项 -mtune=core2(它可以在 Makefile arch/x86/Makefilearch/x86/Makefile_32.cpu).

GCC 手册页中描述了这些选项:

-march=cpu-type

Generate instructions for the machine type cpu-type. In contrast to -mtune=cpu-type, which merely tunes the generated code for the specified cpu-type, -march=cpu-type allows GCC to generate code that may not run at all on processors other than the one indicated.

Specifying -march=cpu-type implies -mtune=cpu-type.

core2

Intel Core 2 CPU with 64-bit extensions, MMX, SSE, SSE2, SSE3 and SSSE3 instruction set support.

说到那个编译选项对应用程序性能的整体影响,应该是比较低的:

  • 在内核中,整体架构很重要。 IE。竞争锁可能很容易破坏性能,而无锁数据结构有助于获得性能。无论编译器选项如何,它们都能正常工作。
  • 内核中有少量操作需要通过该优化启用的 SIMD 操作(可能复制数组或字符串除外)。内核中根本没有 CPU 密集型操作。但是对缓存行大小的优化可能效果很好。
  • 对于非 内核绑定 的应用程序,它们大部分时间都在用户空间中度过,很少使用 系统调用 调用内核该优化的效果按比例降低。 IE。对于仅在内核中花费 10% 的应用程序,内核性能提高 2%,您将仅获得 0.2% 的整体性能提升。