FreeBSD kernel /amd64 XEN device code
timer.c File Reference

A timer driver for the Xen hypervisor's PV clock. More...

#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/timeet.h>
#include <sys/smp.h>
#include <sys/limits.h>
#include <sys/clock.h>
#include <sys/proc.h>
#include <xen/xen-os.h>
#include <xen/features.h>
#include <xen/xen_intr.h>
#include <xen/hypervisor.h>
#include <contrib/xen/io/xenbus.h>
#include <contrib/xen/vcpu.h>
#include <xen/error.h>
#include <machine/cpu.h>
#include <machine/cpufunc.h>
#include <machine/clock.h>
#include <machine/_inttypes.h>
#include <machine/smp.h>
#include <machine/pvclock.h>
#include <dev/xen/timer/timer.h>
#include "clock_if.h"
Include dependency graph for timer.c:

Go to the source code of this file.

Data Structures

struct  xentimer_pcpu_data
 
struct  xentimer_softc
 

Macros

#define NSEC_IN_SEC   1000000000ULL
 
#define NSEC_IN_USEC   1000ULL
 
#define FRAC_IN_NSEC   18446744073LL
 
#define XENTIMER_MIN_PERIOD_IN_NSEC   100*NSEC_IN_USEC
 
#define XENCLOCK_RESOLUTION   1
 
#define XENTIMER_QUALITY   950
 
#define XTREQUIRES(condition, reason...)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 DPCPU_DEFINE (struct xentimer_pcpu_data, xentimer_pcpu)
 
 DPCPU_DECLARE (struct vcpu_info *, vcpu_info)
 
static void xentimer_identify (driver_t *driver, device_t parent)
 
static int xentimer_probe (device_t dev)
 
static uint64_t xen_fetch_vcpu_time (struct vcpu_info *vcpu)
 Get the current time, in nanoseconds, since the hypervisor booted. More...
 
static uint32_t xentimer_get_timecount (struct timecounter *tc)
 
static void xen_fetch_wallclock (struct timespec *ts)
 Fetch the hypervisor boot time, known as the "Xen wallclock". More...
 
static void xen_fetch_uptime (struct timespec *ts)
 
static int xentimer_settime (device_t dev __unused, struct timespec *ts)
 
static int xentimer_gettime (device_t dev, struct timespec *ts)
 Return current time according to the Xen Hypervisor wallclock. More...
 
static int xentimer_intr (void *arg)
 Handle a timer interrupt for the Xen PV timer driver. More...
 
static int xentimer_vcpu_start_timer (int vcpu, uint64_t next_time)
 
static int xentimer_vcpu_stop_timer (int vcpu)
 
static int xentimer_et_start (struct eventtimer *et, sbintime_t first, sbintime_t period)
 Set the next oneshot time for the current CPU. More...
 
static int xentimer_et_stop (struct eventtimer *et)
 Cancel the event timer's currently running timer, if any. More...
 
static int xentimer_attach (device_t dev)
 Attach a Xen PV timer driver instance. More...
 
static int xentimer_detach (device_t dev)
 
static void xentimer_percpu_resume (void *arg)
 
static int xentimer_resume (device_t dev)
 
static int xentimer_suspend (device_t dev)
 
void xen_clock_init (void)
 
void xen_delay (int n)
 
 DRIVER_MODULE (xentimer, xenpv, xentimer_driver, xentimer_devclass, 0, 0)
 
 MODULE_DEPEND (xentimer, xenpv, 1, 1, 1)
 

Variables

static devclass_t xentimer_devclass
 
static device_method_t xentimer_methods []
 
static driver_t xentimer_driver
 

Detailed Description

A timer driver for the Xen hypervisor's PV clock.

Definition in file timer.c.

Macro Definition Documentation

◆ FRAC_IN_NSEC

#define FRAC_IN_NSEC   18446744073LL

Definition at line 76 of file timer.c.

◆ NSEC_IN_SEC

#define NSEC_IN_SEC   1000000000ULL

Definition at line 73 of file timer.c.

◆ NSEC_IN_USEC

#define NSEC_IN_USEC   1000ULL

Definition at line 74 of file timer.c.

◆ XENCLOCK_RESOLUTION

#define XENCLOCK_RESOLUTION   1

Definition at line 85 of file timer.c.

◆ XENTIMER_MIN_PERIOD_IN_NSEC

#define XENTIMER_MIN_PERIOD_IN_NSEC   100*NSEC_IN_USEC

