ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:18.84KB ,
资源ID:12576955      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12576955.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux设备驱动第五章并发和竞争读书笔记Linux device drivers fifth chapters concurrency and compe.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Linux设备驱动第五章并发和竞争读书笔记Linux device drivers fifth chapters concurrency and compe.docx

1、Linux设备驱动第五章并发和竞争读书笔记Linux device drivers fifth chapters concurrency and compeLinux设备驱动第五章(并发和竞争)读书笔记(Linux device drivers, fifth chapters (concurrency and competition), reading notes)The fifth chapter is concurrency and competitionReference article: Id=408682?5.3 flags and mutex1) flag is the core

2、of a single integer value. Combined with a pair of functions, also known as PV operations.One wants to enter the critical section of the P process with the flag raised, if the flag value is greater than 0, this value decreased 1, and the process continues. If the flag is small than or equal to 0, in

3、dicating that the flag has been occupied by other processes, the process must wait until the flag is released.Unlock the flag, flag is released, to complete the operation by calling the V V operation, increasing the value of the flag, and the flag can wake up waiting process.2) mutex function is: mu

4、tual exclusion, to prevent multiple processes simultaneously in the same critical area. The mutex is initialized to 1 flags. Because that is initialized to 1, when the first process of P, 10, so the process can run at the same time, the flag value is 0, 1 decline, the second process to obtain the fl

5、ag is used to access the critical section, but found that the flag value is 0, so the process can not run until the 2 release of the flag process 1.5.3.1 implementation of the LINUX flag1) to use the flag, must type contains . is related to the struct semaphore;2) the flag: create a flag, then use s

6、ema_init to set itSuch as:Struct semaphore *sem; / / define flagSema_init (SEM, Val); / / initialize Val to initialize the value of flag flag.3) usually, flag is used to model the mutex. As a result, the kernel provides a series of macros to initialize.DECLARE_MUTEX (name); / / initialize a mutex, a

7、 value of 1DECLARE_MUTEX_LOCKED (name); / / initialize a mutex, a value of 0 is: flag after initialization is not available.To use this flag any process must first unlock it again.When we need to initialize at runtime (that is, dynamic creation), we use the:Void init_MUTEX (struct semaphore *sem); /

8、 / initialize a mutex, a value of 1Void init_MUTEX_LOCKED (struct semaphore *sem); initializes a mutex with the value of 0For example, we want to create a mutex that is initialized to 0:Struct semaphore *sem; / / define flagECLARE_MUTEX_LOCKED (SEM); / / initialize flag value is 0.The above is the i

9、nitialization flag, after initialization of course we must use the flag, or create it what is the significance?4) flag acquisition and release (can also be a mutex, because basically all flags are used to LINUX mutex)Get the flag also known as P, also called down. Down literally means drop. The flag

10、 is minus 1.The P function is as follows:Void down (struct semaphore *sem); / * is not recommended, will establish not kill process * /Int down_interruptible (struct semaphore *sem); / * recommended the use of down_interruptible need to be careful, if the operation is interrupted, the function retur

11、ns a nonzero value, and it will not have the call signal. The proper use of down_interruptible requires always checking the return value and responding accordingly. * /Int down_trylock (struct semaphore *sem); / * with _trylock never sleeps, if the signal is not available in the call, will return a

12、nonzero value. * /We usually use the down_interruptible function. Recommended drops in the book.Once the flag, the flag of the obtaining process can access the critical area to protect the flag. What do you do when you use it? Of course is to control the discarded in the critical region, is also the

13、 release flag.The release flag also known as V, also called UP up, literally rise.The flag is 1. (down and up description of the image of the flag operation).The V function is as follows:Void up (struct, semaphore, *sem);Once called UP, will not have the flag in the process.5) use flags are easy to

14、make mistakesGet the process to release the flag flag using the call to UP, but not many call UP, that is: a down for a UP.In the hold flag when an error is encountered, we must be in the return (error state) is to call UP release flag, otherwise the critical region has been the process of possessio

15、n, but perhaps the process has been kill, and the other to the use of critical areas will be due process has not been suspended critical region.5.3.2. in scull using the flagThe key to the correct use of the lock primitive is to specify exactly what resources to protect and confirm that each access

16、to these resources uses the correct locking methodFirst of all, look at a scull structure:Struct scull_dev Struct scull_qset *data Pointer to first quantum set; / * * /Int quantum the current quantum size; / * * /Int qset the current array size; / * * /Unsigned long size amount of data stored here;

17、/ * * /Unsigned int access_key used by sculluid and scullpriv; / * * /Struct semaphore SEM mutual exclusion semaphore; / * * /Struct CDEV CDEV Char device structure; / * * /;Struct semaphore SEM is our flag, and this structure is the object we want to protect the.Flag must be initialized before use.

18、 Scull this initialization at load time, in this cycle:For (I = 0; I sem)Return -ERESTARTSYS;Note that the return value of the examination of the down_interruptible; if it returns non-zero, the operation was interrupted. Usually do in this case is to return to -ERESTARTSYS. to see the return value,

19、the kernel or restart the call from the top or return the error to the user. If you return -ERESTARTSYS, you must first restore any user visible has been done to change, to ensure that when the right things happen again when the system call. If you cannot recover in this way, you should be back for

20、-EINTR.When we finished using the critical area, the wirte function must release the flag,Whether it succeeds or fails when we use the write function, for example, kmalloc fails to allocate memory, and copy_form_uesr fails from user space copy data. Remember: be sure to release the flag.Code:Out:Up

21、(&dev-sem);Return retval;When you encounter a different error, use the goto statement to jump to out.Also, you must make sure that you do not access the scull_dev structure when you dont have semaphores.5.3.3 reader / writer flagFlag for all caller exclusive, but sometimes we can think: what is the

22、flag? In general, we used in the access to the critical section, because if there is no flag, can process 1 has just completed the revision of a process variable, 2 and modified the same variable, leading to the later data on the front of the data to cover. Just like the examples in 5.1. scull. But

23、when we read only, we only allow one process to read, which makes it inefficient. Therefore, the reader / writer flag.The reader / write flag: we can realize the concurrent read exclusive write, but only. Improved efficiency. The read-only tasks can work in parallel without waiting for other readers

24、 to exit the critical area1) use rwsem to include .2) initialize a rwsem.Void init_rwsem (struct, rw_semaphore, *sem);3) function as follows:The interface that requires read-only access to the code is:Void down_read (struct, rw_semaphore, *sem);Int down_read_trylock (struct, rw_semaphore, *sem);Void

25、 up_read (struct, rw_semaphore, *sem);Provides read-only access to protected resources of the down_read call can access concurrently with other readers. Note that the down_read may be set to the calling process can not be interrupted sleep. If the down_read_trylock is not waiting for the read access

26、 is not available; if allowed to access it returns non-zero, otherwise it is 0. down_read_trylock convention different from most of the kernel function, a return value of 0 indicates success. The use of a down_read to obtain the rwsem must eventually use up_read release.The readers interface is simi

27、lar:Void down_write (struct, rw_semaphore, *sem);Int down_write_trylock (struct, rw_semaphore, *sem);Void up_write (struct, rw_semaphore, *sem);Void downgrade_write (struct, rw_semaphore, *sem);Down_write, down_write_trylock, and up_write all like their readers corresponding part, besides, of course

28、, they provide write access. If you are in such a situation, the need for a write lock to do a quick change, then read-only access for a long time, you can use downgrade_write once you have completed the change in allow other readers to enter.4) rwsem uses relatively little in driving, but sometimes they are useful. Rwsem allows multiple readers to hold the flag, and write a priority, when a writer trying to get the flag, it does not allow readers to enter until the write completes the work. But it can lead

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1