为什么rdtscp不返回核心id
Why rdtscp doesn't return the core id?
我有这样的代码
#include <iostream>
#include <sched.h>
unsigned long long rdtscp(unsigned int* aux)
{
// For IA32
unsigned long long x;
asm volatile("rdtscp" : "=c" (*aux), "=A" (x) ::);
return x;
}
int main()
{
unsigned int aux0, aux1 = -1, aux2;
aux0 = sched_getcpu();
unsigned long long x = rdtscp(&aux1);
aux2 = sched_getcpu();
std::cout << "aux0 = " << aux0 << ", aux1 = " << aux1 << ", aux2 = " << aux2 << ", x = " << x << std::endl;
return 0;
}
定义了一个函数rdtscp,它使用内联汇编调用rdtscp汇编指令。TSC值看起来很好,但是核心id始终为零,即使sched_getcpu()都返回了正确的核心id并且它不是零。输出看起来像
# g++ test.cpp -o test ; ./test
aux0 = 2, aux1 = 0, aux2 = 2, x = 231368797247511
如何使用rdtscp获得TSC和核心id?
可能您的硬件不支持rdtscp指令。你可以检查这个:
#include <cpuid.h>
#include <stdio.h>
main()
{
unsigned a, b, c, d;
if (__get_cpuid(0x80000001, &a, &b, &c, &d))
puts("unsupported instruction rdtscp" + (d&1<<27 ? 2 : 0));
else
puts("unsupported cpuid level");
}
相关文章:
- 如何找出GDB的SIGTRAP核心转储的根本原因
- C++映射分割错误(核心转储)
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 在c++中初始化矩阵时出现分段错误(核心转储)
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- MPI突然停止了对多个核心的操作
- 在多个核心中处理一个HTTP请求
- 从函数角度看ID到文件路径的内部与外部映射
- 通过组合不同的类型来创建唯一的id
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- FFMPEG配置文件级别id大小无效
- 方法内部但循环仍得到预期的不合格id错误C++
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 如何获取 GLFW 窗口 ID?
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 运算符继承和 cpp 核心准则 c.128 的问题
- 显示数组中的学生 ID 和最高分
- 通过其 USB 入口和C++与 Blackstar ID 核心吉他放大器通信
- 为什么rdtscp不返回核心id