<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-AU" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">A quick first thought: have you checked whether malloc() is failing and returning NULL on the sender side, which is then being delivered as a zero-length NULL
 buffer on the receiver? You do appear to have a memory leak on the receiver (someone needs to free the buffer p after it has been sent), so this might be the cause.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Andrew<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Zeus Gómez Marmolejo [mailto:zeus.gomez@bsc.es]
<br>
<b>Sent:</b> Wednesday, 14 September, 2011 10:29<br>
<b>To:</b> barrelfish-users@lists.inf.ethz.ch<br>
<b>Subject:</b> [Barrelfish-users] Possible bug?<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">I'm trying the Barrelfish' ability of sending large buffers (now 64kb) between cores using flounder. And I'm experiencing a strange behaviour. After sending some messages, and running it for about 1 min in QEMU, the program segfaults or
 simply hangs. I'm not sure if I am doing something wrong... I'm trying it with the latest version of Barrelfish.<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">The program is inspired in &quot;usr/tests/idctest/idctest.c&quot;. It's spawning another instance on core 1 and setting the binding. After that it creates another thread to &quot;dispatch events&quot;. The main loop in core 0 is sending messages, while the
 main loop in core 1 is just waiting for a reply queue to have some messages and send them back. It's using the same &quot;test.if&quot; interface that idctest.c is using. I send it as an attachment. You can simply try it by copying it over the existing idctest.c.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">So, core 0 is sending a message to core 1:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><b>a = malloc(65536);</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>test_buf__tx(b, MKCONT(end, 0), a, 65536);</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">before sending it, it obtains a lock to ensure that next message is not sent before the previous one has been &nbsp;already sent:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><b>&nbsp; while (__sync_lock_test_and_set(&amp;busy, true))</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>&nbsp; &nbsp; thread_yield();</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp;&nbsp;<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">The continuation closure is releasing the lock:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><b>static void end(void *r)</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>{</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>&nbsp; free (a);</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>&nbsp; busy = false;</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>}</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">This function is being called always by the second thread, which is always dispatching messages. I know this is not very efficient to use this spinlock... Is there any other way to block the thread and wake it up by the other thread?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Core 1 when receives the message:<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><b>static void buf1(struct test_binding *b, uint8_t *p, size_t buflen)</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>{</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>&nbsp; debug_printf(&quot;buf1 %u\n&quot;, p[65535]);</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>&nbsp; ambf_buff_send(p);</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b>}</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">Simply prints the last position and sends it back to core 0: queuing it to the other thread in order not to block the event dispatcher.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">The program segfaults when accessing to buffer p, in the previous function, as sometimes p is null. In any case, there is no error reported...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">I would like to know if you see something wrong here ...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Many thanks!!<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">-- <br>
Zeus Gómez Marmolejo<br>
Barcelona Supercomputing Center<br>
PhD student<br>
<a href="http://www.bsc.es" target="_blank">http://www.bsc.es</a><br>
<br>
<o:p></o:p></p>
</div>
</div>
</body>
</html>