kernel/delayacct.c
Source file repositories/reference/linux-study-clean/kernel/delayacct.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/delayacct.c- Extension
.c- Size
- 8498 bytes
- Lines
- 321
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/sched.hlinux/sched/task.hlinux/sched/cputime.hlinux/sched/clock.hlinux/slab.hlinux/taskstats.hlinux/sysctl.hlinux/delayacct.hlinux/module.h
Detected Declarations
function set_delayacctfunction delayacct_setup_enablefunction delayacct_initfunction sysctl_delayacctfunction kernel_delayacct_sysctls_initfunction __delayacct_tsk_initfunction timestampsfunction __delayacct_blkio_startfunction __delayacct_blkio_endfunction delayacct_add_tskfunction __delayacct_blkio_ticksfunction __delayacct_freepages_startfunction __delayacct_freepages_endfunction __delayacct_thrashing_startfunction __delayacct_thrashing_endfunction __delayacct_swapin_startfunction __delayacct_swapin_endfunction __delayacct_compact_startfunction __delayacct_compact_endfunction __delayacct_wpcopy_startfunction __delayacct_wpcopy_endfunction __delayacct_irq
Annotated Snippet
if (ns > *max) {
*max = ns;
ktime_get_real_ts64(ts);
}
if (*min == 0 || ns < *min)
*min = ns;
raw_spin_unlock_irqrestore(lock, flags);
}
}
void __delayacct_blkio_start(void)
{
current->delays->blkio_start = local_clock();
}
/*
* We cannot rely on the `current` macro, as we haven't yet switched back to
* the process being woken.
*/
void __delayacct_blkio_end(struct task_struct *p)
{
delayacct_end(&p->delays->lock,
&p->delays->blkio_start,
&p->delays->blkio_delay,
&p->delays->blkio_count,
&p->delays->blkio_delay_max,
&p->delays->blkio_delay_min,
&p->delays->blkio_delay_max_ts);
}
int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
{
u64 utime, stime, stimescaled, utimescaled;
unsigned long long t2, t3;
unsigned long flags, t1;
s64 tmp;
task_cputime(tsk, &utime, &stime);
tmp = (s64)d->cpu_run_real_total;
tmp += utime + stime;
d->cpu_run_real_total = (tmp < (s64)d->cpu_run_real_total) ? 0 : tmp;
task_cputime_scaled(tsk, &utimescaled, &stimescaled);
tmp = (s64)d->cpu_scaled_run_real_total;
tmp += utimescaled + stimescaled;
d->cpu_scaled_run_real_total =
(tmp < (s64)d->cpu_scaled_run_real_total) ? 0 : tmp;
/*
* No locking available for sched_info (and too expensive to add one)
* Mitigate by taking snapshot of values
*/
t1 = tsk->sched_info.pcount;
t2 = tsk->sched_info.run_delay;
t3 = tsk->se.sum_exec_runtime;
d->cpu_count += t1;
d->cpu_delay_max = tsk->sched_info.max_run_delay;
d->cpu_delay_min = tsk->sched_info.min_run_delay;
d->cpu_delay_max_ts.tv_sec = tsk->sched_info.max_run_delay_ts.tv_sec;
d->cpu_delay_max_ts.tv_nsec = tsk->sched_info.max_run_delay_ts.tv_nsec;
tmp = (s64)d->cpu_delay_total + t2;
d->cpu_delay_total = (tmp < (s64)d->cpu_delay_total) ? 0 : tmp;
tmp = (s64)d->cpu_run_virtual_total + t3;
d->cpu_run_virtual_total =
(tmp < (s64)d->cpu_run_virtual_total) ? 0 : tmp;
if (!tsk->delays)
return 0;
/* zero XXX_total, non-zero XXX_count implies XXX stat overflowed */
raw_spin_lock_irqsave(&tsk->delays->lock, flags);
UPDATE_DELAY(blkio);
UPDATE_DELAY(swapin);
UPDATE_DELAY(freepages);
UPDATE_DELAY(thrashing);
UPDATE_DELAY(compact);
UPDATE_DELAY(wpcopy);
UPDATE_DELAY(irq);
raw_spin_unlock_irqrestore(&tsk->delays->lock, flags);
return 0;
}
__u64 __delayacct_blkio_ticks(struct task_struct *tsk)
{
__u64 ret;
unsigned long flags;
Annotation
- Immediate include surface: `linux/sched.h`, `linux/sched/task.h`, `linux/sched/cputime.h`, `linux/sched/clock.h`, `linux/slab.h`, `linux/taskstats.h`, `linux/sysctl.h`, `linux/delayacct.h`.
- Detected declarations: `function set_delayacct`, `function delayacct_setup_enable`, `function delayacct_init`, `function sysctl_delayacct`, `function kernel_delayacct_sysctls_init`, `function __delayacct_tsk_init`, `function timestamps`, `function __delayacct_blkio_start`, `function __delayacct_blkio_end`, `function delayacct_add_tsk`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.