ngx_msec_t is 32bit on ARM

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ngx_msec_t is 32bit on ARM

ayman
I'm trying to compile nginx on for a raspberry pi

src/core/ngx_times.c

    time_t           sec;
    ngx_uint_t       msec;
    struct timeval   tv;

    ngx_gettimeofday(&tv);
    sec = tv.tv_sec;
    msec = tv.tv_usec / 1000;
    ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;

ngx_current_msec is defined as a ngx_msec_t which in turn is ngx_uint_t. In
an rpi is not big enough to hold Unix epoc in millis. (sec * 1000)

nginx code does compile, but my tests fail: they have hardcoded values for
the epoc.

Is this deliberate? I guess its cropping the high order bits?  So millis
comparisons might work but timestamps generated from this value might not?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277514,277514#msg-277514

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: ngx_msec_t is 32bit on ARM

Maxim Dounin
Hello!

On Sat, Nov 25, 2017 at 07:44:54PM -0500, teknopaul wrote:

> I'm trying to compile nginx on for a raspberry pi
>
> src/core/ngx_times.c
>
>     time_t           sec;
>     ngx_uint_t       msec;
>     struct timeval   tv;
>
>     ngx_gettimeofday(&tv);
>     sec = tv.tv_sec;
>     msec = tv.tv_usec / 1000;
>     ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
>
> ngx_current_msec is defined as a ngx_msec_t which in turn is ngx_uint_t. In
> an rpi is not big enough to hold Unix epoc in millis. (sec * 1000)
>
> nginx code does compile, but my tests fail: they have hardcoded values for
> the epoc.
>
> Is this deliberate? I guess its cropping the high order bits?  So millis
> comparisons might work but timestamps generated from this value might not?

Yes, this is intentional.  The ngx_current_msec variable (and the
ngx_msec_t type) is to be used to effectively implement timers,
and hence it uses platform-specific fast integer.  As such, it can
easily overflow on 32-bit platforms.  You have to fix your tests.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx