kernel/time/clockevents.c
Source file repositories/reference/linux-study-clean/kernel/time/clockevents.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/clockevents.c- Extension
.c- Size
- 21202 bytes
- Lines
- 829
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clockchips.hlinux/hrtimer.hlinux/init.hlinux/module.hlinux/smp.hlinux/device.htick-internal.hasm/clock_inlined.h
Detected Declarations
struct ce_unbindfunction cev_delta2nsfunction clockevent_delta2nsfunction __clockevents_switch_statefunction clockevents_switch_statefunction clockevents_shutdownfunction clockevents_tick_resumefunction clockevents_increase_min_deltafunction clockevents_program_min_deltafunction clockevents_program_min_deltafunction arch_inlined_clockevent_set_next_coupledfunction clockevent_set_next_coupledfunction clockevents_program_eventfunction clockevents_notify_releasedfunction tick_check_new_devicefunction clockevents_replacefunction list_for_each_entryfunction __clockevents_try_unbindfunction __clockevents_unbindfunction clockevents_unbindfunction clockevents_unbind_devicefunction clockevents_register_devicefunction clockevents_configfunction clockevents_config_and_registerfunction __clockevents_update_freqfunction clockevents_update_freqfunction clockevents_handle_noopfunction clockevents_suspendfunction clockevents_resumefunction tick_offline_cpufunction current_device_showfunction unbind_device_storefunction tick_broadcast_init_sysfsfunction tick_broadcast_init_sysfsfunction tick_init_sysfsfunction for_each_possible_cpufunction clockevents_init_sysfsmodule init clockevents_init_sysfsexport clockevent_delta2nsexport clockevents_unbind_deviceexport clockevents_register_deviceexport clockevents_config_and_register
Annotated Snippet
static const struct bus_type clockevents_subsys = {
.name = "clockevents",
.dev_name = "clockevent",
};
static DEFINE_PER_CPU(struct device, tick_percpu_dev);
static struct tick_device *tick_get_tick_dev(struct device *dev);
static ssize_t current_device_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct tick_device *td;
ssize_t count = 0;
raw_spin_lock_irq(&clockevents_lock);
td = tick_get_tick_dev(dev);
if (td && td->evtdev)
count = sysfs_emit(buf, "%s\n", td->evtdev->name);
raw_spin_unlock_irq(&clockevents_lock);
return count;
}
static DEVICE_ATTR_RO(current_device);
/* We don't support the abomination of removable broadcast devices */
static ssize_t unbind_device_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
char name[CS_NAME_LEN];
ssize_t ret = sysfs_get_uname(buf, name, count);
struct clock_event_device *ce = NULL, *iter;
if (ret < 0)
return ret;
ret = -ENODEV;
mutex_lock(&clockevents_mutex);
raw_spin_lock_irq(&clockevents_lock);
list_for_each_entry(iter, &clockevent_devices, list) {
if (!strcmp(iter->name, name)) {
ret = __clockevents_try_unbind(iter, dev->id);
ce = iter;
break;
}
}
raw_spin_unlock_irq(&clockevents_lock);
/*
* We hold clockevents_mutex, so ce can't go away
*/
if (ret == -EAGAIN)
ret = clockevents_unbind(ce, dev->id);
mutex_unlock(&clockevents_mutex);
return ret ? ret : count;
}
static DEVICE_ATTR_WO(unbind_device);
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
static struct device tick_bc_dev = {
.init_name = "broadcast",
.id = 0,
.bus = &clockevents_subsys,
};
static struct tick_device *tick_get_tick_dev(struct device *dev)
{
return dev == &tick_bc_dev ? tick_get_broadcast_device() :
&per_cpu(tick_cpu_device, dev->id);
}
static __init int tick_broadcast_init_sysfs(void)
{
int err = device_register(&tick_bc_dev);
if (!err)
err = device_create_file(&tick_bc_dev, &dev_attr_current_device);
return err;
}
#else
static struct tick_device *tick_get_tick_dev(struct device *dev)
{
return &per_cpu(tick_cpu_device, dev->id);
}
static inline int tick_broadcast_init_sysfs(void) { return 0; }
#endif
static int __init tick_init_sysfs(void)
{
int cpu;
Annotation
- Immediate include surface: `linux/clockchips.h`, `linux/hrtimer.h`, `linux/init.h`, `linux/module.h`, `linux/smp.h`, `linux/device.h`, `tick-internal.h`, `asm/clock_inlined.h`.
- Detected declarations: `struct ce_unbind`, `function cev_delta2ns`, `function clockevent_delta2ns`, `function __clockevents_switch_state`, `function clockevents_switch_state`, `function clockevents_shutdown`, `function clockevents_tick_resume`, `function clockevents_increase_min_delta`, `function clockevents_program_min_delta`, `function clockevents_program_min_delta`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.