kernel/x86: stores cpu number in TSC_AUX if rdtscp is available
On modern x86, one can use __rdtscp to get the current cpu in userland. Change-Id: I1767e379606230a75e4622637c7a5aed9cdf9ab0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2248 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
b9db31f649
commit
073e295aa6
@@ -114,6 +114,7 @@
|
||||
#define IA32_MSR_FS_BASE 0xc0000100
|
||||
#define IA32_MSR_GS_BASE 0xc0000101
|
||||
#define IA32_MSR_KERNEL_GS_BASE 0xc0000102
|
||||
#define IA32_MSR_TSC_AUX 0xc0000103
|
||||
|
||||
// K8 MSR registers
|
||||
#define K8_MSR_IPM 0xc0010055
|
||||
|
||||
@@ -1145,6 +1145,12 @@ arch_cpu_init_percpu(kernel_args* args, int cpu)
|
||||
gCpuIdleFunc = halt_idle;
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
// if RDTSCP is available write cpu number in TSC_AUX
|
||||
if (x86_check_feature(IA32_FEATURE_AMD_EXT_RDTSCP, FEATURE_EXT_AMD))
|
||||
x86_write_msr(IA32_MSR_TSC_AUX, cpu);
|
||||
#endif
|
||||
|
||||
return __x86_patch_errata_percpu(cpu);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ SimpleTest system_watching_test :
|
||||
system_watching_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest get_cpu_num_test :
|
||||
get_cpu_num_test.cpp
|
||||
;
|
||||
|
||||
# Tell Jam where to find these sources
|
||||
SEARCH on [ FGristFiles
|
||||
driver_settings.cpp
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2020, Jérôme Duval, jerome.duval@gmail.com.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <x86intrin.h>
|
||||
|
||||
extern const char* __progname;
|
||||
|
||||
|
||||
static void
|
||||
print_usage(bool error)
|
||||
{
|
||||
fprintf(error ? stderr : stdout,
|
||||
"Usage: %s\n",
|
||||
__progname);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_usage_and_exit(bool error)
|
||||
{
|
||||
print_usage(error);
|
||||
exit(error ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char* const* argv)
|
||||
{
|
||||
|
||||
if (argc > 2)
|
||||
print_usage_and_exit(true);
|
||||
|
||||
if (argc > 1) {
|
||||
const char* arg = argv[1];
|
||||
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
|
||||
print_usage_and_exit(false);
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
uint32 cpuNum;
|
||||
__rdtscp(&cpuNum);
|
||||
printf("%" B_PRIu32 "\n", cpuNum);
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user