arch/loongarch/kernel/time.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/time.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/time.c- Extension
.c- Size
- 5469 bytes
- Lines
- 247
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/clockchips.hlinux/cpuhotplug.hlinux/delay.hlinux/export.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/sched_clock.hlinux/spinlock.hasm/cpu-features.hasm/loongarch.hasm/paravirt.hasm/time.hasm/timex.h
Detected Declarations
function constant_event_handlerfunction constant_set_state_oneshotfunction constant_set_state_periodicfunction constant_set_state_shutdownfunction constant_timer_next_eventfunction arch_timer_startingfunction arch_timer_dyingfunction get_loops_per_jiffyfunction save_counterfunction sync_counterfunction constant_clockevent_initfunction read_const_counterfunction sched_clock_readfunction constant_clocksource_initfunction time_initexport cpu_clock_freqexport const_clock_freq
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Common time service routines for LoongArch machines.
*
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/
#include <linux/clockchips.h>
#include <linux/cpuhotplug.h>
#include <linux/delay.h>
#include <linux/export.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/sched_clock.h>
#include <linux/spinlock.h>
#include <asm/cpu-features.h>
#include <asm/loongarch.h>
#include <asm/paravirt.h>
#include <asm/time.h>
#include <asm/timex.h>
u64 cpu_clock_freq;
EXPORT_SYMBOL(cpu_clock_freq);
u64 const_clock_freq;
EXPORT_SYMBOL(const_clock_freq);
static DEFINE_RAW_SPINLOCK(state_lock);
static DEFINE_PER_CPU(struct clock_event_device, constant_clockevent_device);
static void constant_event_handler(struct clock_event_device *dev)
{
}
static irqreturn_t constant_timer_interrupt(int irq, void *data)
{
int cpu = smp_processor_id();
struct clock_event_device *cd;
/* Clear Timer Interrupt */
write_csr_tintclear(CSR_TINTCLR_TI);
cd = &per_cpu(constant_clockevent_device, cpu);
cd->event_handler(cd);
return IRQ_HANDLED;
}
static int constant_set_state_oneshot(struct clock_event_device *evt)
{
unsigned long timer_config;
raw_spin_lock(&state_lock);
timer_config = csr_read(LOONGARCH_CSR_TCFG);
timer_config |= CSR_TCFG_EN;
timer_config &= ~CSR_TCFG_PERIOD;
csr_write(timer_config, LOONGARCH_CSR_TCFG);
raw_spin_unlock(&state_lock);
return 0;
}
static int constant_set_state_periodic(struct clock_event_device *evt)
{
unsigned long timer_config;
u64 period = const_clock_freq;
raw_spin_lock(&state_lock);
do_div(period, HZ);
timer_config = period & CSR_TCFG_VAL;
timer_config |= (CSR_TCFG_PERIOD | CSR_TCFG_EN);
csr_write(timer_config, LOONGARCH_CSR_TCFG);
raw_spin_unlock(&state_lock);
return 0;
}
static int constant_set_state_shutdown(struct clock_event_device *evt)
{
unsigned long timer_config;
raw_spin_lock(&state_lock);
timer_config = csr_read(LOONGARCH_CSR_TCFG);
timer_config &= ~CSR_TCFG_EN;
csr_write(timer_config, LOONGARCH_CSR_TCFG);
Annotation
- Immediate include surface: `linux/clockchips.h`, `linux/cpuhotplug.h`, `linux/delay.h`, `linux/export.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/sched_clock.h`.
- Detected declarations: `function constant_event_handler`, `function constant_set_state_oneshot`, `function constant_set_state_periodic`, `function constant_set_state_shutdown`, `function constant_timer_next_event`, `function arch_timer_starting`, `function arch_timer_dying`, `function get_loops_per_jiffy`, `function save_counter`, `function sync_counter`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.