From owner-freebsd-questions@freebsd.org Wed Jan 13 13:58:04 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30660A817FA for ; Wed, 13 Jan 2016 13:58:04 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7C51B13A8 for ; Wed, 13 Jan 2016 13:58:03 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id u0DDvwRa020242; Thu, 14 Jan 2016 00:57:58 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Thu, 14 Jan 2016 00:57:58 +1100 (EST) From: Ian Smith To: "darwinsurvivor@gmail.com" cc: kpneal@pobox.com, "William A. Mahaffey III" , freebsd-questions@freebsd.org Subject: Re: Task to busy one CPU 100% for a period of time? In-Reply-To: Message-ID: <20160114000637.U93547@sola.nimnet.asn.au> References: <20160111002439.Q93547@sola.nimnet.asn.au> <56928802.2040802@hiwaay.net> <20160111154616.G93547@sola.nimnet.asn.au> <20160111203832.GC88498@neutralgood.org> <20160113052558.R93547@sola.nimnet.asn.au> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2016 13:58:04 -0000 On Tue, 12 Jan 2016 13:02:26 -0800, darwinsurvivor@gmail.com wrote: > Have you looked at the sysutils/stress utility? It may do what you need. > > > ~Doug I have now, thanks :) It works well, given I've only tested the -c CPU load option so far. If I'd found it sooner, I might not have bothered compiling Kevin's little program and writing the below script to do about the same thing with it .. but I'm grateful for the exercise! > On Tue, Jan 12, 2016 at 10:36 AM, Ian Smith wrote: > > On Mon, 11 Jan 2016 15:38:32 -0500, kpneal@pobox.com wrote: [..] > > > cc -c main.c > > > cc -c dummy.c > > > cc -o load1 main.o dummy.o > > > > > > One invocation of this program should consume an entire CPU and therefore > > > raise the load average by 1.00. Run as many as you like. > > > > > > (The reason for the two compilations is to avoid having any compiler > > > optimize away the for loop. Just to be safe.) > > > > Thankyou Kevin. Works a treat, so far tested 8 at once, loadavg = 8.00 > > > > I'll follow up hopefully tomorrow with results of a sh script to run a > > given number of instances for a given time, needing a bit more testing. So here; both this and stress give equivalent results with 2 to 8 tasks; over 4 I'm running into overheating (~90C), acpi_thermal kicking in, CPU slowing apparently - but it is summer, and still ~28C|82F at midnight! #!/bin/sh # 12/1/16 add2load.sh thanks Kevin Neal for load1 C code me=`basename $0` [ ! "$1" ] && echo "usage: $me tasks(1-12) [seconds (dflt 930)]" && exit 1 tasks=0; [ $1 -ge 1 -a $1 -le 12 ] && tasks=$1 [ $tasks -eq 0 ] && echo "$me tasks ($1) must be 1..12" && exit 1 [ "$2" ] && secs=$2 || secs=930 # default 15.5m ok=''; [ $secs -ge 20 -a $secs -le 1800 ] && ok=y [ ! "$ok" ] && echo "$me seconds ($secs) must be 20..1800" && exit 1 echo "`date` $me running $tasks load1 tasks for ${secs}s" bgpids='' done=0; trap "done=1; sleep=0" int quit term while [ $done -eq 0 ]; do while [ $tasks -gt 0 ]; do ~/bin/load1 & bgpids="$bgpids $!" tasks=$((tasks-1)) done sleep $secs done=1 done kill $bgpids || echo "$me: error killing pids $bgpids" echo "`date` $me done" trap - int quit term exit 0 cheers, Ian