xref: /openbmc/linux/tools/testing/selftests/rcutorture/bin/cpus2use.sh (revision 2f0f2441b4a10948e2ec042b48fef13680387f7c)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Get an estimate of how CPU-hoggy to be.
5#
6# Usage: cpus2use.sh
7#
8# Copyright (C) IBM Corporation, 2013
9#
10# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
11
12ncpus=`grep '^processor' /proc/cpuinfo | wc -l`
13idlecpus=`mpstat | tail -1 | \
14	awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`
15awk -v ncpus=$ncpus -v idlecpus=$idlecpus < /dev/null '
16BEGIN {
17	cpus2use = idlecpus;
18	if (cpus2use < 1)
19		cpus2use = 1;
20	if (cpus2use < ncpus / 10)
21		cpus2use = ncpus / 10;
22	if (cpus2use == int(cpus2use))
23		cpus2use = int(cpus2use)
24	else
25		cpus2use = int(cpus2use) + 1
26	print cpus2use;
27}'
28
29