ptdump, ptxed, pttc: drop --cpu auto

The sample tools offer an option

    -- cpu auto

to determine the family/model/stepping of the processor they are running on,
i.e. on which trace is decoded.

This may lead to confusion as decode requires the family/model/stepping of
the processor on which trace was recorded.

When recording with Linux perf, for example, this information is stored in
the perf.data file, from which script/perf-get-opts.bash extracts it.

Drop the option to avoid confusion.

Change-Id: I2c572a7e540a7577faeeff80408d8fb5d04ef950
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
diff --git a/libipt/internal/include/pt_cpu.h b/libipt/internal/include/pt_cpu.h
index b106a3a..1590fa3 100644
--- a/libipt/internal/include/pt_cpu.h
+++ b/libipt/internal/include/pt_cpu.h
@@ -41,14 +41,4 @@
  */
 extern int pt_cpu_parse(struct pt_cpu *cpu, const char *s);
 
-/* Get the cpu we're running on.
- *
- * Reads the family/model/stepping of the processor on which this function
- * is executed and stores the value in @cpu.
- *
- * Returns zero on success, a negative error code otherwise.
- * Returns -pte_invalid if @cpu is NULL.
- */
-extern int pt_cpu_read(struct pt_cpu *cpu);
-
 #endif /* PT_CPU_H */
diff --git a/libipt/internal/include/pt_cpuid.h b/libipt/internal/include/pt_cpuid.h
deleted file mode 100644
index 8b331fb..0000000
--- a/libipt/internal/include/pt_cpuid.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2013-2021, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of Intel Corporation nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
- */
-
-#ifndef PT_CPUID_H
-#define PT_CPUID_H
-
-#include <inttypes.h>
-
-/* Execute cpuid with @leaf set in the eax register.
- * The result is stored in @eax, @ebx, @ecx and @edx.
- */
-extern void pt_cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,
-		     uint32_t *ecx, uint32_t *edx);
-
-#endif /* PT_CPUID_H */
diff --git a/libipt/src/posix/pt_cpuid.c b/libipt/src/posix/pt_cpuid.c
deleted file mode 100644
index 6456e61..0000000
--- a/libipt/src/posix/pt_cpuid.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2013-2021, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of Intel Corporation nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
- */
-
-#include "pt_cpuid.h"
-
-#include <cpuid.h>
-
-extern void pt_cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,
-		     uint32_t *ecx, uint32_t *edx)
-{
-	__get_cpuid(leaf, eax, ebx, ecx, edx);
-}
diff --git a/libipt/src/pt_cpu.c b/libipt/src/pt_cpu.c
index ea44430..543b8dc 100644
--- a/libipt/src/pt_cpu.c
+++ b/libipt/src/pt_cpu.c
@@ -27,7 +27,6 @@
  */
 
 #include "pt_cpu.h"
-#include "pt_cpuid.h"
 
 #include "intel-pt.h"
 
@@ -35,60 +34,6 @@
 #include <stdlib.h>
 
 
-static const char * const cpu_vendors[] = {
-	"",
-	"GenuineIntel"
-};
-
-enum {
-	pt_cpuid_vendor_size = 12
-};
-
-union cpu_vendor {
-	/* The raw data returned from cpuid. */
-	struct {
-		uint32_t ebx;
-		uint32_t edx;
-		uint32_t ecx;
-	} cpuid;
-
-	/* The resulting vendor string. */
-	char vendor_string[pt_cpuid_vendor_size];
-};
-
-static enum pt_cpu_vendor cpu_vendor(void)
-{
-	union cpu_vendor vendor;
-	uint32_t eax;
-	size_t i;
-
-	memset(&vendor, 0, sizeof(vendor));
-	eax = 0;
-
-	pt_cpuid(0u, &eax, &vendor.cpuid.ebx, &vendor.cpuid.ecx,
-		 &vendor.cpuid.edx);
-
-	for (i = 0; i < sizeof(cpu_vendors)/sizeof(*cpu_vendors); i++)
-		if (strncmp(vendor.vendor_string,
-			    cpu_vendors[i], pt_cpuid_vendor_size) == 0)
-			return (enum pt_cpu_vendor) i;
-
-	return pcv_unknown;
-}
-
-static uint32_t cpu_info(void)
-{
-	uint32_t eax, ebx, ecx, edx;
-
-	eax = 0;
-	ebx = 0;
-	ecx = 0;
-	edx = 0;
-	pt_cpuid(1u, &eax, &ebx, &ecx, &edx);
-
-	return eax;
-}
-
 int pt_cpu_parse(struct pt_cpu *cpu, const char *s)
 {
 	const char sep = '/';
@@ -137,28 +82,3 @@
 
 	return 0;
 }
-
-int pt_cpu_read(struct pt_cpu *cpu)
-{
-	uint32_t info;
-	uint16_t family;
-
-	if (!cpu)
-		return -pte_invalid;
-
-	cpu->vendor = cpu_vendor();
-
-	info = cpu_info();
-
-	cpu->family = family = (info>>8) & 0xf;
-	if (family == 0xf)
-		cpu->family += (info>>20) & 0xf;
-
-	cpu->model = (info>>4) & 0xf;
-	if (family == 0x6 || family == 0xf)
-		cpu->model += (info>>12) & 0xf0;
-
-	cpu->stepping = (info>>0) & 0xf;
-
-	return 0;
-}
diff --git a/libipt/src/windows/pt_cpuid.c b/libipt/src/windows/pt_cpuid.c
deleted file mode 100644
index f34ab1f..0000000
--- a/libipt/src/windows/pt_cpuid.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2013-2021, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of Intel Corporation nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
- */
-
-#include "pt_cpuid.h"
-
-#include <intrin.h>
-
-extern void pt_cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,
-		     uint32_t *ecx, uint32_t *edx)
-{
-	int cpu_info[4];
-
-	__cpuid(cpu_info, leaf);
-	*eax = cpu_info[0];
-	*ebx = cpu_info[1];
-	*ecx = cpu_info[2];
-	*edx = cpu_info[3];
-}
diff --git a/libipt/test/src/ptunit-cpu.c b/libipt/test/src/ptunit-cpu.c
index 3b95c9c..bec5362 100644
--- a/libipt/test/src/ptunit-cpu.c
+++ b/libipt/test/src/ptunit-cpu.c
@@ -29,24 +29,12 @@
 #include "ptunit.h"
 
 #include "pt_cpu.h"
-#include "pt_cpuid.h"
 
 #include "intel-pt.h"
 
 #include <stdlib.h>
 
 
-void pt_cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx,
-	      uint32_t *edx)
-{
-	(void) leaf;
-	(void) eax;
-	(void) ebx;
-	(void) ecx;
-	(void) edx;
-}
-
-
 static struct ptunit_result cpu_valid(void)
 {
 	struct pt_cpu cpu;
diff --git a/ptdump/CMakeLists.txt b/ptdump/CMakeLists.txt
index 199e7d8..563a763 100644
--- a/ptdump/CMakeLists.txt
+++ b/ptdump/CMakeLists.txt
@@ -36,14 +36,6 @@
   ../libipt/src/pt_time.c
 )
 
-if (CMAKE_HOST_UNIX)
-  set(PTDUMP_FILES ${PTDUMP_FILES} ../libipt/src/posix/pt_cpuid.c)
-endif (CMAKE_HOST_UNIX)
-
-if (CMAKE_HOST_WIN32)
-  set(PTDUMP_FILES ${PTDUMP_FILES} ../libipt/src/windows/pt_cpuid.c)
-endif (CMAKE_HOST_WIN32)
-
 add_executable(ptdump
   ${PTDUMP_FILES}
 )
diff --git a/ptdump/src/ptdump.c b/ptdump/src/ptdump.c
index 2cc362a..f58b3ba 100644
--- a/ptdump/src/ptdump.c
+++ b/ptdump/src/ptdump.c
@@ -242,9 +242,8 @@
 	printf("  --pevent:vdso-ia32 <file>   ignored.\n");
 #endif /* defined(FEATURE_PEVENT) */
 #endif /* defined(FEATURE_SIDEBAND) */
-	printf("  --cpu none|auto|f/m[/s]   set cpu to the given value and decode according to:\n");
+	printf("  --cpu none|f/m[/s]        set cpu to the given value and decode according to:\n");
 	printf("                              none     spec (default)\n");
-	printf("                              auto     current cpu\n");
 	printf("                              f/m[/s]  family/model[/stepping]\n");
 	printf("  --mtc-freq <n>            set the MTC frequency (IA32_RTIT_CTL[17:14]) to <n>.\n");
 	printf("  --nom-freq <n>            set the nominal frequency (MSR_PLATFORM_INFO[15:8]) to <n>.\n");
@@ -1836,18 +1835,6 @@
 				return -1;
 			}
 
-			if (strcmp(arg, "auto") == 0) {
-				errcode = pt_cpu_read(&config->cpu);
-				if (errcode < 0) {
-					fprintf(stderr,
-						"%s: error reading cpu: %s.\n",
-						argv[0],
-						pt_errstr(pt_errcode(errcode)));
-					return -1;
-				}
-				continue;
-			}
-
 			if (strcmp(arg, "none") == 0) {
 				memset(&config->cpu, 0, sizeof(config->cpu));
 				continue;
diff --git a/pttc/CMakeLists.txt b/pttc/CMakeLists.txt
index 4592250..78f4a42 100644
--- a/pttc/CMakeLists.txt
+++ b/pttc/CMakeLists.txt
@@ -43,7 +43,6 @@
   set(PTTC_FILES
     ${PTTC_FILES}
     src/posix/util.c
-    ../libipt/src/posix/pt_cpuid.c
   )
 endif (CMAKE_HOST_UNIX)
 
@@ -51,7 +50,6 @@
   set(PTTC_FILES
     ${PTTC_FILES}
     src/windows/util.c
-    ../libipt/src/windows/pt_cpuid.c
   )
 endif (CMAKE_HOST_WIN32)
 
diff --git a/pttc/src/main.c b/pttc/src/main.c
index 54db676..4cc1e28 100644
--- a/pttc/src/main.c
+++ b/pttc/src/main.c
@@ -42,9 +42,8 @@
 	       "options:\n"
 	       "  --help|-h                this text.\n"
 	       "  --version                display version information and exit.\n"
-	       "  --cpu none|auto|f/m[/s]  set cpu to the given value and encode according to:\n"
+	       "  --cpu none|f/m[/s]       set cpu to the given value and encode according to:\n"
 	       "                             none     spec (default)\n"
-	       "                             auto     current cpu\n"
 	       "                             f/m[/s]  family/model[/stepping]\n"
 	       "  <pttfile>                the annotated yasm input file.\n",
 	       prog);
@@ -75,18 +74,6 @@
 		if (strcmp(arg, "--cpu") == 0) {
 			arg = argv[i++];
 
-			if (strcmp(arg, "auto") == 0) {
-				errcode = pt_cpu_read(&options.cpu);
-				if (errcode < 0) {
-					fprintf(stderr,
-						"%s: error reading cpu: %s.\n",
-						prog,
-						pt_errstr(pt_errcode(errcode)));
-					return 1;
-				}
-				continue;
-			}
-
 			if (strcmp(arg, "none") == 0) {
 				memset(&options.cpu, 0, sizeof(options.cpu));
 				continue;
diff --git a/ptxed/CMakeLists.txt b/ptxed/CMakeLists.txt
index 1020bfc..10499f0 100644
--- a/ptxed/CMakeLists.txt
+++ b/ptxed/CMakeLists.txt
@@ -45,14 +45,6 @@
   ../libipt/src/pt_cpu.c
 )
 
-if (CMAKE_HOST_UNIX)
-  set(PTXED_FILES ${PTXED_FILES} ../libipt/src/posix/pt_cpuid.c)
-endif (CMAKE_HOST_UNIX)
-
-if (CMAKE_HOST_WIN32)
-  set(PTXED_FILES ${PTXED_FILES} ../libipt/src/windows/pt_cpuid.c)
-endif (CMAKE_HOST_WIN32)
-
 if (FEATURE_ELF)
   set(PTXED_FILES ${PTXED_FILES} src/load_elf.c)
 endif (FEATURE_ELF)
diff --git a/ptxed/src/ptxed.c b/ptxed/src/ptxed.c
index cb893db..2aadaae 100644
--- a/ptxed/src/ptxed.c
+++ b/ptxed/src/ptxed.c
@@ -294,9 +294,8 @@
 #endif /* defined(FEATURE_ELF) */
 	printf("  --raw <file>[:<from>[-<to>]]:<base>  load a raw binary from <file> at address <base>.\n");
 	printf("                                       an optional offset or range can be given.\n");
-	printf("  --cpu none|auto|f/m[/s]              set cpu to the given value and decode according to:\n");
+	printf("  --cpu none|f/m[/s]                   set cpu to the given value and decode according to:\n");
 	printf("                                         none     spec (default)\n");
-	printf("                                         auto     current cpu\n");
 	printf("                                         f/m[/s]  family/model[/stepping]\n");
 	printf("  --mtc-freq <n>                       set the MTC frequency (IA32_RTIT_CTL[17:14]) to <n>.\n");
 	printf("  --nom-freq <n>                       set the nominal frequency (MSR_PLATFORM_INFO[15:8]) to <n>.\n");
@@ -2745,18 +2744,6 @@
 			}
 			arg = argv[i++];
 
-			if (strcmp(arg, "auto") == 0) {
-				errcode = pt_cpu_read(&config.cpu);
-				if (errcode < 0) {
-					fprintf(stderr,
-						"%s: error reading cpu: %s.\n",
-						prog,
-						pt_errstr(pt_errcode(errcode)));
-					return 1;
-				}
-				continue;
-			}
-
 			if (strcmp(arg, "none") == 0) {
 				memset(&config.cpu, 0, sizeof(config.cpu));
 				continue;