Hi Kirill,<br><br><div class="gmail_quote">2009/1/27 Kirill Smelkov <span dir="ltr">&lt;<a href="mailto:kirr@mns.spb.ru">kirr@mns.spb.ru</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Tue, Jan 13, 2009 at 05:58:23PM +0300, Kirill Smelkov wrote:<br>
&gt; Arjen, Arnaud,<br>
&gt; first of all, I&#39;m sorry for my late reply.<br>
&gt;<br>
&gt; If it&#39;s not too late, here is updated al175:<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Dec 26, 2008 at 11:37:04PM +0100, Arjen de Korte wrote:<br>
&gt; &gt; Citeren Kirill Smelkov &lt;<a href="mailto:kirr@mns.spb.ru">kirr@mns.spb.ru</a>&gt;:<br>
&gt; &gt;<br>
&gt; &gt; [...]<br>
&gt; &gt;<br>
&gt; &gt;&gt; Yes, &quot;All the world is not an x86 Linux box,&quot; and I&#39;ve tried to make all the<br>
&gt; &gt;&gt; world happy.<br>
&gt; &gt;<br>
&gt; &gt; I raised several other issues as well, of which the most important one<br>
&gt; &gt; isn&#39;t addressed. The driver still uses &#39;alloca&#39; which isn&#39;t portable (it<br>
&gt; &gt; is not in POSIX). I also indicated how this could be solved by using<br>
&gt; &gt; automatic variables. In any case I&#39;m not conviced there is no<br>
&gt; &gt; alternative here, so this is a show stopper for now.<br>
&gt;<br>
&gt; I&#39;ve reworked it not to use alloca and to use auto-variables + xmalloc<br>
&gt; in one place.<br>
&gt;<br>
&gt; Now it usually looks like<br>
&gt;<br>
&gt; &nbsp; &nbsp; raw_data &nbsp; &nbsp;reply;<br>
&gt; &nbsp; &nbsp; byte_t &nbsp; &nbsp; &nbsp;reply_buf[11];<br>
&gt;<br>
&gt; &nbsp; &nbsp; ...<br>
&gt;<br>
&gt; &nbsp; &nbsp; raw_alloc_onstack(&amp;reply, reply_buf);<br>
&gt;<br>
&gt; &gt; Also something I really don&#39;t like in this driver is the use of alarm().<br>
&gt; &gt; Although this is presently used in the &#39;net-xml&#39; driver (in case an older<br>
&gt; &gt; neon library is detected), there is no need for this here. We have<br>
&gt; &gt; timeouts on *all* ser_get* functions and these *must* be used instead.<br>
&gt; &gt; Note that with using timeouts I mean something different than setting<br>
&gt; &gt; them to &#39;999&#39; seconds and setting an alarm() to breakout early. Unless<br>
&gt; &gt; there is a really good reason to use an alarm() (ie, there is no<br>
&gt; &gt; alternative), this shouldn&#39;t be used.<br>
&gt;<br>
&gt; I&#39;ve used alarm in the first place for the following reason:<br>
&gt;<br>
&gt; Let&#39;s look at e.g. upsdrv_updateinfo() -- it reads several al175<br>
&gt; registers, and each read_register consists of a chat between host and<br>
&gt; al175.<br>
&gt;<br>
&gt; And I want the whole transaction to be less than say 5 seconds. What<br>
&gt; should I do? manually calculate read/write time budget left for _each_<br>
&gt; read or write?<br>
&gt;<br>
&gt; I think this is not practical.<br>
&gt;<br>
&gt; That&#39;s why I simply<br>
&gt;<br>
&gt; 1. arm the timer via alarm(T) to fire after T seconds<br>
&gt; 2. do all the I/O, logic, etc...<br>
&gt; 3. if I/O would stale at *any* place, it will be *always* aborted right<br>
&gt; &nbsp; &nbsp;after T seconds since the transaction start (thanks to alarm)<br>
&gt; 4. after all the I/O transaction is done -- reset the timer.<br>
&gt;<br>
&gt; And exactly for this reason 999 is used as infinity which means &#39;much<br>
&gt; more longer than _any_ T we&#39;ll pass to alarm() ever&#39;. If there is a way<br>
&gt; to actually pass &#39;please never timeout on select&#39;, I&#39;d be happy to<br>
&gt; rework the code.<br>
&gt;<br>
&gt; Also according to mans, alarm(2) is in SVr4, POSIX.1-2001 and 4.3BSD.<br>
&gt; That&#39;s why I think using alarm() makes sense.<br>
&gt;<br>
&gt; But if there is a similiar functionality in NUT to set whole transaction<br>
&gt; timeout, I&#39;ll be happy to rework the code to use what NUT provides.<br>
&gt;<br>
&gt; &gt; Even in the updated driver, I see quite a couple of fprintf() lines.<br>
&gt; &gt; Although these are in most (all?) cases encased in a &#39;if<br>
&gt; &gt; (nut_debug_level &gt; 0)&#39;, we have the upsdebug* functions for that. Do<br>
&gt; &gt; yourself (and your fellow developers) a favor and use those instead.<br>
&gt;<br>
&gt; &gt; Another thing related to this is the XTRACE macro. This will only use a<br>
&gt; &gt; single (1) debug level to show output. Please use a layered approach,<br>
&gt; &gt; where various levels of debugging information are used.<br>
&gt;<br>
&gt; I&#39;ve split debug/trace output into several levels:<br>
&gt;<br>
&gt; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; /* user-level trace (status, instcmd, etc */<br>
&gt; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; /* proto handling info &nbsp;*/<br>
&gt; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; /* IO trace &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br>
&gt;<br>
&gt;<br>
&gt; so with -D the user will see only high level stuff, with -DD --<br>
&gt; high-level info + any information regarding COMLI proto handling, and<br>
&gt; with -DDD -- everything includiong full IO trace.<br>
&gt;<br>
&gt; Can&#39;t test it because I don&#39;t have the hardware now, but I hope this is<br>
&gt; ok.<br>
&gt;<br>
&gt; (one place still uses fprintf(stderr, ...) but that&#39;s because it is<br>
&gt; &nbsp;difficult to construct one line through several calls to upsdebug,<br>
&gt; &nbsp;although sure this is doable, like upsdebug_hex does. Mine has pretty<br>
&gt; &nbsp;printing for control ascii characters, and I&#39;d better leave it there,<br>
&gt; &nbsp;because as I recall this was usefull for debugging. I hope this is not<br>
&gt; &nbsp;a show-stopper.)<br>
&gt;<br>
&gt;<br>
&gt; &gt; It also helps understanding the driver if you keep the number of<br>
&gt; &gt; macro&#39;s limited.<br>
&gt;<br>
&gt; The reason XTRACE was introduced in the first place is to automatically<br>
&gt; put a function name as prefix into trace output through the use of<br>
&gt; __FUNCTION__. if it is (again) a protability problem, we could always<br>
&gt; workaround this as follows (taken from gcc manual):<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#if __STDC_VERSION__ &lt; 199901L<br>
&gt; &nbsp; &nbsp; &nbsp;# if __GNUC__ &gt;= 2<br>
&gt; &nbsp; &nbsp; &nbsp;# &nbsp;define __func__ __FUNCTION__<br>
&gt; &nbsp; &nbsp; &nbsp;# else<br>
&gt; &nbsp; &nbsp; &nbsp;# &nbsp;define __func__ &quot;&lt;unknown&gt;&quot;<br>
&gt; &nbsp; &nbsp; &nbsp;# endif<br>
&gt; &nbsp; &nbsp; &nbsp;#endif<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Here is the interdiff wrt recent version as posted to the list, and the<br>
&gt; full patch:<br>
<br>
</div></div>[...]<br>
<br>
Arnaud, Arjen,<br>
<br>
So what would we do about this patch?<br>
<br>
I&#39;ve tried to address the issues you&#39;ve raised, and to describe my<br>
rationale behind alarm().<br>
<br>
If it can&#39;t go in -- that&#39;s ok with me, but could you please at least<br>
tell me what you objections (if any) are now.<br>
</blockquote></div><br>sorry, both Arjen and I were caught by real life!<br><br>we&#39;ve had a discussion not long ago about your driver.<br>the conclusion is that there are still show stoppers for including it back in the tree.<br>
so it&#39;s a no-go for 2.4.0!<br>Remember that our aim is not to bother drivers developers, but to
ensure that their work will be maintainable and maintained even if they
disappear...<br>
<br>Arjen should get back to you soon and point/help you in doing what is needed.<br>Though he already stated most (if not all) the points in the previous mails.<br>In the meantime, 2.2.2 will still be available, and you can always use a patched 2.4.0 including al175<br>
<br>so, keep your motivation, we&#39;ll end up in succeeding ;-)<br><br>cheers,<br>Arnaud<br>-- <br>Linux / Unix Expert R&amp;D - Eaton - <a href="http://www.eaton.com/mgeops">http://www.eaton.com/mgeops</a><br>Network UPS Tools (NUT) Project Leader - <a href="http://www.networkupstools.org/">http://www.networkupstools.org/</a><br>
Debian Developer - <a href="http://people.debian.org/~aquette/">http://people.debian.org/~aquette/</a><br>Free Software Developer - <a href="http://arnaud.quette.free.fr/">http://arnaud.quette.free.fr/</a><br><br>