kernel/x86[_64]: remove get_optimized_functions from cpu modules

The possibility to specify custom memcpy and memset implementations
in cpu modules is currently unused and there is generally no point
in such feature.

There are only 2 x86 vendors that really matter and there isn't
very big difference in performance of the generic optmized versions
of these funcions across different models. Even if we wanted different
versions of memset and memcpy depending on the processor model or
features much better solution would be to use STT_GNU_IFUNC and save
one indirect call.

Long story short, we don't really benefit in any way from
get_optimized_functions and the feature it implements and it only adds
unnecessary complexity to the code.

Signed-off-by: Paweł Dziepak <[email protected]>
This commit is contained in:
Paweł Dziepak
2014-09-14 19:16:51 +02:00
parent 5399d1df38
commit 6156a508ad
5 changed files with 16 additions and 94 deletions
@@ -262,13 +262,6 @@ typedef struct x86_mtrr_info {
uint8 type; uint8 type;
} x86_mtrr_info; } x86_mtrr_info;
typedef struct x86_optimized_functions {
void (*memcpy)(void* dest, const void* source, size_t count);
void* memcpy_end;
void (*memset)(void* dest, int value, size_t count);
void* memset_end;
} x86_optimized_functions;
typedef struct x86_cpu_module_info { typedef struct x86_cpu_module_info {
module_info info; module_info info;
uint32 (*count_mtrrs)(void); uint32 (*count_mtrrs)(void);
@@ -280,8 +273,6 @@ typedef struct x86_cpu_module_info {
uint8* _type); uint8* _type);
void (*set_mtrrs)(uint8 defaultType, const x86_mtrr_info* infos, void (*set_mtrrs)(uint8 defaultType, const x86_mtrr_info* infos,
uint32 count); uint32 count);
void (*get_optimized_functions)(x86_optimized_functions* functions);
} x86_cpu_module_info; } x86_cpu_module_info;
// features // features
+6 -35
View File
@@ -105,17 +105,8 @@ static const size_t kDoubleFaultStackSize = 4096; // size per CPU
static x86_cpu_module_info* sCpuModule; static x86_cpu_module_info* sCpuModule;
extern "C" void memcpy_generic(void* dest, const void* source, size_t count); extern int memcpy_end;
extern int memcpy_generic_end; extern int memset_end;
extern "C" void memset_generic(void* dest, int value, size_t count);
extern int memset_generic_end;
x86_optimized_functions gOptimizedFunctions = {
memcpy_generic,
&memcpy_generic_end,
memset_generic,
&memset_generic_end
};
/* CPU topology information */ /* CPU topology information */
static uint32 (*sGetCPUTopologyID)(int currentCPU); static uint32 (*sGetCPUTopologyID)(int currentCPU);
@@ -1163,33 +1154,13 @@ arch_cpu_init_post_modules(kernel_args* args)
call_all_cpus(&init_mtrrs, NULL); call_all_cpus(&init_mtrrs, NULL);
} }
// get optimized functions from the CPU module
if (sCpuModule != NULL && sCpuModule->get_optimized_functions != NULL) {
x86_optimized_functions functions;
memset(&functions, 0, sizeof(functions));
sCpuModule->get_optimized_functions(&functions);
if (functions.memcpy != NULL) {
gOptimizedFunctions.memcpy = functions.memcpy;
gOptimizedFunctions.memcpy_end = functions.memcpy_end;
}
if (functions.memset != NULL) {
gOptimizedFunctions.memset = functions.memset;
gOptimizedFunctions.memset_end = functions.memset_end;
}
}
// put the optimized functions into the commpage // put the optimized functions into the commpage
size_t memcpyLen = (addr_t)gOptimizedFunctions.memcpy_end size_t memcpyLen = (addr_t)&memcpy_end - (addr_t)memcpy;
- (addr_t)gOptimizedFunctions.memcpy;
addr_t memcpyPosition = fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMCPY, addr_t memcpyPosition = fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMCPY,
(const void*)gOptimizedFunctions.memcpy, memcpyLen); (const void*)memcpy, memcpyLen);
size_t memsetLen = (addr_t)gOptimizedFunctions.memset_end size_t memsetLen = (addr_t)&memset_end - (addr_t)memset;
- (addr_t)gOptimizedFunctions.memset;
addr_t memsetPosition = fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMSET, addr_t memsetPosition = fill_commpage_entry(COMMPAGE_ENTRY_X86_MEMSET,
(const void*)gOptimizedFunctions.memset, memsetLen); (const void*)memset, memsetLen);
size_t threadExitLen = (addr_t)x86_end_userspace_thread_exit size_t threadExitLen = (addr_t)x86_end_userspace_thread_exit
- (addr_t)x86_userspace_thread_exit; - (addr_t)x86_userspace_thread_exit;
addr_t threadExitPosition = fill_commpage_entry( addr_t threadExitPosition = fill_commpage_entry(
@@ -79,12 +79,6 @@ dummy()
DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function); DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function);
DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size); DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size);
// struct x86_optimized_functions
DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
memcpy);
DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
memset);
// struct signal_frame_data // struct signal_frame_data
DEFINE_SIZEOF_MACRO(SIGNAL_FRAME_DATA, signal_frame_data); DEFINE_SIZEOF_MACRO(SIGNAL_FRAME_DATA, signal_frame_data);
DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, info); DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, info);
+5 -28
View File
@@ -6,22 +6,12 @@
* Distributed under the terms of the NewOS License. * Distributed under the terms of the NewOS License.
*/ */
#if !_BOOT_MODE
# include "asm_offsets.h"
#endif
#include <asm_defs.h> #include <asm_defs.h>
// We don't need the indirection in the boot loader.
#if _BOOT_MODE
# define memcpy_generic memcpy
# define memset_generic memset
#endif
.align 4 .align 4
FUNCTION(memcpy_generic): FUNCTION(memcpy):
pushl %esi pushl %esi
pushl %edi pushl %edi
movl 12(%esp),%edi /* dest */ movl 12(%esp),%edi /* dest */
@@ -45,13 +35,13 @@ FUNCTION(memcpy_generic):
popl %edi popl %edi
popl %esi popl %esi
ret ret
FUNCTION_END(memcpy_generic) FUNCTION_END(memcpy)
SYMBOL(memcpy_generic_end): SYMBOL(memcpy_end):
/* void *memset(void *dest, int value, size_t length); */ /* void *memset(void *dest, int value, size_t length); */
.align 4 .align 4
FUNCTION(memset_generic): FUNCTION(memset):
push %ebp push %ebp
mov %esp, %ebp mov %esp, %ebp
@@ -111,19 +101,6 @@ FUNCTION(memset_generic):
mov %ebp, %esp mov %ebp, %esp
pop %ebp pop %ebp
ret ret
FUNCTION_END(memset_generic)
SYMBOL(memset_generic_end):
#if !_BOOT_MODE
.align 4
FUNCTION(memcpy):
jmp *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memcpy)
FUNCTION_END(memcpy)
FUNCTION(memset):
jmp *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memset)
FUNCTION_END(memset) FUNCTION_END(memset)
SYMBOL(memset_end):
#endif // !_BOOT_MODE
@@ -6,11 +6,9 @@
#include <asm_defs.h> #include <asm_defs.h>
#include "asm_offsets.h"
.align 8 .align 8
FUNCTION(memcpy_generic): FUNCTION(memcpy):
push %rbp push %rbp
movq %rsp, %rbp movq %rsp, %rbp
@@ -59,12 +57,12 @@ FUNCTION(memcpy_generic):
pop %rbp pop %rbp
ret ret
FUNCTION_END(memcpy_generic) FUNCTION_END(memcpy)
SYMBOL(memcpy_generic_end): SYMBOL(memcpy_end):
.align 8 .align 8
FUNCTION(memset_generic): FUNCTION(memset):
push %rbp push %rbp
movq %rsp, %rbp movq %rsp, %rbp
@@ -82,15 +80,6 @@ FUNCTION(memset_generic):
movq %r8, %rax movq %r8, %rax
pop %rbp pop %rbp
ret ret
FUNCTION_END(memset_generic)
SYMBOL(memset_generic_end):
FUNCTION(memcpy):
jmp *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memcpy)
FUNCTION_END(memcpy)
FUNCTION(memset):
jmp *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memset)
FUNCTION_END(memset) FUNCTION_END(memset)
SYMBOL(memset_end):