If you have any comment or update to the content, please contact the
original document maintainer directly. However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help. Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.
Chinese maintainer: 曾亮亮 <lianglaingzeng93@gmail.com>
---------------------------------------------------------------------
Documentation_powerpc_cpu_features.txt的中文翻译
如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。
中文版维护者:曾亮亮 <lianglaingzeng93@gmail.com>
中文版翻译者:曾亮亮 <lianglaingzeng93@gmail.com>
中文版校译者:曾亮亮 <lianglaingzeng93@gmail.com>
以下为正文
Hollis Blanchard <hollis@austin.ibm.com>
5 Jun 2002
This document describes the system (including self-modifying code) used in the
PPC Linux kernel to support a variety of PowerPC CPUs without requiring
compile-time selection.
这篇文档介绍了一种用于ppc的linux内核中可以支持多种PowerPC的处理器而不需要在编译的时候选择的系统(包括自定义的代码)。
Early in the boot process the ppc32 kernel detects the current CPU type and
chooses a set of features accordingly. Some examples include Altivec support,
split instruction and data caches, and if the CPU supports the DOZE and NAP
sleep modes.
早在启动过程中ppc32的内核就可以检测当前cpu的类型并选择一套相应的功能。
一些例子包括Altivec技术的支持,分裂指令和数据缓存,如果cpu支持DOZE和NAP睡眠模式。
Detection of the feature set is simple. A list of processors can be found in
arch/powerpc/kernel/cputable.c. The PVR register is masked and compared with
each value in the list. If a match is found, the cpu_features of cur_cpu_spec
is assigned to the feature bitmask for this processor and a __setup_cpu
function is called.
检测的功能设置很简单。处理器的列表可以在arch/powerpc/kernel/cputable.c中找到。
PVR寄存器是被隐藏起来的并与表中的每一个值相比较。如果匹配到一个相匹配的,
cur_cpu_spec的cpu功能将被分配给该处理器并且a__ setup_cpu的特征位掩码
函数会被调用。
C code may test 'cur_cpu_spec[smp_processor_id()]->cpu_features' for a
particular feature bit. This is done in quite a few places, for example
in ppc_setup_l2cr().
C代码可以为特定的功能位检测'cur_cpu_spec[smp_processor_id()]->cpu_features'。
这在很多的地方都用的到,例如ppc_setup_12cr()。
Implementing cpufeatures in assembly is a little more involved. There are
several paths that are performance-critical and would suffer if an array
index, structure dereference, and conditional branch were added. To avoid the
performance penalty but still allow for runtime (rather than compile-time) CPU
selection, unused code is replaced by 'nop' instructions. This nop'ing is
based on CPU 0's capabilities, so a multi-processor system with non-identical
processors will not work (but such a system would likely have other problems
anyways).
实现cpu组装功能需要多一点参与。有一些关键性能的路径可能会出错如果一个数组加入
指数,结构解应用引用,并且加入条件分支。为了避免性能损失但仍允许cpu选择在运行
时(而不是编译时),将未使用的代码用“NOP”指令代替。noping功能是基于cpu0的,所
以与之不同的多处理器系统将无法正常工作(不管怎么说这样的系统都是有问题的)。
After detecting the processor type, the kernel patches out sections of code
that shouldn't be used by writing nop's over it. Using cpufeatures requires
just 2 macros (found in arch/powerpc/include/asm/cputable.h), as seen in head.S
transfer_to_handler:
#ifdef CONFIG_ALTIVEC
BEGIN_FTR_SECTION
mfspr r22,SPRN_VRSAVE /* if G4, save vrsave register value */
stw r22,THREAD_VRSAVE(r23)
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
#endif /* CONFIG_ALTIVEC */
在检测出cpu类型之后,内核补丁的代码段不应该被使用与记录nop指令。使用CPU功能要求
仅有2个宏(在arch/ POWERPC/包括/ ASM/ cputable.h的的),在head.S transfer_to_handle
中可以看到:
#ifdef CONFIG_ALTIVEC
BEGIN_FTR_SECTION
mfspr r22,SPRN_VRSAVE /* if G4, save vrsave register value */
stw r22,THREAD_VRSAVE(r23)
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
#endif /* CONFIG_ALTIVEC */
If CPU 0 supports Altivec, the code is left untouched. If it doesn't, both
instructions are replaced with nop's.
如果cpu0支持Altivec,代码保持不变;如果不支持,全部指令将被nop代替。
The END_FTR_SECTION macro has two simpler variations: END_FTR_SECTION_IFSET
and END_FTR_SECTION_IFCLR. These simply test if a flag is set (in
cur_cpu_spec[0]->cpu_features) or is cleared, respectively. These two macros
should be used in the majority of cases.
END_FTR_SECTION宏有两个简单的变化:END_FTR_SECTION_IFSET和END_FTR_SECTION_IFCLR。
这个简单的测试如果设置一个标志位(in cur_cpu_spec[0]->cpu_features)或者被分别清除
掉。这两个宏在大多数情况下应该被使用。
The END_FTR_SECTION macros are implemented by storing information about this
code in the '__ftr_fixup' ELF section. When do_cpu_ftr_fixups
(arch/powerpc/kernel/misc.S) is invoked, it will iterate over the records in
__ftr_fixup, and if the required feature is not present it will loop writing
nop's from each BEGIN_FTR_SECTION to END_FTR_SECTION.
END_FTR_SECTION宏是在存储关于代码“_ftr_FIXUP”ELF时被使用的。当do_cpu_ftr_fixups
被调用时,它会遍历_ftr_fixup的记录,如果所需的功能是不存在的,它会循环写入
NOP的从每个BEGIN_FTR_SECTION END_FTR_SECTION。