public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] UML - time build fix
@ 2007-09-25 17:37 Jeff Dike
  2007-09-25 19:54 ` Thomas Gleixner
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Dike @ 2007-09-25 17:37 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, uml-devel, Thomas Gleixner

Put back an implementation of timeval_to_ns in
arch/um/os-Linux/time.c.  tglx pointed out in his review of tickless
support that there was a perfectly good implementation of it in
linux/time.h.  The problem is that this is userspace code which can't
pull in kernel headers and there doesn't seem to be a libc version.

So, I'm copying the version from linux/time.h rather than resurrecting
my version.  This causes some declaration changes as it now returns a
signed value rather than an unsigned value.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
---
 arch/um/include/os.h    |    4 ++--
 arch/um/os-Linux/time.c |   22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 5 deletions(-)

Index: linux-2.6.22/arch/um/include/os.h
===================================================================
--- linux-2.6.22.orig/arch/um/include/os.h	2007-09-25 09:26:42.000000000 -0400
+++ linux-2.6.22/arch/um/include/os.h	2007-09-25 09:28:42.000000000 -0400
@@ -252,9 +252,9 @@ extern void os_dump_core(void);
 extern void idle_sleep(unsigned long long nsecs);
 extern int set_interval(void);
 extern int timer_one_shot(int ticks);
-extern unsigned long long disable_timer(void);
+extern long long disable_timer(void);
 extern void uml_idle_timer(void);
-extern unsigned long long os_nsecs(void);
+extern long long os_nsecs(void);
 
 /* skas/mem.c */
 extern long run_syscall_stub(struct mm_id * mm_idp,
Index: linux-2.6.22/arch/um/os-Linux/time.c
===================================================================
--- linux-2.6.22.orig/arch/um/os-Linux/time.c	2007-09-25 09:26:42.000000000 -0400
+++ linux-2.6.22/arch/um/os-Linux/time.c	2007-09-25 09:28:42.000000000 -0400
@@ -39,7 +39,23 @@ int timer_one_shot(int ticks)
 	return 0;
 }
 
-unsigned long long disable_timer(void)
+/**
+ * timeval_to_ns - Convert timeval to nanoseconds
+ * @ts:		pointer to the timeval variable to be converted
+ *
+ * Returns the scalar nanosecond representation of the timeval
+ * parameter.
+ *
+ * Ripped from linux/time.h because it's a kernel header, and thus
+ * unusable from here.
+ */
+static inline long long timeval_to_ns(const struct timeval *tv)
+{
+	return ((long long) tv->tv_sec * UM_NSEC_PER_SEC) +
+		tv->tv_usec * UM_NSEC_PER_USEC;
+}
+
+long long disable_timer(void)
 {
 	struct itimerval time = ((struct itimerval) { { 0, 0 }, { 0, 0 } });
 
@@ -47,10 +63,10 @@ unsigned long long disable_timer(void)
 		printk(UM_KERN_ERR "disable_timer - setitimer failed, "
 		       "errno = %d\n", errno);
 
-	return tv_to_nsec(&time.it_value);
+	return timeval_to_ns(&time.it_value);
 }
 
-unsigned long long os_nsecs(void)
+long long os_nsecs(void)
 {
 	struct timeval tv;
 

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

* Re: [PATCH] UML - time build fix
  2007-09-25 17:37 [PATCH] UML - time build fix Jeff Dike
@ 2007-09-25 19:54 ` Thomas Gleixner
  2007-09-25 21:56   ` Jeff Dike
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2007-09-25 19:54 UTC (permalink / raw)
  To: Jeff Dike; +Cc: Andrew Morton, LKML, uml-devel


On Tue, 2007-09-25 at 13:37 -0400, Jeff Dike wrote:
> Put back an implementation of timeval_to_ns in
> arch/um/os-Linux/time.c.  tglx pointed out in his review of tickless
> support that there was a perfectly good implementation of it in
> linux/time.h.  The problem is that this is userspace code which can't
> pull in kernel headers and there doesn't seem to be a libc version.

Oops. Did not notice. Can't we move it into some header file which is
accessible from everywhere ?

	tglx

> So, I'm copying the version from linux/time.h rather than resurrecting
> my version.  This causes some declaration changes as it now returns a
> signed value rather than an unsigned value.
> 
> Signed-off-by: Jeff Dike <jdike@linux.intel.com>
> ---
>  arch/um/include/os.h    |    4 ++--
>  arch/um/os-Linux/time.c |   22 +++++++++++++++++++---
>  2 files changed, 21 insertions(+), 5 deletions(-)
> 
> Index: linux-2.6.22/arch/um/include/os.h
> ===================================================================
> --- linux-2.6.22.orig/arch/um/include/os.h	2007-09-25 09:26:42.000000000 -0400
> +++ linux-2.6.22/arch/um/include/os.h	2007-09-25 09:28:42.000000000 -0400
> @@ -252,9 +252,9 @@ extern void os_dump_core(void);
>  extern void idle_sleep(unsigned long long nsecs);
>  extern int set_interval(void);
>  extern int timer_one_shot(int ticks);
> -extern unsigned long long disable_timer(void);
> +extern long long disable_timer(void);
>  extern void uml_idle_timer(void);
> -extern unsigned long long os_nsecs(void);
> +extern long long os_nsecs(void);
>  
>  /* skas/mem.c */
>  extern long run_syscall_stub(struct mm_id * mm_idp,
> Index: linux-2.6.22/arch/um/os-Linux/time.c
> ===================================================================
> --- linux-2.6.22.orig/arch/um/os-Linux/time.c	2007-09-25 09:26:42.000000000 -0400
> +++ linux-2.6.22/arch/um/os-Linux/time.c	2007-09-25 09:28:42.000000000 -0400
> @@ -39,7 +39,23 @@ int timer_one_shot(int ticks)
>  	return 0;
>  }
>  
> -unsigned long long disable_timer(void)
> +/**
> + * timeval_to_ns - Convert timeval to nanoseconds
> + * @ts:		pointer to the timeval variable to be converted
> + *
> + * Returns the scalar nanosecond representation of the timeval
> + * parameter.
> + *
> + * Ripped from linux/time.h because it's a kernel header, and thus
> + * unusable from here.
> + */
> +static inline long long timeval_to_ns(const struct timeval *tv)
> +{
> +	return ((long long) tv->tv_sec * UM_NSEC_PER_SEC) +
> +		tv->tv_usec * UM_NSEC_PER_USEC;
> +}
> +
> +long long disable_timer(void)
>  {
>  	struct itimerval time = ((struct itimerval) { { 0, 0 }, { 0, 0 } });
>  
> @@ -47,10 +63,10 @@ unsigned long long disable_timer(void)
>  		printk(UM_KERN_ERR "disable_timer - setitimer failed, "
>  		       "errno = %d\n", errno);
>  
> -	return tv_to_nsec(&time.it_value);
> +	return timeval_to_ns(&time.it_value);
>  }
>  
> -unsigned long long os_nsecs(void)
> +long long os_nsecs(void)
>  {
>  	struct timeval tv;
>  
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


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

* Re: [PATCH] UML - time build fix
  2007-09-25 19:54 ` Thomas Gleixner
