11

I recently bought a Moto Atrix 2 mobile. When I tried to look at the processor specs in the phone, Runtime.getRuntime().availableProcessors() returned 1. /proc/cpuinfo too had information about just processor 0.

Out of curiosity I checked the same in my friend's Samsung Galaxy S2, which is again a dual core phone. This too showed that no. of cores is 1.

I checked the same in my Moto xoom tablet which is again dual core. This time availableProcessors() returned 2 and cpuinfo also had both processor 0 and processor 1 details.

I am confused. Why some devices carry different information? Can someone explain this anomaly?

4

2 に答える 2

19

Runtime.getRuntime().availableProcessors()オンライン プロセッサの数のみを返すため、2 番目のコアがスリープ状態の場合は 1 が返されます。これは、リソースを集中的に使用しないタスク中に電力を保持するために行われます。

利用可能なすべてのコアを表示するには、/sys/devices/system/cpu/ を調べます。

于 2012-04-13T00:19:18.573 に答える
0

これにより、Android のコア数が取得されます (この投稿に基づく) :

public static int getCoresCount()
    {
    class CpuFilter implements FileFilter
      {
      @Override
      public boolean accept(final File pathname)
        {
        if(Pattern.matches("cpu[0-9]+",pathname.getName()))
          return true;
        return false;
        }
      }
    try
      {
      final File dir=new File("/sys/devices/system/cpu/");
      final File[] files=dir.listFiles(new CpuFilter());
      return files.length;
      }
    catch(final Exception e)
      {
      return Math.max(1,Runtime.getRuntime().availableProcessors());
      }
    }
于 2014-10-08T23:28:32.583 に答える