From 3c1b4dc46679c6f68068295e61b97c9ed5c6596d Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 7 Aug 2016 17:26:26 +0200
Subject: [PATCH 5/8] i386 removal, part 54/x: Remove perfmon(4) remains.

It only ever was compilable into i386 kernels. I forgot to remove it
too in f4c88b0b86f1810db0482795bc097597d1197c54.
---
 Makefile_upgrade.inc                     |   1 +
 etc/mtree/BSD.usr.dist                   |   2 -
 share/examples/perfmon/Makefile          |   9 --
 share/examples/perfmon/README            |  26 ----
 share/examples/perfmon/perfmon.c         | 196 -------------------------------
 share/man/man9/ioctl.9                   |   2 -
 sys/config/LINT64                        |   7 --
 sys/platform/pc64/conf/options           |   1 -
 sys/platform/pc64/isa/prof_machdep.c     |  41 +------
 sys/platform/pc64/x86_64/machdep.c       |   6 -
 sys/platform/vkernel64/x86_64/cpu_regs.c |   3 -
 11 files changed, 4 insertions(+), 290 deletions(-)
 delete mode 100644 share/examples/perfmon/Makefile
 delete mode 100644 share/examples/perfmon/README
 delete mode 100644 share/examples/perfmon/perfmon.c

diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc
index 9080a72..4e2f8e4 100644
--- a/Makefile_upgrade.inc
+++ b/Makefile_upgrade.inc
@@ -3122,6 +3122,7 @@ TO_REMOVE+=/usr/share/openssl/man/man3/EVP_PKEY_ctrl.3.gz
 TO_REMOVE+=/usr/share/openssl/man/man3/EVP_PKEY_ctrl_str.3.gz
 TO_REMOVE+=/usr/include/emulation
 TO_REMOVE+=/boot/kernel/if_ep.ko
+TO_REMOVE+=/usr/share/examples/perfmon
 
 .if !defined(WANT_INSTALLER)
 TO_REMOVE+=/usr/sbin/dfuibe_installer
diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist
index b694644..fbec30e 100644
--- a/etc/mtree/BSD.usr.dist
+++ b/etc/mtree/BSD.usr.dist
@@ -203,8 +203,6 @@
             ..
             netgraph
             ..
-            perfmon
-            ..
             pf
             ..
             portal
