<HTML xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<HEAD><!-- Template generated by Exclaimer Mail Disclaimers on 02:58:52 Wednesday, 10 October 2012 -->
<STYLE type=text/css>P.cd90c476-0d91-4d15-b60e-a1073efa726c {
        MARGIN: 0cm 0cm 0pt
}
LI.cd90c476-0d91-4d15-b60e-a1073efa726c {
        MARGIN: 0cm 0cm 0pt
}
DIV.cd90c476-0d91-4d15-b60e-a1073efa726c {
        MARGIN: 0cm 0cm 0pt
}
TABLE.cd90c476-0d91-4d15-b60e-a1073efa726cTable {
        MARGIN: 0cm 0cm 0pt
}
DIV.Section1 {
        page: Section1
}
</STYLE>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        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";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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-US" link="blue" vlink="purple">
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c>
<div class="WordSection1">
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div>
<p class="MsoNormal"><span style=color:#1F497D>Hi Arnaud,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal">The below link will provide you a good summary of the situation, what we can do and how.<br />
<br />
AFAICT, there is no way on HPUX (and some other older Unix) to use clock_gettime with CLOCK_MONOTONIC, but CLOCK_REALTIME (which is functionally different).<br />
gethrtime (high resolution time) seems to be the fallback here:<br />
<a href="http://nadeausoftware.com/articles/2012/04/c_c_tip_how_measure_elapsed_real_time_benchmarking">http://nadeausoftware.com/articles/2012/04/c_c_tip_how_measure_elapsed_real_time_benchmarking</a><br />
<br />
<span style=color:#1F497D><o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>Yes, I’ve found that myself, too.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>HP-UX is definitely kind of a troublemaker... :-)<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>CLOCK_MONOTONIC_PRECISE for BSD and<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>CLOCK_HIGHRES for Solaris shall be used for monot. clock..<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>As already mentioned, mach_absolute_time shall be used<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>for Mac OS X for the monotonic clock.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>For RTC on OS X, I’ve found the following (see answer #17):<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><a href="http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x">http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>For the HP-UX, I’llcheck whether gethrtime is available; if so, it’ll be used<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>for monot. clock. If it’s not, well, I guess then HPUX user is screwed;<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>I can’t find any other monot. clock implementation, so POSIX RTC shall<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>have to be used.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>I’ll add the Windows-specific GetSystemTime* support, too,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>although for now, there’ll be no way to even compile the code :-(<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><br />
but this requires (for HPUX) the native compiler and CFLAGS set to "Extended Ansi" mode...<br />
so there is a 2nd (more general) fallback, using... gettimeofday! :-/<br />
<br />
<span style=color:#1F497D><o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>I can see no reason for using gettimeofday; we have POSIX clock (almost) everywhere,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>on OSX, we do have the above solution and on HPUX, we won’t do better than POSIX<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>CLOCK_REALTIME with gettimeofday if we don’t have gethrtime...<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><br />
Another reading on configure checks:<br />
<a href="http://www.nco.ncep.noaa.gov/pmb/codes/nwprod/gempak/nawips2/extlibs/glib/v2.15.6/configure.in">http://www.nco.ncep.noaa.gov/pmb/codes/nwprod/gempak/nawips2/extlibs/glib/v2.15.6/configure.in</a><br />
<br />
<span style=color:#1F497D><o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><br />
As a separate comment, here is the list of remaining gettimeofday:<br />
common/common.c:        gettimeofday(&now, NULL);<br />
drivers/bcmxcp_usb.c:    gettimeofday(&start_time, NULL);<br />
drivers/bcmxcp_usb.c:            gettimeofday(&now, NULL);<br />
drivers/dstate.c:    gettimeofday(&now, NULL);<br />
drivers/main.c:        gettimeofday(&timeout, NULL);<br />
drivers/usbhid-ups.c:    gettimeofday(&now, NULL);<br />
<br />
<span style=color:#1F497D><o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>Yep, I know what grep is for... ;-)<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>But I use the –n switch, too.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>Thanks for the comments, tbc,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D>vasek<o:p></o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal"></p></div></blockquote></div></div></div></P>
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c> </P>
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c>
<HR id=HR1 />
Eaton Elektrotechnika s.r.o. ~ S�dlo spolecnosti, jak je zaps�no v rejstr�ku: Kom�rovsk� 2406, Praha 9 - Horn� Pocernice, 193 00, Cesk� Republika ~ Jm�no, m�sto, kde byla spolecnost zaregistrov�na: Praha ~ Identifikacn� c�slo (ICO): 498 11 894 
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c>
<HR id=HR1 />

<P></P>
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c> </P>
<P class=cd90c476-0d91-4d15-b60e-a1073efa726c><div class="WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><p class="MsoNormal">-----Original Message-----<br />
> From: Charles Lepple [mailto:<a href="mailto:clepple@gmail.com">clepple@gmail.com</a>]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> Sent: Monday, October 08, 2012 2:36 PM<br />
> To: Krpec, Vaclav<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> Cc: Arnaud Quette; Emilien KIA; <a href="mailto:nut-upsdev@lists.alioth.debian.org">
nut-upsdev@lists.alioth.debian.org</a> List<br />
> Subject: Re: [Nut-upsdev] NUT Bugs #313634 & #313714: unification &<br />
> encapsulation of timer proposition<br />
><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style=margin-bottom:12.0pt>> [adding nut-upsdev back to CC list.]<br />
><br />
> > While you at it --- I've written the nut_clock_gettime POSIX<br />
> > implementation so that fallback from monotonic POSIX clock impl. to<br />
> > RTC is actually also done if the system defines _POSIX_MONOTONIC_CLOCK<br />
> > macro, but the call ends with EINVAL (i.e. not implemented) if monotonic clock<br />
> is requested.<br />
> > I thought that may be a bit over-protective; as soon as the OS defines<br />
> > the detection macro, we should be entitled to expect it to work;<br />
> > EINVAL should therefore be considered an error and propagated.<br />
><br />
> I'm confused. Could you post pseudocode, or the actual patch, for what is being<br />
> described above?<br />
><br />
> --<br />
> Charles Lepple<br />
> clepple@gmail<br />
><br />
><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</P></P></P></BODY>
</HTML>