MCPcopy Create free account
hub / github.com/F-Stack/f-stack / statclock

Function statclock

freebsd/kern/kern_clock.c:639–721  ·  view source on GitHub ↗

* Statistics clock. Updates rusage information and calls the scheduler * to adjust priorities of the active thread. * * This should be called by all active processors. */

Source from the content-addressed store, hash-verified

637 * This should be called by all active processors.
638 */
639void
640statclock(int cnt, int usermode)
641{
642 struct rusage *ru;
643 struct vmspace *vm;
644 struct thread *td;
645 struct proc *p;
646 long rss;
647 long *cp_time;
648 uint64_t runtime, new_switchtime;
649
650 td = curthread;
651 p = td->td_proc;
652
653 cp_time = (long *)PCPU_PTR(cp_time);
654 if (usermode) {
655 /*
656 * Charge the time as appropriate.
657 */
658 td->td_uticks += cnt;
659 if (p->p_nice > NZERO)
660 cp_time[CP_NICE] += cnt;
661 else
662 cp_time[CP_USER] += cnt;
663 } else {
664 /*
665 * Came from kernel mode, so we were:
666 * - handling an interrupt,
667 * - doing syscall or trap work on behalf of the current
668 * user process, or
669 * - spinning in the idle loop.
670 * Whichever it is, charge the time as appropriate.
671 * Note that we charge interrupts to the current process,
672 * regardless of whether they are ``for'' that process,
673 * so that we know how much of its real time was spent
674 * in ``non-process'' (i.e., interrupt) work.
675 */
676 if ((td->td_pflags & TDP_ITHREAD) ||
677 td->td_intr_nesting_level >= 2) {
678 td->td_iticks += cnt;
679 cp_time[CP_INTR] += cnt;
680 } else {
681 td->td_pticks += cnt;
682 td->td_sticks += cnt;
683 if (!TD_IS_IDLETHREAD(td))
684 cp_time[CP_SYS] += cnt;
685 else
686 cp_time[CP_IDLE] += cnt;
687 }
688 }
689
690 /* Update resource usage integrals and maximums. */
691 MPASS(p->p_vmspace != NULL);
692 vm = p->p_vmspace;
693 ru = &td->td_ru;
694 ru->ru_ixrss += pgtok(vm->vm_tsize) * cnt;
695 ru->ru_idrss += pgtok(vm->vm_dsize) * cnt;
696 ru->ru_isrss += pgtok(vm->vm_ssize) * cnt;

Callers 1

handleeventsFunction · 0.85

Calls 3

vmspace_resident_countFunction · 0.85
sched_tdnameFunction · 0.70
sched_clockFunction · 0.70

Tested by

no test coverage detected