* [PATCH] Do not make trace.c/getnanotime an inlined function
@ 2014-09-28 7:50 Ben Walton
2014-09-28 19:15 ` Johannes Sixt
2014-09-29 12:44 ` Duy Nguyen
0 siblings, 2 replies; 7+ messages in thread
From: Ben Walton @ 2014-09-28 7:50 UTC (permalink / raw)
To: karsten.blees, gitster; +Cc: git, Ben Walton
Oracle Studio compilers don't allow for static variables in functions
that are defined to be inline. GNU C does permit this. Let's reference
the C99 standard though, which doesn't allow for inline functions to
contain modifiable static variables.
Signed-off-by: Ben Walton <bdwalton@gmail.com>
---
trace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/trace.c b/trace.c
index b6f25a2..4778608 100644
--- a/trace.c
+++ b/trace.c
@@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
* Returns nanoseconds since the epoch (01/01/1970), for performance tracing
* (i.e. favoring high precision over wall clock time accuracy).
*/
-inline uint64_t getnanotime(void)
+uint64_t getnanotime(void)
{
static uint64_t offset;
if (offset > 1) {
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Do not make trace.c/getnanotime an inlined function
2014-09-28 7:50 [PATCH] Do not make trace.c/getnanotime an inlined function Ben Walton
@ 2014-09-28 19:15 ` Johannes Sixt
[not found] ` <CAP30j14QGtHC7huU=3t4sJT_dZ3t9V=CBWyGyJW7EjT9H5ZK9w@mail.gmail.com>
2014-09-29 12:44 ` Duy Nguyen
1 sibling, 1 reply; 7+ messages in thread
From: Johannes Sixt @ 2014-09-28 19:15 UTC (permalink / raw)
To: Ben Walton; +Cc: karsten.blees, gitster, git
Am 28.09.2014 um 09:50 schrieb Ben Walton:
> Oracle Studio compilers don't allow for static variables in functions
> that are defined to be inline. GNU C does permit this. Let's reference
> the C99 standard though, which doesn't allow for inline functions to
> contain modifiable static variables.
>
> Signed-off-by: Ben Walton <bdwalton@gmail.com>
> ---
> trace.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/trace.c b/trace.c
> index b6f25a2..4778608 100644
> --- a/trace.c
> +++ b/trace.c
> @@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
> * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
> * (i.e. favoring high precision over wall clock time accuracy).
> */
> -inline uint64_t getnanotime(void)
> +uint64_t getnanotime(void)
> {
> static uint64_t offset;
> if (offset > 1) {
>
But then the function could stay static, no?
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Do not make trace.c/getnanotime an inlined function
2014-09-28 7:50 [PATCH] Do not make trace.c/getnanotime an inlined function Ben Walton
2014-09-28 19:15 ` Johannes Sixt
@ 2014-09-29 12:44 ` Duy Nguyen
2014-09-29 17:48 ` Junio C Hamano
1 sibling, 1 reply; 7+ messages in thread
From: Duy Nguyen @ 2014-09-29 12:44 UTC (permalink / raw)
To: Ben Walton; +Cc: Karsten Blees, Junio C Hamano, Git Mailing List
On Sun, Sep 28, 2014 at 2:50 PM, Ben Walton <bdwalton@gmail.com> wrote:
> Oracle Studio compilers don't allow for static variables in functions
> that are defined to be inline. GNU C does permit this. Let's reference
> the C99 standard though, which doesn't allow for inline functions to
> contain modifiable static variables.
>
> Signed-off-by: Ben Walton <bdwalton@gmail.com>
> ---
> trace.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/trace.c b/trace.c
> index b6f25a2..4778608 100644
> --- a/trace.c
> +++ b/trace.c
> @@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
> * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
> * (i.e. favoring high precision over wall clock time accuracy).
> */
> -inline uint64_t getnanotime(void)
> +uint64_t getnanotime(void)
> {
> static uint64_t offset;
Would moving this offset outside getnanotime() work?
--
Duy
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Do not make trace.c/getnanotime an inlined function
2014-09-29 12:44 ` Duy Nguyen
@ 2014-09-29 17:48 ` Junio C Hamano
2014-09-30 9:25 ` Duy Nguyen
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-09-29 17:48 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Ben Walton, Karsten Blees, Git Mailing List
Duy Nguyen <pclouds@gmail.com> writes:
> On Sun, Sep 28, 2014 at 2:50 PM, Ben Walton <bdwalton@gmail.com> wrote:
>> Oracle Studio compilers don't allow for static variables in functions
>> that are defined to be inline. GNU C does permit this. Let's reference
>> the C99 standard though, which doesn't allow for inline functions to
>> contain modifiable static variables.
>>
>> Signed-off-by: Ben Walton <bdwalton@gmail.com>
>> ---
>> trace.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/trace.c b/trace.c
>> index b6f25a2..4778608 100644
>> --- a/trace.c
>> +++ b/trace.c
>> @@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
>> * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
>> * (i.e. favoring high precision over wall clock time accuracy).
>> */
>> -inline uint64_t getnanotime(void)
>> +uint64_t getnanotime(void)
>> {
>> static uint64_t offset;
>
> Would moving this offset outside getnanotime() work?
I am not sure what the definition of "work" is.
The function computes the difference between the returned value from
gettimeofday(2) and a custom highres_nanos() just once and returns
the value it got from gettimeofday the first time, and then for
subsequent calls massages the returned value from highres_nanos() to
be consistent with the value returned from gettimeofday using the
offset it computed in the first call.
If we have two copies of this function, two independent probes to
these pair of underlying functions will be made to compute their
offsets. With perfect pair of clocks that may not matter, but it
just feels wrong to me.
Besides, I wonder what happens if the computed offset happen to be
1, which is used as a sentinel.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Do not make trace.c/getnanotime an inlined function
2014-09-29 17:48 ` Junio C Hamano
@ 2014-09-30 9:25 ` Duy Nguyen
2014-09-30 15:54 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Duy Nguyen @ 2014-09-30 9:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Ben Walton, Karsten Blees, Git Mailing List
On Tue, Sep 30, 2014 at 12:48 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
>
>> On Sun, Sep 28, 2014 at 2:50 PM, Ben Walton <bdwalton@gmail.com> wrote:
>>> Oracle Studio compilers don't allow for static variables in functions
>>> that are defined to be inline. GNU C does permit this. Let's reference
>>> the C99 standard though, which doesn't allow for inline functions to
>>> contain modifiable static variables.
>>>
>>> Signed-off-by: Ben Walton <bdwalton@gmail.com>
>>> ---
>>> trace.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/trace.c b/trace.c
>>> index b6f25a2..4778608 100644
>>> --- a/trace.c
>>> +++ b/trace.c
>>> @@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
>>> * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
>>> * (i.e. favoring high precision over wall clock time accuracy).
>>> */
>>> -inline uint64_t getnanotime(void)
>>> +uint64_t getnanotime(void)
>>> {
>>> static uint64_t offset;
>>
>> Would moving this offset outside getnanotime() work?
>
> I am not sure what the definition of "work" is.
>
> The function computes the difference between the returned value from
> gettimeofday(2) and a custom highres_nanos() just once and returns
> the value it got from gettimeofday the first time, and then for
> subsequent calls massages the returned value from highres_nanos() to
> be consistent with the value returned from gettimeofday using the
> offset it computed in the first call.
>
> If we have two copies of this function, two independent probes to
> these pair of underlying functions will be made to compute their
> offsets.
Hmm.. no. Even if the function is inlined in multiple places, inline
code still points to the same "offset" variable. So the
gettimeofday_nanos()/highres_nanos() pair should only be called once.
Tested with gcc.
--
Duy
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-09-30 15:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-28 7:50 [PATCH] Do not make trace.c/getnanotime an inlined function Ben Walton
2014-09-28 19:15 ` Johannes Sixt
[not found] ` <CAP30j14QGtHC7huU=3t4sJT_dZ3t9V=CBWyGyJW7EjT9H5ZK9w@mail.gmail.com>
2014-09-29 20:40 ` Johannes Sixt
2014-09-29 12:44 ` Duy Nguyen
2014-09-29 17:48 ` Junio C Hamano
2014-09-30 9:25 ` Duy Nguyen
2014-09-30 15:54 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).