洋红色内核中具有三个选项的 C 结构
C Structs with three options in the magenta kernel
在magenta内核中有一个段落,其中struct不仅有一个类型和名字,还有一个选项。我在参考资料中找不到任何内容来解释该语法。那么什么是 __CPU_ALIGN 作为 struct for 中的参数,我在哪里可以找到它的语法?
struct type name ???
#if WITH_SMP
/* a global state structure, aligned on cpu cache line to minimize aliasing */
struct mp_state mp __CPU_ALIGN = {
.hotplug_lock = MUTEX_INITIAL_VALUE(mp.hotplug_lock),
.ipi_task_lock = SPIN_LOCK_INITIAL_VALUE,
};
我知道 __CPU_ALIGN 本身用于为 CPU 内存大小对齐字节。
它是 aligned
attribute 的宏 shorthand,它是 GCC 扩展。
宏定义如下:
#define __CPU_ALIGN __ALIGNED(CACHE_LINE)
宏__ALIGNED又是这样定义的:
#define __ALIGNED(x) __attribute__((aligned(x)))
...与 GCC 文档中的语法匹配。 (CACHE_LINE 的值取决于架构。)
在magenta内核中有一个段落,其中struct不仅有一个类型和名字,还有一个选项。我在参考资料中找不到任何内容来解释该语法。那么什么是 __CPU_ALIGN 作为 struct for 中的参数,我在哪里可以找到它的语法?
struct type name ???
#if WITH_SMP
/* a global state structure, aligned on cpu cache line to minimize aliasing */
struct mp_state mp __CPU_ALIGN = {
.hotplug_lock = MUTEX_INITIAL_VALUE(mp.hotplug_lock),
.ipi_task_lock = SPIN_LOCK_INITIAL_VALUE,
};
我知道 __CPU_ALIGN 本身用于为 CPU 内存大小对齐字节。
它是 aligned
attribute 的宏 shorthand,它是 GCC 扩展。
宏定义如下:
#define __CPU_ALIGN __ALIGNED(CACHE_LINE)
宏__ALIGNED又是这样定义的:
#define __ALIGNED(x) __attribute__((aligned(x)))
...与 GCC 文档中的语法匹配。 (CACHE_LINE 的值取决于架构。)