Files
MPIonCell/documentation/developer/html/d7/d1f/imoc__buffer__malloc_8c-source.html
T
2017-10-26 19:57:24 +02:00

162 lines
20 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>MPI On Cell (Documentation): src/noarch/internal/imoc_buffer_malloc.c Source File</title>
<link href="../../doxygen.css" rel="stylesheet" type="text/css">
<link href="../../tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="../../main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="../../modules.html"><span>Modules</span></a></li>
<li><a href="../../annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li class="current"><a href="../../files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>src/noarch/internal/imoc_buffer_malloc.c</h1><a href="../../d2/d7b/imoc__buffer__malloc_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00003"></a>00003
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;<a class="code" href="../../d9/db3/imoc_8h.html">internal/imoc.h</a>&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#ifdef __SPU__</span>
<a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="../../d9/d00/imoc__core__spu_8h.html">internal/spu/imoc_core_spu.h</a>&gt;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#else</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="../../d6/d09/imoc__core__ppu_8h.html">internal/ppu/imoc_core_ppu.h</a>&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#endif</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">/**</span>
<a name="l00012"></a>00012 <span class="comment"> * \addtogroup internal_p2p_bmalloc</span>
<a name="l00013"></a>00013 <span class="comment"> **/</span><span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">//@{</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment"></span>
<a name="l00017"></a>00017 <span class="comment">/**</span>
<a name="l00018"></a>00018 <span class="comment"> * Pointer to first entry of linked-list.</span>
<a name="l00019"></a>00019 <span class="comment"> **/</span>
<a name="l00020"></a><a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#gaf9be7d34fe367a9244d50dde82777ed">00020</a> <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* <a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#gaf9be7d34fe367a9244d50dde82777ed" title="Pointer to first entry of linked-list.">bmalloc_first_node</a> = 0;
<a name="l00021"></a>00021
<a name="l00022"></a>00022 <span class="comment">/*</span>
<a name="l00023"></a>00023 <span class="comment"> * Prints out the nodes of the linked list.</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> * Used for debugging</span>
<a name="l00026"></a>00026 <span class="comment"> */</span><span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment">/**void bmalloc_print_nodes()</span>
<a name="l00028"></a>00028 <span class="comment"> {</span>
<a name="l00029"></a>00029 <span class="comment"> if (!bmalloc_first_node)</span>
<a name="l00030"></a>00030 <span class="comment"> printf("No nodes in list\n");</span>
<a name="l00031"></a>00031 <span class="comment"> else</span>
<a name="l00032"></a>00032 <span class="comment"> {</span>
<a name="l00033"></a>00033 <span class="comment"> int z = 0;</span>
<a name="l00034"></a>00034 <span class="comment"> moc_internal_buffer_node_t* t;</span>
<a name="l00035"></a>00035 <span class="comment"> for (t = bmalloc_first_node; t != 0; t = t-&gt;next_node)</span>
<a name="l00036"></a>00036 <span class="comment"> {</span>
<a name="l00037"></a>00037 <span class="comment"> printf( "Node %i: offset %u - size %u - valid %i - mid %u\n", z,</span>
<a name="l00038"></a>00038 <span class="comment"> node_handle.status_array_base[ t-&gt;mid ].buffer_offset,</span>
<a name="l00039"></a>00039 <span class="comment"> node_handle.status_array_base[ t-&gt;mid ].message_size,</span>
<a name="l00040"></a>00040 <span class="comment"> node_handle.status_array_base[ t-&gt;mid ].flags.bits.buffer_used,</span>
<a name="l00041"></a>00041 <span class="comment"> t-&gt;mid );</span>
<a name="l00042"></a>00042 <span class="comment"> z++;</span>
<a name="l00043"></a>00043 <span class="comment"> }</span>
<a name="l00044"></a>00044 <span class="comment"> }</span>
<a name="l00045"></a>00045 <span class="comment"> }**/</span>
<a name="l00046"></a>00046 <span class="comment"></span>
<a name="l00047"></a>00047 <span class="comment">/**</span>
<a name="l00048"></a>00048 <span class="comment"> * Returns the next node holding valid buffer-information coming after node start.</span>
<a name="l00049"></a>00049 <span class="comment"> *</span>
<a name="l00050"></a>00050 <span class="comment"> * During the search all invalid nodes the function stumbles across are freed and</span>
<a name="l00051"></a>00051 <span class="comment"> * the links are corrected.</span>
<a name="l00052"></a>00052 <span class="comment"> *</span>
<a name="l00053"></a>00053 <span class="comment"> * @param start \b in start-node of search (NULL means beginning of list)</span>
<a name="l00054"></a>00054 <span class="comment"> * @return next valid node</span>
<a name="l00055"></a>00055 <span class="comment"> **/</span>
<a name="l00056"></a><a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#gad8750c7ba3d6da9c137c2c462d2c531">00056</a> <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* <a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#gad8750c7ba3d6da9c137c2c462d2c531" title="void bmalloc_print_nodes() { if (!bmalloc_first_node) printf(&amp;quot;No nodes in list\n&amp;quot;);...">__attribute__</a>((always_inline)) bmalloc_nextValidNode(
<a name="l00057"></a>00057 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* start)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* currentNode = 0;
<a name="l00060"></a>00060 uint8_t unusedNodes = 0;
<a name="l00061"></a>00061 <span class="keywordflow">if</span> (start)
<a name="l00062"></a>00062 currentNode = start-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#289260f38a9ad908733278bc674b3679" title="Pointer to next entry.">next_node</a>;
<a name="l00063"></a>00063 <span class="keywordflow">else</span>
<a name="l00064"></a>00064 currentNode = bmalloc_first_node;
<a name="l00065"></a>00065 <span class="comment">/* skip and free unused nodes of linked list */</span>
<a name="l00066"></a>00066 <span class="keywordflow">while</span> (currentNode
<a name="l00067"></a>00067 &amp;&amp; !<a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[currentNode-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#5d1d937feff5aa2432aeed723a22ed7e" title="Message-ID of message using buffer-space.">mid</a>].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#086c0d449d25774d43512b6f7fdab8ed" title="flag-union">flags</a>.<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#c0bdc214525521d58f12c72874de0512" title="flag-struct">bits</a>.buffer_used)
<a name="l00068"></a>00068 {
<a name="l00069"></a>00069 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* temp = currentNode;
<a name="l00070"></a>00070 unusedNodes = 1;
<a name="l00071"></a>00071 currentNode = currentNode-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#289260f38a9ad908733278bc674b3679" title="Pointer to next entry.">next_node</a>;
<a name="l00072"></a>00072 free(temp);
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 <span class="comment">/* when nodes have been freed then correct links of linked-list */</span>
<a name="l00075"></a>00075 <span class="keywordflow">if</span> (unusedNodes)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077 <span class="keywordflow">if</span> (start)
<a name="l00078"></a>00078 start-&gt;next_node = currentNode;
<a name="l00079"></a>00079 <span class="keywordflow">else</span>
<a name="l00080"></a>00080 bmalloc_first_node = currentNode;
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 <span class="keywordflow">return</span> currentNode;
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084
<a name="l00085"></a><a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#g5295b372d853993b2e6cfb6912a0ee41">00085</a> uint64_t <a class="code" href="../../d3/dd3/group__internal__p2p__bmalloc.html#g5295b372d853993b2e6cfb6912a0ee41" title="Allocate buffer-space.">IMOC_bmalloc</a>(uint32_t size, uint8_t mid)
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 <span class="keywordtype">int</span> temp;
<a name="l00088"></a>00088 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* lower_node = 0;
<a name="l00089"></a>00089 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* upper_node = bmalloc_nextValidNode(0);
<a name="l00090"></a>00090 uint64_t lower_bound = 0, upper_bound = 0;
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <span class="keywordflow">if</span> (upper_node)
<a name="l00093"></a>00093 upper_bound
<a name="l00094"></a>00094 = <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[upper_node-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#5d1d937feff5aa2432aeed723a22ed7e" title="Message-ID of message using buffer-space.">mid</a>].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#e8c63164c741fbe8af05ab10225f910e" title="allocated buffer-offset from buffer-base">buffer_offset</a>;
<a name="l00095"></a>00095 <span class="keywordflow">else</span>
<a name="l00096"></a>00096 upper_bound = <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#90096c2a63d01f0251fdd6c642601f45" title="size of own buffer">buffer_size</a>;
<a name="l00097"></a>00097
<a name="l00098"></a>00098 <span class="keywordflow">while</span> (1)
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100 temp = 16 - (lower_bound % 16);
<a name="l00101"></a>00101 <span class="keywordflow">if</span> (temp &lt; 16)
<a name="l00102"></a>00102 lower_bound += temp;
<a name="l00103"></a>00103 <span class="keywordflow">if</span> (upper_bound &gt; lower_bound &amp;&amp; (upper_bound - lower_bound) &gt;= size)
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105 <a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>* temp = malloc(
<a name="l00106"></a>00106 <span class="keyword">sizeof</span>(<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html" title="Node of linked list holding information about allocated buffer-space.">moc_internal_buffer_node_t</a>));
<a name="l00107"></a>00107 <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[mid].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#086c0d449d25774d43512b6f7fdab8ed" title="flag-union">flags</a>.<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#c0bdc214525521d58f12c72874de0512" title="flag-struct">bits</a>.buffer_used = 1;
<a name="l00108"></a>00108 <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[mid].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#e8c63164c741fbe8af05ab10225f910e" title="allocated buffer-offset from buffer-base">buffer_offset</a> = lower_bound;
<a name="l00109"></a>00109 <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[mid].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#e2130ff455b57d82f77116fca11deb33" title="size of message in byte">message_size</a> = size;
<a name="l00110"></a>00110 temp-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#5d1d937feff5aa2432aeed723a22ed7e" title="Message-ID of message using buffer-space.">mid</a> = mid;
<a name="l00111"></a>00111 temp-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#289260f38a9ad908733278bc674b3679" title="Pointer to next entry.">next_node</a> = upper_node;
<a name="l00112"></a>00112 <span class="keywordflow">if</span> (lower_node)
<a name="l00113"></a>00113 lower_node-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#289260f38a9ad908733278bc674b3679" title="Pointer to next entry.">next_node</a> = temp;
<a name="l00114"></a>00114 <span class="keywordflow">else</span>
<a name="l00115"></a>00115 bmalloc_first_node = temp;
<a name="l00116"></a>00116 <span class="keywordflow">while</span> (upper_node)
<a name="l00117"></a>00117 upper_node = bmalloc_nextValidNode(upper_node);
<a name="l00118"></a>00118 <span class="keywordflow">return</span> (uint64_t) <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#ee118aad604058291438923545af37db" title="base-address of own buffer">buffer_base</a> + lower_bound;
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 <span class="keywordflow">else</span>
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122 <span class="keywordflow">if</span> (!upper_node)
<a name="l00123"></a>00123 <span class="keywordflow">return</span> 0;
<a name="l00124"></a>00124 lower_node = upper_node;
<a name="l00125"></a>00125 upper_node = bmalloc_nextValidNode(upper_node);
<a name="l00126"></a>00126
<a name="l00127"></a>00127 lower_bound
<a name="l00128"></a>00128 = upper_bound
<a name="l00129"></a>00129 + <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[lower_node-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#5d1d937feff5aa2432aeed723a22ed7e" title="Message-ID of message using buffer-space.">mid</a>].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#e2130ff455b57d82f77116fca11deb33" title="size of message in byte">message_size</a>;
<a name="l00130"></a>00130 <span class="keywordflow">if</span> (upper_node)
<a name="l00131"></a>00131 upper_bound
<a name="l00132"></a>00132 = <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#abccbc7beefa7b1e2ccc84b8bd2b8805" title="base-address of own message-status-array">status_array_base</a>[upper_node-&gt;<a class="code" href="../../dd/dc0/structmoc__internal__buffer__node__struct.html#5d1d937feff5aa2432aeed723a22ed7e" title="Message-ID of message using buffer-space.">mid</a>].<a class="code" href="../../dd/df5/structmoc__message__status__struct.html#e8c63164c741fbe8af05ab10225f910e" title="allocated buffer-offset from buffer-base">buffer_offset</a>;
<a name="l00133"></a>00133 <span class="keywordflow">else</span>
<a name="l00134"></a>00134 upper_bound = <a class="code" href="../../dd/df8/group__internal__core.html#geed5a271d50368d3cf9a858c4f57c895" title="Information each node knowns about himself and the world.">node_handle</a>.<a class="code" href="../../d8/d93/structmoc__node__handle__ppu__struct.html#90096c2a63d01f0251fdd6c642601f45" title="size of own buffer">buffer_size</a>;
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 <span class="comment"></span>
<a name="l00139"></a>00139 <span class="comment">//@}</span>
</span></pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Feb 12 13:49:47 2009 for MPI On Cell (Documentation) by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="../../doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>