Skip to contentSkip to conversation

UML - time build fix

PATCH In review Jeff Dike 3 participants 5 messages Sep 25, 2007 – Sep 26, 2007 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 1/1 UML - time build fix

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.

---
 arch/um/include/os.h    |    4 ++--
 arch/um/os-Linux/time.c |   22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 5 deletions(-)
arch/um/include/os.h +2 -2
Index: linux-2.6.22/arch/um/include/os.h
===================================================================
@@ -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,
arch/um/os-Linux/time.c +19 -3
Index: linux-2.6.22/arch/um/os-Linux/time.c
===================================================================
@@ -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;
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 5 lines · Jeff Dike

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

Quoted 73 lines

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.

---
 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
===================================================================

arch/um/include/os.h +2 -2
@@ -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
===================================================================

arch/um/os-Linux/time.c +19 -4
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#2 lore raw
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Jeff Dike

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...

Quoted 1 line

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

Signature · 10 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw

Jeff,

Quoted 10 lines · Jeff Dike
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Jeff Dike

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.

Quoted 8 lines

It's a UML peculiarity...

Quoted 1 line

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

#4 lore raw
Quoted 17 lines · Thomas Gleixner

Jeff,

Quoted 14 lines · Jeff Dike
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Jeff Dike

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...

Quoted 2 lines

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.

Signature · 2 lines
"Doh!" (cit.), I've made another mistake!
Paolo Giarrusso, aka Blaisorblade

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel