mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
@ 2023-02-20 13:41 Ian Abbott
  2023-02-23 15:42 ` Michael Olbrich
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Abbott @ 2023-02-20 13:41 UTC (permalink / raw)
  To: ptxdist; +Cc: Ian Abbott

libtahu exposes a library function `get_current_timestamp()` to return
the real-time clock as the number of milliseconds since the Unix epoch
as a 64-bit value.  It calls `clock_gettime(CLOCK_REALTIME, &ts)` (where
`ts` is a `struct timespec`) to get the system time and does some simple
arithmetic on `ts.tv_sec` and `ts.tv_nsec` to convert the time to a
number of milliseconds.

Ideally, we want `ts.tv_sec` to have a 64-bit type to avoid Y2038
problems, but on most 32-bit architectures, `ts.tv_sec` will have a
32-bit type by default.  Try and select the 64-bit time interface even
on 32-bit architectures by appending `-D_FILE_OFFSET_BITS=64` and
`-D_TIME_BITS=64` to the `CFLAGS` variable when invoking `make`.  This
works for glibc 2.34 or later when the system is running on Linux kernel
5.1 or later.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 rules/libtahu.make | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/rules/libtahu.make b/rules/libtahu.make
index 26c064c6d..3e392216d 100644
--- a/rules/libtahu.make
+++ b/rules/libtahu.make
@@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
 # Compile
 # ----------------------------------------------------------------------------
 
-#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
-
+LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
+LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC
 # Just build the dynamic library.
 LIBTAHU_MAKE_OPT	:= \
 	$(CROSS_ENV_PROGS) \
+	CFLAGS='$(CROSS_CPPFLAGS) $(LIBTAHU_CPPFLAGS) $(CROSS_CFLAGS) $(LIBTAHU_CFLAGS)' \
 	lib/libtahu.so
 
 # ----------------------------------------------------------------------------
-- 
2.39.1




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-20 13:41 [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time Ian Abbott
@ 2023-02-23 15:42 ` Michael Olbrich
  2023-02-24  9:55   ` Ian Abbott
  2023-02-24 12:03   ` Ian Abbott
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Olbrich @ 2023-02-23 15:42 UTC (permalink / raw)
  To: Ian Abbott; +Cc: ptxdist

On Mon, Feb 20, 2023 at 01:41:05PM +0000, Ian Abbott wrote:
> libtahu exposes a library function `get_current_timestamp()` to return
> the real-time clock as the number of milliseconds since the Unix epoch
> as a 64-bit value.  It calls `clock_gettime(CLOCK_REALTIME, &ts)` (where
> `ts` is a `struct timespec`) to get the system time and does some simple
> arithmetic on `ts.tv_sec` and `ts.tv_nsec` to convert the time to a
> number of milliseconds.
> 
> Ideally, we want `ts.tv_sec` to have a 64-bit type to avoid Y2038
> problems, but on most 32-bit architectures, `ts.tv_sec` will have a
> 32-bit type by default.  Try and select the 64-bit time interface even
> on 32-bit architectures by appending `-D_FILE_OFFSET_BITS=64` and
> `-D_TIME_BITS=64` to the `CFLAGS` variable when invoking `make`.  This
> works for glibc 2.34 or later when the system is running on Linux kernel
> 5.1 or later.
> 
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> ---
>  rules/libtahu.make | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/rules/libtahu.make b/rules/libtahu.make
> index 26c064c6d..3e392216d 100644
> --- a/rules/libtahu.make
> +++ b/rules/libtahu.make
> @@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
>  # Compile
>  # ----------------------------------------------------------------------------
>  
> -#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
> -
> +LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> +LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC

No need to mess with the existing CFLAGS. You can inject extra CFLAGS
though the toolchain wrappers. And for correctness, make it conditional:

ifdef PTXCONF_GLOBAL_LARGE_FILE
LIBTAHU_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
endif

nothing else is needed.

Michael

>  # Just build the dynamic library.
>  LIBTAHU_MAKE_OPT	:= \
>  	$(CROSS_ENV_PROGS) \
> +	CFLAGS='$(CROSS_CPPFLAGS) $(LIBTAHU_CPPFLAGS) $(CROSS_CFLAGS) $(LIBTAHU_CFLAGS)' \
>  	lib/libtahu.so
>  
>  # ----------------------------------------------------------------------------
> -- 
> 2.39.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-23 15:42 ` Michael Olbrich
@ 2023-02-24  9:55   ` Ian Abbott
  2023-02-24 14:43     ` Michael Olbrich
  2023-02-24 12:03   ` Ian Abbott
  1 sibling, 1 reply; 7+ messages in thread
From: Ian Abbott @ 2023-02-24  9:55 UTC (permalink / raw)
  To: ptxdist

On 23/02/2023 15:42, Michael Olbrich wrote:
> On Mon, Feb 20, 2023 at 01:41:05PM +0000, Ian Abbott wrote:
>> diff --git a/rules/libtahu.make b/rules/libtahu.make
>> index 26c064c6d..3e392216d 100644
>> --- a/rules/libtahu.make
>> +++ b/rules/libtahu.make
>> @@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
>>   # Compile
>>   # ----------------------------------------------------------------------------
>>   
>> -#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
>> -
>> +LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
>> +LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC
> 
> No need to mess with the existing CFLAGS. You can inject extra CFLAGS
> though the toolchain wrappers. And for correctness, make it conditional:
> 
> ifdef PTXCONF_GLOBAL_LARGE_FILE
> LIBTAHU_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> endif
> 
> nothing else is needed.

libtahu does not actually use files, large or otherwise.  It's the 
64-bit time support that I want, not the large file support.  However 
glibc does not support _TIME_BITS=64 unless _FILE_OFFSET_BITS=64, so 
that needs to come along for the ride.

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-23 15:42 ` Michael Olbrich
  2023-02-24  9:55   ` Ian Abbott
@ 2023-02-24 12:03   ` Ian Abbott
  2023-02-24 14:45     ` Michael Olbrich
  1 sibling, 1 reply; 7+ messages in thread
From: Ian Abbott @ 2023-02-24 12:03 UTC (permalink / raw)
  To: ptxdist

On 23/02/2023 15:42, Michael Olbrich wrote:
> On Mon, Feb 20, 2023 at 01:41:05PM +0000, Ian Abbott wrote:
>> libtahu exposes a library function `get_current_timestamp()` to return
>> the real-time clock as the number of milliseconds since the Unix epoch
>> as a 64-bit value.  It calls `clock_gettime(CLOCK_REALTIME, &ts)` (where
>> `ts` is a `struct timespec`) to get the system time and does some simple
>> arithmetic on `ts.tv_sec` and `ts.tv_nsec` to convert the time to a
>> number of milliseconds.
>>
>> Ideally, we want `ts.tv_sec` to have a 64-bit type to avoid Y2038
>> problems, but on most 32-bit architectures, `ts.tv_sec` will have a
>> 32-bit type by default.  Try and select the 64-bit time interface even
>> on 32-bit architectures by appending `-D_FILE_OFFSET_BITS=64` and
>> `-D_TIME_BITS=64` to the `CFLAGS` variable when invoking `make`.  This
>> works for glibc 2.34 or later when the system is running on Linux kernel
>> 5.1 or later.
>>
>> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
>> ---
>>   rules/libtahu.make | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/rules/libtahu.make b/rules/libtahu.make
>> index 26c064c6d..3e392216d 100644
>> --- a/rules/libtahu.make
>> +++ b/rules/libtahu.make
>> @@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
>>   # Compile
>>   # ----------------------------------------------------------------------------
>>   
>> -#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
>> -
>> +LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
>> +LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC
> 
> No need to mess with the existing CFLAGS. You can inject extra CFLAGS
> though the toolchain wrappers. And for correctness, make it conditional:
> 
> ifdef PTXCONF_GLOBAL_LARGE_FILE
> LIBTAHU_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> endif
> 
> nothing else is needed.
> 
> Michael

Hi Michael,

Sorry to be a pain.  I'm attempting to inject extra CFLAGS through the 
toolchain wrappers, but I'm not sure how to do it.  Here is one of my 
attempts that does not work:

# 
----------------------------------------------------------------------------
# Prepare
# 
----------------------------------------------------------------------------

LIBTAHU_CONF_TOOL	:= NO

# 
----------------------------------------------------------------------------
# Compile
# 
----------------------------------------------------------------------------

# -D_TIME_BITS=64 requires -D_FILE_OFFSET_BITS=64
LIBTAHU_CPPFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
LIBTAHU_CFLAGS := -O2
LIBTAHU_MAKE_ENV := $(CROSS_ENV)
# Just build the dynamic library.
LIBTAHU_MAKE_OPT := \
	$(CROSS_ENV_PROGS) \
	lib/libtahu.so

