Semaphore in Scull
Scenario :Writer application must execute before the reader application.
There are two applications which have to perform several operations on the node
1. Application 1: Application 1 is a multithreaded application in which open() , write() and close() functions are called in multiple threads.And because this has to be done in this specific order ,synchronization is achieved with the help of thread semaphores.
2.Application 2:Application 2 is also a multithreaded application in which open() , read() and close() functions are also called in multiple threads and synchronization between them is achieved by thread semaphores.
As these two multi-threaded applications issues open() call.There is a need to implement the semaphores at the kernel level also .
RCS file: openf.c,v
Working file: openf.c
head: 1.15
branch:
locks: strict
root: 1.15
access list:
symbolic names:
keyword substitution: kv
total revisions: 15; selected revisions: 15
description:
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.
—————————-
revision 1.15 locked by: root;
date: 2014/03/07 19:18:40; author: root; state: Exp; lines: +1 -1
If the application issues open() system call in O_RDONLY mode , then it decrements the value of the semaphore sem which is initialized with 0 and blocks itself untill the writer executes up() on the same semaphore.
Status : chardev_open() , chardev_write() and chardev_read() are perfectly synchronized.
—————————-
revision 1.14
date: 2014/03/07 19:12:31; author: root; state: Exp; lines: +12 -15
Logical bug fixed.
Issue:&& is used instead of & while bitwise ANDing O_ACCMODE with filep->f_flags.
Also added a check for O_RDONLY mode.
Status : Open is working correctly.
—————————-
revision 1.13
date: 2014/03/01 20:24:26; author: root; state: Exp; lines: +12 -4
Compilation successfull and chardev_trim() function is working fine.
Issue:Trying the free the memory that is not allocated in case of quantum.
Logical error fixed.
—————————-
revision 1.12
date: 2014/03/01 19:41:54; author: root; state: Exp; lines: +4 -0
kernel crash taking place inside chardev_trim() function.
Issue inside chardev_trim() function.
Debugging……………………………
—————————-
revision 1.11
date: 2014/03/01 19:38:30; author: root; state: Exp; lines: +1 -1
Syntax error fixed.
Issue:Missing semicolon.
—————————-
revision 1.10
date: 2014/03/01 19:37:04; author: root; state: Exp; lines: +12 -4
One bug fixed.
Issue:qset_size variable is included using extern.
Debugging…..
—————————-
revision 1.9
date: 2014/03/01 13:09:52; author: root; state: Exp; lines: +49 -3
Implementing chardev_trim() function.Inside this function,firstly certain checks are made to make sure that Sculldec , scullqset , qset and quantums exist or not.
If any of such things do not exist an error message is reported.Now performing trimming………..
—————————-
revision 1.8
date: 2014/03/01 12:08:22; author: root; state: Exp; lines: +23 -1
Two printk statements are added inside the chardev_trim() function to mark its beginning and end.
Checking……….
—————————-
revision 1.7
date: 2014/03/01 11:57:45; author: root; state: Exp; lines: +5 -0
O_ACCMODE is a macro that stands for a mask that can be bitwise-ANDed with the file status flag value to produce a value representing the file access mode.The mode will be O_WRONLY,O_RDONLY or O_RDWR.
The O_ACCMODE macro is used inside the chardev_open() function to find out the file access mode.
—————————-
revision 1.6
date: 2014/03/01 08:45:54; author: root; state: Exp; lines: +5 -1
Printing the address stored inside the lsculldev to check whether it matches with the filep->private data address printed inside the chardev_release() function.
—————————-
revision 1.5
date: 2014/03/01 08:33:40; author: root; state: Exp; lines: +1 -0
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access .
—————————-
revision 1.4
date: 2014/03/01 08:25:52; author: root; state: Exp; lines: +11 -4
A local variable of type struct Sculldev is declared.
Used container_of() inside the open function.This macro has 3 arguments:
1.A pointer to a field named container_field.
2.This container field within a structure of type container_type,and
3.ccontainer field.
On success it returns a pointer to the containing structure.
—————————-
revision 1.3
date: 2014/02/28 18:51:08; author: root; state: Exp; lines: +2 -0
Included the prototype of chardev_open() using extern.
—————————-
revision 1.2
date: 2014/02/28 18:42:56; author: root; state: Exp; lines: +15 -0
Two printk statements are used to test that whether the open function is actually begin and ended.\
—————————-
revision 1.1
date: 2014/02/28 18:33:28; author: root; state: Exp;
Initial revision
=============================================================================
/home/Deepak/Desktop/wror