---
name: "ET_LOCK"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/ET_LOCK"
---

# ET\_LOCK(9)

kernel event timers subsystem

## NAME

**eventtimers** – kernel event timers subsystem

## SYNOPSIS

**#include \<sys/timeet.h\>**

```
struct eventtimer;
typedef int et_start_t(struct eventtimer *et,
    sbintime_t first, sbintime_t period);
typedef int et_stop_t(struct eventtimer *et);
typedef void et_event_cb_t(struct eventtimer *et, void *arg);
typedef int et_deregister_cb_t(struct eventtimer *et, void *arg);
struct eventtimer {
	SLIST_ENTRY(eventtimer)	et_all;
	char			*et_name;
	int			et_flags;
#define ET_FLAGS_PERIODIC	1
#define ET_FLAGS_ONESHOT	2
#define ET_FLAGS_PERCPU		4
#define ET_FLAGS_C3STOP		8
#define ET_FLAGS_POW2DIV	16
	int			et_quality;
	int			et_active;
	uint64_t		et_frequency;
	sbintime_t		et_min_period;
	sbintime_t		et_max_period;
	et_start_t		*et_start;
	et_stop_t		*et_stop;
	et_event_cb_t		*et_event_cb;
	et_deregister_cb_t	*et_deregister_cb;
	void 			*et_arg;
	void			*et_priv;
	struct sysctl_oid	*et_sysctl;
};
```

*int*\

**et\_register**(*struct eventtimer \*et*);

*int*\

**et\_deregister**(*struct eventtimer \*et*);

*void*\

**et\_change\_frequency**(*struct eventtimer \*et*, *uint64\_t newfreq*);

**ET\_LOCK**();

**ET\_UNLOCK**();

*struct* *eventtimer* *\**\

**et\_find**(*const char \*name*, *int check*, *int want*);

*int*\

**et\_init**(*struct eventtimer \*et*, *et\_event\_cb\_t \*event*, *et\_deregister\_cb\_t \*deregister*, *void \*arg*);

*int*\

**et\_start**(*struct eventtimer \*et*, *sbintime\_t first*, *sbintime\_t period*);

*int*\

**et\_stop**(*struct eventtimer \*et*);

*int*\

**et\_ban**(*struct eventtimer \*et*);

*int*\

**et\_free**(*struct eventtimer \*et*);

## DESCRIPTION

Event timers are responsible for generating interrupts at specified time or periodically, to run different time-based events. Subsystem consists of three main parts:

- Drivers

  Manage hardware to generate requested time events.

- Consumers

  *sys/kern/kern\_clocksource.c* uses event timers to supply kernel with **hardclock**(), **statclock**() and **profclock**() time events.

- Glue code

  *sys/sys/timeet.h*, *sys/kern/kern\_et.c* provide APIs for event timer drivers and consumers.

## DRIVER API

Driver API is built around eventtimer structure. To register its functionality driver allocates that structure and calls **et\_register**(). Driver should fill following fields there:

- *et\_name*

  Unique name of the event timer for management purposes.

- *et\_flags*

  Set of flags, describing timer capabilities:

  - ET\_FLAGS\_PERIODIC

    Periodic mode supported.

  - ET\_FLAGS\_ONESHOT

    One-shot mode supported.

  - ET\_FLAGS\_PERCPU

    Timer is per-CPU.

  - ET\_FLAGS\_C3STOP

    Timer may stop in CPU sleep state.

  - ET\_FLAGS\_POW2DIV

    Timer supports only 2^n divisors.

- *et\_quality*

  Abstract value to certify whether this timecounter is better than the others. Higher value means better.

- *et\_frequency*

  Timer oscillator's base frequency, if applicable and known. Used by consumers to predict set of possible frequencies that could be obtained by dividing it. Should be zero if not applicable or unknown.

- *et\_min\_period*, *et\_max\_period*

  Minimal and maximal reliably programmable time periods.

- *et\_start*

  Driver's timer start function pointer.

- *et\_stop*

  Driver's timer stop function pointer.

- *et\_priv*

  Driver's private data storage.

After the event timer functionality is registered, it is controlled via *et\_start* and *et\_stop* methods. *et\_start* method is called to start the specified event timer. The last two arguments are used to specify time when events should be generated. *first* argument specifies time period before the first event generated. In periodic mode NULL value specifies that first period is equal to the *period* argument value. *period* argument specifies the time period between following events for the periodic mode. The NULL value there specifies the one-shot mode. At least one of these two arguments should be not NULL. When event time arrive, driver should call *et\_event\_cb* callback function, passing *et\_arg* as the second argument. *et\_stop* method is called to stop the specified event timer. For the per-CPU event timers *et\_start* and *et\_stop* methods control timers associated with the current CPU.

Driver may deregister its functionality by calling **et\_deregister**().

If the frequency of the clock hardware can change while it is running (for example, during power-saving modes), the driver must call **et\_change\_frequency**() on each change. If the given event timer is the active timer, **et\_change\_frequency**() stops the timer on all CPUs, updates *et-\>frequency*, then restarts the timer on all CPUs so that all current events are rescheduled using the new frequency. If the given timer is not currently active, **et\_change\_frequency**() simply updates *et-\>frequency*.

## CONSUMER API

**et\_find**() allows consumer to find available event timer, optionally matching specific name and/or capability flags. Consumer may read returned eventtimer structure, but should not modify it. When wanted event timer is found, **et\_init**() should be called for it, submitting *event* and optionally *deregister* callbacks functions, and the opaque argument *arg*. That argument will be passed as argument to the callbacks. Event callback function will be called on scheduled time events. It is called from the hardware interrupt context, so no sleep is permitted there. Deregister callback function may be called to report consumer that the event timer functionality is no longer available. On this call, consumer should stop using event timer before the return.

After the timer is found and initialized, it can be controlled via **et\_start**() and **et\_stop**(). The arguments are the same as described in driver API. Per-CPU event timers can be controlled only from specific CPUs.

**et\_ban**() allows consumer to mark event timer as broken via clearing both one-shot and periodic capability flags, if it was somehow detected. **et\_free**() is the opposite to **et\_init**(). It releases the event timer for other consumers use.

**ET\_LOCK**() and **ET\_UNLOCK**() macros should be used to manage [mutex(9)](/mutex/9.md) lock around **et\_find**(), **et\_init**() and **et\_free**() calls to serialize access to the list of the registered event timers and the pointers returned by **et\_find**(). **et\_start**() and **et\_stop**() calls should be serialized in consumer's internal way to avoid concurrent timer hardware access.

## SEE ALSO

[eventtimers(4)](/eventtimers/4.md)

## AUTHORS

Alexander Motin ⟨*mav@FreeBSD.org*⟩
