[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [SCM] Debian package checker branch, master, updated. 2.5.9-27-g9e61a25



* Niels Thykier <niels@thykier.net>, 2012-06-27, 17:12:
+    if ( -r '/proc/cpuinfo') {
+        my $jobs = 0;
+        my $cpus = 0;
+        open my $fd, '<', '/proc/cpuinfo'
+            or fail ("failed to open /proc/cpuinfo: $!");
+        while (<$fd>) {
+            next unless m/^cpu cores\s*:\s*(\d+)/;
+            $jobs += $1;
+            $cpus++;
+        }
+        close $fd;
+
+        if ($cpus) {
+            # Running up to twice the number of cores usually gets the most out
+            # of the CPUs and disks but it might be too aggresive to be the
+            # default for -j. Only use <cores>+1 then.
+            debug_msg (1, "Number of cores: $jobs (CPUs: $cpus)");
+
+            return $jobs + 1;
+        }
+        debug_msg (1, "Did not find any core information for any cpus in /proc/cpuinfo?");
+    }
+
+    # No decent number of jobs? Just use 2 as a default
+    return 2;
+}

I would advice against parsing /proc/cpuinfo. Format of this file varies with architecture, and it's very easy to get it wrong. For example, the subroutine returns 5 on my machine (even though it has only one CPU with 2 cores) and 2 on gabrielli.d.o (16 cores).

How about something like this:

my $cpus = int(`nproc` or 1)
return $cpus + 1

?

--
Jakub Wilk


Reply to: