Skip to content

Commit cff65c4

Browse files
Gennady SharapovLinus Torvalds
authored andcommitted
[PATCH] uml: move libc-dependent time code
The serial UML OS-abstraction layer patch (um/kernel dir). This moves all systemcalls from time.c file under os-Linux dir and joins time.c and tine_kernel.c files Signed-off-by: Gennady Sharapov <Gennady.V.Sharapov@intel.com> Signed-off-by: Jeff Dike <jdike@addtoit.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 4fef0c1 commit cff65c4

16 files changed

Lines changed: 211 additions & 94 deletions

File tree

‎arch/um/include/os.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ extern int os_protect_memory(void *addr, unsigned long len,
190190
int r, int w, int x);
191191
extern int os_unmap_memory(void *addr, int len);
192192
extern void os_flush_stdout(void);
193-
extern unsigned long long os_usecs(void);
194193

195194
/* tt.c
196195
* for tt mode only (will be deleted in future...)
@@ -245,4 +244,15 @@ extern void setup_machinename(char *machine_out);
245244
extern void setup_hostinfo(void);
246245
extern int setjmp_wrapper(void (*proc)(void *, void *), ...);
247246

247+
/* time.c */
248+
#define BILLION (1000 * 1000 * 1000)
249+
250+
extern void switch_timers(int to_real);
251+
extern void idle_sleep(int secs);
252+
extern void enable_timer(void);
253+
extern void disable_timer(void);
254+
extern void user_time_init(void);
255+
extern void uml_idle_timer(void);
256+
extern unsigned long long os_nsecs(void);
257+
248258
#endif

‎arch/um/include/time_user.h‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎arch/um/kernel/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ clean-files :=
99
obj-y = config.o exec_kern.o exitcode.o \
1010
init_task.o irq.o irq_user.o ksyms.o mem.o physmem.o \
1111
process_kern.o ptrace.o reboot.o resource.o sigio_user.o sigio_kern.o \
12-
signal_kern.o smp.o syscall_kern.o sysrq.o time.o \
12+
signal_kern.o smp.o syscall_kern.o sysrq.o \
1313
time_kern.o tlb.o trap_kern.o uaccess.o um_arch.o umid.o
1414

1515
obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
@@ -23,7 +23,7 @@ obj-$(CONFIG_MODE_SKAS) += skas/
2323

2424
user-objs-$(CONFIG_TTY_LOG) += tty_log.o
2525

26-
USER_OBJS := $(user-objs-y) config.o time.o tty_log.o
26+
USER_OBJS := $(user-objs-y) config.o tty_log.o
2727

2828
include arch/um/scripts/Makefile.rules
2929

‎arch/um/kernel/exec_kern.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "irq_user.h"
1818
#include "tlb.h"
1919
#include "os.h"
20-
#include "time_user.h"
2120
#include "choose-mode.h"
2221
#include "mode_kern.h"
2322

‎arch/um/kernel/process_kern.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "init.h"
4040
#include "irq_user.h"
4141
#include "mem_user.h"
42-
#include "time_user.h"
4342
#include "tlb.h"
4443
#include "frame_kern.h"
4544
#include "sigcontext.h"

‎arch/um/kernel/skas/process.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <asm/types.h>
1919
#include "user.h"
2020
#include "ptrace_user.h"
21-
#include "time_user.h"
2221
#include "sysdep/ptrace.h"
2322
#include "user_util.h"
2423
#include "kern_util.h"

‎arch/um/kernel/skas/process_kern.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "asm/uaccess.h"
1414
#include "asm/atomic.h"
1515
#include "kern_util.h"
16-
#include "time_user.h"
1716
#include "skas.h"
1817
#include "os.h"
1918
#include "user_util.h"

‎arch/um/kernel/syscall.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ int record_syscall_start(int syscall)
2525
syscall_record[index].syscall = syscall;
2626
syscall_record[index].pid = current_pid();
2727
syscall_record[index].result = 0xdeadbeef;
28-
syscall_record[index].start = os_usecs();
28+
syscall_record[index].start = os_nsecs();
2929
return(index);
3030
}
3131

