arch/xtensa/kernel/time.c
Source file repositories/reference/linux-study-clean/arch/xtensa/kernel/time.c
File Facts
- System
- Linux kernel
- Corpus path
arch/xtensa/kernel/time.c- Extension
.c- Size
- 5014 bytes
- Lines
- 211
- Domain
- Architecture Layer
- Bucket
- arch/xtensa
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/of_clk.hlinux/errno.hlinux/sched.hlinux/time.hlinux/clocksource.hlinux/clockchips.hlinux/interrupt.hlinux/module.hlinux/init.hlinux/irq.hlinux/profile.hlinux/delay.hlinux/irqdomain.hlinux/sched_clock.hasm/timex.hasm/platform.h
Detected Declarations
struct ccount_timerfunction ccount_readfunction ccount_sched_clock_readfunction ccount_timer_set_next_eventfunction ccount_timer_shutdownfunction ccount_timer_set_oneshotfunction timer_interruptfunction local_timer_setupfunction calibrate_ccountfunction calibrate_ccountfunction time_initfunction calibrate_delayexport ccount_freq
Annotated Snippet
struct ccount_timer {
struct clock_event_device evt;
int irq_enabled;
char name[24];
};
static int ccount_timer_set_next_event(unsigned long delta,
struct clock_event_device *dev)
{
unsigned long flags, next;
int ret = 0;
local_irq_save(flags);
next = get_ccount() + delta;
set_linux_timer(next);
if (next - get_ccount() > delta)
ret = -ETIME;
local_irq_restore(flags);
return ret;
}
/*
* There is no way to disable the timer interrupt at the device level,
* only at the intenable register itself. Since enable_irq/disable_irq
* calls are nested, we need to make sure that these calls are
* balanced.
*/
static int ccount_timer_shutdown(struct clock_event_device *evt)
{
struct ccount_timer *timer =
container_of(evt, struct ccount_timer, evt);
if (timer->irq_enabled) {
disable_irq_nosync(evt->irq);
timer->irq_enabled = 0;
}
return 0;
}
static int ccount_timer_set_oneshot(struct clock_event_device *evt)
{
struct ccount_timer *timer =
container_of(evt, struct ccount_timer, evt);
if (!timer->irq_enabled) {
enable_irq(evt->irq);
timer->irq_enabled = 1;
}
return 0;
}
static DEFINE_PER_CPU(struct ccount_timer, ccount_timer) = {
.evt = {
.features = CLOCK_EVT_FEAT_ONESHOT,
.rating = 300,
.set_next_event = ccount_timer_set_next_event,
.set_state_shutdown = ccount_timer_shutdown,
.set_state_oneshot = ccount_timer_set_oneshot,
.tick_resume = ccount_timer_set_oneshot,
},
};
static irqreturn_t timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evt = &this_cpu_ptr(&ccount_timer)->evt;
set_linux_timer(get_linux_timer());
evt->event_handler(evt);
return IRQ_HANDLED;
}
void local_timer_setup(unsigned cpu)
{
struct ccount_timer *timer = &per_cpu(ccount_timer, cpu);
struct clock_event_device *clockevent = &timer->evt;
timer->irq_enabled = 1;
snprintf(timer->name, sizeof(timer->name), "ccount_clockevent_%u", cpu);
clockevent->name = timer->name;
clockevent->cpumask = cpumask_of(cpu);
clockevent->irq = irq_create_mapping(NULL, LINUX_TIMER_INT);
if (WARN(!clockevent->irq, "error: can't map timer irq"))
return;
clockevents_config_and_register(clockevent, ccount_freq,
0xf, 0xffffffff);
}
#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
#ifdef CONFIG_OF
Annotation
- Immediate include surface: `linux/clk.h`, `linux/of_clk.h`, `linux/errno.h`, `linux/sched.h`, `linux/time.h`, `linux/clocksource.h`, `linux/clockchips.h`, `linux/interrupt.h`.
- Detected declarations: `struct ccount_timer`, `function ccount_read`, `function ccount_sched_clock_read`, `function ccount_timer_set_next_event`, `function ccount_timer_shutdown`, `function ccount_timer_set_oneshot`, `function timer_interrupt`, `function local_timer_setup`, `function calibrate_ccount`, `function calibrate_ccount`.
- Atlas domain: Architecture Layer / arch/xtensa.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.