From owner-FreeBSD-tech-jp@jp.freebsd.org  Sat Feb 13 02:18:56 1999
Received: (from daemon@localhost)
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) id CAA20115;
	Sat, 13 Feb 1999 02:18:56 +0900 (JST)
	(envelope-from owner-FreeBSD-tech-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (root@tasogare.imasy.or.jp [202.227.24.5])
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) with ESMTP id CAA20090;
	Sat, 13 Feb 1999 02:18:41 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (ppp7.imasy.or.jp [202.227.24.17])
	by tasogare.imasy.or.jp (8.9.3+3.1W/3.7W-tasogare) with ESMTP id CAA15050;
	Sat, 13 Feb 1999 02:18:33 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Message-Id: <199902121718.CAA15050@tasogare.imasy.or.jp>
To: FreeBSD-users-jp@jp.freebsd.org, magara@maizuru-ct.ac.jp
Cc: FreeBSD-tech-jp@jp.freebsd.org
In-Reply-To: Your message of "Fri, 12 Feb 1999 17:19:33 +0900"
	<199902121719.BHC65270.BBBSHN@maizuru-ct.ac.jp>
References: <199902121719.BHC65270.BBBSHN@maizuru-ct.ac.jp>
X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Date: Sat, 13 Feb 1999 02:15:58 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 980905(IM100)
Lines: 111
Reply-To: FreeBSD-tech-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+981115
X-Sequence: FreeBSD-tech-jp 2006
Subject: [FreeBSD-tech-jp 2006] Re: [FreeBSD-users-jp 38655] Re: Cputime limit exceeded
Errors-To: owner-FreeBSD-tech-jp@jp.freebsd.org
Sender: owner-FreeBSD-tech-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

$B$$$o$5$-$H?=$7$^$9!#(B
3.1R $BL\A0$G$9$,!"$3$NLdBj$O7k9=:,$,?<$$$H;W$o$l$k$N$G(B tech $B$K(B Cc $B$G$9!#(B

