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

[Top][All Lists]


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


From: Giuseppe Scrivano
Subject: Re: [PATCH] core-count: A new program to count the number of cpu cores
Date: Sun, 01 Nov 2009 03:40:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Hi Pádraig,

Pádraig Brady <address@hidden> writes:

I do wonder though whether it would be better to have numprocessors() try to return this by default?

num_processors is going to be used by programs as nproc will be used by scripts; all considerations we made for nproc can be applied to num_processors.

I.E. can you think of a use case where someone would want to use the --installed option? BTW "installed" differs from the terms discussed here, and perhaps "online" would be better (if we did want to expose it at all).

I don't see any common use case, except a quick way to see how many processors can potentially be available.

Also I'm wondering why you used the pthread interface to this? I didn't notice pthreadgetaffinitynp() in POSIX for example (is that what the np represents?), so why not call schedgetaffinity directly without needing to link with the pthread library.

Thanks, I am attaching a new version that uses sched instead of pthread. The _np suffix means "non portable".

Also perhaps we should be comparing to /proc/stat just in case /proc/cpuinfo was not showing the online processors: grep '^cpu[0-9]' /proc/stat | wc -l

From what I can see, /proc/cpuinfo shows the number of online processors:

grep '^proc' /proc/cpuinfo | wc -l

2

echo 0 > /sys/devices/system/cpu/cpu1/online

grep '^proc' /proc/cpuinfo | wc -l

1

echo 1 > /sys/devices/system/cpu/cpu1/online

grep '^proc' /proc/cpuinfo | wc -l

2

Regards, Giuseppe

From 31b047ef9f0e83b7f6387bdd7e628cbb17f24079 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano <address@hidden> Date: Sat, 31 Oct 2009 18:59:50 +0100 Subject: [PATCH] nproc: A new program to count the number of processors


AUTHORS | 1 + NEWS | 4 + README | 2 +- bootstrap.conf | 2 + doc/coreutils.texi | 39 +++++++++++++ po/POTFILES.in | 1 + src/Makefile.am | 3 + src/nproc.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 3 + tests/nproc/avail | 31 ++++++++++ tests/nproc/cpuinfo | 33 +++++++++++ tests/nproc/positive | 31 ++++++++++ 12 files changed, 304 insertions(+), 1 deletions(-) create mode 100644 src/nproc.c create mode 100755 tests/nproc/avail create mode 100755 tests/nproc/cpuinfo create mode 100755 tests/nproc/positive

1.6.5