参考文章:
http://www.cnblogs.com/samchen2009/p/3316001.html

test_server服务进程可能有多个线程,而在发送数据的时候handle只表示了那个进程

(1)发给谁?handle只表示了那个进程,数据是发给进程还是某个线程

一般数据放在binder_proc的todo链表,其会唤醒等待与binder_proc.wait上的空闲线程;

对于双向传输,则放在binder_thread.todo链表上,然后唤醒该线程(用transaction_stack来判断是否是双向传输)

(2)回复给谁?没有handle表示目的进程,必定在某个地方记录之前的发送者

某个地方就是transaction_stack

test_client步骤分析:

(1)发送BC_TRANSACTION类型数据

 a、单进程也会有一个binder_thread,其在调用ioctl的时候被创建,其thread->transaction_stack开始为空,表示非双向传输。

b、入栈 test_client里面的binder_thread.transaction_stack结构,其指向的就是binder_transaction结构体,binder_transaction结构体的成员from_parent = transaction_stack,刚开始为null、from=test_client、to_proc=test_server、to_thread = thread(test_server的某个线程,单线程的时候就是test_server)

c、数据将放在test_server的binder_proc.todo链表中;唤醒test_server的binder_proc.wait上的线程

(4)接受BR_REPLY类型数据

唤醒后返回给用户空间,不涉及栈

test_server步骤分析:

(2)接受BR_TRANSACTION类型数据

在binder_thread_read函数中做如下事情:

a、从test_server的binder_proc.todo链表中取出数据处理

b、入栈 test_server里面的binder_thread.transaction_stack结构,其指向的就是binder_transaction结构体,binder_transaction结构体的成员to_parent = transaction_stack,刚开始为null、from=test_client、to_proc=test_server、to_thread = thread((test_server的某个线程,单线程的时候就是test_server))

(这里的binder_transaction和test_client中的binder_transaction是一个,通过from_parent放入发送者的栈,通过to_parent放入接受者的栈,transaction_stack的字面意思就是传输栈)

(3)发送BC_REPLY类型数据

a、发送给谁:从栈中取出binder_transaction,其中from=test_client、to_proc=test_server、to_thread = thread,可知要回复给前面的发送者test_client

b、出栈, test_server里面的binder_thread.transaction_stack结构等于in_reliy_to->to_parent,其为NULL,即transaction_stack等于NULL

c、数据copy_from_user进内核态传给test_client

d、出栈, test_client里面的binder_thread.transaction_stack结构等于transaction_stack->from_parent,其为NULL,即transaction_stack等于NULL

e、放入todo链表,唤醒

在双向传输过程中transaction_stack的作用

P1进程提供S1服务,其有线程t1、t11

P2进程提供S2服务,其有线程t2、t22

P3进程提供S3服务,其有线程t3、t33

假设:t1线程要使用S2服务,它会给t2线程发送数据,t2线程在处理过程中要用到S3服务,它会给t2线程发送数据,如果t3线程又要用到S1服务,这个时候t3是给t1还是新建个线程t11发送数据呢

如果新建一个线程,那么只要调用S1服务就新建一次,这样太浪费资源了,所以t3是给t1发送数据,这就是双向传输

即:P1的t1发送服务请求后休眠,在服务处理过程中又用到S1服务,会发送服务请求给P1的t1来处理S1服务

情景分析:

一、t1传送binder_transaction1结构体给t2:

(1)t1发送BC_TRANSACTION

  t1.sp(栈).binder_transaction1.form_parent = NULL

  binder_transaction1.from = t1;

  binder_transaction1.to_proc = P2;

  binder_transaction1.from_parent = NULL;

(4)收到t3的BR_TRANSACTION

  t1.sp(栈).binder_transaction3.to_parent = binder_transaction1

(5)t1发出BC_REPLY

  出栈:t1.sp(栈).binder_transaction1.form_parent = NULL

  出栈:t3.sp(栈).binder_transaction2.to_parent =NULL

(8)t1收到t2的BR_REPLY 处理完毕

二、t2接受t1的binder_transaction1,然后发送binder_transaction2给t2

(2)t2接受BR_TRANSACTION

  t2.sp(栈).binder_transaction1.to_parent = NULL

 t2发送BC_TRANSACTION

  t2.sp(栈).binder_transaction2.from_parent = binder_transaction1

  binder_transaction2.from = t2;

  binder_transaction2.to_proc = P3;

  binder_transaction2.from_parent = binder_transaction1;

(7)t2收到t3的BR_REPLY

 处理binder_transaction2,从t3.sp中取出binder_transaction1(栈顶),其成员from为t1,所以发出BC_REPLY给t1

  出栈:t2.sp(栈) = NULL

  出栈:t1.sp(栈) =NULL

(三)t3接受t2的binder_transaction2,然后发送binder_transaction3给t1(经过一窜代码分析出来是发给t1,不是发给P1,见图)

