aboutsummaryrefslogtreecommitdiff
path: root/procps/mpstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'procps/mpstat.c')
-rw-r--r--procps/mpstat.c49
1 files changed, 1 insertions, 48 deletions
diff --git a/procps/mpstat.c b/procps/mpstat.c
index 1199b98dd..7610a68fb 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -816,45 +816,11 @@ static void print_header(struct tm *t)
816} 816}
817 817
818/* 818/*
819 * Get number of processors in /sys
820 */
821static int get_sys_cpu_nr(void)
822{
823 DIR *dir;
824 struct dirent *d;
825 struct stat buf;
826 char line[MAX_PF_NAME];
827 int proc_nr = 0;
828
829 dir = opendir(SYSFS_DEVCPU);
830 if (!dir)
831 return 0; /* /sys not mounted */
832
833 /* Get current file entry */
834 while ((d = readdir(dir)) != NULL) {
835 if (starts_with_cpu(d->d_name) && isdigit(d->d_name[3])) {
836 snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU,
837 d->d_name);
838 line[MAX_PF_NAME - 1] = '\0';
839 /* Get information about file */
840 if (stat(line, &buf) < 0)
841 continue;
842 /* If found 'cpuN', we have one more processor */
843 if (S_ISDIR(buf.st_mode))
844 proc_nr++;
845 }
846 }
847
848 closedir(dir);
849 return proc_nr;
850}
851
852/*
853 * Get number of processors in /proc/stat 819 * Get number of processors in /proc/stat
854 * Return value '0' means one CPU and non SMP kernel. 820 * Return value '0' means one CPU and non SMP kernel.
855 * Otherwise N means N processor(s) and SMP kernel. 821 * Otherwise N means N processor(s) and SMP kernel.
856 */ 822 */
857static int get_proc_cpu_nr(void) 823static int get_cpu_nr(void)
858{ 824{
859 FILE *fp; 825 FILE *fp;
860 char line[256]; 826 char line[256];
@@ -881,19 +847,6 @@ static int get_proc_cpu_nr(void)
881 return proc_nr + 1; 847 return proc_nr + 1;
882} 848}
883 849
884static int get_cpu_nr(void)
885{
886 int n;
887
888 /* Try to use /sys, if possible */
889 n = get_sys_cpu_nr();
890 if (n == 0)
891 /* Otherwise use /proc/stat */
892 n = get_proc_cpu_nr();
893
894 return n;
895}
896
897/* 850/*
898 * Get number of interrupts available per processor 851 * Get number of interrupts available per processor
899 */ 852 */