$(STATEDIR)/libtahu.compile:
	@$(call targetinfo)
	@$(call world/compile, LIBTAHU)
	@$(call touch)

I'm obviously missing something to pass the properly wrapped CC and CPP 
variables (incorporating the extra flags) to 'make'.  Could you provide 
a clue how to fix it?

Thanks

Ian

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-24  9:55   ` Ian Abbott
@ 2023-02-24 14:43     ` Michael Olbrich
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Olbrich @ 2023-02-24 14:43 UTC (permalink / raw)
  To: Ian Abbott; +Cc: ptxdist

On Fri, Feb 24, 2023 at 09:55:12AM +0000, Ian Abbott wrote:
> On 23/02/2023 15:42, Michael Olbrich wrote:
> > On Mon, Feb 20, 2023 at 01:41:05PM +0000, Ian Abbott wrote:
> > > diff --git a/rules/libtahu.make b/rules/libtahu.make
> > > index 26c064c6d..3e392216d 100644
> > > --- a/rules/libtahu.make
> > > +++ b/rules/libtahu.make
> > > @@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
> > >   # Compile
> > >   # ----------------------------------------------------------------------------
> > > -#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
> > > -
> > > +LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> > > +LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC
> > 
> > No need to mess with the existing CFLAGS. You can inject extra CFLAGS
> > though the toolchain wrappers. And for correctness, make it conditional:
> > 
> > ifdef PTXCONF_GLOBAL_LARGE_FILE
> > LIBTAHU_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> > endif
> > 
> > nothing else is needed.
> 
> libtahu does not actually use files, large or otherwise.  It's the 64-bit
> time support that I want, not the large file support.  However glibc does
> not support _TIME_BITS=64 unless _FILE_OFFSET_BITS=64, so that needs to come
> along for the ride.

I just read _FILE_OFFSET_BITS=64 and that matched with
PTXCONF_GLOBAL_LARGE_FILE in my brain... :-)

Anyways, making it conditionally like that is actually correct in some
ways, because as you said, you need the large file stuff anyways before the
64bit time stuff can be enabled.

But I'm not so sure any more, if that patch makes sense in general:
This is not something that should be enabled for a single package and
adding cflags to every package does not scale.

Doing that for PTXdist as a whole is on my todo list but I've not had the
time to implement this.

Michael

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-24 12:03   ` Ian Abbott
@ 2023-02-24 14:45     ` Michael Olbrich
  2023-02-24 16:10       ` Ian Abbott
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Olbrich @ 2023-02-24 14:45 UTC (permalink / raw)
  To: Ian Abbott; +Cc: ptxdist

On Fri, Feb 24, 2023 at 12:03:14PM +0000, Ian Abbott wrote:
> On 23/02/2023 15:42, Michael Olbrich wrote:
> > On Mon, Feb 20, 2023 at 01:41:05PM +0000, Ian Abbott wrote:
> > > libtahu exposes a library function `get_current_timestamp()` to return
> > > the real-time clock as the number of milliseconds since the Unix epoch
> > > as a 64-bit value.  It calls `clock_gettime(CLOCK_REALTIME, &ts)` (where
> > > `ts` is a `struct timespec`) to get the system time and does some simple
> > > arithmetic on `ts.tv_sec` and `ts.tv_nsec` to convert the time to a
> > > number of milliseconds.
> > > 
> > > Ideally, we want `ts.tv_sec` to have a 64-bit type to avoid Y2038
> > > problems, but on most 32-bit architectures, `ts.tv_sec` will have a
> > > 32-bit type by default.  Try and select the 64-bit time interface even
> > > on 32-bit architectures by appending `-D_FILE_OFFSET_BITS=64` and
> > > `-D_TIME_BITS=64` to the `CFLAGS` variable when invoking `make`.  This
> > > works for glibc 2.34 or later when the system is running on Linux kernel
> > > 5.1 or later.
> > > 
> > > Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> > > ---
> > >   rules/libtahu.make | 5 +++--
> > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/rules/libtahu.make b/rules/libtahu.make
> > > index 26c064c6d..3e392216d 100644
> > > --- a/rules/libtahu.make
> > > +++ b/rules/libtahu.make
> > > @@ -37,11 +37,12 @@ LIBTAHU_CONF_TOOL	:= NO
> > >   # Compile
> > >   # ----------------------------------------------------------------------------
> > > -#LIBTAHU_MAKE_ENV	:= $(CROSS_ENV)
> > > -
> > > +LIBTAHU_CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> > > +LIBTAHU_CFLAGS := -O2 -g -g3 -fPIC
> > 
> > No need to mess with the existing CFLAGS. You can inject extra CFLAGS
> > though the toolchain wrappers. And for correctness, make it conditional:
> > 
> > ifdef PTXCONF_GLOBAL_LARGE_FILE
> > LIBTAHU_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> > endif
> > 
> > nothing else is needed.
> > 
> > Michael
> 
> Hi Michael,
> 
> Sorry to be a pain.  I'm attempting to inject extra CFLAGS through the
> toolchain wrappers, but I'm not sure how to do it.  Here is one of my
> attempts that does not work:
> 
> #
> ----------------------------------------------------------------------------
> # Prepare
> #
> ----------------------------------------------------------------------------
> 
> LIBTAHU_CONF_TOOL	:= NO
> 
> #
> ----------------------------------------------------------------------------
> # Compile
> #
> ----------------------------------------------------------------------------
> 
> # -D_TIME_BITS=64 requires -D_FILE_OFFSET_BITS=64
> LIBTAHU_CPPFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
> LIBTAHU_CFLAGS := -O2
> LIBTAHU_MAKE_ENV := $(CROSS_ENV)
> # Just build the dynamic library.
> LIBTAHU_MAKE_OPT := \
> 	$(CROSS_ENV_PROGS) \
> 	lib/libtahu.so
> 
> $(STATEDIR)/libtahu.compile:
> 	@$(call targetinfo)
> 	@$(call world/compile, LIBTAHU)
> 	@$(call touch)
> 
> I'm obviously missing something to pass the properly wrapped CC and CPP
> variables (incorporating the extra flags) to 'make'.  Could you provide a
> clue how to fix it?

Are you sure it does not work? It will not be visible in the regular make
output. Run PTXdist with '-v' and then check platform-XXX/logfile.

You should find a 'wrapper: ...' line for each compiler run and the extra
flags should be visible here.

Michael


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time
  2023-02-24 14:45     ` Michael Olbrich
