<bdo id='cxDe1'></bdo><ul id='cxDe1'></ul>

    <legend id='cxDe1'><style id='cxDe1'><dir id='cxDe1'><q id='cxDe1'></q></dir></style></legend>

      <tfoot id='cxDe1'></tfoot>

      <small id='cxDe1'></small><noframes id='cxDe1'>

      1. <i id='cxDe1'><tr id='cxDe1'><dt id='cxDe1'><q id='cxDe1'><span id='cxDe1'><b id='cxDe1'><form id='cxDe1'><ins id='cxDe1'></ins><ul id='cxDe1'></ul><sub id='cxDe1'></sub></form><legend id='cxDe1'></legend><bdo id='cxDe1'><pre id='cxDe1'><center id='cxDe1'></center></pre></bdo></b><th id='cxDe1'></th></span></q></dt></tr></i><div id='cxDe1'><tfoot id='cxDe1'></tfoot><dl id='cxDe1'><fieldset id='cxDe1'></fieldset></dl></div>

        __builtin___clear_cache 是如何工作的?

        时间:2023-09-18

              <i id='wlv0v'><tr id='wlv0v'><dt id='wlv0v'><q id='wlv0v'><span id='wlv0v'><b id='wlv0v'><form id='wlv0v'><ins id='wlv0v'></ins><ul id='wlv0v'></ul><sub id='wlv0v'></sub></form><legend id='wlv0v'></legend><bdo id='wlv0v'><pre id='wlv0v'><center id='wlv0v'></center></pre></bdo></b><th id='wlv0v'></th></span></q></dt></tr></i><div id='wlv0v'><tfoot id='wlv0v'></tfoot><dl id='wlv0v'><fieldset id='wlv0v'></fieldset></dl></div>
                <legend id='wlv0v'><style id='wlv0v'><dir id='wlv0v'><q id='wlv0v'></q></dir></style></legend>
                  <tbody id='wlv0v'></tbody>

                <small id='wlv0v'></small><noframes id='wlv0v'>

                <tfoot id='wlv0v'></tfoot>
                • <bdo id='wlv0v'></bdo><ul id='wlv0v'></ul>
                  本文介绍了__builtin___clear_cache 是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  通过 gcc 文档,我偶然发现了内置函数 __builtin___clear_cache.

                  Going through the gcc documentation, I stumbled into the builtin function __builtin___clear_cache.

                  ——内置函数:void __builtin____clear_cache (char *begin, char*end) 此函数用于刷新处理器的指令缓存,用于开始包含和结束不包含之间的内存区域.某些目标要求刷新指令缓存,之后修改包含代码的内存,以获得确定性行为.

                  — Built-in Function: void __builtin___clear_cache (char *begin, char *end) This function is used to flush the processor's instruction cache for the region of memory between begin inclusive and end exclusive. Some targets require that the instruction cache be flushed, after modifying memory containing code, in order to obtain deterministic behavior.

                  如果目标不需要指令缓存刷新,__builtin___clear_cache 没有效果.否则,要么内联发出指令以清除指令缓存,要么调用libgcc中的__clear_cache函数制作完成.

                  If the target does not require instruction cache flushes, __builtin___clear_cache has no effect. Otherwise either instructions are emitted in-line to clear the instruction cache or a call to the __clear_cache function in libgcc is made.

                  我觉得这很有趣,但令人惊讶.在很多情况下,当前堆栈的大量指令存储在 L1 缓存(指令缓存)中.因此,乍一看,这个内置函数可能会严重破坏我们程序的流程,因为它会清除堆栈中的下一条指令.

                  I find this interesting, but surprising. In many cases, a large number of the instructions for the current stack is stored in the L1 cache (instruction cache). So it would seem at first glance that this builtin could corrupt significantly the flow of our program, by making it wipe out the next instructions on the stack.

                  这条指令是否也重新填充了 L1 缓存中的堆栈部分?

                  Does this instruction also repopulates the part of the stack that was in the L1 cache?

                  这似乎不太可能.如果没有,那么我想用户有责任使用正确的 beginend 参数,以免破坏我们的进程.在实践中,如何找到正确的 beginend 使用?

                  This seems unlikely. If it does not, then I suppose the onus is on the user to use the right begin and end arguments, so as to not corrupt our process. In practice, how could one find what the right begin and end to use?

                  推荐答案

                  它只是在需要它们的目标处理器上发出一些奇怪的机器指令 [s](x86 不需要).

                  It is just emitting some weird machine instruction[s] on target processors requiring them (x86 don't need that).

                  __builtin___clear_cache 视为刷新指令缓存的可移植"(对 GCC 和兼容编译器)方式(例如在某些 JIT 库).

                  Think of __builtin___clear_cache as a "portable" (to GCC and compatible compilers) way to flush the instruction cache (e.g. in some JIT library).

                  在实践中,如何找到正确的开始和结束使用?

                  In practice, how could one find what the right begin and end to use?

                  为了安全起见,我会在某些页面范围内使用它(例如,通过 sysconf(_SC_PAGESIZE).... 获得),所以通常是 4Kbyte 对齐的内存范围(4Kbyte 的倍数).否则,您需要一些特定于目标的技巧来找到缓存线宽...

                  To be safe, I would use that on some page range (e.g. obtained with sysconf(_SC_PAGESIZE)....), so usually a 4Kbyte aligned memory range (multiple of 4Kbyte). Otherwise, you want some target specific trick to find the cache line width...

                  在 Linux 上,您可以阅读 /proc/cpuinfo 并使用 cache_alignment &cache_size 行以获得更精确的缓存行大小和对齐方式.

                  On Linux, you might read /proc/cpuinfo and use the cache_alignment & cache_size lines to get a more precise cache line size and alignment.

                  顺便说一句,使用 __builtin__clear_cache 的代码很可能(出于其他原因)特定于目标机器,因此它具有或知道一些机器参数(并且应该包括缓存大小和对齐).

                  BTW, a code using __builtin__clear_cache is very likely to be (for other reasons) target machine specific, so it has or knows some machine parameters (and that should include cache size & alignment).

                  这篇关于__builtin___clear_cache 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 std::unordered_map 很慢,我可以更有效地使用 下一篇:当前的 x86 架构是否支持非临时加载(来自“正常

                  相关文章

                  最新文章

                  <legend id='LJ9Nb'><style id='LJ9Nb'><dir id='LJ9Nb'><q id='LJ9Nb'></q></dir></style></legend>
                  <i id='LJ9Nb'><tr id='LJ9Nb'><dt id='LJ9Nb'><q id='LJ9Nb'><span id='LJ9Nb'><b id='LJ9Nb'><form id='LJ9Nb'><ins id='LJ9Nb'></ins><ul id='LJ9Nb'></ul><sub id='LJ9Nb'></sub></form><legend id='LJ9Nb'></legend><bdo id='LJ9Nb'><pre id='LJ9Nb'><center id='LJ9Nb'></center></pre></bdo></b><th id='LJ9Nb'></th></span></q></dt></tr></i><div id='LJ9Nb'><tfoot id='LJ9Nb'></tfoot><dl id='LJ9Nb'><fieldset id='LJ9Nb'></fieldset></dl></div>
                    <tfoot id='LJ9Nb'></tfoot>

                    <small id='LJ9Nb'></small><noframes id='LJ9Nb'>

                      <bdo id='LJ9Nb'></bdo><ul id='LJ9Nb'></ul>