[Midnightbsd-cvs] src [6943] trunk/libexec/atrun: change the load detection to take into account the number of cpus in the system for atrun

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Nov 11 22:45:22 EST 2014


Revision: 6943
          http://svnweb.midnightbsd.org/src/?rev=6943
Author:   laffer1
Date:     2014-11-11 22:45:22 -0500 (Tue, 11 Nov 2014)
Log Message:
-----------
change the load detection to take into account the number of cpus in the system for atrun

Modified Paths:
--------------
    trunk/libexec/atrun/atrun.c
    trunk/libexec/atrun/atrun.man

Modified: trunk/libexec/atrun/atrun.c
===================================================================
--- trunk/libexec/atrun/atrun.c	2014-11-12 03:18:46 UTC (rev 6942)
+++ trunk/libexec/atrun/atrun.c	2014-11-12 03:45:22 UTC (rev 6943)
@@ -33,6 +33,9 @@
 #include <sys/fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef __MidnightBSD__
+#include <sys/sysctl.h>
+#endif
 #include <sys/wait.h>
 #include <sys/param.h>
 #include <ctype.h>
@@ -123,7 +126,7 @@
     pid_t pid;
     int fd_out, fd_in;
     int queue;
-    char mailbuf[MAXLOGNAME], fmt[49];
+    char mailbuf[MAXLOGNAME], fmt[64];
     char *mailname = NULL;
     FILE *stream;
     int send_mail = 0;
@@ -454,7 +457,12 @@
     gid_t batch_gid;
     int c;
     int run_batch;
+#ifdef __MidnightBSD__
+    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 @@
 	case 'l': 
 	    if (sscanf(optarg, "%lf", &load_avg) != 1)
 		perr("garbled option -l");
+#ifndef __MidnightBSD__
 	    if (load_avg <= 0.)
 		load_avg = LOADAVG_MX;
+#endif
 	    break;
 
 	case 'd':
@@ -489,6 +499,15 @@
     if (chdir(ATJOB_DIR) != 0)
 	perr("cannot change to %s", ATJOB_DIR);
 
+#ifdef __MidnightBSD__
+    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: trunk/libexec/atrun/atrun.man
===================================================================
--- trunk/libexec/atrun/atrun.man	2014-11-12 03:18:46 UTC (rev 6942)
+++ trunk/libexec/atrun/atrun.man	2014-11-12 03:45:22 UTC (rev 6943)
@@ -1,5 +1,5 @@
 .\" $MidnightBSD$
-.Dd June 17, 2007
+.Dd November 11, 2014
 .Dt ATRUN 8
 .Os
 .Sh NAME
@@ -45,7 +45,7 @@
 .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 .



More information about the Midnightbsd-cvs mailing list