Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Alon Bar-Lev
For all who cannot build and have access to Windows machine.
Please run binary[1] and send output.

[1] https://github.com/downloads/alonbl/openvpn/timebench.exe

On Wed, Feb 22, 2012 at 6:12 PM, Alon Bar-Lev  wrote:
> Hello all,
>
> There is an abnormality in the openvpn sources I want to resolve.
>
> In windows there is own implementation of gettimeofday().
> In the past there was no gettimeofday(), so we used performance counters,
> then James optimize it to reduce CPU consumption.
>
> Unlike in the past, mingw does provide this function these days.
> The question is if it is good enough.
>
> There is also a note:
> /* on WIN32, gettimeofday is faster than time(NULL) */
>
> I am not sure about any of these, can you please try to run the
> benchmark and report back the results?
> It must be compiled using mingw, either at cygwin or at linux.
>
> Thanks,
> Alon



Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread David Sommerseth
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 22/02/12 17:40, Alon Bar-Lev wrote:
> On Wed, Feb 22, 2012 at 6:37 PM, David Sommerseth 
>  wrote:
>> -BEGIN PGP SIGNED MESSAGE- Hash: SHA1
>> 
>> On 22/02/12 17:27, Heiko Hund wrote:
>>> On Wednesday 22 February 2012 16:12:24 Alon Bar-Lev wrote:
 In windows there is own implementation of gettimeofday(). In
 the past there was no gettimeofday(), so we used performance
 counters, then James optimize it to reduce CPU consumption.
 
 Unlike in the past, mingw does provide this function these days.
 The question is if it is good enough.
>>> 
>>> Since there's no gettimeofday() in MSVC this will break building
>>> with the python build system. Not sure if we're in the process of
>>> getting rid of it, which I would welcome, so this is just for
>>> additional information.
>> 
>> That's a valid point ... But it makes me think.  What about to put
>> James' old code in compat.[ch] for platforms without gettimeofday.
>> Would that be an appropriate middle-road?
>> 
>> I too would like to see MSVC go away.  Very much.  But again, let's
>> not decide that without James approval for it.
> 
> Again, There is nothing written about not supporting the proprietary
> gettimeofday implementation in MSVC. What exactly is the problem? You
> compile on *NIX you get system gettimeofday. You compile on mingw you
> get library gettimeofday. You compile on msvc you get own
> implementation.
> 
> Wasn't I clear?

Sorry, I saw your reply to Heiko too late.  That response was more than
clear enough.  Disregard my comment, my single-threaded workflow doesn't
scale too well :)


kind regards,

David Sommerseth


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9FHFkACgkQDC186MBRfro+IQCgpRzrvNnW7VguHtMaO+E86COq
euoAoIkgx4tS5GJszE2ZZG9zHfTnREuL
=bnqZ
-END PGP SIGNATURE-



Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Alon Bar-Lev
On Wed, Feb 22, 2012 at 6:37 PM, David Sommerseth
 wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 22/02/12 17:27, Heiko Hund wrote:
>> On Wednesday 22 February 2012 16:12:24 Alon Bar-Lev wrote:
>>> In windows there is own implementation of gettimeofday(). In the
>>> past there was no gettimeofday(), so we used performance counters,
>>> then James optimize it to reduce CPU consumption.
>>>
>>> Unlike in the past, mingw does provide this function these days. The
>>> question is if it is good enough.
>>
>> Since there's no gettimeofday() in MSVC this will break building with
>> the python build system. Not sure if we're in the process of getting
>> rid of it, which I would welcome, so this is just for additional
>> information.
>
> That's a valid point ... But it makes me think.  What about to put James'
> old code in compat.[ch] for platforms without gettimeofday.  Would that
> be an appropriate middle-road?
>
> I too would like to see MSVC go away.  Very much.  But again, let's not
> decide that without James approval for it.

Again,
There is nothing written about not supporting the proprietary gettimeofday
implementation in MSVC.
What exactly is the problem?
You compile on *NIX you get system gettimeofday.
You compile on mingw you get library gettimeofday.
You compile on msvc you get own implementation.

Wasn't I clear?

Alon.



Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread David Sommerseth
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 22/02/12 17:27, Heiko Hund wrote:
> On Wednesday 22 February 2012 16:12:24 Alon Bar-Lev wrote:
>> In windows there is own implementation of gettimeofday(). In the
>> past there was no gettimeofday(), so we used performance counters, 
>> then James optimize it to reduce CPU consumption.
>> 
>> Unlike in the past, mingw does provide this function these days. The
>> question is if it is good enough.
> 
> Since there's no gettimeofday() in MSVC this will break building with
> the python build system. Not sure if we're in the process of getting
> rid of it, which I would welcome, so this is just for additional
> information.

That's a valid point ... But it makes me think.  What about to put James'
old code in compat.[ch] for platforms without gettimeofday.  Would that
be an appropriate middle-road?

I too would like to see MSVC go away.  Very much.  But again, let's not
decide that without James approval for it.