> ohishi>$B30$7$F$$$k$+$bCN$l$^$;$s$1$I(B....BA2$B$C$F;v$J$N$G!"Nc$N%+%l%s%@4X78$N%P%0(B(*1)
> ohishi>$B$rJz$($?E[$8$c$J$$$G$7$g$&$+!);d$,;}$C$F$$$k(BBs$B$bF1%P%0$r;}$C$F$$$k%?%$%W(B
> ohishi>$B$G$9$,!"$3$A$i$G$OH/@8$7$?;v$O$"$j$^$;$s(B($B@x:_E*$KH/@8$9$k2DG=@-$O$"$k$H(B
> ohishi>$B;W$&$N$@$1$I(B...)$B!#(B
> 
> $B2DG=@-$O$"$j$^$9$,!$(B
> $B:#$N$H$3$m%&%A$N%^%7%s%+%l%s%@!<$O(B
> $B@5>o$K;~$r9o$_B3$1$F$*$j$^$9!%(B

$B$&$A$G$b(B pao3 $B$X0z$C1[$7$7$?$i$H$?$s$KIQH/$7$F$*$j!"(B
$BFC$K(B suspend/resume $B$5$;$k$H(B 100% $B:F8=$7$^$9!#(B
# pao228 -> pao3 $B$O(B 1$B;~4V<e$G:Q$s$@$N$K!"$3$NLdBj$G(B 2$BF|$[$IG:$s$G$^$9(B :-(

CVS $B$r$N$>$$$F$_$k$H!"(B2.2.X $B$H(B 3.0 $B$G$O(B kern_clock.c $B$J$I$,%,%i%C$H(B
$BJQ$C$F$*$j!"$=$N$;$$$G(B "calcru negative..." $B$,=P$d$9$/$J$C$?$N$+!"(B
$B:G6a$N(B -current ($B$*$h$S(B -stable) $B$N%3!<%I$K$O(B NTIMECOUNTER $B$H$$$&(B
option $B$,DI2C$5$l$F$$$^$9!#(B
$B4XO"$9$k(B log $B$r%T%C%/%"%C%W$9$k$H!"(B
----------------------------
revision 1.81
date: 1998/10/23 10:44:52;  author: phk;  state: Exp;  lines: +51 -56
Change the way we simulate stable storage for timecounters.

If you have problems with the "calcru" messages and processes being
killed for excessive cpu time, try to increase the NTIMECOUNTER
#define and report your findings.

----------------------------
revision 1.85
date: 1998/11/23 09:58:53;  author: phk;  state: Exp;  lines: +18 -10
Make timecounters more resistant to badly behaved SW/HW which locks
out interrupts for too long.  If you still see the "calcru: negative
time..." message you can increase NTIMECOUNTER (see LINT).

Sideeffect is that a timecounter is required to not wrap around in
less than (1 + delta) seconds instead of the (1/hz + delta) required
until now.

----------------------------
revision 1.86
date: 1998/11/29 20:31:02;  author: phk;  state: Exp;  lines: +42 -12
Make the previous behaviour the default, add a sysctl which you
can set if your hw/sw produces the "calcru negative..." message.

Setting the alternate method (sysctl -w kern.timecounter.method=1)
makes the the get{nano|micro}*() functions call the real thing at
resulting in a measurable but minor overhead.

I decided to NOT have the "calcru" change the method automatically
because you should be aware of this problem if you have it.

The problems currently seen, related to usleep and a few other corners
are fixed for both methods.

$B$9$G$K(B kern_clock.c $B$rF~$lBX$($F(B NTIMECOUNTER=20 $B$0$i$$$G;n$7$^$7$?$,!"(B
$B$&$A$G$O8z2L$J$7$G$9!#(Bsuspend/resume $B$+$iLa$C$F$/$k$HA4BNE*$KF0:n$,$N$m$/$J$j!"(B
$B$*$*$/$N%W%m%;%9$,(B kern_synch.c:mi_switch() $B$N(B
        /*
         * Compute the amount of time during which the current
         * process was running, and add that to its total so far.
         */
        microuptime(&switchtime);
        p->p_runtime += (switchtime.tv_usec - p->p_switchtime.tv_usec) +
            (switchtime.tv_sec - p->p_switchtime.tv_sec) * (int64_t)1000000;

$B$3$3$G(B p_runtime $B$KIi$NCM$,BeF~$5$l(B ($B<B:]$O(B u_int64_t $B$J$N$G$H$C$F$bBg$-$JCM(B)$B!"(B

        /*
         * Check if the process exceeds its cpu resource allocation.
         * If over max, kill it.
         */
        if (p->p_stat != SZOMB && p->p_runtime > p->p_limit->p_cpulimit) {
                rlim = &p->p_rlimit[RLIMIT_CPU];
                if (p->p_runtime / (rlim_t)1000000 >= rlim->rlim_max) {
                        killproc(p, "exceeded maximum CPU limit");

$B$H$5$l$F$$$k$h$&$K$_$($^$9!#$3$&$J$kA0C{$O(B kern_resource.c:calcru() $B$N(B
                microuptime(&tv);
                totusec += (tv.tv_usec - p->p_switchtime.tv_usec) +
                    (tv.tv_sec - p->p_switchtime.tv_sec) * (int64_t)1000000;
($BCfN,(B)
                switchtime = tv;
        }
        if (totusec < 0) {
                /* XXX no %qd in kernel.  Truncate. */
                printf("calcru: negative time of %ld usec for pid %d (%s)\n",
                       (long)totusec, p->p_pid, p->p_comm);
                totusec = 0;
        }
$B$G3NG'$G$-$k$N$G$9$,!"$3$3$G$OBP:v$O9V$8$i$l$F$$$J$$$^$^!"(B
$B@h$[$I$N(B mi_switch() $B$G(B kill $B$5$l$A$c$&$_$?$$$G$9!#(B
# microuptime() $B$,$H$C$F$b2x$7$=$&(B...
$B=i?4<T$N$\$/$G$b0BD>$J=$@5$J$i$9$0$G$-$=$&$J$s$G$9$,!"(BSMP $B$H$NMm$_$H$+9M$($k$H(B
$B$3$NJU$h$/$o$+$C$F$$$k?M$K8+$FM_$7$$$H;W$$$^$9!#(B

> $BJL$N%9%l%C%I(B(users-jp 38619 by $B1v8+(B@3web$B$5$s(B)
> $B$HF1$8>I>u$N$h$&$G$9$,!$(B
> $B$=$N%9%l%C%I$+$i$O!$(B
> $B$I$&$b(B 3.0-RELEASE $B$N@x:_E*$J%P%0$N$h$&$J5$$,$7$^$9!%(B

$B$N2DG=@-$,Bg$-$$$G$9$M!#(B

> $B1v8+(B@3web$B$5$s(B $B$N(B dmesg $B$r8+$F$_$?$$$s$G$9$1$I!%(B
> $B!JFC$K(B frequency $B$N$H$3$m!K(B

$B$A$J$_$K$&$A$N(B dmesg $B$N3:Ev8D=j$O(B
Timecounter "i8254"  frequency 1193182 Hz  cost 1908 ns
$B$G$9$,!"$3$l$O$$$$$s$G$O$J$$$G$7$g$&$+(B?
