Welcome! Log In Create A New Profile

Advanced

ngx_msec_t is 32bit on ARM

Posted by teknopaul 
teknopaul
ngx_msec_t is 32bit on ARM
November 26, 2017 01:50AM
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
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: ngx_msec_t is 32bit on ARM
November 27, 2017 02:20PM
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
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login