diff --git a/share/examples/perfmon/Makefile b/share/examples/perfmon/Makefile
deleted file mode 100644
index fb02025..0000000
--- a/share/examples/perfmon/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# $FreeBSD: src/share/examples/perfmon/Makefile,v 1.4 1999/08/28 00:19:25 peter Exp $
-# $DragonFly: src/share/examples/perfmon/Makefile,v 1.2 2003/06/17 04:36:57 dillon Exp $
-
-PROG=	perfmon
-NOMAN=
-
-install:
-
-.include <bsd.prog.mk>
diff --git a/share/examples/perfmon/README b/share/examples/perfmon/README
deleted file mode 100644
index 84a7710..0000000
--- a/share/examples/perfmon/README
+++ /dev/null
@@ -1,26 +0,0 @@
-`perfmon' is a sample program to access the performance-monitoring
-counters on Pentium and Pentium Pro CPUs.  See perfmon(4) for a
-description of this facility.
-
-The program takes the following options:
-
-	-u	count events in user mode
-	-o	count events in kernel mode
-		(these two can be combined)
-
-	-e	count events, not duration
-	-l n	run `n' loops (default 50)
-	-s n	sleep `n' seconds between loop iterations (default 0)
-
-The following options are not implemented on Pentium CPUs:
-
-	-m n	use count mask `n'
-	-i	invert sense of count mask comparison
-	-U n	use unit mask `n'
-
-There is one mandatory argument, which is the event number to be
-monitored, defined in <machine/perfmon.h>.  All numbers can be
-specified in any format acceptable to strtol(3).
-
-$FreeBSD: src/share/examples/perfmon/README,v 1.4.2.1 2001/05/16 02:01:25 dd Exp $
-$DragonFly: src/share/examples/perfmon/README,v 1.2 2003/06/17 04:36:57 dillon Exp $
diff --git a/share/examples/perfmon/perfmon.c b/share/examples/perfmon/perfmon.c
deleted file mode 100644
index 133091a..0000000
--- a/share/examples/perfmon/perfmon.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright 1996 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that both the above copyright notice and this
- * permission notice appear in all copies, that both the above
- * copyright notice and this permission notice appear in all
- * supporting documentation, and that the name of M.I.T. not be used
- * in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  M.I.T. makes
- * no representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied
- * warranty.
- * 
- * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
- * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
- * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/share/examples/perfmon/perfmon.c,v 1.5 1999/08/28 00:19:26 peter Exp $
- * $DragonFly: src/share/examples/perfmon/perfmon.c,v 1.2 2003/06/17 04:36:57 dillon Exp $
- */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-
-#include <machine/cpu.h>
-#include <machine/perfmon.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <err.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>
-
-static int getnum(const char *, int, int);
-static void usage(const char *) __dead2;
-
-int
-main(int argc, char **argv)
-{
-	int c, fd, num;
-	int loops, i, sleeptime;
-	char *cmd;
-	struct pmc pmc;
-	struct pmc_tstamp then, now;
-	struct pmc_data value;
-	quad_t *buf;
-	double total;
-
-	pmc.pmc_num = 0;
-	pmc.pmc_event = 0;
-	pmc.pmc_unit = 0;
-	pmc.pmc_flags = 0;
-	pmc.pmc_mask = 0;
-	cmd = NULL;
-	loops = 50;
-	sleeptime = 0;
-
-	while ((c = getopt(argc, argv, "s:l:uoeiU:m:c:")) != -1) {
-		switch(c) {
-		case 'u':
-			pmc.pmc_flags |= PMCF_USR;
-			break;
-		case 'o':
-			pmc.pmc_flags |= PMCF_OS;
-			break;
-		case 'e':
-			pmc.pmc_flags |= PMCF_E;
-			break;
-		case 'i':
-			pmc.pmc_flags |= PMCF_INV;
-			break;
-		case 'U':
-			pmc.pmc_unit = getnum(optarg, 0, 256);
-			break;
-		case 'm':
-			pmc.pmc_mask = getnum(optarg, 0, 256);
-			break;
-		case 'l':
-			loops = getnum(optarg, 1, INT_MAX - 1);
-			break;
-		case 's':
-			sleeptime = getnum(optarg, 0, INT_MAX - 1);
-			break;
-		case 'c':
-			cmd = optarg;
-			break;
-		default:
-			usage(argv[0]);
-		}
-	}
-
-	if (argc - optind != 1)
-		usage(argv[0]);
-
-	pmc.pmc_event = getnum(argv[optind], 0, 255);
-
-	buf = malloc((loops + 1) * sizeof *buf);
-	if (!buf)
-		err(1, "malloc(%lu)", (unsigned long)(loops +1) * sizeof *buf);
-
-	fd = open(_PATH_PERFMON, O_RDWR, 0);
-	if (fd < 0)
-		err(1, "open: " _PATH_PERFMON);
-
-	if (ioctl(fd, PMIOSETUP, &pmc) < 0)
-		err(1, "ioctl(PMIOSETUP)");
-
-	if (ioctl(fd, PMIOTSTAMP, &then) < 0)
-		err(1, "ioctl(PMIOTSTAMP)");
-
-	num = 0;
-	if (ioctl(fd, PMIOSTART, &num) < 0)
-		err(1, "ioctl(PMIOSTART)");
-
-	value.pmcd_num = 0;
-	for (i = 0; i < loops; i++) {
-		if (ioctl(fd, PMIOSTOP, &num) < 0)
-			err(1, "ioctl(PMIOSTOP)");
-		if (ioctl(fd, PMIOREAD, &value) < 0)
-			err(1, "ioctl(PMIOREAD)");
-		buf[i] = value.pmcd_value;
-		if (ioctl(fd, PMIORESET, &value.pmcd_num) < 0)
-			err(1, "ioctl(PMIORESET)");
-		if (ioctl(fd, PMIOSTART, &num) < 0)
-			err(1, "ioctl(PMIOSTART)");
-		if (sleeptime)
-			sleep(sleeptime);
-		if (cmd)
-			system(cmd);
-	}
-
-	if (ioctl(fd, PMIOSTOP, &num) < 0)
-		err(1, "ioctl(PMIOSTOP)");
-	if (ioctl(fd, PMIOREAD, &value) < 0)
-		err(1, "ioctl(PMIOREAD)");
-	buf[i] = value.pmcd_value;
-	if (ioctl(fd, PMIOTSTAMP, &now) < 0)
-		err(1, "ioctl(PMIOTSTAMP)");
-
-	total = 0;
-	for (i = 1; i <= loops; i++) {
-		printf("%d: %qd\n", i, buf[i]);
-		total += buf[i];
-	}
-	printf("total: %f\nmean: %f\n", total, total / loops);
-
-	printf("clocks (at %d-MHz): %qd\n", now.pmct_rate,
-	       now.pmct_value - then.pmct_value);
-
-	return 0;
-}
-
-static int
-getnum(const char *buf, int min, int max)
-{
-	char *ep;
-	long l;
-
-	errno = 0;
-	l = strtol(buf, &ep, 0);
-	if (*buf && !*ep && !errno) {
-		if (l < min || l > max) {
-			errx(1, "`%s': must be between %d and %d", 
-			     buf, min, max);
-		}
-		return (int)l;
-	} else if(errno) {
-		errx(1, "`%s': must be between %ld and %ld", 
-		     LONG_MIN, LONG_MAX);
-	}
-	errx(1, "`%s': parameter must be an integer");
-}
-
-static void
-usage(const char *pname)
-{
-	fprintf(stderr, 
-	"usage: %s [-eiou] [-c command] [-l nloops] [-m mask] [-s sleeptime]\n"
-	"       [-U unit] counter\n",
-		pname);
-	exit(1);
-}
diff --git a/share/man/man9/ioctl.9 b/share/man/man9/ioctl.9
index 2e53a15..fdd66c6 100644
--- a/share/man/man9/ioctl.9
+++ b/share/man/man9/ioctl.9
@@ -88,8 +88,6 @@ This integer describes to which subsystem the ioctl applies.
 Here are some examples:
 .Pp
 .Bl -tag -width xxxxx -compact
