arch/arm/kernel/smp_twd.c
Source file repositories/reference/linux-study-clean/arch/arm/kernel/smp_twd.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm/kernel/smp_twd.c- Extension
.c- Size
- 7791 bytes
- Lines
- 340
- Domain
- Architecture Layer
- Bucket
- arch/arm
- 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/init.hlinux/kernel.hlinux/clk.hlinux/cpu.hlinux/delay.hlinux/device.hlinux/err.hlinux/smp.hlinux/jiffies.hlinux/clockchips.hlinux/interrupt.hlinux/io.hlinux/of_irq.hlinux/of_address.hasm/smp_twd.h
Detected Declarations
function twd_shutdownfunction twd_set_oneshotfunction twd_set_periodicfunction twd_set_next_eventfunction twd_timer_ackfunction twd_timer_stopfunction twd_update_frequencyfunction twd_rate_changefunction twd_clk_initfunction twd_calibrate_ratefunction twd_handlerfunction twd_get_clockfunction twd_timer_setupfunction twd_timer_starting_cpufunction twd_timer_dying_cpufunction twd_local_timer_common_registerfunction twd_local_timer_of_registermodule init twd_clk_init
Annotated Snippet
core_initcall(twd_clk_init);
static void twd_calibrate_rate(void)
{
unsigned long count;
u64 waitjiffies;
/*
* If this is the first time round, we need to work out how fast
* the timer ticks
*/
if (twd_timer_rate == 0) {
pr_info("Calibrating local timer... ");
/* Wait for a tick to start */
waitjiffies = get_jiffies_64() + 1;
while (get_jiffies_64() < waitjiffies)
udelay(10);
/* OK, now the tick has started, let's get the timer going */
waitjiffies += 5;
/* enable, no interrupt or reload */
writel_relaxed(0x1, twd_base + TWD_TIMER_CONTROL);
/* maximum value */
writel_relaxed(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
while (get_jiffies_64() < waitjiffies)
udelay(10);
count = readl_relaxed(twd_base + TWD_TIMER_COUNTER);
twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
pr_cont("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
(twd_timer_rate / 10000) % 100);
}
}
static irqreturn_t twd_handler(int irq, void *dev_id)
{
struct clock_event_device *evt = dev_id;
if (twd_timer_ack()) {
evt->event_handler(evt);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void twd_get_clock(struct device_node *np)
{
int err;
if (np)
twd_clk = of_clk_get(np, 0);
else
twd_clk = clk_get_sys("smp_twd", NULL);
if (IS_ERR(twd_clk)) {
pr_err("smp_twd: clock not found %d\n", (int) PTR_ERR(twd_clk));
return;
}
err = clk_prepare_enable(twd_clk);
if (err) {
pr_err("smp_twd: clock failed to prepare+enable: %d\n", err);
clk_put(twd_clk);
return;
}
twd_timer_rate = clk_get_rate(twd_clk);
}
/*
* Setup the local clock events for a CPU.
*/
static void twd_timer_setup(void)
{
struct clock_event_device *clk = raw_cpu_ptr(twd_evt);
int cpu = smp_processor_id();
/*
* If the basic setup for this CPU has been done before don't
* bother with the below.
*/
if (per_cpu(percpu_setup_called, cpu)) {
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/clk.h`, `linux/cpu.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/smp.h`.
- Detected declarations: `function twd_shutdown`, `function twd_set_oneshot`, `function twd_set_periodic`, `function twd_set_next_event`, `function twd_timer_ack`, `function twd_timer_stop`, `function twd_update_frequency`, `function twd_rate_change`, `function twd_clk_init`, `function twd_calibrate_rate`.
- Atlas domain: Architecture Layer / arch/arm.
- 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.