@ 2007-09-25 21:56   ` Jeff Dike
  2007-09-25 22:08     ` Thomas Gleixner
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Dike @ 2007-09-25 21:56 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andrew Morton, LKML, uml-devel

On Tue, Sep 25, 2007 at 09:54:15PM +0200, Thomas Gleixner wrote:
> On Tue, 2007-09-25 at 13:37 -0400, Jeff Dike wrote:
> > Put back an implementation of timeval_to_ns in
> > arch/um/os-Linux/time.c.  tglx pointed out in his review of tickless
> > support that there was a perfectly good implementation of it in
> > linux/time.h.  The problem is that this is userspace code which can't
> > pull in kernel headers and there doesn't seem to be a libc version.
> 
> Oops. Did not notice. 

It's a UML peculiarity...

> Can't we move it into some header file which is accessible from everywhere ?

Not in the generic kernel.  UML has some generally includable headers
of its own, but that doesn't really help.

The one thing that would help is a libc timeval_to_ns.

				Jeff

-- 
Work email - jdike at linux dot intel dot com

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

* Re: [PATCH] UML - time build fix
  2007-09-25 21:56   ` Jeff Dike
@ 2007-09-25 22:08     ` Thomas Gleixner
  2007-09-26 15:46       ` [uml-devel] " Paolo Giarrusso
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2007-09-25 22:08 UTC (permalink / raw)
  To: Jeff Dike; +Cc: Andrew Morton, LKML, uml-devel

Jeff,

On Tue, 2007-09-25 at 17:56 -0400, Jeff Dike wrote:
> On Tue, Sep 25, 2007 at 09:54:15PM +0200, Thomas Gleixner wrote:
> > On Tue, 2007-09-25 at 13:37 -0400, Jeff Dike wrote:
> > > Put back an implementation of timeval_to_ns in
> > > arch/um/os-Linux/time.c.  tglx pointed out in his review of tickless
> > > support that there was a perfectly good implementation of it in
> > > linux/time.h.  The problem is that this is userspace code which can't
> > > pull in kernel headers and there doesn't seem to be a libc version.
> > 
> > Oops. Did not notice. 
> 
> It's a UML peculiarity...
> 
> > Can't we move it into some header file which is accessible from everywhere ?
> 
> Not in the generic kernel.  UML has some generally includable headers
> of its own, but that doesn't really help.
> 
> The one thing that would help is a libc timeval_to_ns.

Fair enough.

	tglx



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

* Re: [uml-devel] [PATCH] UML - time build fix
  2007-09-25 22:08     ` Thomas Gleixner
