Thanks Yamamoto! Feel free to push this if you think its ready.

Ryan
________________________________________
From: YAMAMOTO Takashi <[email protected]>
Sent: Tuesday, June 3, 2014 7:20 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [ovs-dev] [PATCH v2] timeval: Add monotonic time functionality for 
NetBSD and FreeBSD.

> This patch also checks the system platform as clock_gettime
> could exist on different platforms but with different values of
> CLOCK_MONOTONIC and different definitions of 'struct timespec'.
> In this case, the system call would be expected to catch the
> error, which is dangerous.
>
> This patch ensures Linux, NetBSD and FreeBSD platforms use
> clock_gettime with their corresponding correct values and
> definitions. All other platforms use time.time().
>
> Signed-off-by: Ryan Wilson <[email protected]>

Acked-by: YAMAMOTO Takashi <[email protected]>

>
> ---
> v2: Added Yamamoto's diff to fix NetBSD case
> ---
>  python/ovs/timeval.py |   34 +++++++++++++++++++++++++++-------
>  1 file changed, 27 insertions(+), 7 deletions(-)
>
> diff --git a/python/ovs/timeval.py b/python/ovs/timeval.py
> index 4463e87..a16bf60 100644
> --- a/python/ovs/timeval.py
> +++ b/python/ovs/timeval.py
> @@ -12,22 +12,41 @@
>  # See the License for the specific language governing permissions and
>  # limitations under the License.
>
> +import sys
>  import time
>
> -LIBRT = 'librt.so.1'
> -CLOCK_MONOTONIC = 1
> -
>  try:
>      import ctypes
>
> +    LIBRT = 'librt.so.1'
> +    clock_gettime_name = 'clock_gettime'
> +
> +    if sys.platform.startswith("linux"):
> +        CLOCK_MONOTONIC = 1
> +        time_t = ctypes.c_long
> +    elif sys.platform.startswith("netbsd"):
> +        # NetBSD uses function renaming for ABI versioning.  While the proper
> +        # way to get the appropriate version is of course "#include 
> <time.h>",
> +        # it is difficult with ctypes.  The following is appropriate for
> +        # recent versions of NetBSD, including NetBSD-6.
> +        LIBRT = 'libc.so.12'
> +        clock_gettime_name = '__clock_gettime50'
> +        CLOCK_MONOTONIC = 3
> +        time_t = ctypes.c_int64
> +    elif sys.platform.startswith("freebsd"):
> +        CLOCK_MONOTONIC = 4
> +        time_t = ctypes.c_int64
> +    else:
> +        raise Exception
> +
>      class timespec(ctypes.Structure):
>          _fields_ = [
> -            ('tv_sec', ctypes.c_long),
> +            ('tv_sec', time_t),
>              ('tv_nsec', ctypes.c_long),
>          ]
>
>      librt = ctypes.CDLL(LIBRT)
> -    clock_gettime = librt.clock_gettime
> +    clock_gettime = getattr(librt, clock_gettime_name)
>      clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
>  except:
>      # Librt shared library could not be loaded
> @@ -48,8 +67,9 @@ if not hasattr(time, 'monotonic'):
>      time.monotonic = monotonic
>
>  def msec():
> -    """Returns the current time, as the amount of time since the epoch, in
> -    milliseconds, as a float."""
> +    """ Returns the system's monotonic time if possible, otherwise returns 
> the
> +    current time as the amount of time since the epoch, in milliseconds, as a
> +    float."""
>      return time.monotonic() * 1000.0
>
>
> --
> 1.7.9.5
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://urldefense.proofpoint.com/v1/url?u=http://openvswitch.org/mailman/listinfo/dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=TfBS78Vw3dzttvXidhbffg%3D%3D%0A&m=CdXHUwz7qp9jYqbVhUmiz5DiYOOYJTfgJBzDTIoKFew%3D%0A&s=45a6973a1013806b91f267f236d9e3f8d6c5becb846cfc7662f99da84bb8c06b
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to