우선순위 역전은 우선순위가 낮은 작업이 우선순위가 높은 작업에 필요한 리소스를 보유하고 있기 때문에 우선순위가 높은 트랜잭션이 우선순위가 낮은 작업에 의해 지연되는 상황입니다. 우선순위 역전을 완화하기 위해 Android는 트랜잭션 우선순위 상속, 노드 우선순위 상속, 실시간 우선순위 상속의 세 가지 우선순위 상속 형식을 통해 다양한 우선순위로 스레드를 실행하는 것을 지원합니다.
이 페이지에서는 이러한 다양한 형태의 우선순위 상속을 설명합니다.
트랜잭션 우선순위 상속
동기 바인더 호출을 할 때 우선순위가 낮은 스레드가 응답을 보낼 때까지 우선순위가 높은 스레드가 우선순위가 낮은 스레드에 의해 차단될 수 있습니다. 예를 들어 nice 값이 -19인 스레드는 기본 nice 값이 0인 스레드에 의해 차단될 수 있습니다.
트랜잭션 우선순위 상속은 트랜잭션을 처리하는 바인더 스레드의 우선순위를 호출자의 우선순위와 일치하도록 바인더 드라이버가 일시적으로 변경하므로 이 문제를 수정합니다. 트랜잭션이 완료되면 바인더 드라이버는 바인더 스레드의 우선순위를 이전 값으로 복원합니다.
노드 우선순위 상속
지연 시간이 짧아야 하는 상황과 같은 일부 상황에서는 비동기 트랜잭션의 우선순위가 중요합니다.
노드 우선순위 상속을 사용하면 노드의 모든 트랜잭션이 실행되어야 하는 최소 우선순위를 구성할 수 있습니다. 노드 우선순위 상속이 구성되면 노드의 모든 트랜잭션이 이 최소 우선순위로 실행됩니다.
노드 우선순위 상속 규칙은 다음과 같습니다.
트랜잭션이 동기식인 경우 우선순위는 max(min_node_priority, caller_priority);가 됩니다.
트랜잭션이 비동기인 경우 우선순위는 max(default_priority (nice 0), min_node_priority);가 됩니다.
Android는 SCHED_FIFO와 같은 실시간 예약 정책을 사용하여 지연 시간에 민감한 스레드가 제때 작업을 완료하도록 합니다. 또한 Android의 지연 시간에 민감한 작업 중 일부는 두 개 이상의 프로세스로 분할됩니다.
실시간 우선순위 상속은 다음을 제외하고 nice 값과 동일하게 작동합니다.
실시간 우선순위 상속은 기본적으로 사용 중지되어 있습니다.
실시간 우선순위 값이 클수록 작은 값보다 우선순위가 높습니다.
실시간 우선순위 상속 사용 설정
실시간 우선순위 상속은 BBinder::setInheritRt(true) 호출을 사용하여 개별 노드에 사용 설정해야 합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-30(UTC)
[null,null,["최종 업데이트: 2025-07-30(UTC)"],[],[],null,["# Priority inheritance\n\n*Priority inversion* is a situation where a high-priority transaction is\ndelayed by a low-priority task because the low-priority task holds a\nresource needed by the high-priority task. To mitigate priority inversion,\nAndroid supports running threads at different priorities through\nthree different forms of priority inheritance: transaction\npriority inheritance, node priority inheritance, and real-time priority\ninheritance.\n\nThis page explains these different forms of priority inheritance.\n\nTransaction priority inheritance\n--------------------------------\n\nWhen making a synchronous binder call, a high-priority thread can be blocked\nby a low-priority thread until the low-priority thread has sent a reply. For\nexample, a thread with a nice value of -19 can become blocked by a thread with a\ndefault nice value of 0.\n\n*Transaction priority inheritance* fixes this issue because the binder driver\ntemporarily changes the priority of the binder thread handling the transaction\nto match the priority of the caller. When the transaction is done, the binder\ndriver restores the priority of the binder thread to its previous value.\n| **Note:** In an asynchronous transaction, a binder thread doesn't inherit the priority from the caller because an asynchronous transaction doesn't block the caller. While it might be important for the caller to complete the asynchronous transaction as soon as possible, the actual handling of the transaction might not be latency critical, and it would be unnecessary to run the handling thread at a high-priority.\n\nNode priority inheritance\n-------------------------\n\nIn some situations, such as those that require low latency, the\npriority of asynchronous transactions matters.\n\n*Node priority inheritance* lets you configure the minimum priority that all\ntransactions on a node should run at. After node priority inheritance is\nconfigured, all transactions on the node run at this minimum priority.\n| **Note:** If the caller has a higher priority than the node for a synchronous transaction, transactions on the node might run at a higher priority than the node priority inheritance.\n\nThe rules for node priority inheritance are:\n\n- If the transaction is synchronous, the priority becomes\n `max(min_node_priority, caller_priority);`.\n\n- If the transaction is asynchronous, the priority becomes\n `max(default_priority (nice 0), min_node_priority);`.\n\n| **Note:** Real-time priority is always greater than any nice value with a non-real-time priority.\n\n### Configure node priority inheritance\n\nTo configure node priority inheritance, use `BBinder::setMinSchedulerPolicy`.\n\nReal-time priority inheritance\n------------------------------\n\nAndroid uses real-time scheduling policies, such as `SCHED_FIFO`, to cause\nlatency-critical threads to complete their work in time. Additionally, some of\nAndroid's latency-critical work is split over two or more processes.\n\n*Real-time priority inheritance* works identically to nice values, except:\n\n- Real-time priority inheritance is disabled by default.\n- Greater real-time priority values have higher priority than smaller values.\n\n### Enable real-time priority inheritance\n\nReal-time priority inheritance must be enabled for individual nodes\nusing the `BBinder::setInheritRt(true)` call."]]