Documented Platform::get_core_count

This commit is contained in:
Graham Nelson 2020-07-18 08:44:10 +01:00
parent 86ce0d6d6d
commit 62d102e7bf
7 changed files with 37 additions and 17 deletions

View file

@ -1,6 +1,6 @@
# Inweb 7
v7-alpha.1+1A56 'Escape to Danger' (16 July 2020)
v7-alpha.1+1A57 'Escape to Danger' (18 July 2020)
## About Inweb

View file

@ -1,3 +1,3 @@
Prerelease: alpha.1
Build Date: 16 July 2020
Build Number: 1A56
Build Date: 18 July 2020
Build Number: 1A57

View file

@ -500,8 +500,14 @@ differently on Windows.
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This paragraph is used only if PLATFORM_POSIX is defined.</li><li>The function Platform::create_thread is used in Windows Platform (<a href="1-wp.html#SP15">&#167;15</a>).</li><li>The function Platform::join_thread is used in Windows Platform (<a href="1-wp.html#SP15">&#167;15</a>).</li><li>The function Platform::init_thread is used in Windows Platform (<a href="1-wp.html#SP15">&#167;15</a>).</li><li>The function Platform::get_thread_stack_size is used in Windows Platform (<a href="1-wp.html#SP15">&#167;15</a>).</li></ul>
<p class="commentary firstcommentary"><a id="SP23"></a><b>&#167;23. </b>It's not easy to find a function which reliably returns the core count.
Linux provides <span class="extract"><span class="extract-syntax">sys/sysinfo.h</span></span>, but this header is a POSIX extension which
<p class="commentary firstcommentary"><a id="SP23"></a><b>&#167;23. </b>This function returns the number of logical cores in the host computer &mdash;
i.e., twice the number of physical cores if there's hyperthreading. The
result is used as a guess for an appropriate number of simultaneous threads
to launch.
</p>
<p class="commentary">It's not easy to find a function which reliably does this on all POSIX platforms.
On Linux we can use <span class="extract"><span class="extract-syntax">sys/sysinfo.h</span></span>, but this header is a POSIX extension which
MacOS does not support.
</p>
@ -519,7 +525,8 @@ MacOS does not support.
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This paragraph is used only if PLATFORM_LINUX and PLATFORM_POSIX are defined.</li><li>The function Platform::get_core_count is used in <a href="1-pp.html#SP26">&#167;26</a>, <a href="1-pp.html#SP27">&#167;27</a>, Windows Platform (<a href="1-wp.html#SP16">&#167;16</a>).</li></ul>
<p class="commentary firstcommentary"><a id="SP25"></a><b>&#167;25. </b></p>
<p class="commentary firstcommentary"><a id="SP25"></a><b>&#167;25. </b>While MacOS lacks <span class="extract"><span class="extract-syntax">sysinfo.h</span></span>, it does have <span class="extract"><span class="extract-syntax">sysctl.h</span></span>:
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">#</span><span class="identifier-syntax">include</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;sys/sysctl.h&gt;</span>
@ -537,7 +544,8 @@ MacOS does not support.
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This paragraph is used only if PLATFORM_MACOS and PLATFORM_POSIX are defined.</li><li>The function Platform::get_core_count is used in <a href="1-pp.html#SP24">&#167;24</a>, <a href="1-pp.html#SP27">&#167;27</a>, Windows Platform (<a href="1-wp.html#SP16">&#167;16</a>).</li></ul>
<p class="commentary firstcommentary"><a id="SP27"></a><b>&#167;27. </b></p>
<p class="commentary firstcommentary"><a id="SP27"></a><b>&#167;27. </b>For Android it seems prudent simply to ignore multithreading:
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><a href="1-wp.html#SP16" class="function-link"><span class="function-syntax">Platform::get_core_count</span></a><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>

View file

@ -384,14 +384,17 @@ find this).
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This paragraph is used only if PLATFORM_WINDOWS is defined.</li></ul>
<p class="commentary firstcommentary"><a id="SP16"></a><b>&#167;16. </b>To do: replace this with something finding the answer correctly. It ought
to be the number of logical cores (i.e., twice the number of physical cores
if there's hyperthreading).
<p class="commentary firstcommentary"><a id="SP16"></a><b>&#167;16. </b>This function returns the number of logical cores in the host computer &mdash;
i.e., twice the number of physical cores if there's hyperthreading. The
result is used as a guess for an appropriate number of simultaneous threads
to launch.
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Platform::get_core_count</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">Platform::get_core_count</span></span>:<br/>POSIX Platforms - <a href="1-pp.html#SP24">&#167;24</a>, <a href="1-pp.html#SP26">&#167;26</a>, <a href="1-pp.html#SP27">&#167;27</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">SYSTEM_INFO</span><span class="plain-syntax"> </span><span class="identifier-syntax">sysInfo</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">GetSystemInfo</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">sysInfo</span><span class="plain-syntax">);</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">sysInfo</span><span class="plain-syntax">.</span><span class="identifier-syntax">dwNumberOfProcessors</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This paragraph is used only if PLATFORM_WINDOWS is defined.</li></ul>

Binary file not shown.

View file

@ -406,8 +406,13 @@ size_t Platform::get_thread_stack_size(foundation_thread_attributes *pa) {
}
@ ^"ifdef-PLATFORM_LINUX"
It's not easy to find a function which reliably returns the core count.
Linux provides |sys/sysinfo.h|, but this header is a POSIX extension which
This function returns the number of logical cores in the host computer --
i.e., twice the number of physical cores if there's hyperthreading. The
result is used as a guess for an appropriate number of simultaneous threads
to launch.
It's not easy to find a function which reliably does this on all POSIX platforms.
On Linux we can use |sys/sysinfo.h|, but this header is a POSIX extension which
MacOS does not support.
= (very early code)
@ -422,6 +427,7 @@ int Platform::get_core_count(void) {
}
@ ^"ifdef-PLATFORM_MACOS"
While MacOS lacks |sysinfo.h|, it does have |sysctl.h|:
= (very early code)
#include <sys/sysctl.h>
@ -437,6 +443,8 @@ int Platform::get_core_count(void) {
}
@ ^"ifdef-PLATFORM_ANDROID"
For Android it seems prudent simply to ignore multithreading:
=
int Platform::get_core_count(void) {
return 1;

View file

@ -311,15 +311,16 @@ size_t Platform::get_thread_stack_size(foundation_thread_attributes* pa) {
return 0;
}
@ To do: replace this with something finding the answer correctly. It ought
to be the number of logical cores (i.e., twice the number of physical cores
if there's hyperthreading).
@ This function returns the number of logical cores in the host computer --
i.e., twice the number of physical cores if there's hyperthreading. The
result is used as a guess for an appropriate number of simultaneous threads
to launch.
=
int Platform::get_core_count(void) {
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
return (int)sysInfo.dwNumberOfProcessors;
return (int) sysInfo.dwNumberOfProcessors;
}
@h Timestamp and file size.