kind regards,

David Sommerseth
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9FGd0ACgkQDC186MBRfrp4SQCeKnZFdeJpLz4SCxfVmKr+Ffmv
2HYAn3/sVVgjonZ/HBh+axoXTF1s+At8
=MIxf
-END PGP SIGNATURE-



Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Alon Bar-Lev
On Wed, Feb 22, 2012 at 6:27 PM, Heiko Hund  wrote:
> Since there's no gettimeofday() in MSVC this will break building with the
> python build system. Not sure if we're in the process of getting rid of it,
> which I would welcome, so this is just for additional information.

The python build system will be replaced with my work.
Anyway, I did not write that in MSVC the windows implementation will be removed.
Just want to know if indeed the time(NULL) is slower and if we can use standard
gettimeofday in mingw.

Alon.



Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Heiko Hund
On Wednesday 22 February 2012 16:12:24 Alon Bar-Lev wrote:
> In windows there is own implementation of gettimeofday().
> In the past there was no gettimeofday(), so we used performance counters,
> then James optimize it to reduce CPU consumption.
> 
> Unlike in the past, mingw does provide this function these days.
> The question is if it is good enough.

Since there's no gettimeofday() in MSVC this will break building with the 
python build system. Not sure if we're in the process of getting rid of it, 
which I would welcome, so this is just for additional information.

Heiko
-- 
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen




Re: [Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Jan Just Keijser

Hi Alon,

Alon Bar-Lev wrote:

Hello all,

There is an abnormality in the openvpn sources I want to resolve.

In windows there is own implementation of gettimeofday().
In the past there was no gettimeofday(), so we used performance counters,
then James optimize it to reduce CPU consumption.

Unlike in the past, mingw does provide this function these days.
The question is if it is good enough.

There is also a note:
/* on WIN32, gettimeofday is faster than time(NULL) */

I am not sure about any of these, can you please try to run the
benchmark and report back the results?
It must be compiled using mingw, either at cygwin or at linux.

  

First:
$ i686-pc-mingw32-gcc -o timebench.exe timebench.c

In a virtual WinXP SP3 env on my 2.50 GHz Intel T9300:

c:\users\janjust>timebench.exe
time(): 18
gettimeofday(): 47
openvpn_gettimeofday(): 16



share and enjoy,

JJK




[Openvpn-devel] [RFC][windows] gettimeofday()

2012-02-22 Thread Alon Bar-Lev
Hello all,

There is an abnormality in the openvpn sources I want to resolve.

In windows there is own implementation of gettimeofday().
In the past there was no gettimeofday(), so we used performance counters,
then James optimize it to reduce CPU consumption.

Unlike in the past, mingw does provide this function these days.
The question is if it is good enough.

There is also a note:
/* on WIN32, gettimeofday is faster than time(NULL) */

I am not sure about any of these, can you please try to run the
benchmark and report back the results?
It must be compiled using mingw, either at cygwin or at linux.

Thanks,
Alon
#include 
#include 
#include 

static time_t gtc_base = 0;
static DWORD gtc_last = 0;
static time_t last_sec = 0;
static unsigned int last_msec = 0;
static int bt_last = 0;

static void
gettimeofday_calibrate (void)
{
  const time_t t = time(NULL);
  const DWORD gtc = GetTickCount();
  gtc_base = t - gtc/1000;
  gtc_last = gtc;
}

/*
 * Rewritten by JY for OpenVPN 2.1, after I realized that
 * QueryPerformanceCounter takes nearly 2 orders of magnitude
 * more processor cycles than GetTickCount.
 */
int
openvpn_gettimeofday (struct timeval *tv, void *tz)
{
  const DWORD gtc = GetTickCount();
  int bt = 0;
  time_t sec;
  unsigned int msec;
  const int backtrack_hold_seconds = 10;

  /* recalibrate at the dreaded 49.7 day mark */
  if (!gtc_base || gtc < gtc_last)
gettimeofday_calibrate ();
  gtc_last = gtc;

  sec = gtc_base + gtc / 1000;
  msec = gtc % 1000;

  if (sec == last_sec)
{
  if (msec < last_msec)
	{
	  msec = last_msec;
	  bt = 1;
	}
}
  else if (sec < last_sec)
{
  /* We try to dampen out backtracks of less than backtrack_hold_seconds.
	 Larger backtracks will be passed through and dealt with by the
	 TIME_BACKTRACK_PROTECTION code (if enabled) */
  if (sec > last_sec - backtrack_hold_seconds)
	{
	  sec = last_sec;
	  msec = last_msec;
	}
  bt = 1;
}

  tv->tv_sec = last_sec = sec;
  tv->tv_usec = (last_msec = msec) * 1000;

  if (bt && !bt_last)
gettimeofday_calibrate ();
  bt_last = bt;

  return 0;
}

int main(void) {
	struct timeval tv;
	long i;
	long n=10;
	time_t mark;
	mark = time(NULL);
	for(i=0;i