mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 03:01:36 +01:00
This commit is contained in:
168
index.html
168
index.html
@@ -1082,8 +1082,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<ul class="sectlevel4">
|
||||
<li><a href="#number-of-cores">18.2.2.1. Number of cores</a>
|
||||
<ul class="sectlevel5">
|
||||
<li><a href="#number-of-cores-in-qemu-user-mode">18.2.2.1.1. Number of cores in QEMU user mode</a></li>
|
||||
<li><a href="#number-of-cores-in-gem5-user-mode">18.2.2.1.2. Number of cores in gem5 user mode</a></li>
|
||||
<li><a href="#qemu-user-mode-multithreading">18.2.2.1.1. QEMU user mode multithreading</a></li>
|
||||
<li><a href="#gem5-syscall-emulation-multithreading">18.2.2.1.2. gem5 syscall emulation multithreading</a></li>
|
||||
<li><a href="#gem5-se-py-user-mode-with-2-or-more-pthreads-fails-with-because-simulate-limit-reached">18.2.2.1.3. gem5 se.py user mode with 2 or more pthreads fails with because simulate() limit reached</a></li>
|
||||
<li><a href="#gem5-arm-full-system-with-more-than-8-cores">18.2.2.1.4. gem5 ARM full system with more than 8 cores</a></li>
|
||||
</ul>
|
||||
@@ -1168,25 +1168,26 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#gem5-python-scripts-without-rebuild">18.11. gem5 Python scripts without rebuild</a></li>
|
||||
<li><a href="#gem5-fs_biglittle">18.12. gem5 fs_bigLITTLE</a></li>
|
||||
<li><a href="#gem5-unit-tests">18.13. gem5 unit tests</a></li>
|
||||
<li><a href="#gem5-simulate-limit-reached">18.14. gem5 simulate() limit reached</a></li>
|
||||
<li><a href="#gem5-build-options">18.15. gem5 build options</a>
|
||||
<li><a href="#gem5-regression-tests">18.14. gem5 regression tests</a></li>
|
||||
<li><a href="#gem5-simulate-limit-reached">18.15. gem5 simulate() limit reached</a></li>
|
||||
<li><a href="#gem5-build-options">18.16. gem5 build options</a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#gem5-debug-build">18.15.1. gem5 debug build</a></li>
|
||||
<li><a href="#gem5-clang-build">18.15.2. gem5 clang build</a></li>
|
||||
<li><a href="#gem5-sanitation-build">18.15.3. gem5 sanitation build</a></li>
|
||||
<li><a href="#gem5-ruby-build">18.15.4. gem5 Ruby build</a></li>
|
||||
<li><a href="#gem5-python-3-build">18.15.5. gem5 Python 3 build</a></li>
|
||||
<li><a href="#gem5-debug-build">18.16.1. gem5 debug build</a></li>
|
||||
<li><a href="#gem5-clang-build">18.16.2. gem5 clang build</a></li>
|
||||
<li><a href="#gem5-sanitation-build">18.16.3. gem5 sanitation build</a></li>
|
||||
<li><a href="#gem5-ruby-build">18.16.4. gem5 Ruby build</a></li>
|
||||
<li><a href="#gem5-python-3-build">18.16.5. gem5 Python 3 build</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#gem5-cpu-types">18.16. gem5 CPU types</a>
|
||||
<li><a href="#gem5-cpu-types">18.17. gem5 CPU types</a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#gem5-arm-rsk">18.16.1. gem5 ARM RSK</a></li>
|
||||
<li><a href="#gem5-arm-rsk">18.17.1. gem5 ARM RSK</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#gem5-arm-platforms">18.17. gem5 ARM platforms</a></li>
|
||||
<li><a href="#gem5-internals">18.18. gem5 internals</a>
|
||||
<li><a href="#gem5-arm-platforms">18.18. gem5 ARM platforms</a></li>
|
||||
<li><a href="#gem5-internals">18.19. gem5 internals</a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#gem5-python-c-interaction">18.18.1. gem5 Python C++ interaction</a></li>
|
||||
<li><a href="#gem5-python-c-interaction">18.19.1. gem5 Python C++ interaction</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -1231,10 +1232,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#gcc-c-extensions">20.1.2. GCC C extensions</a>
|
||||
<li><a href="#c-multithreading">20.1.2. C multithreading</a></li>
|
||||
<li><a href="#gcc-c-extensions">20.1.3. GCC C extensions</a>
|
||||
<ul class="sectlevel4">
|
||||
<li><a href="#c-empty-struct">20.1.2.1. C empty struct</a></li>
|
||||
<li><a href="#openmp">20.1.2.2. OpenMP</a></li>
|
||||
<li><a href="#c-empty-struct">20.1.3.1. C empty struct</a></li>
|
||||
<li><a href="#openmp">20.1.3.2. OpenMP</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -1267,6 +1269,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#c-debugging">20.5. C debugging</a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#stack-smashing">20.5.1. Stack smashing</a></li>
|
||||
<li><a href="#memory-leaks">20.5.2. Memory leaks</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#userland-content-bibliography">20.6. Userland content bibliography</a></li>
|
||||
@@ -3700,7 +3703,7 @@ echo "$(./getvar --arch aarch64 --emulator gem5 image)"</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>see also: <a href="#gem5-arm-platforms">Section 18.17, “gem5 ARM platforms”</a>.</p>
|
||||
<p>see also: <a href="#gem5-arm-platforms">Section 18.18, “gem5 ARM platforms”</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This generates yet new separate images with new magic constants:</p>
|
||||
@@ -7629,7 +7632,7 @@ time \
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-syscall-emulation-mode-syscall-tracing"><a class="anchor" href="#gem5-syscall-emulation-mode-syscall-tracing"></a><a class="link" href="#gem5-syscall-emulation-mode-syscall-tracing">10.6.4. gem5 syscall emulation mode syscall tracing</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>Since gem5 has to implement syscalls itself in syscall emulation mode, it can of course clearly see which syscalls are bing made, and we can log them for debug purposes with <a href="#gem5-tracing">gem5 tracing</a>, e.g.:</p>
|
||||
<p>Since gem5 has to implement syscalls itself in syscall emulation mode, it can of course clearly see which syscalls are being made, and we can log them for debug purposes with <a href="#gem5-tracing">gem5 tracing</a>, e.g.:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
@@ -17628,7 +17631,7 @@ getconf _NPROCESSORS_CONF</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="number-of-cores-in-qemu-user-mode"><a class="anchor" href="#number-of-cores-in-qemu-user-mode"></a><a class="link" href="#number-of-cores-in-qemu-user-mode">18.2.2.1.1. Number of cores in QEMU user mode</a></h6>
|
||||
<h6 id="qemu-user-mode-multithreading"><a class="anchor" href="#qemu-user-mode-multithreading"></a><a class="link" href="#qemu-user-mode-multithreading">18.2.2.1.1. QEMU user mode multithreading</a></h6>
|
||||
<div class="paragraph">
|
||||
<p>TODO why in <a href="#user-mode-simulation">User mode simulation</a> QEMU always shows the number of cores of the host. E.g., both of the following output the same as <code>nproc</code> on the host:</p>
|
||||
</div>
|
||||
@@ -17659,9 +17662,9 @@ ps Haux | grep qemu | wc</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="number-of-cores-in-gem5-user-mode"><a class="anchor" href="#number-of-cores-in-gem5-user-mode"></a><a class="link" href="#number-of-cores-in-gem5-user-mode">18.2.2.1.2. Number of cores in gem5 user mode</a></h6>
|
||||
<h6 id="gem5-syscall-emulation-multithreading"><a class="anchor" href="#gem5-syscall-emulation-multithreading"></a><a class="link" href="#gem5-syscall-emulation-multithreading">18.2.2.1.2. gem5 syscall emulation multithreading</a></h6>
|
||||
<div class="paragraph">
|
||||
<p>gem5 user mode multi core has been particularly flaky compared <a href="#number-of-cores-in-qemu-user-mode">to QEMU’s</a>.</p>
|
||||
<p>gem5 user mode multithreading has been particularly flaky compared <a href="#qemu-user-mode-multithreading">to QEMU’s</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>You have the limitation that you must have at least one core per guest thread, otherwise <code>pthread_create</code> fails. For example:</p>
|
||||
@@ -19837,20 +19840,26 @@ clock=500</pre>
|
||||
<div class="paragraph">
|
||||
<p>Note that the command and it’s corresponding results don’t need to show consecutively on stdout because tests are run in parallel. You just have to match them based on the class name <code>CircleBufTest</code> to the file <code>circlebuf.test.cpp</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-regression-tests"><a class="anchor" href="#gem5-regression-tests"></a><a class="link" href="#gem5-regression-tests">18.14. gem5 regression tests</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>Running the larger regression tests is exposed with:</p>
|
||||
<p><a href="https://stackoverflow.com/questions/52279971/how-to-run-the-gem5-unit-tests" class="bare">https://stackoverflow.com/questions/52279971/how-to-run-the-gem5-unit-tests</a></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Running the larger 2019 regression tests is exposed for example with:</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./build-gem5 --regression-test quick/fs</pre>
|
||||
<pre>./gem5-regression --arch aarch64 -- --length quick</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>but TODO: those require magic blobs on <code>M5_PATH</code> that we don’t currently automate.</p>
|
||||
<p>TODO skip the build by default with <code>--skip-build</code> since we already manage it with <code>./build-gem5</code>. But we can’t do this because it is the build step that downloads the test binaries. We need to find a way to either download the binaries without building, or to pass the exact same scons build options through <code>test/main.py</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-simulate-limit-reached"><a class="anchor" href="#gem5-simulate-limit-reached"></a><a class="link" href="#gem5-simulate-limit-reached">18.14. gem5 simulate() limit reached</a></h3>
|
||||
<h3 id="gem5-simulate-limit-reached"><a class="anchor" href="#gem5-simulate-limit-reached"></a><a class="link" href="#gem5-simulate-limit-reached">18.15. gem5 simulate() limit reached</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>This error happens when the following instruction limits are reached:</p>
|
||||
</div>
|
||||
@@ -19979,18 +19988,18 @@ Exiting @ tick 18446744073709551615 because simulate() limit reached</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-build-options"><a class="anchor" href="#gem5-build-options"></a><a class="link" href="#gem5-build-options">18.15. gem5 build options</a></h3>
|
||||
<h3 id="gem5-build-options"><a class="anchor" href="#gem5-build-options"></a><a class="link" href="#gem5-build-options">18.16. gem5 build options</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>In order to use different build options, you might also want to use <a href="#gem5-build-variants">gem5 build variants</a> to keep the build outputs separate from one another.</p>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-debug-build"><a class="anchor" href="#gem5-debug-build"></a><a class="link" href="#gem5-debug-build">18.15.1. gem5 debug build</a></h4>
|
||||
<h4 id="gem5-debug-build"><a class="anchor" href="#gem5-debug-build"></a><a class="link" href="#gem5-debug-build">18.16.1. gem5 debug build</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>Explained at: <a href="#debug-the-emulator">Section 17.7, “Debug the emulator”</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-clang-build"><a class="anchor" href="#gem5-clang-build"></a><a class="link" href="#gem5-clang-build">18.15.2. gem5 clang build</a></h4>
|
||||
<h4 id="gem5-clang-build"><a class="anchor" href="#gem5-clang-build"></a><a class="link" href="#gem5-clang-build">18.16.2. gem5 clang build</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>TODO test properly, benchmark vs GCC.</p>
|
||||
</div>
|
||||
@@ -20003,7 +20012,7 @@ Exiting @ tick 18446744073709551615 because simulate() limit reached</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-sanitation-build"><a class="anchor" href="#gem5-sanitation-build"></a><a class="link" href="#gem5-sanitation-build">18.15.3. gem5 sanitation build</a></h4>
|
||||
<h4 id="gem5-sanitation-build"><a class="anchor" href="#gem5-sanitation-build"></a><a class="link" href="#gem5-sanitation-build">18.16.3. gem5 sanitation build</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>If there gem5 appears to have a C++ undefined behaviour bug, which is often very difficult to track down, you can try to build it with the following extra SCons options:</p>
|
||||
</div>
|
||||
@@ -20065,7 +20074,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-ruby-build"><a class="anchor" href="#gem5-ruby-build"></a><a class="link" href="#gem5-ruby-build">18.15.4. gem5 Ruby build</a></h4>
|
||||
<h4 id="gem5-ruby-build"><a class="anchor" href="#gem5-ruby-build"></a><a class="link" href="#gem5-ruby-build">18.16.4. gem5 Ruby build</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>Ruby is a system that includes the SLICC domain specific language to describe memory systems: <a href="http://gem5.org/Ruby" class="bare">http://gem5.org/Ruby</a></p>
|
||||
</div>
|
||||
@@ -20119,7 +20128,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-python-3-build"><a class="anchor" href="#gem5-python-3-build"></a><a class="link" href="#gem5-python-3-build">18.15.5. gem5 Python 3 build</a></h4>
|
||||
<h4 id="gem5-python-3-build"><a class="anchor" href="#gem5-python-3-build"></a><a class="link" href="#gem5-python-3-build">18.16.5. gem5 Python 3 build</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>Python 3 support was mostly added in 2019 Q3 at arounda347a1a68b8a6e370334be3a1d2d66675891e0f1 but remained buggy for some time afterwards.</p>
|
||||
</div>
|
||||
@@ -20137,7 +20146,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-cpu-types"><a class="anchor" href="#gem5-cpu-types"></a><a class="link" href="#gem5-cpu-types">18.16. gem5 CPU types</a></h3>
|
||||
<h3 id="gem5-cpu-types"><a class="anchor" href="#gem5-cpu-types"></a><a class="link" href="#gem5-cpu-types">18.17. gem5 CPU types</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>gem5 has a few in tree CPU models for different purposes. In fs.py and se.py, those are selectable with the <code>--cpu-type</code> option. Here is an overview of the most interesting ones:</p>
|
||||
</div>
|
||||
@@ -20157,7 +20166,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>MinorCPU</code>: in-order core. Its 4 stage pipeline is described at the "MinorCPU" section of <a href="#gem5-arm-rsk">gem5 ARM RSK</a>.</p>
|
||||
<p><code>MinorCPU</code>: in-order core. The weird name "Minor" stands for "M (TODO what is M) IN ONder". Its 4 stage pipeline is described at the "MinorCPU" section of <a href="#gem5-arm-rsk">gem5 ARM RSK</a>. As of 2019, in-order cores are mostly present in low power / cost contexts, for example little cores of <a href="https://en.wikipedia.org/wiki/ARM_big.LITTLE">ARM bigLITTLE</a>.</p>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
@@ -20172,7 +20181,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</ul>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-arm-rsk"><a class="anchor" href="#gem5-arm-rsk"></a><a class="link" href="#gem5-arm-rsk">18.16.1. gem5 ARM RSK</a></h4>
|
||||
<h4 id="gem5-arm-rsk"><a class="anchor" href="#gem5-arm-rsk"></a><a class="link" href="#gem5-arm-rsk">18.17.1. gem5 ARM RSK</a></h4>
|
||||
<div class="paragraph">
|
||||
<p><a href="https://github.com/arm-university/arm-gem5-rsk/blob/aa3b51b175a0f3b6e75c9c856092ae0c8f2a7cdc/gem5_rsk.pdf" class="bare">https://github.com/arm-university/arm-gem5-rsk/blob/aa3b51b175a0f3b6e75c9c856092ae0c8f2a7cdc/gem5_rsk.pdf</a></p>
|
||||
</div>
|
||||
@@ -20182,7 +20191,7 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-arm-platforms"><a class="anchor" href="#gem5-arm-platforms"></a><a class="link" href="#gem5-arm-platforms">18.17. gem5 ARM platforms</a></h3>
|
||||
<h3 id="gem5-arm-platforms"><a class="anchor" href="#gem5-arm-platforms"></a><a class="link" href="#gem5-arm-platforms">18.18. gem5 ARM platforms</a></h3>
|
||||
<div class="paragraph">
|
||||
<p>The gem5 platform is selectable with the <code>--machine</code> option, which is named after the analogous QEMU <code>-machine</code> option, and which sets the <code>--machine-type</code>.</p>
|
||||
</div>
|
||||
@@ -20210,9 +20219,9 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from:
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="gem5-internals"><a class="anchor" href="#gem5-internals"></a><a class="link" href="#gem5-internals">18.18. gem5 internals</a></h3>
|
||||
<h3 id="gem5-internals"><a class="anchor" href="#gem5-internals"></a><a class="link" href="#gem5-internals">18.19. gem5 internals</a></h3>
|
||||
<div class="sect3">
|
||||
<h4 id="gem5-python-c-interaction"><a class="anchor" href="#gem5-python-c-interaction"></a><a class="link" href="#gem5-python-c-interaction">18.18.1. gem5 Python C++ interaction</a></h4>
|
||||
<h4 id="gem5-python-c-interaction"><a class="anchor" href="#gem5-python-c-interaction"></a><a class="link" href="#gem5-python-c-interaction">18.19.1. gem5 Python C++ interaction</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>The interaction uses the Python C extension interface <a href="https://docs.python.org/2/extending/extending.html" class="bare">https://docs.python.org/2/extending/extending.html</a> interface through the pybind11 helper library: <a href="https://github.com/pybind/pybind11" class="bare">https://github.com/pybind/pybind11</a></p>
|
||||
</div>
|
||||
@@ -21028,7 +21037,7 @@ git -C "$(./getvar qemu_source_dir)" checkout -
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/infinite_loop.c">userland/c/infinite_loop.c</a></p>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/loop.c">userland/c/loop.c</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -21044,7 +21053,10 @@ git -C "$(./getvar qemu_source_dir)" checkout -
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/malloc.c">userland/c/malloc.c</a>: <code>malloc</code> hello world: allocate two ints and use them.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>LInux 5.1 / glibc 2.29 implements it with the <a href="#mmap"><code>mmap</code> system call</a>.</p>
|
||||
<p>Linux 5.1 / glibc 2.29 implements it with the <a href="#mmap"><code>mmap</code> system call</a>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><code>malloc</code> leads to the infinite joys of <a href="#memory-leaks">Memory leaks</a>.</p>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="malloc-implementation"><a class="anchor" href="#malloc-implementation"></a><a class="link" href="#malloc-implementation">20.1.1.1. malloc implementation</a></h5>
|
||||
@@ -21181,9 +21193,32 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gcc-c-extensions"><a class="anchor" href="#gcc-c-extensions"></a><a class="link" href="#gcc-c-extensions">20.1.2. GCC C extensions</a></h4>
|
||||
<h4 id="c-multithreading"><a class="anchor" href="#c-multithreading"></a><a class="link" href="#c-multithreading">20.1.2. C multithreading</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>Added in C11!</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/atomic.c">userland/c/atomic.c</a>: <code>atomic_int</code> and <code>thrd_create</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Bibliography:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/3908031/how-to-multithread-c-code/52453354#52453354" class="bare">https://stackoverflow.com/questions/3908031/how-to-multithread-c-code/52453354#52453354</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="gcc-c-extensions"><a class="anchor" href="#gcc-c-extensions"></a><a class="link" href="#gcc-c-extensions">20.1.3. GCC C extensions</a></h4>
|
||||
<div class="sect4">
|
||||
<h5 id="c-empty-struct"><a class="anchor" href="#c-empty-struct"></a><a class="link" href="#c-empty-struct">20.1.2.1. C empty struct</a></h5>
|
||||
<h5 id="c-empty-struct"><a class="anchor" href="#c-empty-struct"></a><a class="link" href="#c-empty-struct">20.1.3.1. C empty struct</a></h5>
|
||||
<div class="paragraph">
|
||||
<p>Example: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/gcc/empty_struct.c">userland/gcc/empty_struct.c</a></p>
|
||||
</div>
|
||||
@@ -21195,7 +21230,7 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="openmp"><a class="anchor" href="#openmp"></a><a class="link" href="#openmp">20.1.2.2. OpenMP</a></h5>
|
||||
<h5 id="openmp"><a class="anchor" href="#openmp"></a><a class="link" href="#openmp">20.1.3.2. OpenMP</a></h5>
|
||||
<div class="paragraph">
|
||||
<p>GCC implements the <a href="#openmp">OpenMP</a> threading implementation: <a href="https://stackoverflow.com/questions/3949901/pthreads-vs-openmp" class="bare">https://stackoverflow.com/questions/3949901/pthreads-vs-openmp</a></p>
|
||||
</div>
|
||||
@@ -21245,16 +21280,6 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/cpp/if_constexpr.cpp">userland/cpp/if_constexpr.cpp</a>: C++17 <code>if constexpr</code></p>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/12160765/if-else-at-compile-time-in-c/54647315#54647315" class="bare">https://stackoverflow.com/questions/12160765/if-else-at-compile-time-in-c/54647315#54647315</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://stackoverflow.com/questions/37617677/implementing-a-compile-time-static-if-logic-for-different-string-types-in-a-co" class="bare">https://stackoverflow.com/questions/37617677/implementing-a-compile-time-static-if-logic-for-different-string-types-in-a-co</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -21275,6 +21300,12 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/cpp/thread_hardware_concurrency.cpp">userland/cpp/thread_hardware_concurrency.cpp</a> <code>std::thread::hardware_concurrency</code></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/cpp/thread_get_id.cpp">userland/cpp/thread_get_id.cpp</a> <code>std::thread::get_id</code></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/cpp/thread_return_value.cpp">userland/cpp/thread_return_value.cpp</a>: how to return a value from a thread</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
@@ -21457,6 +21488,9 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="#c-multithreading">C multithreading</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="#cpp-multithreading">C++ multithreading</a></p>
|
||||
</li>
|
||||
<li>
|
||||
@@ -21483,10 +21517,10 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="#number-of-cores-in-qemu-user-mode">Number of cores in QEMU user mode</a></p>
|
||||
<p><a href="#qemu-user-mode-multithreading">QEMU user mode multithreading</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="#number-of-cores-in-gem5-user-mode">Number of cores in gem5 user mode</a></p>
|
||||
<p><a href="#gem5-syscall-emulation-multithreading">gem5 syscall emulation multithreading</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -21504,8 +21538,25 @@ echo 1 > /proc/sys/vm/overcommit_memory
|
||||
<div class="paragraph">
|
||||
<p><a href="https://stackoverflow.com/questions/1345670/stack-smashing-detected/51897264#51897264" class="bare">https://stackoverflow.com/questions/1345670/stack-smashing-detected/51897264#51897264</a></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<div class="dlist">
|
||||
<dl>
|
||||
<dt class="hdlist1">Example</dt>
|
||||
<dd>
|
||||
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/smash_stack.c">userland/c/smash_stack.c</a></p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Leads to the dreadful "Stack smashing detected" message. Which is infinitely better than a silent break in any case.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="memory-leaks"><a class="anchor" href="#memory-leaks"></a><a class="link" href="#memory-leaks">20.5.2. Memory leaks</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>How to debug: <a href="https://stackoverflow.com/questions/6261201/how-to-find-memory-leak-in-a-c-code-project/57877190#57877190" class="bare">https://stackoverflow.com/questions/6261201/how-to-find-memory-leak-in-a-c-code-project/57877190#57877190</a></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Example: <a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/userland/c/memory_leak.c">userland/c/memory_leak.c</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -27815,6 +27866,9 @@ cntv_cval_el0 0xB439642</pre>
|
||||
<p>and new <code>IRQ number</code> section appears every second, when a clock interrupt is raised!</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>TODO make work on gem5. Fails with <a href="#gem5-simulate-limit-reached">gem5 simulate() limit reached</a> at the first WFI done in main, which means that the interrupt is never raised.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Once an interrupt is raised, the interrupt itself sets up a new interrupt to happen in one second in the future after <code>cntv_cval_el0</code> is reached by the counter.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
@@ -30057,7 +30111,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>./run --eval-after './sample_package.out'</pre>
|
||||
<pre>./run --eval-after '/sample_package.out'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
|
||||
Reference in New Issue
Block a user