Computer Systems Research Group BSD Distribution
Check-in [d5fb3d3f8d]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: ^T
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d5fb3d3f8d5966be79370e1c86480dab6d4c29d7
User & Date: marc 1990-05-01 07:19:27
Context
1990-05-01
07:19
only ktrace i/o if successful check-in: f99d652dde user: marc tags: trunk
07:19
^T check-in: d5fb3d3f8d user: marc tags: trunk
06:28
add -x flag to specify hex output (default) check-in: ab1f021c93 user: bostic tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to sys/kern/tty.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 *
 *	@(#)tty.c	7.21 (Berkeley) 04/03/90
 */

#include "param.h"
#include "systm.h"
#include "user.h"
#include "ioctl.h"
#define TTYDEFCHARS





|







1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 *
 *	@(#)tty.c	7.22 (Berkeley) 05/01/90
 */

#include "param.h"
#include "systm.h"
#include "user.h"
#include "ioctl.h"
#define TTYDEFCHARS
1723
1724
1725
1726
1727
1728
1729

1730
1731
1732
1733
1734
1735
1736
1737




1738
1739
1740

















1741
1742
1743

1744
1745
1746



1747












































1748
1749
1750
1751
1752
1753
1754
1755
1756


1757
1758





















1759



















1760
















1761
1762
1763
1764
1765
1766
1767

	for (i = 0; table[i].sp_speed != -1; i++)
		if (table[i].sp_speed == speed)
			return(table[i].sp_code);
	return(-1);
}


/*
 * (^T)
 * Report on state of foreground process group.
 */
ttyinfo(tp)
	struct tty *tp;
{
	register struct proc *p;





	if (ttycheckoutq(tp,0) == 0) 
		return;

















	if (tp->t_session == NULL)
		ttyprintf(tp, "kernel: not a controlling terminal\n");
	else if (tp->t_pgrp == NULL || 

		(p = tp->t_pgrp->pg_mem) == NULL)
		ttyprintf(tp, "kernel: no foreground process group\n");
	else {



		int i = 0;













































		for (; p != NULL; p = p->p_pgrpnxt) {
			ttyprintf(tp, 
			 "kernel: pid: %d state: %x wchan: %x ticks: %d\n",
				p->p_pid, p->p_stat, p->p_wchan, p->p_cpticks);
			if (++i > 6) {
				ttyprintf(tp, "kernel: more...\n");
				break;
			}


		}
	}





















}




































#define TOTTY	0x2	/* XXX should be in header */
/*VARARGS2*/
ttyprintf(tp, fmt, x1)
	struct tty *tp;
	char *fmt;
	unsigned x1;
{







>







|
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|
>
|
|

>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
|
|
|
|
|
|
|
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818

1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894

	for (i = 0; table[i].sp_speed != -1; i++)
		if (table[i].sp_speed == speed)
			return(table[i].sp_code);
	return(-1);
}

int ttyhostname = 0;
/*
 * (^T)
 * Report on state of foreground process group.
 */
ttyinfo(tp)
	struct tty *tp;
{
	register struct proc *p, *pick = NULL;
	register char *cp = hostname;
	int x, s;
	struct timeval utime, stime;
#define	pgtok(a)	((a)/(1024/NBPG))

	if (ttycheckoutq(tp,0) == 0) 
		return;
	/* 
	 * hostname 
	 */
	if (ttyhostname) {
		if (*cp == '\0')
			ttyprintf(tp, "amnesia");
		else
			while (*cp && *cp != '.')
				tputchar(*cp++, tp);
		tputchar(' ');
	}
	/* 
	 * load average 
	 */
	x = (averunnable[0] * 100 + FSCALE/2) >> FSHIFT;
	ttyprintf(tp, "load: %d.", x/100);
	ttyoutint(x%100, 10, 2, tp);
	if (tp->t_session == NULL)
		ttyprintf(tp, " not a controlling terminal\n");
	else if (tp->t_pgrp == NULL)
		ttyprintf(tp, " no foreground process group\n");
	else if ((p = tp->t_pgrp->pg_mem) == NULL)
		ttyprintf(tp, " empty foreground process group\n");
	else {
		/* pick interesting process */
		for (; p != NULL; p = p->p_pgrpnxt) {
			if (proc_compare(pick, p))
				pick = p;
		}
		ttyprintf(tp, "  cmd: %s %d [%s] ",
			pick->p_comm, pick->p_pid,
			pick->p_wmesg ? pick->p_wmesg : "running");
		/* 
		 * cpu time 
		 */
		if (u.u_procp == pick)
			s = splclock();
		utime = pick->p_utime;
		stime = pick->p_stime;
		if (u.u_procp == pick)
			splx(s);
		/* user time */
		x = (utime.tv_usec + 5000) / 10000; /* scale to 100's */
		ttyoutint(utime.tv_sec, 10, 1, tp);
		tputchar('.', tp);
		ttyoutint(x, 10, 2, tp);
		tputchar('u', tp);
		tputchar(' ', tp);
		/* system time */
		x = (stime.tv_usec + 5000) / 10000; /* scale to 100's */
		ttyoutint(stime.tv_sec, 10, 1, tp);
		tputchar('.', tp);
		ttyoutint(x, 10, 2, tp);
		tputchar('s', tp);
		tputchar(' ', tp);
		/* 
		 * pctcpu 
		 */
		x = pick->p_pctcpu * 10000 + FSCALE/2 >> FSHIFT;
		ttyoutint(x/100, 10, 1, tp);
#ifdef notdef	/* do we really want this ??? */
		tputchar('.', tp);
		ttyoutint(x%100, 10, 2, tp);
#endif
		ttyprintf(tp, "%% %dk\n", pgtok(pick->p_ssize + pick->p_dsize));
	}
	tp->t_rocount = 0;	/* so pending input will be retyped if BS */
}

ttyoutint(n, base, min, tp)
	register int n, base, min;
	register struct tty *tp;
{

	char info[16];
	register char *p = info;

	while (--min >= 0 || n) {
		*p++ = "0123456789abcdef"[n%base];
		n /= base;
	}
	while (p > info)
		ttyoutput(*--p, tp);
}

/*
 * Returns 1 if p2 is "better" than p1
 *
 * The algorithm for picking the "interesting" process is thus:
 *
 *	1) (Only foreground processes are eligable - implied)
 *	2) Runnable processes are favored over anything
 *	   else.  The runner with the highest cpu
 *	   utilization is picked (p_cpu).  Ties are
 *	   broken by picking the highest pid.
 *	3  Next, the sleeper with the shortest sleep
 *	   time is favored.  With ties, we pick out
 *	   just "short-term" sleepers (SSINTR == 0).
 *	   Further ties are broken by picking the highest
 *	   pid.
 *
 */
#define isrun(p)	(((p)->p_stat == SRUN) || ((p)->p_stat == SIDL))
proc_compare(p1, p2)
	register struct proc *p1, *p2;
{

	if (p1 == NULL)
		return (1);
	/*
	 * see if at least one of them is runnable
	 */
	switch (isrun(p1)<<1 | isrun(p2)) {
	case 0x01:
		return (1);
	case 0x10:
		return (0);
	case 0x11:
		/*
		 * tie - favor one with highest recent cpu utilization
		 */
		if (p2->p_cpu > p1->p_cpu)
			return (1);
		if (p1->p_cpu > p2->p_cpu)
			return (0);
		return (p2->p_pid > p1->p_pid);	/* tie - return highest pid */
	}
	/* 
	 * pick the one with the smallest sleep time
	 */
	if (p2->p_slptime > p1->p_slptime)
		return (0);
	if (p1->p_slptime > p2->p_slptime)
		return (1);
	/*
	 * favor one sleeping in a non-interruptible sleep
	 */
	if (p1->p_flag&SSINTR && (p2->p_flag&SSINTR) == 0)
		return (1);
	if (p2->p_flag&SSINTR && (p1->p_flag&SSINTR) == 0)
		return (0);
	return(p2->p_pid > p1->p_pid);		/* tie - return highest pid */
}
#define TOTTY	0x2	/* XXX should be in header */
/*VARARGS2*/
ttyprintf(tp, fmt, x1)
	struct tty *tp;
	char *fmt;
	unsigned x1;
{