当前位置:   article > 正文

Android cpu信息获取/修改_qt android 获得cpu信息

qt android 获得cpu信息

CPU信息查看

通过 cat proc/cpuinfo 查看

  1. processor : 7
  2. BogoMIPS : 38.40
  3. Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
  4. CPU implementer : 0x51
  5. CPU architecture: 8
  6. CPU variant : 0xa
  7. CPU part : 0x800
  8. CPU revision : 2
  9. Hardware : Qualcomm Technologies, Inc

应用端,类似某兔兔中CPU信息应该也是从这里获取的

CPU信息修改 

 cpuinfo 文件内容是在 kernel/msm-4.19/arch/arm64/kernel/cpuinfo.c 中 c_show 函数中写入的

  1. static int c_show(struct seq_file *m, void *v)
  2. {
  3. int i, j;
  4. bool compat = personality(current->personality) == PER_LINUX32;
  5. seq_printf(m, "Processor\t: AArch64 Processor rev %d (%s)\n",
  6. read_cpuid_id() & 15, ELF_PLATFORM);
  7. for_each_present_cpu(i) {
  8. struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i);
  9. u32 midr = cpuinfo->reg_midr;
  10. /*
  11. * glibc reads /proc/cpuinfo to determine the number of
  12. * online processors, looking for lines beginning with
  13. * "processor". Give glibc what it expects.
  14. */
  15. seq_printf(m, "processor\t: %d\n", i);
  16. if (compat)
  17. seq_printf(m, "model name\t: ARMv8 Processor rev %d (%s)\n",
  18. MIDR_REVISION(midr), COMPAT_ELF_PLATFORM);
  19. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  20. loops_per_jiffy / (500000UL/HZ),
  21. loops_per_jiffy / (5000UL/HZ) % 100);
  22. /*
  23. * Dump out the common processor features in a single line.
  24. * Userspace should read the hwcaps with getauxval(AT_HWCAP)
  25. * rather than attempting to parse this, but there's a body of
  26. * software which does already (at least for 32-bit).
  27. */
  28. seq_puts(m, "Features\t:");
  29. if (compat) {
  30. #ifdef CONFIG_COMPAT
  31. for (j = 0; compat_hwcap_str[j]; j++)
  32. if (compat_elf_hwcap & (1 << j))
  33. seq_printf(m, " %s", compat_hwcap_str[j]);
  34. for (j = 0; compat_hwcap2_str[j]; j++)
  35. if (compat_elf_hwcap2 & (1 << j))
  36. seq_printf(m, " %s", compat_hwcap2_str[j]);
  37. #endif /* CONFIG_COMPAT */
  38. } else {
  39. for (j = 0; hwcap_str[j]; j++)
  40. if (elf_hwcap & (1 << j))
  41. seq_printf(m, " %s", hwcap_str[j]);
  42. }
  43. seq_puts(m, "\n");
  44. seq_printf(m, "CPU implementer\t: 0x%02x\n",
  45. MIDR_IMPLEMENTOR(midr));
  46. seq_printf(m, "CPU architecture: 8\n");
  47. seq_printf(m, "CPU variant\t: 0x%x\n", MIDR_VARIANT(midr));
  48. seq_printf(m, "CPU part\t: 0x%03x\n", MIDR_PARTNUM(midr));
  49. seq_printf(m, "CPU revision\t: %d\n\n", MIDR_REVISION(midr));
  50. }
  51. if (!arch_read_hardware_id)
  52. seq_printf(m, "Hardware\t: %s\n", machine_name);
  53. else
  54. seq_printf(m, "Hardware\t: %s\n", arch_read_hardware_id());
  55. return 0;
  56. }

注:上面 arch_read_hardware_id 函数,高通平台是在 kernel/msm-4.19/drivers/soc/qcom/socinfo.c 文件中,等于 msm_read_hardware_id 函数

  1. static char *msm_read_hardware_id(void)
  2. {
  3. static char msm_soc_str[256] = "Qualcomm Technologies, Inc ";
  4. static bool string_generated;
  5. int ret = 0;
  6. if (string_generated)
  7. return msm_soc_str;
  8. if (!socinfo)
  9. goto err_path;
  10. if (!cpu_of_id[socinfo->v0_1.id].soc_id_string)
  11. goto err_path;
  12. ret = strlcat(msm_soc_str, cpu_of_id[socinfo->v0_1.id].soc_id_string,
  13. sizeof(msm_soc_str));
  14. if (ret > sizeof(msm_soc_str))
  15. goto err_path;
  16. string_generated = true;
  17. return msm_soc_str;
  18. err_path:
  19. return "UNKNOWN SOC TYPE";
  20. }

