Skip to content

Commit

Permalink
arch: add cpu probing
Browse files Browse the repository at this point in the history
For now, just a check to see if we have SSE4.2.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Aug 22, 2013
1 parent 841a695 commit f008ac4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ crush_files = \
# this list ommits the ceph_ver.c file
libcommon_files = \
./ceph_ver.c \
arch/probe.cc \
arch/intel.c \
auth/AuthAuthorizeHandler.cc \
auth/AuthClientHandler.cc \
auth/AuthSessionHandler.cc \
Expand Down Expand Up @@ -1746,6 +1748,8 @@ python_PYTHON = pybind/rados.py \
# that autotools doesn't magically identify.
noinst_HEADERS = \
rados_sync.h \
arch/probe.h \
arch/intel.h \
auth/cephx/CephxAuthorizeHandler.h\
auth/cephx/CephxKeyServer.h\
auth/cephx/CephxProtocol.h\
Expand Down
46 changes: 46 additions & 0 deletions src/arch/intel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "arch/probe.h"

/* flags we export */
int ceph_arch_intel_sse42 = 0;


/* this probably isn't specific enough for x86_64? fix me someday */
#ifdef __LP64__

/* intel cpu? */
static void do_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
unsigned int *edx)
{
int id = *eax;

asm("movl %4, %%eax;"
"cpuid;"
"movl %%eax, %0;"
"movl %%ebx, %1;"
"movl %%ecx, %2;"
"movl %%edx, %3;"
: "=r" (*eax), "=r" (*ebx), "=r" (*ecx), "=r" (*edx)
: "r" (id)
: "eax", "ebx", "ecx", "edx");
}

int ceph_arch_intel_probe(void)
{
/* i know how to check this on x86_64... */
unsigned int eax = 1, ebx, ecx, edx;
do_cpuid(&eax, &ebx, &ecx, &edx);
if ((ecx & (1 << 20)) != 0) {
ceph_arch_intel_sse42 = 1;
}
return 0;
}

#else // __LP64__

int ceph_arch_intel_probe(void)
{
/* no features */
return 0;
}

#endif // __LP64__
16 changes: 16 additions & 0 deletions src/arch/intel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef CEPH_ARCH_INTEL_H
#define CEPH_ARCH_INTEL_H

#ifdef __cplusplus
extern "C" {
#endif

extern int ceph_arch_intel_sse42; /* true if we have sse 4.2 features */

extern int ceph_arch_intel_probe(void);

#ifdef __cplusplus
}
#endif

#endif
20 changes: 20 additions & 0 deletions src/arch/probe.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "arch/probe.h"

#include "arch/intel.h"

int ceph_arch_probe(void)
{
if (ceph_arch_probed)
return 1;

ceph_arch_intel_probe();

ceph_arch_probed = 1;
return 1;
}

// do this once using the magic of c++.
int ceph_arch_probed = ceph_arch_probe();
16 changes: 16 additions & 0 deletions src/arch/probe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef CEPH_ARCH_PROBE_H
#define CEPH_ARCH_PROBE_H

#ifdef __cplusplus
extern "C" {
#endif

extern int ceph_arch_probed; /* non-zero if we've probed features */

extern int ceph_arch_probe(void);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit f008ac4

Please sign in to comment.