On 10 December 2015 at 09:40, Maxim Uvarov <maxim.uva...@linaro.org> wrote:

> On 12/10/2015 11:21, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
>> Signed-off-by: Bill Fischofer <bill.fischo...@linaro.org>
>>> ---
>>>   .../linux-generic/include/odp/plat/time_types.h    |  5 +++-
>>>   platform/linux-generic/odp_time.c                  | 27
>>> +++++++++++++----
>>> -----
>>>   2 files changed, 20 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/platform/linux-generic/include/odp/plat/time_types.h
>>> b/platform/linux-generic/include/odp/plat/time_types.h
>>> index e5765ec..05e2b59 100644
>>> --- a/platform/linux-generic/include/odp/plat/time_types.h
>>> +++ b/platform/linux-generic/include/odp/plat/time_types.h
>>> @@ -21,7 +21,10 @@ extern "C" {
>>>    *  @{
>>>    **/
>>>
>>> -typedef struct timespec odp_time_t;
>>> +typedef struct {
>>> +       uint64_t tv_sec;
>>> +       int64_t  tv_nsec;
>>> +} odp_time_t;
>>>
>>
>> This struct should match timespec exactly. If that’s not possible, union
>> should not be used but copy data between timespec and odp_time_t.
>>
>> POSIX: "The <time.h> header shall declare the structure timespec, which
>> has at least the following members:"
>>
>> time_t  tv_sec    Seconds.
>> long    tv_nsec   Nanoseconds.
>>
>> int64_t is not long. I think we hit that previously this week. Long may
>> be 32 bits on a 32 bit system.
>>
>> time_t is defined in C headers.
>>
>> Also POSIX spec states that there can be more members than these. That
>> hints that field order/offset and struct size may vary. At least the hack
>> should be well documented and build/run time checked.
>>
>> -Petri
>>
>
> Yes, Petri is right. Yesterday I went thought headers but did not see
> mismatch.
> Both values are signed in linux:
>
> struct timespec
>   {
>     __time_t tv_sec;        /* Seconds.  */
>     __syscall_slong_t tv_nsec;    /* Nanoseconds.  */
>   };
>
> /* Signed long type used in system calls.  */
> __STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t;
>
> #if defined __x86_64__ && defined __ILP32__
> # define __SYSCALL_SLONG_TYPE    __SQUAD_TYPE
> # define __SYSCALL_ULONG_TYPE    __UQUAD_TYPE
> #else
> # define __SYSCALL_SLONG_TYPE    __SLONGWORD_TYPE
> # define __SYSCALL_ULONG_TYPE    __ULONGWORD_TYPE
> #endif
>
> # define __SQUAD_TYPE        long int
> #define __SLONGWORD_TYPE    long int
>
> btw, time_t is also signed value:
> __STD_TYPE __TIME_T_TYPE __time_t;    /* Seconds since the Epoch. */
> #define __TIME_T_TYPE        __SYSCALL_SLONG_TYPE
>
> But it's reachable from <sys/types.h>
>
> Question - why that values are signed in linux?

time_t has always been signed in Unix. Probably the original Unix
implementors were more interested in that past (before 1970) than in the
future (beyond year 2038).


>
>
> Maxim.
>
>
>
>>
>>   odp_time_t odp_time_null(void);
>>>
>>> diff --git a/platform/linux-generic/odp_time.c b/platform/linux-
>>> generic/odp_time.c
>>> index 1c7c214..b5737f6 100644
>>> --- a/platform/linux-generic/odp_time.c
>>> +++ b/platform/linux-generic/odp_time.c
>>> @@ -11,7 +11,12 @@
>>>   #include <odp/hints.h>
>>>   #include <odp_debug_internal.h>
>>>
>>> -static struct timespec start_time;
>>> +typedef union {
>>> +       odp_time_t      ex;
>>> +       struct timespec in;
>>> +} _odp_time_t;
>>> +
>>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to