\hypertarget{tty__info_8c_source}{}\doxysection{tty\+\_\+info.\+c}
\label{tty__info_8c_source}\index{kern/tty\_info.c@{kern/tty\_info.c}}
\mbox{\hyperlink{tty__info_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/3-\/Clause}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 1982, 1986, 1990, 1991, 1993}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00005}00005 \textcolor{comment}{ *      The Regents of the University of California.  All rights reserved.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00006}00006 \textcolor{comment}{ * (c) UNIX System Laboratories, Inc.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00007}00007 \textcolor{comment}{ * All or some portions of this file are derived from material licensed}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00008}00008 \textcolor{comment}{ * to the University of California by American Telephone and Telegraph}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00009}00009 \textcolor{comment}{ * Co. or Unix System Laboratories, Inc. and are reproduced herein with}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00010}00010 \textcolor{comment}{ * the permission of UNIX System Laboratories, Inc.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00011}00011 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00012}00012 \textcolor{comment}{ * Copyright (c) 2002 Networks Associates Technologies, Inc.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00013}00013 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00014}00014 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00015}00015 \textcolor{comment}{ * Portions of this software were developed for the FreeBSD Project by}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00016}00016 \textcolor{comment}{ * ThinkSec AS and NAI Labs, the Security Research Division of Network}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00017}00017 \textcolor{comment}{ * Associates, Inc.  under DARPA/SPAWAR contract N66001-\/01-\/C-\/8035}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00018}00018 \textcolor{comment}{ * ("{}CBOSS"{}), as part of the DARPA CHATS research program.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00019}00019 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00020}00020 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00021}00021 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00022}00022 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00023}00023 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00024}00024 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00025}00025 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00026}00026 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00027}00027 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00028}00028 \textcolor{comment}{ * 3. Neither the name of the University nor the names of its contributors}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00029}00029 \textcolor{comment}{ *    may be used to endorse or promote products derived from this software}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00030}00030 \textcolor{comment}{ *    without specific prior written permission.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00031}00031 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00032}00032 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00033}00033 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00034}00034 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00035}00035 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00036}00036 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00037}00037 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00038}00038 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00039}00039 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00040}00040 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00041}00041 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00042}00042 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00043}00043 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00044}00044 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00046}\mbox{\hyperlink{tty__info_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00046}} \mbox{\hyperlink{tty__info_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00047}00047 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00048}00048 \textcolor{preprocessor}{\#include "{}opt\_stack.h"{}}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00049}00049 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00050}00050 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00051}00051 \textcolor{preprocessor}{\#include <sys/cons.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <sys/kdb.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00053}00053 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00054}00054 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00055}00055 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00056}00056 \textcolor{preprocessor}{\#include <sys/proc.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00057}00057 \textcolor{preprocessor}{\#include <sys/resourcevar.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00058}00058 \textcolor{preprocessor}{\#include <sys/sbuf.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00059}00059 \textcolor{preprocessor}{\#include <sys/sched.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00060}00060 \textcolor{preprocessor}{\#include <sys/stack.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00061}00061 \textcolor{preprocessor}{\#include <sys/sysctl.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00062}00062 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00063}00063 \textcolor{preprocessor}{\#include <sys/tty.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00064}00064 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00065}00065 \textcolor{preprocessor}{\#include <vm/vm.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00066}00066 \textcolor{preprocessor}{\#include <vm/pmap.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00067}00067 \textcolor{preprocessor}{\#include <vm/vm\_map.h>}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00068}00068 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00069}00069 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00070}00070 \textcolor{comment}{ * Returns 1 if p2 is "{}better"{} than p1}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00071}00071 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00072}00072 \textcolor{comment}{ * The algorithm for picking the "{}interesting"{} process is thus:}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00073}00073 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00074}00074 \textcolor{comment}{ *      1) Only foreground processes are eligible -\/ implied.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00075}00075 \textcolor{comment}{ *      2) Runnable processes are favored over anything else.  The runner}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00076}00076 \textcolor{comment}{ *         with the highest cpu utilization is picked (p\_estcpu).  Ties are}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00077}00077 \textcolor{comment}{ *         broken by picking the highest pid.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00078}00078 \textcolor{comment}{ *      3) The sleeper with the shortest sleep time is next.  With ties,}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00079}00079 \textcolor{comment}{ *         we pick out just "{}short-\/term"{} sleepers (P\_SINTR == 0).}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00080}00080 \textcolor{comment}{ *      4) Further ties are broken by picking the highest pid.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00081}00081 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00082}00082 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00083}\mbox{\hyperlink{tty__info_8c_ab5d42ab0190ce1319e4b213d378a88a3}{00083}} \textcolor{preprocessor}{\#define TESTAB(a, b)    ((a)<<1 | (b))}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00084}\mbox{\hyperlink{tty__info_8c_ac861a4f76845366e73497de2abac95a5}{00084}} \textcolor{preprocessor}{\#define ONLYA   2}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00085}\mbox{\hyperlink{tty__info_8c_a11426c2858d61ff04b4b5980fa629ee0}{00085}} \textcolor{preprocessor}{\#define ONLYB   1}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00086}\mbox{\hyperlink{tty__info_8c_a85ddca800985505ab1036cf0d1be748b}{00086}} \textcolor{preprocessor}{\#define BOTH    3}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00087}00087 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00088}00088 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00089}\mbox{\hyperlink{tty__info_8c_a57d93e68f4ff7eb4e01b9fbe7ee479e0}{00089}} \mbox{\hyperlink{tty__info_8c_a57d93e68f4ff7eb4e01b9fbe7ee479e0}{proc\_sum}}(\textcolor{keyword}{struct} proc *p, fixpt\_t *estcpup)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00090}00090 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00091}00091         \textcolor{keyword}{struct }thread *td;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00092}00092         \textcolor{keywordtype}{int} estcpu;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00093}00093         \textcolor{keywordtype}{int} val;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00094}00094 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00095}00095         val = 0;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00096}00096         estcpu = 0;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00097}00097         FOREACH\_THREAD\_IN\_PROC(p, td) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00098}00098                 thread\_lock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00099}00099                 \textcolor{keywordflow}{if} (TD\_ON\_RUNQ(td) ||}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00100}00100                     TD\_IS\_RUNNING(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00101}00101                         val = 1;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00102}00102                 estcpu += \mbox{\hyperlink{sched__4bsd_8c_a0b8b10a9e6dad416aad831e26edbe740}{sched\_pctcpu}}(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00103}00103                 thread\_unlock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00104}00104         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00105}00105         *estcpup = estcpu;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00106}00106 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00107}00107         \textcolor{keywordflow}{return} (val);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00108}00108 \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00109}00109 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00110}00110 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00111}\mbox{\hyperlink{tty__info_8c_a2142118c552ca774e1e0fc3b284060f5}{00111}} \mbox{\hyperlink{tty__info_8c_a2142118c552ca774e1e0fc3b284060f5}{thread\_compare}}(\textcolor{keyword}{struct} thread *td, \textcolor{keyword}{struct} thread *td2)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00112}00112 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00113}00113         \textcolor{keywordtype}{int} runa, runb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00114}00114         \textcolor{keywordtype}{int} slpa, slpb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00115}00115         fixpt\_t esta, estb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00116}00116 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00117}00117         \textcolor{keywordflow}{if} (td == NULL)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00118}00118                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00119}00119 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00120}00120         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00121}00121 \textcolor{comment}{         * Fetch running stats, pctcpu usage, and interruptable flag.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00122}00122 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00123}00123         thread\_lock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00124}00124         runa = TD\_IS\_RUNNING(td) || TD\_ON\_RUNQ(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00125}00125         slpa = td-\/>td\_flags \& TDF\_SINTR;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00126}00126         esta = \mbox{\hyperlink{sched__4bsd_8c_a0b8b10a9e6dad416aad831e26edbe740}{sched\_pctcpu}}(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00127}00127         thread\_unlock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00128}00128         thread\_lock(td2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00129}00129         runb = TD\_IS\_RUNNING(td2) || TD\_ON\_RUNQ(td2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00130}00130         estb = \mbox{\hyperlink{sched__4bsd_8c_a0b8b10a9e6dad416aad831e26edbe740}{sched\_pctcpu}}(td2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00131}00131         slpb = td2-\/>td\_flags \& TDF\_SINTR;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00132}00132         thread\_unlock(td2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00133}00133         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00134}00134 \textcolor{comment}{         * see if at least one of them is runnable}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00135}00135 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00136}00136         \textcolor{keywordflow}{switch} (\mbox{\hyperlink{tty__info_8c_ab5d42ab0190ce1319e4b213d378a88a3}{TESTAB}}(runa, runb)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00137}00137         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_ac861a4f76845366e73497de2abac95a5}{ONLYA}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00138}00138                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00139}00139         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a11426c2858d61ff04b4b5980fa629ee0}{ONLYB}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00140}00140                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00141}00141         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a85ddca800985505ab1036cf0d1be748b}{BOTH}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00142}00142                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00143}00143         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00144}00144         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00145}00145 \textcolor{comment}{         *  favor one with highest recent cpu utilization}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00146}00146 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00147}00147         \textcolor{keywordflow}{if} (estb > esta)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00148}00148                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00149}00149         \textcolor{keywordflow}{if} (esta > estb)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00150}00150                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00151}00151         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00152}00152 \textcolor{comment}{         * favor one sleeping in a non-\/interruptible sleep}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00153}00153 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00154}00154         \textcolor{keywordflow}{switch} (\mbox{\hyperlink{tty__info_8c_ab5d42ab0190ce1319e4b213d378a88a3}{TESTAB}}(slpa, slpb)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00155}00155         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_ac861a4f76845366e73497de2abac95a5}{ONLYA}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00156}00156                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00157}00157         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a11426c2858d61ff04b4b5980fa629ee0}{ONLYB}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00158}00158                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00159}00159         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a85ddca800985505ab1036cf0d1be748b}{BOTH}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00160}00160                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00161}00161         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00162}00162 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00163}00163         \textcolor{keywordflow}{return} (td < td2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00164}00164 \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00165}00165 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00166}00166 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00167}\mbox{\hyperlink{tty__info_8c_a03da81e282cb3468da579c3cacec4e12}{00167}} \mbox{\hyperlink{tty__info_8c_a03da81e282cb3468da579c3cacec4e12}{proc\_compare}}(\textcolor{keyword}{struct} proc *p1, \textcolor{keyword}{struct} proc *p2)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00168}00168 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00169}00169 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00170}00170         \textcolor{keywordtype}{int} runa, runb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00171}00171         fixpt\_t esta, estb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00172}00172 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00173}00173         \textcolor{keywordflow}{if} (p1 == NULL)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00174}00174                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00175}00175 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00176}00176         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00177}00177 \textcolor{comment}{         * Fetch various stats about these processes.  After we drop the}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00178}00178 \textcolor{comment}{         * lock the information could be stale but the race is unimportant.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00179}00179 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00180}00180         PROC\_LOCK(p1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00181}00181         runa = \mbox{\hyperlink{tty__info_8c_a57d93e68f4ff7eb4e01b9fbe7ee479e0}{proc\_sum}}(p1, \&esta);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00182}00182         PROC\_UNLOCK(p1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00183}00183         PROC\_LOCK(p2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00184}00184         runb = \mbox{\hyperlink{tty__info_8c_a57d93e68f4ff7eb4e01b9fbe7ee479e0}{proc\_sum}}(p2, \&estb);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00185}00185         PROC\_UNLOCK(p2);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00186}00186 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00187}00187         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00188}00188 \textcolor{comment}{         * see if at least one of them is runnable}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00189}00189 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00190}00190         \textcolor{keywordflow}{switch} (\mbox{\hyperlink{tty__info_8c_ab5d42ab0190ce1319e4b213d378a88a3}{TESTAB}}(runa, runb)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00191}00191         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_ac861a4f76845366e73497de2abac95a5}{ONLYA}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00192}00192                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00193}00193         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a11426c2858d61ff04b4b5980fa629ee0}{ONLYB}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00194}00194                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00195}00195         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a85ddca800985505ab1036cf0d1be748b}{BOTH}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00196}00196                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00197}00197         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00198}00198         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00199}00199 \textcolor{comment}{         *  favor one with highest recent cpu utilization}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00200}00200 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00201}00201         \textcolor{keywordflow}{if} (estb > esta)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00202}00202                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00203}00203         \textcolor{keywordflow}{if} (esta > estb)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00204}00204                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00205}00205         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00206}00206 \textcolor{comment}{         * weed out zombies}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00207}00207 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00208}00208         \textcolor{keywordflow}{switch} (\mbox{\hyperlink{tty__info_8c_ab5d42ab0190ce1319e4b213d378a88a3}{TESTAB}}(p1-\/>p\_state == PRS\_ZOMBIE, p2-\/>p\_state == PRS\_ZOMBIE)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00209}00209         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_ac861a4f76845366e73497de2abac95a5}{ONLYA}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00210}00210                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00211}00211         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a11426c2858d61ff04b4b5980fa629ee0}{ONLYB}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00212}00212                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00213}00213         \textcolor{keywordflow}{case} \mbox{\hyperlink{tty__info_8c_a85ddca800985505ab1036cf0d1be748b}{BOTH}}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00214}00214                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00215}00215         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00216}00216 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00217}00217         \textcolor{keywordflow}{return} (p2-\/>p\_pid > p1-\/>p\_pid);         \textcolor{comment}{/* tie -\/ return highest pid */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00218}00218 \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00219}00219 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00220}00220 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00221}\mbox{\hyperlink{tty__info_8c_aa17c1610d6f9951849df624030d8c82f}{00221}} \mbox{\hyperlink{tty__info_8c_aa17c1610d6f9951849df624030d8c82f}{sbuf\_tty\_drain}}(\textcolor{keywordtype}{void} *a, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *d, \textcolor{keywordtype}{int} len)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00222}00222 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00223}00223         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00224}00224         \textcolor{keywordtype}{int} rc;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00225}00225 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00226}00226         tp = a;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00227}00227 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00228}00228         \textcolor{keywordflow}{if} (\mbox{\hyperlink{subr__kdb_8c_a313e8ff6f20d39fd246ef5da5648c08c}{kdb\_active}}) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00229}00229                 \mbox{\hyperlink{kern__cons_8c_a795143a53735c830a13e35a9890dd68f}{cnputsn}}(d, len);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00230}00230                 \textcolor{keywordflow}{return} (len);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00231}00231         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00232}00232         \textcolor{keywordflow}{if} (tp != NULL \&\& !KERNEL\_PANICKED()) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00233}00233                 rc = \mbox{\hyperlink{tty__ttydisc_8c_a250437058cb23c11fc513e0cf62b2d93}{tty\_putstrn}}(tp, d, len);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00234}00234                 \textcolor{keywordflow}{if} (rc != 0)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00235}00235                         \textcolor{keywordflow}{return} (-\/ENXIO);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00236}00236                 \textcolor{keywordflow}{return} (len);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00237}00237         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00238}00238         \textcolor{keywordflow}{return} (-\/ENXIO);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00239}00239 \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00240}00240 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00241}00241 \textcolor{preprocessor}{\#ifdef STACK}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00242}00242 \textcolor{keyword}{static} \textcolor{keywordtype}{int} tty\_info\_kstacks = STACK\_SBUF\_FMT\_COMPACT;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00243}00243 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00244}00244 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00245}00245 sysctl\_tty\_info\_kstacks(SYSCTL\_HANDLER\_ARGS)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00246}00246 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00247}00247         \textcolor{keyword}{enum} stack\_sbuf\_fmt val;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00248}00248         \textcolor{keywordtype}{int} error;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00249}00249 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00250}00250         val = tty\_info\_kstacks;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00251}00251         error = \mbox{\hyperlink{kern__sysctl_8c_aab82ede27ea5d6975c4e91eb6c6111b7}{sysctl\_handle\_int}}(oidp, \&val, 0, req);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00252}00252         \textcolor{keywordflow}{if} (error != 0 || req-\/>newptr == NULL)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00253}00253                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00254}00254 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00255}00255         \textcolor{keywordflow}{switch} (val) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00256}00256         \textcolor{keywordflow}{case} STACK\_SBUF\_FMT\_NONE:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00257}00257         \textcolor{keywordflow}{case} STACK\_SBUF\_FMT\_LONG:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00258}00258         \textcolor{keywordflow}{case} STACK\_SBUF\_FMT\_COMPACT:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00259}00259                 tty\_info\_kstacks = val;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00260}00260                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00261}00261         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00262}00262                 error = EINVAL;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00263}00263         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00264}00264 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00265}00265         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00266}00266 \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00267}00267 \mbox{\hyperlink{imgact__binmisc_8c_ab102523114ab5e342a91cf4d6d564381}{SYSCTL\_PROC}}(\_kern, OID\_AUTO, tty\_info\_kstacks,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00268}00268     CTLFLAG\_RWTUN | CTLFLAG\_MPSAFE | CTLTYPE\_INT, NULL, 0,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00269}00269     sysctl\_tty\_info\_kstacks, \textcolor{stringliteral}{"{}I"{}},}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00270}00270     \textcolor{stringliteral}{"{}Adjust format of kernel stack(9) traces on \string^T (tty info): "{}}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00271}00271     \textcolor{stringliteral}{"{}0 -\/ disabled; 1 -\/ long; 2 -\/ compact"{}});}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00272}00272 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00273}00273 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00274}00274 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00275}00275 \textcolor{comment}{ * Report on state of foreground process group.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00276}00276 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00277}00277 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00278}\mbox{\hyperlink{tty__info_8c_a52c2d18c8cff3f4ed41f7d3908fabdcc}{00278}} \mbox{\hyperlink{tty__info_8c_a52c2d18c8cff3f4ed41f7d3908fabdcc}{tty\_info}}(\textcolor{keyword}{struct} tty *tp)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00279}00279 \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00280}00280         \textcolor{keyword}{struct }timeval rtime, utime, stime;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00281}00281 \textcolor{preprocessor}{\#ifdef STACK}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00282}00282         \textcolor{keyword}{struct }stack stack;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00283}00283         \textcolor{keywordtype}{int} sterr, kstacks\_val;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00284}00284         \textcolor{keywordtype}{bool} print\_kstacks;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00285}00285 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00286}00286         \textcolor{keyword}{struct }proc *p, *ppick;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00287}00287         \textcolor{keyword}{struct }thread *td, *tdpick;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00288}00288         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *stateprefix, *state;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00289}00289         \textcolor{keyword}{struct }sbuf sb;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00290}00290         \textcolor{keywordtype}{long} rss;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00291}00291         \textcolor{keywordtype}{int} load, pctcpu;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00292}00292         pid\_t pid;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00293}00293         \textcolor{keywordtype}{char} comm[MAXCOMLEN + 1];}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00294}00294         \textcolor{keyword}{struct }rusage ru;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00295}00295 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00296}00296         tty\_assert\_locked(tp);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00297}00297 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00298}00298         \textcolor{keywordflow}{if} (\mbox{\hyperlink{tty_8c_a46cecdbd2d7bfcba7d6ae01ebff65034}{tty\_checkoutq}}(tp) == 0)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00299}00299                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00300}00300 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00301}00301         (void)\mbox{\hyperlink{subr__sbuf_8c_ad3cd536452958687b5d1e0005b232f8e}{sbuf\_new}}(\&sb, tp-\/>t\_prbuf, tp-\/>t\_prbufsz, SBUF\_FIXEDLEN);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00302}00302         \mbox{\hyperlink{subr__sbuf_8c_a74031327251e553e1bee5fac5df9f37c}{sbuf\_set\_drain}}(\&sb, \mbox{\hyperlink{tty__info_8c_aa17c1610d6f9951849df624030d8c82f}{sbuf\_tty\_drain}}, tp);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00303}00303 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00304}00304         \textcolor{comment}{/* Print load average. */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00305}00305         load = (\mbox{\hyperlink{kern__synch_8c_aad1664e3b3a77909dcfa16360b7a8996}{averunnable}}.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00306}00306         \mbox{\hyperlink{subr__sbuf_8c_a6c6abdb7c0c9a19d892b1d07757dd056}{sbuf\_printf}}(\&sb, \textcolor{stringliteral}{"{}\%sload: \%d.\%02d "{}}, tp-\/>t\_column == 0 ? \textcolor{stringliteral}{"{}"{}} : \textcolor{stringliteral}{"{}\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00307}00307             load / 100, load \% 100);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00308}00308 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00309}00309         \textcolor{keywordflow}{if} (tp-\/>t\_session == NULL) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00310}00310                 \mbox{\hyperlink{subr__sbuf_8c_a6c6abdb7c0c9a19d892b1d07757dd056}{sbuf\_printf}}(\&sb, \textcolor{stringliteral}{"{}not a controlling terminal\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00311}00311                 \textcolor{keywordflow}{goto} out;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00312}00312         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00313}00313         \textcolor{keywordflow}{if} (tp-\/>t\_pgrp == NULL) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00314}00314                 \mbox{\hyperlink{subr__sbuf_8c_a6c6abdb7c0c9a19d892b1d07757dd056}{sbuf\_printf}}(\&sb, \textcolor{stringliteral}{"{}no foreground process group\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00315}00315                 \textcolor{keywordflow}{goto} out;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00316}00316         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00317}00317         PGRP\_LOCK(tp-\/>t\_pgrp);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00318}00318         \textcolor{keywordflow}{if} (LIST\_EMPTY(\&tp-\/>t\_pgrp-\/>pg\_members)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00319}00319                 PGRP\_UNLOCK(tp-\/>t\_pgrp);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00320}00320                 \mbox{\hyperlink{subr__sbuf_8c_a6c6abdb7c0c9a19d892b1d07757dd056}{sbuf\_printf}}(\&sb, \textcolor{stringliteral}{"{}empty foreground process group\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00321}00321                 \textcolor{keywordflow}{goto} out;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00322}00322         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00323}00323 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00324}00324         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00325}00325 \textcolor{comment}{         * Pick the most interesting process and copy some of its}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00326}00326 \textcolor{comment}{         * state for printing later.  This operation could rely on stale}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00327}00327 \textcolor{comment}{         * data as we can't hold the proc slock or thread locks over the}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00328}00328 \textcolor{comment}{         * whole list. However, we're guaranteed not to reference an exited}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00329}00329 \textcolor{comment}{         * thread or proc since we hold the tty locked.}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00330}00330 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00331}00331         p = NULL;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00332}00332         LIST\_FOREACH(ppick, \&tp-\/>t\_pgrp-\/>pg\_members, p\_pglist)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00333}00333                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{tty__info_8c_a03da81e282cb3468da579c3cacec4e12}{proc\_compare}}(p, ppick))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00334}00334                         p = ppick;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00335}00335 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00336}00336         PROC\_LOCK(p);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00337}00337         PGRP\_UNLOCK(tp-\/>t\_pgrp);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00338}00338         td = NULL;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00339}00339         FOREACH\_THREAD\_IN\_PROC(p, tdpick)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00340}00340                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{tty__info_8c_a2142118c552ca774e1e0fc3b284060f5}{thread\_compare}}(td, tdpick))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00341}00341                         td = tdpick;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00342}00342         stateprefix = \textcolor{stringliteral}{"{}"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00343}00343         thread\_lock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00344}00344         \textcolor{keywordflow}{if} (TD\_IS\_RUNNING(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00345}00345                 state = \textcolor{stringliteral}{"{}running"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00346}00346         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (TD\_ON\_RUNQ(td) || TD\_CAN\_RUN(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00347}00347                 state = \textcolor{stringliteral}{"{}runnable"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00348}00348         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (TD\_IS\_SLEEPING(td)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00349}00349                 \textcolor{comment}{/* XXX: If we're sleeping, are we ever not in a queue? */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00350}00350                 \textcolor{keywordflow}{if} (TD\_ON\_SLEEPQ(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00351}00351                         state = td-\/>td\_wmesg;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00352}00352                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00353}00353                         state = \textcolor{stringliteral}{"{}sleeping without queue"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00354}00354         \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (TD\_ON\_LOCK(td)) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00355}00355                 state = td-\/>td\_lockname;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00356}00356                 stateprefix = \textcolor{stringliteral}{"{}*"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00357}00357         \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (TD\_IS\_SUSPENDED(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00358}00358                 state = \textcolor{stringliteral}{"{}suspended"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00359}00359         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (TD\_AWAITING\_INTR(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00360}00360                 state = \textcolor{stringliteral}{"{}intrwait"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00361}00361         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (p-\/>p\_state == PRS\_ZOMBIE)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00362}00362                 state = \textcolor{stringliteral}{"{}zombie"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00363}00363         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00364}00364                 state = \textcolor{stringliteral}{"{}unknown"{}};}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00365}00365         pctcpu = (\mbox{\hyperlink{sched__4bsd_8c_a0b8b10a9e6dad416aad831e26edbe740}{sched\_pctcpu}}(td) * 10000 + FSCALE / 2) >> FSHIFT;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00366}00366 \textcolor{preprocessor}{\#ifdef STACK}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00367}00367         kstacks\_val = atomic\_load\_int(\&tty\_info\_kstacks);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00368}00368         print\_kstacks = (kstacks\_val != STACK\_SBUF\_FMT\_NONE);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00369}00369 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00370}00370         \textcolor{keywordflow}{if} (print\_kstacks) \{}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00371}00371                 \textcolor{keywordflow}{if} (TD\_IS\_SWAPPED(td))}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00372}00372                         sterr = ENOENT;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00373}00373                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00374}00374                         sterr = stack\_save\_td(\&stack, td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00375}00375         \}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00376}00376 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00377}00377         thread\_unlock(td);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00378}00378         \textcolor{keywordflow}{if} (p-\/>p\_state == PRS\_NEW || p-\/>p\_state == PRS\_ZOMBIE)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00379}00379                 rss = 0;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00380}00380         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00381}00381                 rss = pgtok(vmspace\_resident\_count(p-\/>p\_vmspace));}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00382}00382         \mbox{\hyperlink{kern__tc_8c_ad2ee9cc3eb46aca2703cc3c5945c6c2d}{microuptime}}(\&rtime);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00383}00383         \mbox{\hyperlink{kern__time_8c_a800e9ded7c0a2b4666b49448f4ebe180}{timevalsub}}(\&rtime, \&p-\/>p\_stats-\/>p\_start);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00384}00384         \mbox{\hyperlink{kern__resource_8c_ae974871e2062829630e3726ea75937db}{rufetchcalc}}(p, \&ru, \&utime, \&stime);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00385}00385         pid = p-\/>p\_pid;}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00386}00386         strlcpy(comm, p-\/>p\_comm, \textcolor{keyword}{sizeof} comm);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00387}00387         PROC\_UNLOCK(p);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00388}00388 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00389}00389         \textcolor{comment}{/* Print command, pid, state, rtime, utime, stime, \%cpu, and rss. */}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00390}00390         \mbox{\hyperlink{subr__sbuf_8c_a6c6abdb7c0c9a19d892b1d07757dd056}{sbuf\_printf}}(\&sb,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00391}00391             \textcolor{stringliteral}{"{} cmd: \%s \%d [\%s\%s] \%ld.\%02ldr \%ld.\%02ldu \%ld.\%02lds \%d\%\% \%ldk\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00392}00392             comm, pid, stateprefix, state,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00393}00393             (\textcolor{keywordtype}{long})rtime.tv\_sec, rtime.tv\_usec / 10000,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00394}00394             (\textcolor{keywordtype}{long})utime.tv\_sec, utime.tv\_usec / 10000,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00395}00395             (\textcolor{keywordtype}{long})stime.tv\_sec, stime.tv\_usec / 10000,}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00396}00396             pctcpu / 100, rss);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00397}00397 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00398}00398 \textcolor{preprocessor}{\#ifdef STACK}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00399}00399         \textcolor{keywordflow}{if} (print\_kstacks \&\& sterr == 0)}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00400}00400                 \mbox{\hyperlink{subr__stack_8c_a093c24c8e3e2f293543030a11c360177}{stack\_sbuf\_print\_flags}}(\&sb, \&stack, M\_NOWAIT, kstacks\_val);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00401}00401 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00402}00402 }
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00403}00403 out:}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00404}00404         \mbox{\hyperlink{subr__sbuf_8c_a29e35276bb1dcf4342f5a49ec3d0068a}{sbuf\_finish}}(\&sb);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00405}00405         \mbox{\hyperlink{subr__sbuf_8c_a60934581249642aa5f426992ace71542}{sbuf\_delete}}(\&sb);}
\DoxyCodeLine{\Hypertarget{tty__info_8c_source_l00406}00406 \}}

\end{DoxyCode}
