Add worksource support to binder calls.
Unlike android.os.WorkSource, we only support the leaf UID of the work chain here for performance reasons. We use a similar mechanism to how we propagate the StrictMode flags. The enforceInterface and writeInterfaceToken are used to pass the worksource through the parcel. enforceInterface/writeInterfaceToken is at least used by all the services using AIDL. It might break code which is reading/writing raw parcels. For instance, a client calling an AIDL service and replicating what enforceInterface is doing, e.g. service_manager.c. This is the only client which seems to do that. Here is an example of how this API is supposed to be used: Binder.setThreadWorkSource(uid); try { // Call an API. } finally { Binder.clearThreadWorkSource(); } An alternative would be to clear the work source automatically on behalf of the caller. Manually setting the work source has been chosen to give more control to callers of the API: - they might choose to call setThreadWorkSource once and do multiple binder calls - callers can also decide whether they want to restore the work source to the orginal value. We do not throw an exception when #setThreadWorkSource overrides an existing work source. It would be really hard to figure when it is safe to call #setThreadWorkSource. For instance, adding a binder transaction might make some code down the line that calls #setThreadWorkSource throw an exception (because the binder transaction would set the work source on the thread). Ran the binder performance test suite (test/vts-testcase/performance/binder_benchmark/binder_performance_test/). There is no difference in terms of cpu/real time: - without patch { "name": "BM_sendVec_binder/4", "iterations": 43088, "real_time": 3.0151086752702871e+04, // yes, time is higher without patch "cpu_time": 1.4715999326958785e+04, "time_unit": "ns" { "name": "BM_sendVec_binder/8", "iterations": 48335, "real_time": 2.8371138740033064e+04, "cpu_time": 1.3710703486086690e+04, "time_unit": "ns" }, - with patch { "name": "BM_sendVec_binder/4", "iterations": 48214, "real_time": 2.8613625191853276e+04, "cpu_time": 1.4305279856473226e+04, "time_unit": "ns" }, { "name": "BM_sendVec_binder/8", "iterations": 49998, "real_time": 2.8749066382655215e+04, "cpu_time": 1.4422315992639707e+04, "time_unit": "ns" }, Test: unit tests and manually tested on my phone Change-Id: I167abbbfa6e7c4b0933c4cafa04df810f4814e2b
Loading
Please register or sign in to comment