From owner-svn-src-head@freebsd.org Fri Jun 22 00:02:06 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9AC4D1005505; Fri, 22 Jun 2018 00:02:06 +0000 (UTC) (envelope-from chuck@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 483E6746BF; Fri, 22 Jun 2018 00:02:06 +0000 (UTC) (envelope-from chuck@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2A36018FEB; Fri, 22 Jun 2018 00:02:06 +0000 (UTC) (envelope-from chuck@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5M026pj042225; Fri, 22 Jun 2018 00:02:06 GMT (envelope-from chuck@FreeBSD.org) Received: (from chuck@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5M0262D042224; Fri, 22 Jun 2018 00:02:06 GMT (envelope-from chuck@FreeBSD.org) Message-Id: <201806220002.w5M0262D042224@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: chuck set sender to chuck@FreeBSD.org using -f From: Chuck Tuffli Date: Fri, 22 Jun 2018 00:02:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335516 - head/sys/compat/linprocfs X-SVN-Group: head X-SVN-Commit-Author: chuck X-SVN-Commit-Paths: head/sys/compat/linprocfs X-SVN-Commit-Revision: 335516 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jun 2018 00:02:07 -0000 Author: chuck Date: Fri Jun 22 00:02:05 2018 New Revision: 335516 URL: https://svnweb.freebsd.org/changeset/base/335516 Log: Fix output of linprocfs stat entry The Linux /proc/stat entry has grown over time v2.5.41 < user, nice, system, idle v2.5.41 user, nice, system, idle, iowait, irq v2.6.11 user, nice, system, idle, iowait, irq, softirq, steal v2.6.24 user, nice, system, idle, iowait, irq, softirq, steal, guest v2.6.32 > user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice Some applications (e.g. nodejs) depend on the correct number of entries and will abort otherwise. Fix is to print the correct number of entries based on the value of osrelease set either in sysctl or the jail settings. Change is similar to approach used by illumos. Reviewed by: emaste, imp (mentor) Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D15858 Modified: head/sys/compat/linprocfs/linprocfs.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Fri Jun 22 00:02:03 2018 (r335515) +++ head/sys/compat/linprocfs/linprocfs.c Fri Jun 22 00:02:05 2018 (r335516) @@ -469,9 +469,21 @@ linprocfs_dopartitions(PFS_FILL_ARGS) return (0); } - /* * Filler function for proc/stat + * + * Output depends on kernel version: + * + * v2.5.40 <= + * user nice system idle + * v2.5.41 + * user nice system idle iowait + * v2.6.11 + * user nice system idle iowait irq softirq steal + * v2.6.24 + * user nice system idle iowait irq softirq steal guest + * v2.6.33 >= + * user nice system idle iowait irq softirq steal guest guest_nice */ static int linprocfs_dostat(PFS_FILL_ARGS) @@ -481,22 +493,54 @@ linprocfs_dostat(PFS_FILL_ARGS) long *cp; struct timeval boottime; int i; + char *zero_pad; + bool has_intr = true; + if (linux_kernver(td) >= LINUX_KERNVER(2,6,33)) { + zero_pad = " 0 0 0 0\n"; + } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,24)) { + zero_pad = " 0 0 0\n"; + } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,11)) { + zero_pad = " 0 0\n"; + } else if (linux_kernver(td) >= LINUX_KERNVER(2,5,41)) { + has_intr = false; + zero_pad = " 0\n"; + } else { + has_intr = false; + zero_pad = "\n"; + } + read_cpu_time(cp_time); getboottime(&boottime); - sbuf_printf(sb, "cpu %ld %ld %ld %ld\n", + /* Parameters common to all versions */ + sbuf_printf(sb, "cpu %lu %lu %lu %lu", T2J(cp_time[CP_USER]), T2J(cp_time[CP_NICE]), - T2J(cp_time[CP_SYS] /*+ cp_time[CP_INTR]*/), + T2J(cp_time[CP_SYS]), T2J(cp_time[CP_IDLE])); + + /* Print interrupt stats if available */ + if (has_intr) { + sbuf_printf(sb, " 0 %lu", T2J(cp_time[CP_INTR])); + } + + /* Pad out remaining fields depending on version */ + sbuf_printf(sb, "%s", zero_pad); + CPU_FOREACH(i) { pcpu = pcpu_find(i); cp = pcpu->pc_cp_time; - sbuf_printf(sb, "cpu%d %ld %ld %ld %ld\n", i, + sbuf_printf(sb, "cpu%d %lu %lu %lu %lu", i, T2J(cp[CP_USER]), T2J(cp[CP_NICE]), - T2J(cp[CP_SYS] /*+ cp[CP_INTR]*/), + T2J(cp[CP_SYS]), T2J(cp[CP_IDLE])); + + if (has_intr) { + sbuf_printf(sb, " 0 %lu", T2J(cp[CP_INTR])); + } + + sbuf_printf(sb, "%s", zero_pad); } sbuf_printf(sb, "disk 0 0 0 0\n"