Skip to content

Commit 0bc8fb4

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: Implement ndelay/udelay in time-travel mode
In external or inf-cpu time-travel mode, ndelay/udelay currently just waste CPU time since the simulation time doesn't advance. Implement them properly in this case. Note that the "if (time_travel_mode == ...)" parts compile out if CONFIG_UML_TIME_TRAVEL_SUPPORT isn't set, time_travel_mode is defined to TT_MODE_OFF in that case. Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 88ce642 commit 0bc8fb4

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

arch/um/include/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ generic-y += bpf_perf_event.h
33
generic-y += bug.h
44
generic-y += compat.h
55
generic-y += current.h
6-
generic-y += delay.h
76
generic-y += device.h
87
generic-y += emergency-restart.h
98
generic-y += exec.h

arch/um/include/asm/delay.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __UM_DELAY_H
3+
#define __UM_DELAY_H
4+
#include <asm-generic/delay.h>
5+
#include <linux/time-internal.h>
6+
7+
static inline void um_ndelay(unsigned long nsecs)
8+
{
9+
if (time_travel_mode == TT_MODE_INFCPU ||
10+
time_travel_mode == TT_MODE_EXTERNAL) {
11+
time_travel_ndelay(nsecs);
12+
return;
13+
}
14+
ndelay(nsecs);
15+
}
16+
#undef ndelay
17+
#define ndelay um_ndelay
18+
19+
static inline void um_udelay(unsigned long usecs)
20+
{
21+
if (time_travel_mode == TT_MODE_INFCPU ||
22+
time_travel_mode == TT_MODE_EXTERNAL) {
23+
time_travel_ndelay(1000 * usecs);
24+
return;
25+
}
26+
udelay(usecs);
27+
}
28+
#undef udelay
29+
#define udelay um_udelay
30+
#endif /* __UM_DELAY_H */

arch/um/include/linux/time-internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ static inline void time_travel_wait_readable(int fd)
7575
{
7676
}
7777
#endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */
78+
79+
/*
80+
* Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used,
81+
* which is intentional since we really shouldn't link it in that case.
82+
*/
83+
void time_travel_ndelay(unsigned long nsec);
7884
#endif /* __TIMER_INTERNAL_H__ */

arch/um/kernel/time.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ static void time_travel_update_time(unsigned long long next, bool idle)
374374
time_travel_del_event(&ne);
375375
}
376376

377+
void time_travel_ndelay(unsigned long nsec)
378+
{
379+
time_travel_update_time(time_travel_time + nsec, false);
380+
}
381+
EXPORT_SYMBOL(time_travel_ndelay);
382+
377383
void time_travel_add_irq_event(struct time_travel_event *e)
378384
{
379385
BUG_ON(time_travel_mode != TT_MODE_EXTERNAL);

0 commit comments

Comments
 (0)