android下将指定的进程/线程绑定到指定的CPU

为了优化APP性能,特别是针对CPU密集型任务,开发者可以通过代码将线程绑定到Android设备的特定CPU核心上。由于Android屏蔽了pthread_setaffinity_np API,需要使用sched系统调用来实现这一功能。
摘要由CSDN通过智能技术生成

针对平台优化的APP,需要根据具体的CPU型号来将一些任务重,占CPU资源多的线程绑定到CPU上处理能力更强的大核上,可参考如下代码:

1、将整个进程中的各个线程绑定到指定CPU核

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sched.h>
#include <ctype.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
#include <string.h>
#include <jni.h>
#include <time.h>
#include <poll.h>
#include <errno.h>
#include <fcntl.h>
#include <cutils/log.h>
#include <sys/stat.h>
#include <cutils/properties.h>
JNIEXPORT int JNICALL Java_com_google_vrtoolkit_cardboard_GLSurfaceView2_BindThreadsToCpu45(JNIEnv* env, jobject obj){
    DIR *task_dir;
    struct dirent *tid_dir;
    int pid,tid;
    int ret;
    char filename[64];
 
          ALOGD("BindT
  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值