这里就是将高通和芯片名称 soc_id_string 进行拼接下。上面 msm_soc_info cpu_of_id[] 中枚举了相关芯片信息

  1. static struct msm_soc_info cpu_of_id[] = {
  2. [0] = {MSM_CPU_UNKNOWN, "Unknown CPU"},
  3. /* 8960 IDs */
  4. [87] = {MSM_CPU_8960, "MSM8960"},
  5. /* 8064 IDs */
  6. [109] = {MSM_CPU_8064, "APQ8064"},
  7. [122] = {MSM_CPU_8960, "MSM8960"},
  8. ... ...

根据 socinfo->v0_1.id 进行匹配,这个 id 等于项目的 dtsi 中配置的 qcom,msm-id 

  1. / {
  2. model = "Qualcomm Technologies, Inc. xxx";
  3. compatible = "xxx";
  4. qcom,msm-id = <xxx 0x10000>, <xxx 0x10000>;

注意:

高Android版本,修改 cpu_of_id 可能会影响CTS testConfigHardwareMitigations 此项。相关源码cts/hostsidetests/security/src/android/security/cts/KernelConfigTest.java

  1. private Map<String, String[]> hardwareMitigations = new HashMap<String, String[]>() {
  2. {
  3. put("EXYNOS990", null);
  4. put("EXYNOS980", null);
  5. put("EXYNOS850", null);
  6. put("EXYNOS3830", null);
  7. put("EXYNOS9630", null);
  8. put("EXYNOS9830", null);
  9. put("EXYNOS7870", null);
  10. put("EXYNOS7880", null);
  11. put("EXYNOS7570", null);
  12. put("EXYNOS7872", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  13. put("EXYNOS7885", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  14. put("EXYNOS9610", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  15. put("Kirin980", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  16. put("Kirin970", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  17. put("Kirin810", null);
  18. put("Kirin710", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  19. put("SDMMAGPIE", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  20. put("SM6150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  21. put("SM7150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  22. put("LITO", null);
  23. put("SM8150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  24. put("SM8150P", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  25. put("KONA", null);
  26. put("SDM429", null);
  27. put("SDM439", null);
  28. put("QM215", null);
  29. put("BENGAL", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"});
  30. put("DEFAULT", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y",
  31. "CONFIG_UNMAP_KERNEL_AT_EL0=y"});
  32. }};
  33. private String[] lookupMitigations() throws Exception {
  34. return hardwareMitigations.get(getHardware());
  35. }
  36. /**
  37. * Test that the kernel has Spectre/Meltdown mitigations for architectures and kernel versions
  38. * that support it. Exempt platforms which are known to not be vulnerable.
  39. *
  40. * @throws Exception
  41. */
  42. @CddTest(requirement="9.7")
  43. public void testConfigHardwareMitigations() throws Exception {
  44. String mitigations[];
  45. if (PropertyUtil.getFirstApiLevel(mDevice) < 28) {
  46. return;
  47. }
  48. if (CpuFeatures.isArm64(mDevice) && !CpuFeatures.kernelVersionLessThan(mDevice, 4, 4)) {
  49. mitigations = lookupMitigations();
  50. if (mitigations != null) {
  51. for (String mitigation : mitigations) {
  52. assertTrue("Linux kernel must have " + mitigation + " enabled.",
  53. configSet.contains(mitigation));
  54. }
  55. }
  56. } else if (CpuFeatures.isX86(mDevice)) {
  57. assertTrue("Linux kernel must have KPTI enabled: CONFIG_PAGE_TABLE_ISOLATION=y",
  58. configSet.contains("CONFIG_PAGE_TABLE_ISOLATION=y"));
  59. }
  60. }

测试会根据 hardwareMitigations 中CPU型号,确认需要开启的宏,所以修改CPU名称后需要确认相关宏是否开启。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/526699
推荐阅读
相关标签
  

闽ICP备14008679号