3232
void record_syscall_end(int index, long result)
3333
{
3434
syscall_record[index].result = result;
35-
syscall_record[index].end = os_usecs();
35+
syscall_record[index].end = os_nsecs();
3636
}

‎arch/um/kernel/time_kern.c‎

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
33
* Licensed under the GPL
44
*/
@@ -13,12 +13,12 @@
1313
#include "linux/interrupt.h"
1414
#include "linux/init.h"
1515
#include "linux/delay.h"
16+
#include "linux/hrtimer.h"
1617
#include "asm/irq.h"
1718
#include "asm/param.h"
1819
#include "asm/current.h"
1920
#include "kern_util.h"
2021
#include "user_util.h"
21-
#include "time_user.h"
2222
#include "mode.h"
2323
#include "os.h"
2424

@@ -39,7 +39,7 @@ unsigned long long sched_clock(void)
3939
int timer_irq_inited = 0;
4040

4141
static int first_tick;
42-
static unsigned long long prev_usecs;
42+
static unsigned long long prev_nsecs;
4343
#ifdef CONFIG_UML_REAL_TIME_CLOCK
4444
static long long delta; /* Deviation per interval */
4545
#endif
@@ -58,23 +58,23 @@ void timer_irq(union uml_pt_regs *regs)
5858
if(first_tick){
5959
#ifdef CONFIG_UML_REAL_TIME_CLOCK
6060
/* We've had 1 tick */
61-
unsigned long long usecs = os_usecs();
61+
unsigned long long nsecs = os_nsecs();
6262

63-
delta += usecs - prev_usecs;
64-
prev_usecs = usecs;
63+
delta += nsecs - prev_nsecs;
64+
prev_nsecs = nsecs;
6565

6666
/* Protect against the host clock being set backwards */
6767
if(delta < 0)
6868
delta = 0;
6969

70-
ticks += (delta * HZ) / MILLION;
71-
delta -= (ticks * MILLION) / HZ;
70+
ticks += (delta * HZ) / BILLION;
71+
delta -= (ticks * BILLION) / HZ;
7272
#else
7373
ticks = 1;
7474
#endif
7575
}
7676
else {
77-
prev_usecs = os_usecs();
77+
prev_nsecs = os_nsecs();
7878
first_tick = 1;
7979
}
8080

