* [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
@ 2005-12-06 10:36 David Engraf
2005-12-06 10:44 ` Arjan van de Ven
2005-12-06 19:47 ` Andi Kleen
0 siblings, 2 replies; 14+ messages in thread
From: David Engraf @ 2005-12-06 10:36 UTC (permalink / raw)
To: linux-kernel; +Cc: 'Andrew Morton'
This patch adds a new systemcall on i386 architectures returning the jiffies
value to the application.
As a kernel developer you can use jiffies but from the user space there is
no equivalent function which counts every millisecond like the Win32
GetTickCount.
linux-2.6.15-rc5-mm1
diff -puN include/asm-i386/unistd_orig.h include/asm-i386/unistd.h
--- include/asm-i386/unistd_orig.h 2005-12-06 12:07:16.000000000 +0100
+++ include/asm-i386/unistd.h 2005-12-06 12:10:07.000000000 +0100
@@ -300,8 +300,9 @@
#define __NR_inotify_add_watch 292
#define __NR_inotify_rm_watch 293
#define __NR_migrate_pages 294
+#define __NR_tickcount 295
-#define NR_syscalls 295
+#define NR_syscalls 296
/*
* user-visible error numbers are in the range -1 - -128: see
diff -puN arch/i386/kernel/syscall_table_orig.S
arch/i386/kernel/syscall_table.S
--- arch/i386/kernel/syscall_table_orig.S 2005-12-06
12:07:14.000000000 +0100
+++ arch/i386/kernel/syscall_table.S 2005-12-06 12:10:40.000000000 +0100
@@ -294,3 +294,4 @@ ENTRY(sys_call_table)
.long sys_inotify_add_watch
.long sys_inotify_rm_watch
.long sys_migrate_pages
+ .long sys_tickcount
diff -puN kernel/sys_orig.c kernel/sys.c
--- kernel/sys_orig.c 2005-12-06 12:06:49.000000000 +0100
+++ kernel/sys.c 2005-12-06 12:08:57.000000000 +0100
@@ -1855,3 +1855,9 @@ asmlinkage long sys_prctl(int option, un
}
return error;
}
+
+asmlinkage long sys_tickcount(long __user *ret)
+{
+ if (copy_to_user(ret, (void*)&jiffies, sizeof(long)))
+ return 0;
+}
Thanks
David Engraf
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 16.2037 from 06.12.2005
Virus news: www.antiviruslab.com
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 10:36 [PATCH] Win32 equivalent to GetTickCount systemcall (i386) David Engraf
@ 2005-12-06 10:44 ` Arjan van de Ven
2005-12-06 11:23 ` David Engraf
2005-12-06 19:47 ` Andi Kleen
1 sibling, 1 reply; 14+ messages in thread
From: Arjan van de Ven @ 2005-12-06 10:44 UTC (permalink / raw)
To: David Engraf; +Cc: linux-kernel, 'Andrew Morton'
On Tue, 2005-12-06 at 11:36 +0100, David Engraf wrote:
> This patch adds a new systemcall on i386 architectures returning the jiffies
> value to the application.
> As a kernel developer you can use jiffies but from the user space there is
> no equivalent function which counts every millisecond like the Win32
> GetTickCount.
a few comments
1) jiffies are 64 bit not 32
2) jiffies are not a constant time, eg HZ is a config option,
exposing that internal counter to userspace sounds wrong, after
all what would it be used for
3) wouldn't it be better to expose a wallclock time thing which
has a constant unit of time between all kernels?
(and.. wait.. isn't that called gettimeofday() )
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 10:44 ` Arjan van de Ven
@ 2005-12-06 11:23 ` David Engraf
2005-12-06 11:29 ` Ingo Molnar
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: David Engraf @ 2005-12-06 11:23 UTC (permalink / raw)
To: 'Arjan van de Ven'; +Cc: linux-kernel, 'Andrew Morton'
> On Tue, 2005-12-06 at 11:36 +0100, David Engraf wrote:
> > This patch adds a new systemcall on i386 architectures returning the
jiffies
> > value to the application.
> > As a kernel developer you can use jiffies but from the user space there
is
> > no equivalent function which counts every millisecond like the Win32
> > GetTickCount.
> a few comments
> 1) jiffies are 64 bit not 32
Jiffies is defined as "unsigned long volatile __jiffy_data jiffies". On i386
machines unsigned long is 32.
> 2) jiffies are not a constant time, eg HZ is a config option,
> exposing that internal counter to userspace sounds wrong, after
> all what would it be used for
Right, HZ is defined as USER_HZ which can be set over the config. On normal
desktop systems it should be 1000 on other machines it could also be 100 or
250. Either we can ignore the setting and the function depends on the
USER_HZ config, or we have to calculate the right value with USER_HZ.
> 3) wouldn't it be better to expose a wallclock time thing which
> has a constant unit of time between all kernels?
What is it?
> (and.. wait.. isn't that called gettimeofday() )
Not really gettimeofday is based on the date and time, but what if the user
changes the date, the counter would also change.
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 16.2038 from 06.12.2005
Virus news: www.antiviruslab.com
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 11:23 ` David Engraf
@ 2005-12-06 11:29 ` Ingo Molnar
2005-12-06 12:06 ` David Engraf
2005-12-06 11:35 ` Arjan van de Ven
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Ingo Molnar @ 2005-12-06 11:29 UTC (permalink / raw)
To: David Engraf
Cc: 'Arjan van de Ven', linux-kernel, 'Andrew Morton'
* David Engraf <engraf.david@netcom-sicherheitstechnik.de> wrote:
> > (and.. wait.. isn't that called gettimeofday() )
>
> Not really gettimeofday is based on the date and time, but what if the
> user changes the date, the counter would also change.
see 'man clock_gettime', and CLOCK_MONOTONIC:
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since
some unspecified starting point.
and it has microsecond resolution.
Ingo
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 11:29 ` Ingo Molnar
@ 2005-12-06 12:06 ` David Engraf
0 siblings, 0 replies; 14+ messages in thread
From: David Engraf @ 2005-12-06 12:06 UTC (permalink / raw)
To: 'Ingo Molnar'
Cc: 'Arjan van de Ven', linux-kernel, 'Andrew Morton'
> * David Engraf <engraf.david@netcom-sicherheitstechnik.de> wrote:
>
> > > (and.. wait.. isn't that called gettimeofday() )
> >
> > Not really gettimeofday is based on the date and time, but what if the
> > user changes the date, the counter would also change.
>
> see 'man clock_gettime', and CLOCK_MONOTONIC:
>
> CLOCK_MONOTONIC
> Clock that cannot be set and represents monotonic time
> since
> some unspecified starting point.
>
> and it has microsecond resolution.
>
> Ingo
You're right, clock_gettime with CLOCK_MONOTONIC seems to be date/time
independent. For a GetTickCount implementation it is absolutely enough.
Thanks
David Engraf
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 16.2039 from 06.12.2005
Virus news: www.antiviruslab.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 11:23 ` David Engraf
2005-12-06 11:29 ` Ingo Molnar
@ 2005-12-06 11:35 ` Arjan van de Ven
2005-12-06 11:37 ` Jakub Jelinek
2005-12-06 12:13 ` Bernd Petrovitsch
3 siblings, 0 replies; 14+ messages in thread
From: Arjan van de Ven @ 2005-12-06 11:35 UTC (permalink / raw)
To: David Engraf; +Cc: linux-kernel, 'Andrew Morton'
On Tue, 2005-12-06 at 12:23 +0100, David Engraf wrote:
> > On Tue, 2005-12-06 at 11:36 +0100, David Engraf wrote:
> > > This patch adds a new systemcall on i386 architectures returning the
> jiffies
> > > value to the application.
> > > As a kernel developer you can use jiffies but from the user space there
> is
> > > no equivalent function which counts every millisecond like the Win32
> > > GetTickCount.
>
> > a few comments
>
> > 1) jiffies are 64 bit not 32
>
> Jiffies is defined as "unsigned long volatile __jiffy_data jiffies". On i386
> machines unsigned long is 32.
but it's a subvariable of jiffies64 which is 64 bit
>
>
> > 2) jiffies are not a constant time, eg HZ is a config option,
> > exposing that internal counter to userspace sounds wrong, after
> > all what would it be used for
>
> Right, HZ is defined as USER_HZ which can be set over the config. On normal
> desktop systems it should be 1000 on other machines it could also be 100 or
> 250. Either we can ignore the setting and the function depends on the
> USER_HZ config, or we have to calculate the right value with USER_HZ.
but then.. why?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 11:23 ` David Engraf
2005-12-06 11:29 ` Ingo Molnar
2005-12-06 11:35 ` Arjan van de Ven
@ 2005-12-06 11:37 ` Jakub Jelinek
2005-12-06 12:13 ` Bernd Petrovitsch
3 siblings, 0 replies; 14+ messages in thread
From: Jakub Jelinek @ 2005-12-06 11:37 UTC (permalink / raw)
To: David Engraf
Cc: 'Arjan van de Ven', linux-kernel, 'Andrew Morton'
On Tue, Dec 06, 2005 at 12:23:23PM +0100, David Engraf wrote:
> > (and.. wait.. isn't that called gettimeofday() )
> Not really gettimeofday is based on the date and time, but what if the user
> changes the date, the counter would also change.
If you want a monotonic clock, just use clock_gettime (CLOCK_MONOTONIC, &ts);
Jakub
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 11:23 ` David Engraf
` (2 preceding siblings ...)
2005-12-06 11:37 ` Jakub Jelinek
@ 2005-12-06 12:13 ` Bernd Petrovitsch
2005-12-06 12:26 ` David Engraf
3 siblings, 1 reply; 14+ messages in thread
From: Bernd Petrovitsch @ 2005-12-06 12:13 UTC (permalink / raw)
To: David Engraf
Cc: 'Arjan van de Ven', linux-kernel, 'Andrew Morton'
On Tue, 2005-12-06 at 12:23 +0100, David Engraf wrote:
> > On Tue, 2005-12-06 at 11:36 +0100, David Engraf wrote:
[.../9
> > 3) wouldn't it be better to expose a wallclock time thing which
> > has a constant unit of time between all kernels?
>
> What is it?
>
>
> > (and.. wait.. isn't that called gettimeofday() )
> Not really gettimeofday is based on the date and time, but what if the user
> changes the date, the counter would also change.
man 2 times
And use the returned value.
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 12:13 ` Bernd Petrovitsch
@ 2005-12-06 12:26 ` David Engraf
2005-12-06 19:48 ` Andi Kleen
0 siblings, 1 reply; 14+ messages in thread
From: David Engraf @ 2005-12-06 12:26 UTC (permalink / raw)
To: 'Bernd Petrovitsch'; +Cc: linux-kernel, 'Andrew Morton'
> On Tue, 2005-12-06 at 12:23 +0100, David Engraf wrote:
> > > On Tue, 2005-12-06 at 11:36 +0100, David Engraf wrote:
> [.../9
> > > 3) wouldn't it be better to expose a wallclock time thing which
> > > has a constant unit of time between all kernels?
> >
> > What is it?
> >
> >
> > > (and.. wait.. isn't that called gettimeofday() )
> > Not really gettimeofday is based on the date and time, but what if the
> user
> > changes the date, the counter would also change.
>
> man 2 times
> And use the returned value.
>
> Bernd
> --
> Firmix Software GmbH http://www.firmix.at/
> mobil: +43 664 4416156 fax: +43 1 7890849-55
> Embedded Linux Development and Services
times has only 10ms resolution, we need at least 1ms.
David
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 16.2039 from 06.12.2005
Virus news: www.antiviruslab.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 12:26 ` David Engraf
@ 2005-12-06 19:48 ` Andi Kleen
2005-12-06 18:00 ` Eric Dumazet
0 siblings, 1 reply; 14+ messages in thread
From: Andi Kleen @ 2005-12-06 19:48 UTC (permalink / raw)
To: David Engraf; +Cc: linux-kernel
"David Engraf" <engraf.david@netcom-sicherheitstechnik.de> writes:
>
> times has only 10ms resolution, we need at least 1ms.
It actually has jiffies resultion. Your measurements must have been
quite off.
-Andi
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 19:48 ` Andi Kleen
@ 2005-12-06 18:00 ` Eric Dumazet
2005-12-06 18:01 ` Andi Kleen
0 siblings, 1 reply; 14+ messages in thread
From: Eric Dumazet @ 2005-12-06 18:00 UTC (permalink / raw)
To: Andi Kleen; +Cc: David Engraf, linux-kernel
Andi Kleen a écrit :
> "David Engraf" <engraf.david@netcom-sicherheitstechnik.de> writes:
>
>>times has only 10ms resolution, we need at least 1ms.
>
>
> It actually has jiffies resultion. Your measurements must have been
> quite off.
I beg to differ: times has a 10 ms resolution ( ie 1/USER_HZ)
times() is supposed to return clock_t expressed in USER_HZ, wich is still 100,
regardless of the kernel HZ
I just checked sources and sys_times() do use jiffies_64_to_clock_t()
Eric
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 18:00 ` Eric Dumazet
@ 2005-12-06 18:01 ` Andi Kleen
0 siblings, 0 replies; 14+ messages in thread
From: Andi Kleen @ 2005-12-06 18:01 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Andi Kleen, David Engraf, linux-kernel
On Tue, Dec 06, 2005 at 07:00:34PM +0100, Eric Dumazet wrote:
> Andi Kleen a ?crit :
> >"David Engraf" <engraf.david@netcom-sicherheitstechnik.de> writes:
> >
> >>times has only 10ms resolution, we need at least 1ms.
> >
> >
> >It actually has jiffies resultion. Your measurements must have been
> >quite off.
>
> I beg to differ: times has a 10 ms resolution ( ie 1/USER_HZ)
You're right. Sorry for the confusion. clock_gettime is the way
to go.
-Andi
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 10:36 [PATCH] Win32 equivalent to GetTickCount systemcall (i386) David Engraf
2005-12-06 10:44 ` Arjan van de Ven
@ 2005-12-06 19:47 ` Andi Kleen
2005-12-06 15:25 ` AW: " David Engraf
1 sibling, 1 reply; 14+ messages in thread
From: Andi Kleen @ 2005-12-06 19:47 UTC (permalink / raw)
To: David Engraf; +Cc: 'Andrew Morton', linux-kernel
"David Engraf" <engraf.david@netcom-sicherheitstechnik.de> writes:
> This patch adds a new systemcall on i386 architectures returning the jiffies
> value to the application.
> As a kernel developer you can use jiffies but from the user space there is
> no equivalent function which counts every millisecond like the Win32
> GetTickCount.
You want a timer that never go backwards, right?
Use clock_gettime(CLOCK_MONOTONIC). It's the POSIX way to do this.
-Andi
^ permalink raw reply [flat|nested] 14+ messages in thread
* AW: [PATCH] Win32 equivalent to GetTickCount systemcall (i386)
2005-12-06 19:47 ` Andi Kleen
@ 2005-12-06 15:25 ` David Engraf
0 siblings, 0 replies; 14+ messages in thread
From: David Engraf @ 2005-12-06 15:25 UTC (permalink / raw)
To: ak; +Cc: linux-kernel
> "David Engraf" <engraf.david@netcom-sicherheitstechnik.de> writes:
>
> > This patch adds a new systemcall on i386 architectures returning the
> jiffies
> > value to the application.
> > As a kernel developer you can use jiffies but from the user space there
> is
> > no equivalent function which counts every millisecond like the Win32
> > GetTickCount.
>
> You want a timer that never go backwards, right?
>
> Use clock_gettime(CLOCK_MONOTONIC). It's the POSIX way to do this.
>
> -Andi
Yes, clock_gettime works(CLOCK_MONOTONIC), thanks.
David
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 16.2042 from 06.12.2005
Virus news: www.antiviruslab.com
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-12-06 18:01 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-06 10:36 [PATCH] Win32 equivalent to GetTickCount systemcall (i386) David Engraf
2005-12-06 10:44 ` Arjan van de Ven
2005-12-06 11:23 ` David Engraf
2005-12-06 11:29 ` Ingo Molnar
2005-12-06 12:06 ` David Engraf
2005-12-06 11:35 ` Arjan van de Ven
2005-12-06 11:37 ` Jakub Jelinek
2005-12-06 12:13 ` Bernd Petrovitsch
2005-12-06 12:26 ` David Engraf
2005-12-06 19:48 ` Andi Kleen
2005-12-06 18:00 ` Eric Dumazet
2005-12-06 18:01 ` Andi Kleen
2005-12-06 19:47 ` Andi Kleen
2005-12-06 15:25 ` AW: " David Engraf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox