bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] core-count: A new program to count the number of cpu cores


From: Jim Meyering
Subject: Re: [PATCH] core-count: A new program to count the number of cpu cores
Date: Sat, 31 Oct 2009 18:34:34 +0100

Giuseppe Scrivano wrote:
> I included what we have discussed into my patch.  I renamed the new
> program to `nproc', now it accepts two options: --available and
> --installed.
> By default --available is used, if --available is not know then
> --installed is used.
>
> I added another test to ensure nproc --available <= nproc --installed.
>
> Any comment?

Sure.  That didn't apply via "git am FILE", so I applied via patch.
Please rebase against latest, before posting.

Here's a quick and superficial review.

A few changes were required for "make syntax-check" and
./configure --enable-gcc-warnings:

...
> +void
> +usage (int status)
> +{
> +  if (status != EXIT_SUCCESS)
> +    fprintf (stderr, _("Try `%s --help' for more information.\n"),
> +             program_name);
> +  else
> +    {
> +      printf (_("Usage: %s [OPTION]...\n"), program_name);
> +      fputs (_("\
> +Print the number of online cpu cores.\n\
> +\n\
> +"), stdout);
> +      fputs (_("\
> +      --available          report the number of processors available to 
> the\n \

s/report/print/

> +                           current process.\n \
> +      --installed          return the number of installed processors\n\

s/return/print/

> +"), stdout);
> +
> +      fputs (HELP_OPTION_DESCRIPTION, stdout);
> +      fputs (VERSION_OPTION_DESCRIPTION, stdout);
> +      emit_ancillary_info ();
> +    }
> +  exit (status);
> +}
> +
> +/* Compute the number of available processors.  Return 0 on error.  */
> +
> +static u_long

u_long?  No thanks.
There are no other uses of that type in the coreutils.

This first was for a syntax-check violation.

diff --git a/README b/README
index 7545eab..0951b62 100644
--- a/README
+++ b/README
@@ -11,7 +11,7 @@ The programs that can be built with this package are:
   csplit cut date dd df dir dircolors dirname du echo env expand expr
   factor false fmt fold groups head hostid hostname id install join kill
   link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup
-  od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
+  nproc od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
   runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf
   sleep sort split stat stdbuf stty su sum sync tac tail tee test timeout
   touch tr true truncate tsort tty uname unexpand uniq unlink uptime users
diff --git a/src/nproc.c b/src/nproc.c
index 2449fc9..fbf2e59 100644
--- a/src/nproc.c
+++ b/src/nproc.c
@@ -73,10 +73,10 @@ Print the number of online cpu cores.\n\

 /* Compute the number of available processors.  Return 0 on error.  */

-static u_long
-nproc_available ()
+static unsigned long
+nproc_available (void)
 {
-  u_long nproc = 0;
+  unsigned long nproc = 0;

 #ifdef CPU_SETSIZE
   size_t j;
@@ -100,12 +100,12 @@ nproc_available ()
    can't be computed rollback to the installed processors.  The result is
    guaranteed to be at least 1.  */

-static u_long
+static unsigned long
 nproc (bool available)
 {
   if (available)
     {
-      u_long available_proc = nproc_available ();
+      unsigned long available_proc = nproc_available ();
       if (available_proc)
         return available_proc;
     }
@@ -149,7 +149,7 @@ main (int argc, char **argv)
         }
     }

-  printf ("%u\n", nproc (available));
+  printf ("%lu\n", nproc (available));

   exit (EXIT_SUCCESS);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]