@ 2023-02-24 16:10       ` Ian Abbott
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2023-02-24 16:10 UTC (permalink / raw)
  To: ptxdist

On 24/02/2023 14:45, Michael Olbrich wrote:
> On Fri, Feb 24, 2023 at 12:03:14PM +0000, Ian Abbott wrote:
>> Hi Michael,
>>
>> Sorry to be a pain.  I'm attempting to inject extra CFLAGS through the
>> toolchain wrappers, but I'm not sure how to do it.  Here is one of my
>> attempts that does not work:
>>
>> #
>> ----------------------------------------------------------------------------
>> # Prepare
>> #
>> ----------------------------------------------------------------------------
>>
>> LIBTAHU_CONF_TOOL	:= NO
>>
>> #
>> ----------------------------------------------------------------------------
>> # Compile
>> #
>> ----------------------------------------------------------------------------
>>
>> # -D_TIME_BITS=64 requires -D_FILE_OFFSET_BITS=64
>> LIBTAHU_CPPFLAGS := -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
>> LIBTAHU_CFLAGS := -O2
>> LIBTAHU_MAKE_ENV := $(CROSS_ENV)
>> # Just build the dynamic library.
>> LIBTAHU_MAKE_OPT := \
>> 	$(CROSS_ENV_PROGS) \
>> 	lib/libtahu.so
>>
>> $(STATEDIR)/libtahu.compile:
>> 	@$(call targetinfo)
>> 	@$(call world/compile, LIBTAHU)
>> 	@$(call touch)
>>
>> I'm obviously missing something to pass the properly wrapped CC and CPP
>> variables (incorporating the extra flags) to 'make'.  Could you provide a
>> clue how to fix it?
> 
> Are you sure it does not work? It will not be visible in the regular make
> output. Run PTXdist with '-v' and then check platform-XXX/logfile.
> 
> You should find a 'wrapper: ...' line for each compiler run and the extra
> flags should be visible here.

Oops, so they are!  I never noticed.  I understand what is going on now!

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-24 16:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20 13:41 [ptxdist] [PATCH] libtahu: Change CFLAGS to use 64-bit system time Ian Abbott
2023-02-23 15:42 ` Michael Olbrich
2023-02-24  9:55   ` Ian Abbott
2023-02-24 14:43     ` Michael Olbrich
2023-02-24 12:03   ` Ian Abbott
2023-02-24 14:45     ` Michael Olbrich
2023-02-24 16:10       ` Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox