Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
VERSION=1.31pre

CFLAGS = -DVERSION="$(VERSION)"
OS=$(shell uname)

CFLAGS := -DVERSION="$(VERSION)"

CFLAGS += -Wall -W -g -O2 -D_FORTIFY_SOURCE=2 -I. -Iinclude
ifneq ($(SYSROOT),)
Expand All @@ -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)
Expand All @@ -35,8 +37,8 @@ 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 += $(shell pkg-config --libs libpci)
LDFLAGS := -Wl,-z,relro,-z,now
LDFLAGS += $(shell pkg-config --libs libpci 2>/dev/null)

ifeq ($(CC),"")
CC = gcc
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand Down
2 changes: 0 additions & 2 deletions cpuid-freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions cpuid-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
2 changes: 0 additions & 2 deletions cpuid-netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 19 additions & 44 deletions cpuid-solaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Solaris routines for retrieving cpuid registers.
* Originally submitted by John Levon <levon@movementarian.org>
*
* Copyright 2018 Joyent, Inc.
*/

#ifdef __sun__
Expand All @@ -18,10 +20,19 @@
#include <unistd.h>
#include <errno.h>
#include <x86info.h>
#include <sys/processor.h>
#include <sys/procset.h>


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,
Expand All @@ -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__ */
2 changes: 2 additions & 0 deletions include/x86info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 21 additions & 0 deletions rdmsr-solaris.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the terms of the GNU GPL License version 2.
*
* Copyright 2018 Joyent, Inc.
*/

#if defined(__sun)

#include <x86info.h>

/*
* 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 */
4 changes: 4 additions & 0 deletions vendors/amd/dumppsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,3 +133,5 @@ void dump_PSB(struct cpudata *cpu, unsigned int maxfid, unsigned int startvid)
}
return;
}

#endif /* !__sun */
2 changes: 2 additions & 0 deletions vendors/amd/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down