[PATCH V2] xfstests: src/feature.c: print a number of online CPUs

Dave Chinner david at fromorbit.com
Mon Oct 28 17:15:40 CDT 2013


On Thu, Oct 24, 2013 at 04:10:40PM +0400, Stanislav Kholmanskikh wrote:
> For this purpose we use sysconf() as it is the
> preferred platform neutral interface for getting this
> sort of information.
> 
> Based on Dave Chinner proposal.
> 
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh at oracle.com>
> ---
....
> +	if (oflag) {
> +		long ncpus;
> +
> +#if defined(_SC_NPROCESSORS_ONLN)
> +		/* Linux */
> +		ncpus = sysconf(_SC_NPROCESSORS_ONLN);
> +#elif defined(_SC_NPROC_ONLN)
> +		/* IRIX */
> +		ncpus = sysconf(_SC_NPROC_ONLN);
> +#else
> +		ncpus = 1;
> +#endif
> +		if (ncpus == -1)
> +			ncpus = 1;

That can be simplified, and there's probably not much point in
listing the OS's that the different calls are for.

	if (oflag) {
		long ncpus = -1;

#if defined(_SC_NPROCESSORS_ONLN)
		ncpus = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
		ncpus = sysconf(_SC_NPROC_ONLN);
#endif
		if (ncpus == -1)
			ncpus = 1;

		....

Cheers,

Dave.
-- 
Dave Chinner
david at fromorbit.com



More information about the xfs mailing list