ANDROID: binder: add min sched_policy to node.

This change adds flags to flat_binder_object.flags
to allow indicating a minimum scheduling policy for
the node. It also clarifies the valid value range
for the priority bits in the flags.

Internally, we use the priority map that the kernel
uses, e.g. [0..99] for real-time policies and [100..139]
for the SCHED_NORMAL/SCHED_BATCH policies.

We also need to start keeping track of the default
scheduling policy for a process, as that is what
we will restore to after handling oneway transactions
that temporarily increased the priority.

Bug: 34461621
Bug: 37293077
Change-Id: Ifc6a0d691c2feb48e8349a21f56fb2eeb22f1bb5
Signed-off-by: Martijn Coenen <maco@google.com>
This commit is contained in:
Martijn Coenen
2017-05-08 09:44:51 -07:00
committed by Thierry Strudel
parent 1e99fc9c25
commit 539760bcea
2 changed files with 53 additions and 7 deletions

View File

@@ -301,6 +301,7 @@ struct binder_node {
unsigned has_async_transaction:1;
unsigned accept_fds:1;
unsigned min_priority:8;
unsigned sched_policy:2;
bool is_zombie;
struct binder_worklist async_todo;
};
@@ -798,8 +799,10 @@ static void binder_transaction_priority(struct task_struct *task,
if (!binder_supported_policy(desired_prio.sched_policy))
return;
if (target_node->min_priority < t->priority.prio) {
desired_prio.sched_policy = SCHED_NORMAL;
if (target_node->min_priority < t->priority.prio ||
(target_node->min_priority == t->priority.prio &&
target_node->sched_policy == SCHED_FIFO)) {
desired_prio.sched_policy = target_node->sched_policy;
desired_prio.prio = target_node->min_priority;
}
@@ -1686,13 +1689,17 @@ static int binder_translate_binder(struct flat_binder_object *fp,
node = binder_get_node(proc, fp->binder);
if (!node) {
s8 priority = fp->flags & FLAT_BINDER_FLAG_PRIORITY_MASK;
int sched_policy =
(fp->flags & FLAT_BINDER_FLAG_SCHED_POLICY_MASK) >>
FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT;
node = binder_new_node(proc, fp->binder, fp->cookie);
if (!node)
return -ENOMEM;
binder_proc_lock(node->proc, __LINE__);
node->min_priority = NICE_TO_PRIO(
fp->flags & FLAT_BINDER_FLAG_PRIORITY_MASK);
node->sched_policy = sched_policy;
node->min_priority = to_kernel_prio(sched_policy, priority);
node->accept_fds = !!(fp->flags & FLAT_BINDER_FLAG_ACCEPTS_FDS);
binder_proc_unlock(node->proc, __LINE__);
}
@@ -4666,9 +4673,10 @@ static void _print_binder_node(struct seq_file *m,
hlist_for_each_entry(ref, &node->refs, node_entry)
count++;
seq_printf(m, " node %d: u%016llx c%016llx pri %d hs %d hw %d ls %d lw %d is %d iw %d",
seq_printf(m, " node %d: u%016llx c%016llx pri %d:%d hs %d hw %d ls %d lw %d is %d iw %d",
node->debug_id, (u64)node->ptr, (u64)node->cookie,
node->min_priority, node->has_strong_ref, node->has_weak_ref,
node->sched_policy, node->min_priority,
node->has_strong_ref, node->has_weak_ref,
node->local_strong_refs, node->local_weak_refs,
node->internal_strong_refs, count);
if (count) {

View File

@@ -37,9 +37,47 @@ enum {
BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE),
};
enum {
/**
* enum flat_binder_object_flags - flags for use in flat_binder_object.flags
*/
enum flat_binder_object_flags {
/**
* @FLAT_BINDER_FLAG_PRIORITY_MASK: bit-mask for min scheduler priority
*
* These bits can be used to set the minimum scheduler priority
* at which transactions into this node should run. Valid values
* in these bits depend on the scheduler policy encoded in
* @FLAT_BINDER_FLAG_SCHED_POLICY_MASK.
*
* For SCHED_NORMAL, the valid range is between [-20..19]
* For SCHED_FIFO/SCHED_RR, the value can run between [1..99]
*/
FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
/**
* @FLAT_BINDER_FLAG_ACCEPTS_FDS: whether the node accepts fds.
*/
FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
/**
* @FLAT_BINDER_FLAG_SCHED_POLICY_MASK: bit-mask for scheduling policy
*
* These two bits can be used to set the min scheduling policy at which
* transactions on this node should run. These match the UAPI
* scheduler policy values, eg:
* 00b: SCHED_NORMAL
* 01b: SCHED_FIFO
* 10b: SCHED_RR
* 11b: SCHED_BATCH
*/
FLAT_BINDER_FLAG_SCHED_POLICY_MASK = 0x600,
};
/**
* enum flat_binder_object_shifts: shift values for flat_binder_object_flags
* @FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT: shift for getting scheduler policy.
*
*/
enum flat_binder_object_shifts {
FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT = 9,
};
#ifdef BINDER_IPC_32BIT