Commit fcb9a9bf authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

cpu: Make cpu routines being per-acrh

They are really depends on CPU we're running on.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f50f7d01
...@@ -39,7 +39,6 @@ obj-y += pstree.o ...@@ -39,7 +39,6 @@ obj-y += pstree.o
obj-y += protobuf.o obj-y += protobuf.o
obj-y += tty.o obj-y += tty.o
obj-y += cr-exec.o obj-y += cr-exec.o
obj-y += cpu.o
obj-y += file-lock.o obj-y += file-lock.o
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
......
...@@ -5,6 +5,7 @@ SYS-ASM := syscalls.S ...@@ -5,6 +5,7 @@ SYS-ASM := syscalls.S
syscalls-asm-y += $(SYS-ASM:.S=).o syscalls-asm-y += $(SYS-ASM:.S=).o
crtools-obj-y += crtools.o crtools-obj-y += crtools.o
crtools-obj-y += cpu.o
SYS-DEF := syscall.def SYS-DEF := syscall.def
SYS-ASM-COMMON := syscall-common.S SYS-ASM-COMMON := syscall-common.S
......
#undef LOG_PREFIX
#define LOG_PREFIX "cpu: "
void cpu_set_feature(unsigned int feature)
{
}
bool cpu_has_feature(unsigned int feature)
{
return false;
}
int cpu_init(void)
{
return 0;
}
...@@ -5,6 +5,7 @@ SYS-ASM := syscalls.S ...@@ -5,6 +5,7 @@ SYS-ASM := syscalls.S
syscalls-asm-y += $(SYS-ASM:.S=).o syscalls-asm-y += $(SYS-ASM:.S=).o
crtools-obj-y += crtools.o crtools-obj-y += crtools.o
crtools-obj-y += cpu.o
SYS-DEF := syscall-x86-64.def SYS-DEF := syscall-x86-64.def
SYS-ASM-COMMON := syscall-common-x86-64.S SYS-ASM-COMMON := syscall-common-x86-64.S
......
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
#include <sys/types.h> #include <sys/types.h>
#include "compiler.h"
#include "asm/types.h"
#include "log.h"
#include "util.h"
#include "asm/bitops.h" #include "asm/bitops.h"
#include "asm/types.h"
#include "asm/cpu.h"
#include "compiler.h"
#include "proc_parse.h" #include "proc_parse.h"
#include "util.h"
#include "log.h"
#include "fpu.h" #include "fpu.h"
#include "cpu.h" #include "cpu.h"
...@@ -42,9 +44,20 @@ bool cpu_has_feature(unsigned int feature) ...@@ -42,9 +44,20 @@ bool cpu_has_feature(unsigned int feature)
return false; return false;
} }
static int proc_cpuinfo_match(char *tok)
{
if (!strcmp(tok, x86_cap_flags[X86_FEATURE_FXSR]))
cpu_set_feature(X86_FEATURE_FXSR);
else if (!strcmp(tok, x86_cap_flags[X86_FEATURE_XSAVE]))
cpu_set_feature(X86_FEATURE_XSAVE);
else if (!strcmp(tok, x86_cap_flags[X86_FEATURE_FPU]))
cpu_set_feature(X86_FEATURE_FPU);
return 0;
}
int cpu_init(void) int cpu_init(void)
{ {
if (parse_cpuinfo_features()) if (parse_cpuinfo_features(proc_cpuinfo_match))
return -1; return -1;
BUILD_BUG_ON(sizeof(struct xsave_struct) != XSAVE_SIZE); BUILD_BUG_ON(sizeof(struct xsave_struct) != XSAVE_SIZE);
......
#ifndef __CR_ASM_CPU_H__
#define __CR_ASM_CPU_H__
#include "asm/types.h"
/*
* Adopted from linux kernel.
*/
#define NCAPINTS (10) /* N 32-bit words worth of info */
#define NCAPINTS_BITS (NCAPINTS * 32)
#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE/FXRSTOR, CR4.OSFXSR */
#define X86_FEATURE_XSAVE (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
extern const char * const x86_cap_flags[NCAPINTS_BITS];
extern void cpu_set_feature(unsigned int feature);
extern bool cpu_has_feature(unsigned int feature);
extern int cpu_init(void);
#endif /* __CR_CPU_H__ */
#ifndef __CR_CPU_H__ #ifndef __CR_CPU_H__
#define __CR_CPU_H__ #define __CR_CPU_H__
#include "asm/types.h" #include "asm/cpu.h"
/*
* Adopted from linux kernel.
*/
#define NCAPINTS (10) /* N 32-bit words worth of info */
#define NCAPINTS_BITS (NCAPINTS * 32)
#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE/FXRSTOR, CR4.OSFXSR */
#define X86_FEATURE_XSAVE (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
extern const char * const x86_cap_flags[NCAPINTS_BITS];
extern void cpu_set_feature(unsigned int feature); extern void cpu_set_feature(unsigned int feature);
extern bool cpu_has_feature(unsigned int feature); extern bool cpu_has_feature(unsigned int feature);
......
...@@ -139,7 +139,7 @@ union fdinfo_entries { ...@@ -139,7 +139,7 @@ union fdinfo_entries {
extern int parse_fdinfo(int fd, int type, extern int parse_fdinfo(int fd, int type,
int (*cb)(union fdinfo_entries *e, void *arg), void *arg); int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
extern int parse_cpuinfo_features(void); extern int parse_cpuinfo_features(int (*handler)(char *tok));
extern int parse_file_locks(void); extern int parse_file_locks(void);
#endif /* __CR_PROC_PARSE_H__ */ #endif /* __CR_PROC_PARSE_H__ */
...@@ -35,7 +35,7 @@ static char *buf = __buf.buf; ...@@ -35,7 +35,7 @@ static char *buf = __buf.buf;
#define BUF_SIZE sizeof(__buf.buf) #define BUF_SIZE sizeof(__buf.buf)
int parse_cpuinfo_features(void) int parse_cpuinfo_features(int (*handler)(char *tok))
{ {
FILE *cpuinfo; FILE *cpuinfo;
...@@ -53,12 +53,8 @@ int parse_cpuinfo_features(void) ...@@ -53,12 +53,8 @@ int parse_cpuinfo_features(void)
for (tok = strtok(buf, " \t\n"); tok; for (tok = strtok(buf, " \t\n"); tok;
tok = strtok(NULL, " \t\n")) { tok = strtok(NULL, " \t\n")) {
if (!strcmp(tok, x86_cap_flags[X86_FEATURE_FXSR])) if (handler(tok) < 0)
cpu_set_feature(X86_FEATURE_FXSR); break;
else if (!strcmp(tok, x86_cap_flags[X86_FEATURE_XSAVE]))
cpu_set_feature(X86_FEATURE_XSAVE);
else if (!strcmp(tok, x86_cap_flags[X86_FEATURE_FPU]))
cpu_set_feature(X86_FEATURE_FPU);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment