Multi-core Android

后端 未结 2 1954
北海茫月
北海茫月 2021-01-03 03:04

I have run simple parallel algorithm drawing the mandelbrot set to test parallel computations on a Nexus 7 (Tegra 3, 4+1 cores). After running several times I get 1.5 secon

2条回答
  •  清酒与你
    2021-01-03 03:40

    A normal Android system tries to be conservative. So if you create a new thread and start some heavy computations, the Linux kernel will first run on one core and increase its core speed. Once the core has been 'busy' over a certain threshhold for a while, only then the kernel starts another core.

    The same is true in the other direction: once the system calms down, it will slowly turn off cores and reduce frequency.

    From a developer point of view, you cannot influence this on a 'normal' Android. Android has no API to wake up a certain amount of cores or set a certain core frequency.


    If you can switch to a rooted Android, you have more options, as the regular Linux kernel does have options to influence the core frequencies and the number of active cores. This is done through 'governors'. A normal Linux kernel has quite a few options. For this question, you are interested in setting the performance governor, which will keep a core awake and at its highest frequency.

    The Linux kernel interface is in the /sys file system. I'm going to show adb shell commands here and leave it to you to turn it into Java open, read and write commands.

    cd /sys/devices/system/cpu
    

    Within this directory, you'll find virtual files that indicate how many cores are present in the system:

    cat possible
    

    should give the answer 0-3 in your Tegra 3 case. The kernel doesn't know that if only one core is running, it secretly moves to the spare low-power core. There are also directories cpu0 cpu1 cpu2 cpu3. Depending on the kernel version, they may only appear if a core is activated. Each of the cpu directories contains a directory cpufreq where you can interact with the cpufreq subsystem. It should contain a file scaling_available_governors that shows which cpu governors are available. Only on a rooted system, you can do:

    echo "performance" >cpu0/cpufreq/scaling_governor
    

    To set the governor that will keep the core running at its highest frequency. On a non-rooted system, you'll get the error "permission denied".


    To show the influence of this behavior, Vector Fabrics created a test application that performs an inpainting algorithm on OpenCV in parallel. The application measures both sequential and parallel performance up to 4 cores. Even when running the parallel version twice, the measurements vary due to starting up the cores. Have a look for yourself (download form the app store): http://www.vectorfabrics.com/products/case-study/opencv_inpaint

提交回复
热议问题