Android 什么是调度策略-1?
我正在编写一个实用程序来动态更改Android上任务的调度策略。我主要使用sched_getscheduler()和sched_setscheduler()系统调用来实现这一点 在sched.h(内核中)中,调度策略定义为:Android 什么是调度策略-1?,android,linux-kernel,scheduler,Android,Linux Kernel,Scheduler,我正在编写一个实用程序来动态更改Android上任务的调度策略。我主要使用sched_getscheduler()和sched_setscheduler()系统调用来实现这一点 在sched.h(内核中)中,调度策略定义为: /* * Scheduling policies */ #define SCHED_NORMAL 0 #define SCHED_FIFO 1 #define SCHED_RR 2 #define SCHED_BATCH 3 /*
/*
* Scheduling policies
*/
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE 5
但是,有些任务(主要是IRQ,尽管不是每个IRQ)在调用sched_getscheduler()时返回-1
我在sched.c的内核中找到了sched_getscheduler()系统调用的定义:
SYSCALL_DEFINE1(sched_getscheduler, pid_t, pid)
{
struct task_struct *p;
int retval;
if (pid < 0)
return -EINVAL;
retval = -ESRCH;
rcu_read_lock();
p = find_process_by_pid(pid);
if (p) {
retval = security_task_getscheduler(p);
if (!retval)
retval = p->policy
| (p->sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0);
}
rcu_read_unlock();
return retval;
}
SYSCALL\u DEFINE1(sched\u getscheduler,pid\u t,pid)
{
结构任务_struct*p;
内部检索;
if(pid<0)
返回-艾因瓦尔;
retval=-ESRCH;
rcu_读取_锁定();
p=通过pid(pid)查找流程;
如果(p){
retval=security\u task\u getscheduler(p);
如果(!retval)
retval=p->policy
|(p->sched_reset_on_fork?sched_reset_on_fork:0);
}
rcu_读取_解锁();
返回返回;
}
ESRCH和EINVAL分别定义为3和22。这让我无法理解sched_getscheduler()如何返回-1
为感兴趣的人提供一些背景信息。我在第一代Nexus7上使用Android 4.4.2上的Linux内核3.1.10。返回-1的IRQ具体是:210-host_sp、214-host_sp和218-host_sp。我知道这些IRQ与图形驱动程序有关,但也可能有其他我没有注意到的IRQ
如有任何见解,将不胜感激
谢谢像大多数其他用户空间函数一样,
sched_getscheduler
返回-1以指示错误
要获取实际错误代码,请参见
errno
您好,谢谢您的反馈。事实上我知道厄尔诺。很抱歉,我可能应该用“为什么某些进程会返回-1?”这句话来表达我的问题,我现在正在深入研究内核代码。我不认为这与进程的优先级或UID有任何关系,因为我能够在具有相同UID的其他进程上成功调用sched_getscheduler,而且我能够在以最高RT优先级运行的进程上调用sched_getscheduler。内核告诉您为什么它没有返回调度策略。到目前为止,您一直对errno
的值保密。很抱歉,我在原始程序中没有使用errno。此后,我使用errno重新编译了它,现在我无法重复以前遇到的问题。我感谢您的反馈,我将从一开始就使用errno。