在Android上以编程方式获取缓存线大小
如何在ARM Android上获取缓存线大小?这相当于以下页面,但专门针对Android: 该页面上的答案以及我知道的其他方式在Android上不起作用:在Android上以编程方式获取缓存线大小,android,caching,arm,systems-programming,Android,Caching,Arm,Systems Programming,如何在ARM Android上获取缓存线大小?这相当于以下页面,但专门针对Android: 该页面上的答案以及我知道的其他方式在Android上不起作用: /sys/devices/system/cpu/cpu0/cache/不存在 \u SC\u LEVEL1\u DCACHE\u LINESIZE不作为sysconf参数存在,即使我手动传入值190 AT_DCACHEBSIZE不作为getauxval参数存在,即使我手动传入值19 /proc/cpuinfo不包含缓存线信息 与x86不
不存在/sys/devices/system/cpu/cpu0/cache/
不作为\u SC\u LEVEL1\u DCACHE\u LINESIZE
参数存在,即使我手动传入值sysconf
190
不作为AT_DCACHEBSIZE
参数存在,即使我手动传入值getauxval
19
不包含缓存线信息/proc/cpuinfo
与x86不同,ARM的CPU信息仅在内核模式下可用,因此应用程序没有可用的
cpuid
等价物。我进行了一次小调查,发现了一些东西:
首先,它看起来像是带有\u SC\u LEVEL1\u ICACHE\u SIZE
的sysconf()
,\u SC\u LEVEL1\u ICACHE\u ASSOC
,\u SC\u LEVEL1\u ICACHE\u LINESIZE
或其他与CPU缓存相关的标志总是返回-1(有时可能是0),并且它们根本没有实现
但有一个解决办法。如果您能够在项目中使用JNI,请使用。此库对于检索有关CPU的信息(我的设备非常旧):
下面是我用来获取CPU缓存信息的代码:
#include <string>
#include <sstream>
#include <cpuinfo.h>
void get_cache_info(const char* name, const struct cpuinfo_cache* cache, std::ostringstream& oss)
{
oss << "CPU Cache: " << name << std::endl;
oss << " > size : " << cache->size << std::endl;
oss << " > associativity : " << cache->associativity << std::endl;
oss << " > sets : " << cache->sets << std::endl;
oss << " > partitions : " << cache->partitions << std::endl;
oss << " > line_size : " << cache->line_size << std::endl;
oss << " > flags : " << cache->flags << std::endl;
oss << " > processor_start : " << cache->processor_start << std::endl;
oss << " > processor_count : " << cache->processor_count << std::endl;
oss << std::endl;
}
const std::string get_cpu_info()
{
cpuinfo_initialize();
const struct cpuinfo_processor* proc = cpuinfo_get_current_processor();
std::ostringstream oss;
if (proc->cache.l1d)
get_cache_info("L1 Data", proc->cache.l1d, oss);
if (proc->cache.l1i)
get_cache_info("L1 Instruction", proc->cache.l1i, oss);
if (proc->cache.l2)
get_cache_info("L2", proc->cache.l2, oss);
if (proc->cache.l3)
get_cache_info("L3", proc->cache.l3, oss);
if (proc->cache.l4)
get_cache_info("L4", proc->cache.l4, oss);
return oss.str();
}
#包括
#包括
#包括
void get_cache_info(常量字符*名称,常量结构cpuinfo_cache*缓存,std::ostringstream&oss)
{
你得到答案了吗?我也面临同样的问题。