您的位置:首页 > 文旅 > 美景 > 甘肃网站seo技术厂家_深圳公租房_今天最新消息_嘉兴seo报价

甘肃网站seo技术厂家_深圳公租房_今天最新消息_嘉兴seo报价

2025/1/5 8:22:10 来源:https://blog.csdn.net/langjian2012/article/details/144437259  浏览:    关键词:甘肃网站seo技术厂家_深圳公租房_今天最新消息_嘉兴seo报价
甘肃网站seo技术厂家_深圳公租房_今天最新消息_嘉兴seo报价

Thread优先级设置方式:

java:

Process.setThreadPriority: android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST、Process.THREAD_PRIORITY_URGENT_AUDIO、-20)

c++:

#include <sched.h>
setpriority(
https://blog.csdn.net/yangming2466/article/details/83280643

Linux进程优先级系统——设置实时进程优先级_schedule里面priority 0-CSDN博客

Thread优先级原理(Android)

priority和nice关系:PR(NI+20):将nice级别显示为映射到更大优先级队列,-20映射到0,+19映射到39

  • main,renderthread 在app启动过程修改优先级源码:

if (curSchedGroup == ProcessList.SCHED_GROUP_TOP_APP) { // do nothing if we already switched to RT if (oldSchedGroup != ProcessList.SCHED_GROUP_TOP_APP)

{ app.getWindowProcessController().onTopProcChanged();

if (mService.mUseFifoUiScheduling) { // Switch UI pipeline for app to     

SCHED_FIFO

state.setSavedPriority(Process.getThreadPriority(app.getPid()));      mService.scheduleAsFifoPriority(app.getPid(), true);

if (renderThreadTid != 0) {

    mService.scheduleAsFifoPriority(renderThreadTid, /* suppressLogs */true);      if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Set RenderThread (TID " + renderThreadTid + ") to FIFO"); } } else {

    if (DEBUG_OOM_ADJ) { Slog.d("UI_FIFO", "Not setting RenderThread TID"); } } } else { // Boost priority for top app UI and render threads setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST);

if (renderThreadTid != 0) { try {

setThreadPriority(renderThreadTid, THREAD_PRIORITY_TOP_APP_BOOST);

} catch (IllegalArgumentException e) { // thread died, ignore } } } } }

恢复:

else if (oldSchedGroup == ProcessList.SCHED_GROUP_TOP_APP && curSchedGroup != ProcessList.SCHED_GROUP_TOP_APP) { app.getWindowProcessController().onTopProcChanged();

if (mService.mUseFifoUiScheduling) {

try {// Reset UI pipeline to SCHED_OTHER

   setThreadScheduler(app.getPid(), SCHED_OTHER, 0);       setThreadPriority(app.getPid(), state.getSavedPriority());

if (renderThreadTid != 0) {

  setThreadScheduler(renderThreadTid, SCHED_OTHER, 0);

} } catch (IllegalArgumentException e) {

  Slog.w(TAG, "Failed to set scheduling policy, thread does not exist:\n" + e);

} catch (SecurityException e) {

  Slog.w(TAG, "Failed to set scheduling policy, not allowed:\n" + e); } } else { // Reset priority for top app UI and render threads                setThreadPriority(app.getPid(), 0);

} if (renderThreadTid != 0) {

  setThreadPriority(renderThreadTid, THREAD_PRIORITY_DISPLAY);

}

  • 可控制不继续设置线程优先级:android.os.Process.setCanSelfBackground(false 作用是不让后面再有线程将优先级设置为background-level的行为,如有设置则直接抛出异常)

Scheduler 调度

调度算法分3大类:

SCHED_OTHER 默认调度策略线程优先级100~120

SCHED_FIFO 线程优先级11~99

SCHED_RR

其中 RR+FIFO 是实时线程优先级,它们之间的区别是RR在相同优先级的线程之间会公平轮询,FIFO会独占CPU直到阻塞为止

修改方法:

Process.setThreadScheduler(tid, Process.SCHED_FIFO,1)

Process.setThreadScheduler(tid, Process.SCHED_RR | Process.SCHED_RESET_ON_FORK

说明:

不加Process.SCHED_RESET_ON_FORK,Process所有线程会被设置成RR

加上Process.SCHED_RESET_ON_FORK,指定线程会被设置成RR

Android的schedule包含4个cgroups:foreground,background,top-app,rt

线程绑定核心实现方案:

Process.setThreadGroupAndCpuset(renderThreadTid, 8)

Android中cpuset包含5个cgroups:foreground,background,system-background,restricted,top-app

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com