多核Android多核、Android

2023-09-06 03:40:20 作者:醉逍遥

我已经运行简单的并行算法绘制Mandelbrot集到一台Nexus 7测试并行计算(Tegra的3,4 + 1核)。跑了几次后,我得到1.5秒串行和1.0平行,但并行和串行来真的彼此接近1.3秒。

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 seconds for serial and 1.0 for parallel, but parallel and serial come really close to each other at 1.3 seconds.

这个广场是700x700像素,曼德尔布罗code我用的是

The square is 700x700 pixels, and the mandelbrot code I use is from

HTTP://rosetta$c$c.org/wiki/Mandelbrot_set#Java

并行运行,实现两半曼德尔布罗像这样

The parallel implementation runs two halves of mandelbrot like this

    public void mandelbrotParallel() {
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            mandelbrotOne();
        }
    });
    Thread t2 = new Thread(new Runnable() {
        public void run() {
            mandelbrotTwo();
        }
    });
    t1.start();
    t2.start();
    try {
        t1.join();
        t2.join();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mHandler.post(new Runnable() {
        public void run() {
            v.setBmp(bmp);
            v.invalidate();
        }
    });
}

我已经运行一个简单的向量加法前,发现类似传闻的结果(无科学严谨)。所以,我不知道是否有什么特别的一个人做的就是Android的火了多个内核来获得完成任务。

I have run a simple vector addition before and found similar anecdotal results (no scientific rigor). So I wonder if there is anything special one has to do to get Android to fire up multiple cores to get a task done.

,这可能是因为内核处于休眠状态,等待计算要真正长期运行(多秒)的核心被打开之前...这是真的吗?如果是这样,从Java(没有JNI)有API调用可以做,以preemptively醒来的核心?

Based on quick conversations with Google, it could be that the cores are dormant and wait for the computation to be truly long running (multiple seconds) before the cores are turned on... Is this true ? If so, are there API calls from Java (no JNI) that can be done to preemptively wake up the cores ?

推荐答案

A 正常 Android系统试图保守。所以,如果你创建一个新的线程,并开始了一些重计算,Linux内核将首先运行在一个核心,并提高其核心速度。一旦核心一直忙超过一定门限一会儿,才内核启动另一个核心。

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.

从一个开发者角度,你不能在一个正常的Andr​​oid影响这一点。 Android有没有API醒来一定量的核或设置一定的核心频率。

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.

如果你可以切换到根机器人,你有更多的选择,作为常规的Linux内核确实有选项来影响的核心频率和活跃内核的数量。 这是通过'州长'完成。一个普通的Linux内核有相当多的选择。对于这个问题,您有兴趣设置的性能的省长,这将保持一个清醒的核心,并在其最高频率。

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.

Linux内核接口是在 / SYS 的文件系统。我要告诉亚行外壳命令,这里留给你把它变成Java的开放状态,读取和写入命令。

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

在这个目录,你会发现,说明有多少核心是present系统中的虚拟文件:

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

cat possible

应该给你的Teg​​ra 3的情况下,答案的 0-3 的。内核不知道,如果只有一个内核的运行,偷偷转移到备用低功耗的核心。 也有目录的 CPU0 CPU1 CPU2 CPU3 的。根据不同的内核版本,它们可能,如果一个核心被激活才会出现。 每个CPU目录包含一个目录的 CPU频率的,你可以通过的 CPU频率子系统。它应该包含一个文件scaling_available_governors,显示其的 CPU省长可用。 只有在一个有根的系统,你可以这样做:

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".

要显示的这种行为,向量面料的影响 创建一个测试应用程序,执行上的修复算法 OpenCV的并联。该应用程序的措施顺序和 并行性能高达4核。即使在运行并行 版本两次,测量结果由于启动芯而变化。 看一看自己(下载表格应用程序商店): http://www.vectorfabrics.com/products/case-study/opencv_inpaint

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