-.It '5'
-.Xr perfmon 4
 .It '8'
 .Xr aac 4
 .It 'a'
diff --git a/sys/config/LINT64 b/sys/config/LINT64
index 02373e6..2b41e16 100644
--- a/sys/config/LINT64
+++ b/sys/config/LINT64
@@ -207,13 +207,6 @@ options 	INVARIANTS
 options 	DIAGNOSTIC
 
 #
-# PERFMON causes the driver for Pentium/Pentium Pro performance counters
-# to be compiled.  See perfmon(4) for more information.
-#
-options 	PERFMON
-
-
-#
 # This option let some drivers co-exist that can't co-exist in a running
 # system.  This is used to be able to compile all kernel code in one go for
 # quality assurance purposes (like this file, which the option takes it name
diff --git a/sys/platform/pc64/conf/options b/sys/platform/pc64/conf/options
index 6c66a92..10c911b 100644
--- a/sys/platform/pc64/conf/options
+++ b/sys/platform/pc64/conf/options
@@ -3,7 +3,6 @@ PMAP_SHPGPERPROC	opt_pmap.h
 PPC_PROBE_CHIPSET	opt_ppc.h
 PPC_DEBUG		opt_ppc.h
 MAXMEM
-PERFMON			opt_perfmon.h
 AUTO_EOI_1		opt_auto_eoi.h
 AUTO_EOI_2		opt_auto_eoi.h
 CONSPEED		opt_comconsole.h
diff --git a/sys/platform/pc64/isa/prof_machdep.c b/sys/platform/pc64/isa/prof_machdep.c
index f43905a..19f5e01 100644
--- a/sys/platform/pc64/isa/prof_machdep.c
+++ b/sys/platform/pc64/isa/prof_machdep.c
@@ -29,7 +29,6 @@
 
 #ifdef GUPROF
 #include "opt_i586_guprof.h"
-#include "opt_perfmon.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -38,7 +37,6 @@
 #include <sys/sysctl.h>
 
 #include <machine/clock.h>
-#include <machine/perfmon.h>
 #include <machine/profile.h>
 #undef MCOUNT
 #endif
@@ -216,39 +214,13 @@ sysctl_machdep_cputime_clock(SYSCTL_HANDLER_ARGS)
 {
 	int clock;
 	int error;
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
-	int event;
-	struct pmc pmc;
-#endif
 
 	clock = cputime_clock;
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
-	if (clock == CPUTIME_CLOCK_I586_PMC) {
-		pmc.pmc_val = cputime_clock_pmc_conf;
-		clock += pmc.pmc_event;
-	}
-#endif
 	error = sysctl_handle_opaque(oidp, &clock, sizeof clock, req);
 	if (error == 0 && req->newptr != NULL) {
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
-		if (clock >= CPUTIME_CLOCK_I586_PMC) {
-			event = clock - CPUTIME_CLOCK_I586_PMC;
-			if (event >= 256)
-				return (EINVAL);
-			pmc.pmc_num = 0;
-			pmc.pmc_event = event;
-			pmc.pmc_unit = 0;
-			pmc.pmc_flags = PMCF_E | PMCF_OS | PMCF_USR;
-			pmc.pmc_mask = 0;
-			cputime_clock_pmc_conf = pmc.pmc_val;
-			cputime_clock = CPUTIME_CLOCK_I586_PMC;
-		} else
-#endif
-		{
-			if (clock < 0 || clock >= CPUTIME_CLOCK_I586_PMC)
-				return (EINVAL);
-			cputime_clock = clock;
-		}
+		if (clock < 0 || clock >= CPUTIME_CLOCK_I586_PMC)
+			return (EINVAL);
+		cputime_clock = clock;
 	}
 	return (error);
 }
@@ -274,13 +246,6 @@ startguprof(struct gmonparam *gp)
 void
 stopguprof(struct gmonparam *gp)
 {
-#if defined(PERFMON) && defined(I586_PMC_GUPROF)
-	if (cputime_clock_pmc_init) {
-		*gp = saved_gmp;
-		perfmon_fini(0);
-		cputime_clock_pmc_init = FALSE;
-	}
-#endif
 }
 
 #else /* !GUPROF */
diff --git a/sys/platform/pc64/x86_64/machdep.c b/sys/platform/pc64/x86_64/machdep.c
index 087cb8c..69b407b 100644
--- a/sys/platform/pc64/x86_64/machdep.c
+++ b/sys/platform/pc64/x86_64/machdep.c
@@ -108,9 +108,6 @@
 #include <machine/pcb_ext.h>		/* pcb.h included via sys/user.h */
 #include <machine/globaldata.h>		/* CPU_prvspace */
 #include <machine/smp.h>
-#ifdef PERFMON
-#include <machine/perfmon.h>
-#endif
 #include <machine/cputypes.h>
 #include <machine/intr_machdep.h>
 #include <machine/framebuffer.h>
@@ -333,9 +330,6 @@ cpu_startup(void *dummy)
 	startrtclock();
 	printcpuinfo();
 	panicifcpuunsupported();
-#ifdef PERFMON
-	perfmon_init();
-#endif
 	kprintf("real memory  = %ju (%ju MB)\n",
 		(intmax_t)Realmem,
 		(intmax_t)Realmem / 1024 / 1024);
diff --git a/sys/platform/vkernel64/x86_64/cpu_regs.c b/sys/platform/vkernel64/x86_64/cpu_regs.c
index 882ce44..f91c272 100644
--- a/sys/platform/vkernel64/x86_64/cpu_regs.c
+++ b/sys/platform/vkernel64/x86_64/cpu_regs.c
@@ -91,9 +91,6 @@
 #include <machine/pcb_ext.h>		/* pcb.h included via sys/user.h */
 #include <machine/globaldata.h>		/* CPU_prvspace */
 #include <machine/smp.h>
-#ifdef PERFMON
-#include <machine/perfmon.h>
-#endif
 #include <machine/cputypes.h>
 
 #include <bus/isa/rtc.h>
-- 
2.9.2