@ 2007-09-26 15:46       ` Paolo Giarrusso
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Giarrusso @ 2007-09-26 15:46 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Thomas Gleixner, Jeff Dike, Andrew Morton, LKML

[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]

On mercoledì 26 settembre 2007, Thomas Gleixner wrote:
> Jeff,
>
> On Tue, 2007-09-25 at 17:56 -0400, Jeff Dike wrote:
> > On Tue, Sep 25, 2007 at 09:54:15PM +0200, Thomas Gleixner wrote:
> > > On Tue, 2007-09-25 at 13:37 -0400, Jeff Dike wrote:
> > > > Put back an implementation of timeval_to_ns in
> > > > arch/um/os-Linux/time.c.  tglx pointed out in his review of tickless
> > > > support that there was a perfectly good implementation of it in
> > > > linux/time.h.  The problem is that this is userspace code which can't
> > > > pull in kernel headers and there doesn't seem to be a libc version.
> > >
> > > Oops. Did not notice.
> >
> > It's a UML peculiarity...
> >
> > > Can't we move it into some header file which is accessible from
> > > everywhere ?
There is a way to do this without code duplication, but it is creating a 
non-inline function which calls the inline and calling the non-inline from 
userspace. It's done for a variety of other functions.

There is a tradeoff of speed vs code duplication - and if this function is not 
supposed to change and to need to be kept in sync, it could be copied. I 
conceptually hate this solution, but it can make some sense.

-- 
"Doh!" (cit.), I've made another mistake!
Paolo Giarrusso, aka Blaisorblade

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2007-09-26 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-25 17:37 [PATCH] UML - time build fix Jeff Dike
2007-09-25 19:54 ` Thomas Gleixner
2007-09-25 21:56   ` Jeff Dike
2007-09-25 22:08     ` Thomas Gleixner
2007-09-26 15:46       ` [uml-devel] " Paolo Giarrusso

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