(3)t3接受BR_TRANSACTION

  t3.sp(栈).binder_transaction2.to_parent = NULL

 t3发送BC_TRANSACTION

  t3.sp(栈).binder_transaction3.from_parent = binder_transaction2

  binder_transaction3.from = t3;

  binder_transaction3.to_proc = P1;

  binder_transaction3.to_thread= t1;

(6)t3收到t1发送的BR_REPLY

 处理binder_transaction1,从t2.sp中取出binder_transaction2(栈顶),其成员from为t2,所以发出BC_REPLY给t2

  出栈:t3.sp(栈) = NULL

  出栈:t2.sp(栈).binder_transaction1.to_parent =NULL

9.5 Binder系统_驱动情景分析_transaction_stack机制的更多相关文章

  1. 9.2 Binder系统_驱动情景分析_服务注册过程

    1. 几个重要结构体的引入给test_server添加一个goodbye服务, 由此引入以下概念: 进程间通信其实质也是需要三要素:源.目的.数据,源是自己,目的用handle表示:通讯的过程是源向实 ...

  2. 9.6 Binder系统_驱动情景分析_server的多线程实现

    当多个client对server发出请求的时候,如果server忙不过来的时候会创建多线程来处理请求 那么忙不过来由谁来判断? server进程有个binder_proc结构体,其里面有todo链表( ...

  3. 9.3 Binder系统_驱动情景分析_服务获取过程

    4. 服务获取过程 test_client客户端: (1)在用户态先构造name=“hello”的数据(服务的名字是hello),调用ioctl发送数据给service_manager(handle= ...

  4. 9.4 Binder系统_驱动情景分析_服务使用过程

    5. 服务使用过程 test_client进程: 用户态: (1)已结获得了“hello”服务,handle=1; (2)构造数据:code(那个函数)和函数参数 (3)发送ioctl后进入内核态,先 ...

  5. Android系统--Binder系统具体框架分析(二)Binder驱动情景分析

    Android系统--Binder系统具体框架分析(二)Binder驱动情景分析 1. Binder驱动情景分析 1.1 进程间通信三要素 源 目的:handle表示"服务",即向 ...

  6. Android : 跟我学Binder --- (4) 驱动情景分析

    目录: Android : 跟我学Binder --- (1) 什么是Binder IPC?为何要使用Binder机制? Android : 跟我学Binder --- (2) AIDL分析及手动实现 ...

  7. 9.11 Binder系统_分层

    1.Binder系统过程分析,情景分析 server提供服务 (1)addService(服务名称,xxx)执行后会导致binder驱动在server的内核空间为服务创建一个binder_node结构 ...

  8. 10.7 android输入系统_Dispatcher线程情景分析_Reader线程传递事件和dispatch前处理

    android输入系统C++最上层文件是com_android_serve_input_InputManagerService.cpp global key:按下按键,启动某个APP可以自己指定,修改 ...

  9. [RK3288][Android6.0] 系统按键驱动流程分析【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/77894406 Rockchip的按键驱动位于 kernel/drivers/input/ke ...

随机推荐

  1. js---10作用域链

    <html> <head> <title>scope basic</title> </head> <body> <scri ...

  2. vue中关于prop

    组件之间的项目通信在vue中十分常见,父组件的数据传到子组件需要prop的支持,我们来看下prop 1.html的特性名大小写不敏感,浏览器会把所有大写字母解释为小写字母,使用dom模板时,使用等价的 ...

  3. CSS3的属性选择器

    CSS3中新增了许多选择器,今天零度给大家说说CSS3的属性选择器. 与CSS2相比,CSS3新增了3种属性选择器:[attr^=value].[attr$=value].[attr*=value]: ...

  4. pip 更新安装失败解决方法

    python3 -m ensurepip https://stackoverflow.com/questions/28664082/python-no-module-pip-main-error-wh ...

  5. 今日题解------uvalive 2689

    今天学到了代码以外的东西,就是你在vj上挂了content ,然后你想更新它,你就要刷新一下,不然你提交的那题可能提交到别的地方. 好了回到重点,本题的题意是: #include<bits/st ...

  6. 洛谷——P1307 数字反转

    https://www.luogu.org/problem/show?pid=1307#sub 题目描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数的常见形式,即除非给定的原 ...

  7. poj3244(公式题)

    Difference between Triplets Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2476   Acce ...

  8. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 托管代码(.NET)

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览  托管代码(.NET)         在SP2010中,微软提 ...

  9. vmware-虚拟机播放器的下载、安装

    如果是在window下安装的话: 1.下载vmware: 到官网下载免费个人版本 https://my.vmware.com/cn/web/vmware/free#desktop_end_user_c ...

  10. 在IE中opacity透明度

    body{ background: red; opacity: 0.5; filter:alpha(opacity=50); } jQuery: if($.support.opacity == tur ...