drivers/xen/time.c
Source file repositories/reference/linux-study-clean/drivers/xen/time.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/time.c- Extension
.c- Size
- 4132 bytes
- Lines
- 176
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/kernel_stat.hlinux/math64.hlinux/gfp.hlinux/slab.hlinux/static_call.hlinux/sched/cputime.hasm/xen/hypervisor.hasm/xen/hypercall.hxen/events.hxen/features.hxen/interface/xen.hxen/interface/vcpu.hxen/xen-ops.h
Detected Declarations
function get64function xen_get_runstate_snapshot_cpu_deltafunction xen_get_runstate_snapshot_cpufunction xen_manage_runstate_timefunction for_each_possible_cpufunction for_each_possible_cpufunction xen_vcpu_stolenfunction xen_steal_clockfunction xen_setup_runstate_infofunction xen_time_setup_guest
Annotated Snippet
if (unlikely(!runstate_delta)) {
pr_warn("%s: failed to allocate runstate_delta\n",
__func__);
return;
}
for_each_possible_cpu(cpu) {
xen_get_runstate_snapshot_cpu_delta(&state, cpu);
memcpy(runstate_delta[cpu].time, state.time,
sizeof(runstate_delta[cpu].time));
}
break;
case 0: /* backup runstate time after resume */
if (unlikely(!runstate_delta)) {
pr_warn("%s: cannot accumulate runstate time as runstate_delta is NULL\n",
__func__);
return;
}
for_each_possible_cpu(cpu) {
for (i = 0; i < 4; i++)
per_cpu(old_runstate_time, cpu)[i] +=
runstate_delta[cpu].time[i];
}
break;
default: /* do not accumulate runstate time for checkpointing */
break;
}
if (action != -1 && runstate_delta) {
kfree(runstate_delta);
runstate_delta = NULL;
}
}
/* return true when a vcpu could run but has no real cpu to run on */
bool xen_vcpu_stolen(int vcpu)
{
return per_cpu(xen_runstate, vcpu).state == RUNSTATE_runnable;
}
u64 xen_steal_clock(int cpu)
{
struct vcpu_runstate_info state;
xen_get_runstate_snapshot_cpu(&state, cpu);
return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline];
}
void xen_setup_runstate_info(int cpu)
{
struct vcpu_register_runstate_memory_area area;
area.addr.v = &per_cpu(xen_runstate, cpu);
if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area,
xen_vcpu_nr(cpu), &area))
BUG();
}
void __init xen_time_setup_guest(void)
{
bool xen_runstate_remote;
xen_runstate_remote = !HYPERVISOR_vm_assist(VMASST_CMD_enable,
VMASST_TYPE_runstate_update_flag);
static_call_update(pv_steal_clock, xen_steal_clock);
static_key_slow_inc(¶virt_steal_enabled);
if (xen_runstate_remote)
static_key_slow_inc(¶virt_steal_rq_enabled);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kernel_stat.h`, `linux/math64.h`, `linux/gfp.h`, `linux/slab.h`, `linux/static_call.h`, `linux/sched/cputime.h`, `asm/xen/hypervisor.h`.
- Detected declarations: `function get64`, `function xen_get_runstate_snapshot_cpu_delta`, `function xen_get_runstate_snapshot_cpu`, `function xen_manage_runstate_time`, `function for_each_possible_cpu`, `function for_each_possible_cpu`, `function xen_vcpu_stolen`, `function xen_steal_clock`, `function xen_setup_runstate_info`, `function xen_time_setup_guest`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: source implementation candidate.
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.