Definition at line 79 of file timer.c.

◆ XENTIMER_QUALITY

#define XENTIMER_QUALITY   950

Definition at line 87 of file timer.c.

◆ XTREQUIRES

#define XTREQUIRES (   condition,
  reason... 
)
Value:
if (!(condition)) { \
device_printf(dev, ## reason); \
device_detach(dev); \
return (ENXIO); \
}

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DPCPU_DECLARE()

DPCPU_DECLARE ( struct vcpu_info *  ,
vcpu_info   
)

◆ DPCPU_DEFINE()

DPCPU_DEFINE ( struct xentimer_pcpu_data  ,
xentimer_pcpu   
)

◆ DRIVER_MODULE()

DRIVER_MODULE ( xentimer  ,
xenpv  ,
xentimer_driver  ,
xentimer_devclass  ,
,
 
)

◆ MODULE_DEPEND()

MODULE_DEPEND ( xentimer  ,
xenpv  ,
,
,
 
)

◆ xen_clock_init()

void xen_clock_init ( void  )

Definition at line 511 of file timer.c.

◆ xen_delay()

void xen_delay ( int  n)

Definition at line 523 of file timer.c.

References NSEC_IN_USEC, and xen_fetch_vcpu_time().

Here is the call graph for this function:

◆ xen_fetch_uptime()

static void xen_fetch_uptime ( struct timespec *  ts)
static

Definition at line 209 of file timer.c.

References NSEC_IN_SEC, and xen_fetch_vcpu_time().

Referenced by xentimer_gettime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xen_fetch_vcpu_time()

static uint64_t xen_fetch_vcpu_time ( struct vcpu_info *  vcpu)
static

Get the current time, in nanoseconds, since the hypervisor booted.

Parameters
vcpuvcpu_info structure to fetch the time from.

Definition at line 162 of file timer.c.

Referenced by xen_delay(), xen_fetch_uptime(), xentimer_et_start(), xentimer_get_timecount(), xentimer_intr(), and xentimer_settime().

Here is the caller graph for this function:

◆ xen_fetch_wallclock()

static void xen_fetch_wallclock ( struct timespec *  ts)
static

Fetch the hypervisor boot time, known as the "Xen wallclock".

Parameters
tsTimespec to store the current stable value.
versionPointer to store the corresponding wallclock version.
Note
This value is updated when Domain-0 shifts its clock to follow clock drift, e.g. as detected by NTP.

Definition at line 198 of file timer.c.

Referenced by xentimer_gettime().

Here is the caller graph for this function:

◆ xentimer_attach()

static int xentimer_attach ( device_t  dev)
static

Attach a Xen PV timer driver instance.

Parameters
devBus device object to attach.
Note
Returns
EINVAL

Definition at line 371 of file timer.c.

References xentimer_softc::dev, xentimer_softc::et, xentimer_pcpu_data::irq_handle, NSEC_IN_SEC, xentimer_softc::tc, XENCLOCK_RESOLUTION, xentimer_et_start(), xentimer_et_stop(), xentimer_get_timecount(), xentimer_intr(), XENTIMER_MIN_PERIOD_IN_NSEC, and XENTIMER_QUALITY.

Here is the call graph for this function:

◆ xentimer_detach()

static int xentimer_detach ( device_t  dev)
static

Definition at line 448 of file timer.c.

◆ xentimer_et_start()

static int xentimer_et_start ( struct eventtimer *  et,
sbintime_t  first,
sbintime_t  period 
)
static

Set the next oneshot time for the current CPU.

Parameters
etXen timer driver event timer to schedule on.
firstDelta to the next time to schedule the interrupt for.
periodNot used.
Note
See eventtimers(9) for more information.
Returns
0

Definition at line 319 of file timer.c.

References xentimer_softc::dev, xentimer_softc::et, NSEC_IN_SEC, xentimer_pcpu_data::timer, xen_fetch_vcpu_time(), and xentimer_vcpu_start_timer().

Referenced by xentimer_attach(), and xentimer_percpu_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xentimer_et_stop()

static int xentimer_et_stop ( struct eventtimer *  et)
static

Cancel the event timer's currently running timer, if any.

Definition at line 353 of file timer.c.

References xentimer_pcpu_data::timer, and xentimer_vcpu_stop_timer().

Referenced by xentimer_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xentimer_get_timecount()

static uint32_t xentimer_get_timecount ( struct timecounter *  tc)
static

Definition at line 172 of file timer.c.

References xen_fetch_vcpu_time().

Referenced by xentimer_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xentimer_gettime()

static int xentimer_gettime ( device_t  dev,
struct timespec *  ts 
)
static

Return current time according to the Xen Hypervisor wallclock.

Parameters
devXentimer device.
tsPointer to store the wallclock time.
Note
The Xen time structures document the hypervisor start time and the uptime-since-hypervisor-start (in nsec.) They need to be combined in order to calculate a TOD clock.

Definition at line 258 of file timer.c.

References xen_fetch_uptime(), and xen_fetch_wallclock().

Here is the call graph for this function:

◆ xentimer_identify()

static void xentimer_identify ( driver_t *  driver,
device_t  parent 
)
static

Definition at line 106 of file timer.c.

References xentimer_devclass.

◆ xentimer_intr()

static int xentimer_intr ( void *  arg)
static

Handle a timer interrupt for the Xen PV timer driver.

Parameters
argXen timer driver softc that is expecting the interrupt.

Definition at line 276 of file timer.c.

References xentimer_softc::et, xentimer_pcpu_data::last_processed, xentimer_pcpu_data::timer, and xen_fetch_vcpu_time().

Referenced by xentimer_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xentimer_percpu_resume()

static void xentimer_percpu_resume ( void *  arg)
static

Definition at line 461 of file timer.c.

References xentimer_softc::dev, xentimer_softc::et, and xentimer_et_start().

Referenced by xentimer_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xentimer_probe()

static int xentimer_probe ( device_t  dev)
static

Definition at line 119 of file timer.c.

References XTREQUIRES.

◆ xentimer_resume()

static int xentimer_resume ( device_t  dev)
static

Definition at line 470 of file timer.c.

References xentimer_softc::dev, and xentimer_percpu_resume().

Here is the call graph for this function:

◆ xentimer_settime()

static int xentimer_settime ( device_t dev  __unused,
struct timespec *  ts 
)
static

Definition at line 220 of file timer.c.

References xen_fetch_vcpu_time().

Here is the call graph for this function:

◆ xentimer_suspend()

static int xentimer_suspend ( device_t  dev)
static

Definition at line 502 of file timer.c.

◆ xentimer_vcpu_start_timer()

static int xentimer_vcpu_start_timer ( int  vcpu,
uint64_t  next_time 
)
static

Definition at line 289 of file timer.c.

Referenced by xentimer_et_start().

Here is the caller graph for this function:

◆ xentimer_vcpu_stop_timer()

static int xentimer_vcpu_stop_timer ( int  vcpu)
static

Definition at line 300 of file timer.c.

Referenced by xentimer_et_stop().

Here is the caller graph for this function:

Variable Documentation

◆ xentimer_devclass

devclass_t xentimer_devclass
static

Definition at line 71 of file timer.c.

Referenced by xentimer_identify().

◆ xentimer_driver

driver_t xentimer_driver
static
Initial value:
= {
"xen_et",
sizeof(struct xentimer_softc),
}
static device_method_t xentimer_methods[]
Definition: timer.c:539

Definition at line 552 of file timer.c.

◆ xentimer_methods

device_method_t xentimer_methods[]
static
Initial value:
= {
DEVMETHOD(device_identify, xentimer_identify),
DEVMETHOD(device_probe, xentimer_probe),
DEVMETHOD(device_attach, xentimer_attach),
DEVMETHOD(device_detach, xentimer_detach),
DEVMETHOD(device_suspend, xentimer_suspend),
DEVMETHOD(device_resume, xentimer_resume),
DEVMETHOD(clock_gettime, xentimer_gettime),
DEVMETHOD(clock_settime, xentimer_settime),
DEVMETHOD_END
}
static int xentimer_detach(device_t dev)
Definition: timer.c:448
static int xentimer_probe(device_t dev)
Definition: timer.c:119
static int xentimer_attach(device_t dev)
Attach a Xen PV timer driver instance.
Definition: timer.c:371
static int xentimer_settime(device_t dev __unused, struct timespec *ts)
Definition: timer.c:220
static int xentimer_gettime(device_t dev, struct timespec *ts)
Return current time according to the Xen Hypervisor wallclock.
Definition: timer.c:258
static int xentimer_suspend(device_t dev)
Definition: timer.c:502
static int xentimer_resume(device_t dev)
Definition: timer.c:470
static void xentimer_identify(driver_t *driver, device_t parent)
Definition: timer.c:106

Definition at line 539 of file timer.c.