@@ -88,45 +88,99 @@ void boot_timer_handler(int sig)
8888
{
8989
struct pt_regs regs;
9090

91-
CHOOSE_MODE((void)
91+
CHOOSE_MODE((void)
9292
(UPT_SC(&regs.regs) = (struct sigcontext *) (&sig + 1)),
9393
(void) (regs.regs.skas.is_user = 0));
9494
do_timer(&regs);
9595
}
9696

97+
static DEFINE_SPINLOCK(timer_spinlock);
98+
99+
static unsigned long long local_offset = 0;
100+
101+
static inline unsigned long long get_time(void)
102+
{
103+
unsigned long long nsecs;
104+
unsigned long flags;
105+
106+
spin_lock_irqsave(&timer_spinlock, flags);
107+
nsecs = os_nsecs();
108+
nsecs += local_offset;
109+
spin_unlock_irqrestore(&timer_spinlock, flags);
110+
111+
return nsecs;
112+
}
113+
97114
irqreturn_t um_timer(int irq, void *dev, struct pt_regs *regs)
98115
{
116+
unsigned long long nsecs;
99117
unsigned long flags;
100118

101119
do_timer(regs);
120+
102121
write_seqlock_irqsave(&xtime_lock, flags);
103-
timer();
122+
nsecs = get_time() + local_offset;
123+
xtime.tv_sec = nsecs / NSEC_PER_SEC;
124+
xtime.tv_nsec = nsecs - xtime.tv_sec * NSEC_PER_SEC;
104125
write_sequnlock_irqrestore(&xtime_lock, flags);
126+
105127
return(IRQ_HANDLED);
106128
}
107129

108130
long um_time(int __user *tloc)
109131
{
110-
struct timeval now;
132+
long ret = get_time() / NSEC_PER_SEC;
111133

112-
do_gettimeofday(&now);
113-
if (tloc) {
114-
if (put_user(now.tv_sec, tloc))
115-
now.tv_sec = -EFAULT;
116-
}
117-
return now.tv_sec;
134+
if((tloc != NULL) && put_user(ret, tloc))
135+
return -EFAULT;
136+
137+
return ret;
138+
}
139+
140+
void do_gettimeofday(struct timeval *tv)
141+
{
142+
unsigned long long nsecs = get_time();
143+
144+
tv->tv_sec = nsecs / NSEC_PER_SEC;
145+
/* Careful about calculations here - this was originally done as
146+
* (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC
147+
* which gave bogus (> 1000000) values. Dunno why, suspect gcc
148+
* (4.0.0) miscompiled it, or there's a subtle 64/32-bit conversion
149+
* problem that I missed.
150+
*/
151+
nsecs -= tv->tv_sec * NSEC_PER_SEC;
152+
tv->tv_usec = (unsigned long) nsecs / NSEC_PER_USEC;
153+
}
154+
155+
static inline void set_time(unsigned long long nsecs)
156+
{
157+
unsigned long long now;
158+
unsigned long flags;
159+
160+
spin_lock_irqsave(&timer_spinlock, flags);
161+
now = os_nsecs();
162+
local_offset = nsecs - now;
163+
spin_unlock_irqrestore(&timer_spinlock, flags);
164+
165+
clock_was_set();
118166
}
119167

120168
long um_stime(int __user *tptr)
121169
{
122170
int value;
123-
struct timespec new;
124171

125172
if (get_user(value, tptr))
126173
return -EFAULT;
127-
new.tv_sec = value;
128-
new.tv_nsec = 0;
129-
do_settimeofday(&new);
174+
175+
set_time((unsigned long long) value * NSEC_PER_SEC);
176+
177+
return 0;
178+
}
179+
180+
int do_settimeofday(struct timespec *tv)
181+
{
182+
set_time((unsigned long long) tv->tv_sec * NSEC_PER_SEC + tv->tv_nsec);
183+
130184
return 0;
131185
}
132186

@@ -142,21 +196,6 @@ void timer_handler(int sig, union uml_pt_regs *regs)
142196
timer_irq(regs);
143197
}
144198

145-
static DEFINE_SPINLOCK(timer_spinlock);
146-
147-
unsigned long time_lock(void)
148-
{
149-
unsigned long flags;
150-
151-
spin_lock_irqsave(&timer_spinlock, flags);
152-
return(flags);
153-
}
154-
155-
void time_unlock(unsigned long flags)
156-
{
157-
spin_unlock_irqrestore(&timer_spinlock, flags);
158-
}
159-
160199
int __init timer_init(void)
161200
{
162201
int err;
@@ -171,14 +210,3 @@ int __init timer_init(void)
171210
}
172211

173212
__initcall(timer_init);
174-
175-
/*
176-
* Overrides for Emacs so that we follow Linus's tabbing style.
177-
* Emacs will notice this stuff at the end of the file and automatically
178-
* adjust the settings for this buffer only. This must remain at the end
179-
* of the file.
180-
* ---------------------------------------------------------------------------
181-
* Local variables:
182-
* c-file-style: "linux"
183-
* End:
184-
*/

‎arch/um/kernel/tt/exec_kern.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "user_util.h"
1414
#include "kern_util.h"
1515
#include "irq_user.h"
16-
#include "time_user.h"
1716
#include "mem_user.h"
1817
#include "os.h"
1918
#include "tlb.h"

0 commit comments

Comments
 (0)