From owner-svn-src-head@FreeBSD.ORG Tue Oct 30 19:46:00 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E10AED3D; Tue, 30 Oct 2012 19:46:00 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AFBDB8FC0A; Tue, 30 Oct 2012 19:46:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9UJk0qi061968; Tue, 30 Oct 2012 19:46:00 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9UJk02a061964; Tue, 30 Oct 2012 19:46:00 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201210301946.q9UJk02a061964@svn.freebsd.org> From: Mateusz Guzik Date: Tue, 30 Oct 2012 19:46:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242372 - head/libexec/atrun X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2012 19:46:01 -0000 Author: mjg Date: Tue Oct 30 19:46:00 2012 New Revision: 242372 URL: http://svn.freebsd.org/changeset/base/242372 Log: atrun(8): scale default load average limit with the number of CPUs Previously atrun refused to run jobs if load average was not below fixed limit of 1.5. PR: 173175 Reviewed by: peterj Approved by: trasz (mentor) MFC after: 2 weeks Modified: head/libexec/atrun/atrun.c head/libexec/atrun/atrun.man Modified: head/libexec/atrun/atrun.c ============================================================================== --- head/libexec/atrun/atrun.c Tue Oct 30 19:34:45 2012 (r242371) +++ head/libexec/atrun/atrun.c Tue Oct 30 19:46:00 2012 (r242372) @@ -33,6 +33,9 @@ static const char rcsid[] = #include #include #include +#ifdef __FreeBSD__ +#include +#endif #include #include #include @@ -454,7 +457,12 @@ main(int argc, char *argv[]) gid_t batch_gid; int c; int run_batch; +#ifdef __FreeBSD__ + size_t ncpu, ncpusz; + double load_avg = -1; +#else double load_avg = LOADAVG_MX; +#endif /* We don't need root privileges all the time; running under uid and gid daemon * is fine. @@ -472,8 +480,10 @@ main(int argc, char *argv[]) case 'l': if (sscanf(optarg, "%lf", &load_avg) != 1) perr("garbled option -l"); +#ifndef __FreeBSD__ if (load_avg <= 0.) load_avg = LOADAVG_MX; +#endif break; case 'd': @@ -489,6 +499,15 @@ main(int argc, char *argv[]) if (chdir(ATJOB_DIR) != 0) perr("cannot change to %s", ATJOB_DIR); +#ifdef __FreeBSD__ + if (load_avg <= 0.) { + ncpusz = sizeof(size_t); + if (sysctlbyname("hw.ncpu", &ncpu, &ncpusz, NULL, 0) < 0) + ncpu = 1; + load_avg = LOADAVG_MX * ncpu; + } +#endif + /* Main loop. Open spool directory for reading and look over all the * files in there. If the filename indicates that the job should be run * and the x bit is set, fork off a child which sets its user and group Modified: head/libexec/atrun/atrun.man ============================================================================== --- head/libexec/atrun/atrun.man Tue Oct 30 19:34:45 2012 (r242371) +++ head/libexec/atrun/atrun.man Tue Oct 30 19:46:00 2012 (r242372) @@ -1,5 +1,5 @@ .\" $FreeBSD$ -.Dd June 17, 2007 +.Dd October 30, 2012 .Dt ATRUN 8 .Os .Sh NAME @@ -45,7 +45,7 @@ e.g., locked out or expired. .Bl -tag -width indent .It Fl l Ar load_avg Specify a limiting load factor, over which batch jobs should -not be run, instead of the compiled in default of 1.5. +not be run, instead of the default of 1.5 * number of active CPUs. .It Fl d Debug; print error messages to standard error instead of using .Xr syslog 3 .