Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can we specify physical address for variable?
    primarykey
    data
    text
    <p>Any suggestions/discussions are welcome! </p> <p>The question is actually brief as title, but I'll explain why I need physical address.</p> <hr> <p><strong>Background</strong>: </p> <p>These days I'm fascinated by cache and multi-core architecture, and now I'm quite curious how cache influence our programs, under the parallel environment.</p> <p>In some CPU models (for example, my Intel Core Duo T5800), the L2 cache is shared among cores. So, if program A is accessing memory at physical address like </p> <p><code>0x00000000, 0x20000000, 0x40000000...</code> </p> <p>and program B accessing data at </p> <p><code>0x10000000, 0x30000000, 0x50000000...</code> </p> <p>Since these addresses share the same suffix, the related set in L2 cache will be flushed frequently. And we're expected to see two programs fighting with each other, reading data slowly from memory instead of cache, although, they are separated in different cores.</p> <p>Then I want to verify the result in practice. In this experiment, I have to know the physical address instead of virtual address. But how can I cope with this?</p> <hr> <p><strong>The first attempt:</strong> </p> <p>Eat a large space from heap, mask, and get the certain address.</p> <p>My CPU has a L2 cache with size=2048KB and associativity=8, so physical addressess like <code>0x12340000, 0x12380000, 0x123c0000</code> will be related to the first set in L2 cache.</p> <pre class="lang-cpp prettyprint-override"><code>int HEAP[200000000]={0}; int *v[2]; int main(int argc, char **argv) { v[0] = (int*)(((unsigned)(HEAP)+0x3fffc) &amp; 0xfffc0000); v[1] = (int*) ((unsigned)(v[0]) + 0x40000); // one program pollute v[0], another polluting v[1] } </code></pre> <p>Sadly, with the "help" of virtual memory, variable <code>HEAP</code> is not always continuous inside physical memory. <code>v[0]</code> and <code>v[1]</code> might be related to different cache sets.</p> <hr> <p><strong>The second attempt</strong></p> <p>access <code>/proc/self/mem</code>, and try to get memory information.</p> <p>Hmm... seems that the results are still about virtual memory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload