From fb1d5f052346e7e425adff21f205b4008cb34328 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 12 Jan 2018 17:28:18 +0000 Subject: [PATCH 1/3] Use simple variable expansion to avoid re-running pkg-config every time. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 97ae00e..b7d2f1e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION=1.31pre -CFLAGS = -DVERSION="$(VERSION)" +CFLAGS := -DVERSION="$(VERSION)" CFLAGS += -Wall -W -g -O2 -D_FORTIFY_SOURCE=2 -I. -Iinclude ifneq ($(SYSROOT),) @@ -35,7 +35,7 @@ CPP_MINOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f2) DEVEL := $(shell grep VERSION Makefile | head -n1 | grep pre | wc -l) CFLAGS += $(shell if [ $(CPP_MAJOR) -eq 4 -a $(CPP_MINOR) -ge 8 -a $(DEVEL) -eq 1 ] ; then echo "-Werror"; else echo ""; fi) -LDFLAGS = -Wl,-z,relro,-z,now +LDFLAGS := -Wl,-z,relro,-z,now LDFLAGS += $(shell pkg-config --libs libpci) ifeq ($(CC),"") From fea9fdb57e9770a33686e8204e64ad9dc364e545 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 12 Jan 2018 17:37:50 +0000 Subject: [PATCH 2/3] Only define NATIVE_CPUID_FAILED_MSG once. --- cpuid-freebsd.c | 2 -- cpuid-linux.c | 2 -- cpuid-netbsd.c | 2 -- include/x86info.h | 2 ++ 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cpuid-freebsd.c b/cpuid-freebsd.c index 6b6b906..dc0f360 100644 --- a/cpuid-freebsd.c +++ b/cpuid-freebsd.c @@ -28,8 +28,6 @@ void bind_cpu(unsigned int cpunr) sizeof(mask), &mask); } -static const char *NATIVE_CPUID_FAILED_MSG = "WARNING: Native cpuid failed\n"; - void cpuid(unsigned int CPU_number, unsigned long long idx, unsigned int *eax, unsigned int *ebx, diff --git a/cpuid-linux.c b/cpuid-linux.c index 72527bd..20e4a4f 100644 --- a/cpuid-linux.c +++ b/cpuid-linux.c @@ -50,8 +50,6 @@ void bind_cpu(unsigned int cpunr) return; } -static const char *NATIVE_CPUID_FAILED_MSG = "WARNING: Native cpuid failed\n"; - /* Kernel CPUID driver's minimum supported read size * (see linux/arch/i386/kernel/cpuid.c) */ diff --git a/cpuid-netbsd.c b/cpuid-netbsd.c index 716dc92..57789bb 100644 --- a/cpuid-netbsd.c +++ b/cpuid-netbsd.c @@ -29,8 +29,6 @@ void bind_cpu(unsigned int cpunr) cpuset_destroy(cpuset); } -static const char *NATIVE_CPUID_FAILED_MSG = "WARNING: Native cpuid failed\n"; - void cpuid(unsigned int CPU_number, unsigned long long idx, unsigned int *eax, unsigned int *ebx, diff --git a/include/x86info.h b/include/x86info.h index 8a95789..2c3158b 100644 --- a/include/x86info.h +++ b/include/x86info.h @@ -211,3 +211,5 @@ extern unsigned int verbose; #define __stringify_1(x...) #x #define __stringify(x...) __stringify_1(x) + +#define NATIVE_CPUID_FAILED_MSG "WARNING: Native cpuid failed\n" From 54b0696405ef5a4dd8bbcee71cce07d18331a1a8 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 12 Jan 2018 17:40:29 +0000 Subject: [PATCH 3/3] Make Solaris/Illumos work again - no MSR support, and don't try to use cpuid driver any more. --- Makefile | 12 ++++++-- apic.c | 7 +++++ cpuid-solaris.c | 63 +++++++++++++----------------------------- rdmsr-solaris.c | 21 ++++++++++++++ vendors/amd/dumppsb.c | 4 +++ vendors/amd/identify.c | 2 ++ 6 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 rdmsr-solaris.c diff --git a/Makefile b/Makefile index b7d2f1e..6a2f720 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ VERSION=1.31pre +OS=$(shell uname) + CFLAGS := -DVERSION="$(VERSION)" CFLAGS += -Wall -W -g -O2 -D_FORTIFY_SOURCE=2 -I. -Iinclude @@ -18,7 +20,7 @@ CFLAGS += -Wstrict-prototypes -Wmissing-prototypes CFLAGS += -Wswitch-enum CFLAGS += -Wundef CFLAGS += -Wwrite-strings -CFLAGS += $(shell pkg-config --cflags libpci) +CFLAGS += $(shell pkg-config --cflags libpci 2>/dev/null) # gcc specific ifneq ($(shell $(CC) -v 2>&1 | grep -c "clang"), 1) @@ -36,7 +38,7 @@ DEVEL := $(shell grep VERSION Makefile | head -n1 | grep pre | wc -l) CFLAGS += $(shell if [ $(CPP_MAJOR) -eq 4 -a $(CPP_MINOR) -ge 8 -a $(DEVEL) -eq 1 ] ; then echo "-Werror"; else echo ""; fi) LDFLAGS := -Wl,-z,relro,-z,now -LDFLAGS += $(shell pkg-config --libs libpci) +LDFLAGS += $(shell pkg-config --libs libpci 2>/dev/null) ifeq ($(CC),"") CC = gcc @@ -67,6 +69,12 @@ X86INFO_SRC = \ X86INFO_OBJS = $(sort $(patsubst %.c,%.o,$(wildcard *.c))) \ $(sort $(patsubst %.c,%.o,$(wildcard vendors/*/*.c))) +ifeq ($(OS),SunOS) + X86INFO_OBJS := $(filter-out vendors/amd/powernow.o,$(X86INFO_OBJS)) + LDFLAGS = + LIBPCI = +endif + x86info: $(X86INFO_OBJS) $(X86INFO_HEADERS) $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o x86info $(X86INFO_OBJS) \ $(LIBPCI) diff --git a/apic.c b/apic.c index cf78106..22b0684 100644 --- a/apic.c +++ b/apic.c @@ -105,6 +105,13 @@ void dump_apics(struct cpudata *cpu) if (!(cpu->flags_edx & (X86_FEATURE_APIC))) return; + /** + * No MSR read support on Illumos. + **/ +#ifdef __sun + return; +#endif + /** * Verify if apic is enable **/ diff --git a/cpuid-solaris.c b/cpuid-solaris.c index a8ec2d0..23a5ebd 100644 --- a/cpuid-solaris.c +++ b/cpuid-solaris.c @@ -3,6 +3,8 @@ * * Solaris routines for retrieving cpuid registers. * Originally submitted by John Levon + * + * Copyright 2018 Joyent, Inc. */ #ifdef __sun__ @@ -18,10 +20,19 @@ #include #include #include +#include +#include + -void bind_cpu(int cpunr) +/* + * This can easily fail if we don't have permission to bind; drive on. + */ +void bind_cpu(unsigned int cpunr) { - //FIXME + if (processor_bind(P_PID, P_MYID, cpunr, NULL) != 0) { + fprintf(stderr, "warning: failed to bind to CPU%u: %s\n", + cpunr, strerror(errno)); + } } void cpuid(unsigned int CPU_number, unsigned long long idx, @@ -30,53 +41,17 @@ void cpuid(unsigned int CPU_number, unsigned long long idx, unsigned int *ecx, unsigned int *edx) { - static int nodriver = 0; - char cpuname[20]; - unsigned char buffer[CPUID_CHUNK_SIZE]; - unsigned int *ptr = (unsigned int *)buffer; - int fh; - if (eax != NULL) { *eax = (unsigned int) idx; if (*eax == 4) *ecx = idx >> 32; } - if (nodriver == 1) { - if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx)) - printf("%s", NATIVE_CPUID_FAILED_MSG); - return; - } - - memset(cpuname, 0, sizeof(cpuname)); - /* Solaris doesn't (yet) have per-CPU interface */ - (void)snprintf(cpuname, sizeof(cpuname), "/dev/cpu/self/cpuid"); - - fh = open(cpuname, O_RDONLY); - if (fh != -1) { - if (lseek64(fh, (off64_t)idx, SEEK_CUR) < 0) { - printf("cpuid seek error: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - - if (read(fh, &buffer[0], CPUID_CHUNK_SIZE) == -1) { - perror(cpuname); - exit(EXIT_FAILURE); - } - if (eax!=0) *eax = *ptr; - if (ebx!=0) *ebx = *(++ptr); - if (ecx!=0) *ecx = *(++ptr); - if (edx!=0) *edx = *(++ptr); - if (close(fh) == -1) { - perror("close"); - exit(EXIT_FAILURE); - } - } else { - /* Something went wrong, just do UP and hope for the best. */ - nodriver = 1; - if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx)) - printf("%s", NATIVE_CPUID_FAILED_MSG); - return; - } + /* + * Solaris/Illumos do have /dev/cpu/self/cpuid, but caps idx at + * UINT_MAX, so just always use native. + */ + if (native_cpuid(CPU_number, idx, eax, ebx, ecx, edx)) + printf("%s", NATIVE_CPUID_FAILED_MSG); } #endif /* __sun__ */ diff --git a/rdmsr-solaris.c b/rdmsr-solaris.c new file mode 100644 index 0000000..c47e852 --- /dev/null +++ b/rdmsr-solaris.c @@ -0,0 +1,21 @@ +/* + * Licensed under the terms of the GNU GPL License version 2. + * + * Copyright 2018 Joyent, Inc. + */ + +#if defined(__sun) + +#include + +/* + * No userspace MSR access under Solaris or Illumos. + */ +int read_msr(__attribute__((__unused__))int cpu, + __attribute__((__unused__))unsigned int idx, + __attribute__((__unused__))unsigned long long *val) +{ + return 0; +} + +#endif /* __sun */ diff --git a/vendors/amd/dumppsb.c b/vendors/amd/dumppsb.c index bf327a9..1c378fa 100644 --- a/vendors/amd/dumppsb.c +++ b/vendors/amd/dumppsb.c @@ -37,6 +37,8 @@ struct pst_s { }; +#if !defined(__sun) + void dump_PSB(struct cpudata *cpu, unsigned int maxfid, unsigned int startvid) { int fd, i; @@ -131,3 +133,5 @@ void dump_PSB(struct cpudata *cpu, unsigned int maxfid, unsigned int startvid) } return; } + +#endif /* !__sun */ diff --git a/vendors/amd/identify.c b/vendors/amd/identify.c index 68fc21f..fc1dcbf 100644 --- a/vendors/amd/identify.c +++ b/vendors/amd/identify.c @@ -861,8 +861,10 @@ void display_amd_info(struct cpudata *cpu) if (show_microcode && family(cpu) >= 0xf) show_patch_level(cpu); +#if !defined(__sun) if (show_pm) decode_powernow(cpu); +#endif if (show_bugs) show_amd_bugs(cpu);