简体   繁体   English

如何将 __attribute__((section(“name”))) 用于 per-cpu 全局变量

[英]How to use __attribute__((section(“name”))) for a per-cpu global variable

I have come accross code that uses __attribute__((section(“name”))) for per cpu global variables.我遇到了对每个 cpu 全局变量使用__attribute__((section(“name”)))的代码。 I have searched about it and have come to know that it is used for placing the data at a specified memory location with the help of linker scripts.我已经搜索过它并知道它用于在链接器脚本的帮助下将数据放置在指定的内存位置。 What I do not understand is how it can be used for per-cpu data - that is, if a global variable is placed inside a section defined with __attribute__((section(“name”))) , then every cpu has its own copy of this global variable.我不明白的是它如何用于per-cpu数据 - 也就是说,如果将全局变量放置在用__attribute__((section(“name”)))定义的__attribute__((section(“name”))) ,那么每个 cpu 都有自己的副本这个全局变量。 I may be wrong, but my intuition is that linker scripts are used along with __attribute__((section)) to make this happen.我可能错了,但我的直觉是链接器脚本与__attribute__((section))来实现这一点。 But I do not know how.但是我不知道怎么做。 A small working example, or a hint of how to realize this in code would be great.一个小的工作示例,或者如何在代码中实现这一点的提示会很棒。

Note: this question is with respect to the C language.注意:这个问题是关于 C 语言的。

The operating system/kernel initializes the hardware in such a way that the data at this memory location is not globally shared, but specific to each CPU.操作系统/内核以这样一种方式初始化硬件,即该内存位置的数据不是全局共享的,而是特定于每个 CPU 的。 Presumably, this is achieved by having slightly different page tables installed on each CPU.据推测,这是通过在每个 CPU 上安装略有不同的页表来实现的。 All the section attribute does is place the variable into that special memory region, but once the underlying hardware is configured to enable the lack of cross-CPU sharing, this is all it takes to make a variable CPU-specific. section 属性所做的就是将变量放入那个特殊的内存区域,但是一旦底层硬件被配置为允许缺少跨 CPU 共享,这就是使变量特定于 CPU 所需的全部内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 __attribute__((section("name"))) 用法? - __attribute__((section("name"))) usage? 如何获得像“top”命令一样的per-cpu统计信息(system,idle,nice,...)? - How do I get per-cpu stats (system, idle, nice, …) like the “top” command does? 如何在 GCC C 中使用 __attribute__ 关键字? - How to use the __attribute__ keyword in GCC C? gcc中如何正确使用__attribute__((fallthrough)) - How to use __attribute__((fallthrough)) correctly in gcc 删除使用 __attribute__((section)) 创建的部分 - Remove section created with __attribute__((section)) GCC 忽略 __attribute__((section("CCMRAM")))。 怎么修? - GCC ignores __attribute__((section("CCMRAM"))). How to fix? 将变量完全放在带有 __attribute__ ((section("STACK")) 的“STACK”部分有什么意义? - What might be the point in putting a variable exactly in the "STACK" section with __attribute__ ((section("STACK"))? 当我有每个CPU的数据结构时,是否可以提高性能以将它们放在不同的页面上? - When I have per-CPU data structures, does it improve performance to have them on different pages? gcc-使用#pragma将__attribute __((section(“。dflash_code”))))应用于整个源文件 - gcc - use #pragma to apply __attribute__((section(“.dflash_code”))) to entire source file avr-gcc:如何将 __attribute__((address)) 与 EEMEM 一起使用? - avr-gcc: How to use __attribute__((address)) with EEMEM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM