OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Sep 23, 2017 7:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Multitask Floppy Driver
PostPosted: Mon Dec 19, 2005 2:43 pm 
hello...
My kernel is now able to run different tasks at a time. All my tasks are void functions() which are running simultaneously. I need a floppy driver to load programs from floppy.
I have a floppy driver which i coded before i started multitasking. So now its not that useful.
Can anyone tell me how to design (I repeat design as i know the code) a floppy driver for a multitask environment.

A floppy read_or_write() function must wait for interrupt from fdc, so when we wait for that interrupt the Timer can preempt the current process. So how to deal with this?


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Mon Dec 19, 2005 2:47 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5959
Location: In a galaxy, far, far away
i suggest you grab Tim Robinson's code from the Mobius. He did a quite great job about how to do disk I/Os in a multithreaded environment by the use of request queues, buffer lists, state machines and the like.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Mon Dec 19, 2005 3:29 pm 
Thanks for the instant reply...
I have gone through that code.. But can grab it. Can you tell me the steps to follow. I guess:

1. When a process tries to read from floppy, add a read request like (read, FLOPPY_A, LBA: 50, BUFFER: b, PROCESS:pid) into a queue.

2. Now their may be a task which will continuosly scan this queue and execute an acctual read command to floppy.

3. Process will resume when its read request will be executed successfully.

I know this is not totally correct. Plz give me the steps to do it.


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Mon Dec 19, 2005 3:50 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8077
Location: At his keyboard!
Hi,

viral wrote:
My kernel is now able to run different tasks at a time. All my tasks are void functions() which are running simultaneously. I need a floppy driver to load programs from floppy.
I have a floppy driver which i coded before i started multitasking. So now its not that useful.
Can anyone tell me how to design (I repeat design as i know the code) a floppy driver for a multitask environment.


I'm not too sure if this is useful for you (you may have already done it), but instead of designing the floppy driver I'd suggest designing some form of generic storage device driver interface.

This interface would include low-level facilities for reading/writing raw sectors, handling "media changed" notification, formatting the device, etc.

The same thing applies to file systems - design a common interface and make all file system code comply with it. If this is done correctly, any normal code (applications, etc) should be able to use any file system without caring what it actually is, and any file system code should be able to use any storage device driver (without caring what it actually is).

For most OSs, the "storage device driver specification" and the "file I/O specification" are very closely related, and sometimes they are the same thing (e.g. combined into some sort of "Virtual File System Interface"). This is (IMHO) a better way to do things - it allows you to treat devices and files the same way. For e.g. mounting a file, or copying raw disk images to/from devices.

In the end, writing a device driver means following the interface specification on the OSs side, and following the manufacturers specification on the hardware side. This shouldn't leave much to "design"...

viral wrote:
A floppy read_or_write() function must wait for interrupt from fdc, so when we wait for that interrupt the Timer can preempt the current process. So how to deal with this?


First, I'd ask why it matters if the floppy driver is pre-empted (it'd get control back when the IRQ arrives).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Tue Dec 20, 2005 3:52 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5959
Location: In a galaxy, far, far away
viral wrote:
2. Now their may be a task which will continuosly scan this queue and execute an acctual read command to floppy.


Yes, that's somehow the idea ... yet it don't need to be a "task" running: it can all be done in interrupt handlers. E.g. when floppy IRQ (6? is that the one?) is received,
- either it means the current request is completed, in which case, get the next request from the queue and start processing it
- or it means we've performed one more step in the current request, in which case, let's just issue the commands until the next step.

i once wrote a teacup about it. it was too technical for most ppl on MT, but you might enjoy it.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Tue Dec 20, 2005 1:12 pm 
Hi...
Thanks for the reply. Now i got that all I have to do is to code most of the things in floppy ISR. So my driver will be divided into two part. One USER side and other KERNEL side. Both this part will communicate thrw a queue in which request will be stored.

USER SIDE
|
REQUEST QUEUE
|
KERNEL
|
FLOPPY CONTROLLER

I am not getting one thing here. When a user process wants to read or write some sector, it will send a request into REQUEST QUEUE. Now what this process will do ? Ofcourse it should wait for the request to complete. Then how will KERNEL notify the process that "your request has or has'nt been completed".
The floppy ISR will take one by one request from the queue and process it, but how will it notify the completion of the request to its appropriate process ?


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Tue Dec 20, 2005 1:33 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3860
Location: Eindhoven
viral wrote:
Hi...
Thanks for the reply. Now i got that all I have to do is to code most of the things in floppy ISR. So my driver will be divided into two part. One USER side and other KERNEL side. Both this part will communicate thrw a queue in which request will be stored.

USER SIDE
|
REQUEST QUEUE
|
KERNEL
|
FLOPPY CONTROLLER

I am not getting one thing here. When a user process wants to read or write some sector, it will send a request into REQUEST QUEUE. Now what this process will do ? Ofcourse it should wait for the request to complete. Then how will KERNEL notify the process that "your request has or has'nt been completed".
The floppy ISR will take one by one request from the queue and process it, but how will it notify the completion of the request to its appropriate process ?


The user program calls the kernel call "write". It sees it can't satisfy the request directly and sends a message to the floppy driver "read this for me to this bit of memory and send me a signal when you're done". Then it sends the process manager a message "I would like to stop processing" or sleep. When it's woken up the floppy driver is done and it can return.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Tue Dec 20, 2005 2:25 pm 
Hello....
Its fine that the USER Process sends a READ system call to kernel and then go to sleep untill its request has been satisfied.
As right now i dont have any IPC so how this process will woke up after completion of request. What I get is something like this:

USER PROCESS:

asm(" int READ_SOMETHING_FROM_FLOPPY");
while(REQUEST_IS_NOT_COMPLETED);

Another thing that can be done is as Candy has suggested. I dont know how will u accomplish it thrw Process_Manager ?


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Tue Dec 20, 2005 2:30 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3860
Location: Eindhoven
viral wrote:
Hello....
Its fine that the USER Process sends a READ system call to kernel and then go to sleep untill its request has been satisfied.
As right now i dont have any IPC so how this process will woke up after completion of request. What I get is something like this:

USER PROCESS:

asm(" int READ_SOMETHING_FROM_FLOPPY");
while(REQUEST_IS_NOT_COMPLETED);

Another thing that can be done is as Candy has suggested. I dont know how will u accomplish it thrw Process_Manager ?



Well. the idea requires a kernel that can multitask or multithread. You need to have some thing I called the "process manager" that keeps track of processes and threads and that can accept "wake-up" signals for threads or processes.

If you can't do that, you'll have to do busy-waiting (while not done; do nothing; repeat) or halt in awaital of an interrupt. If you don't receive an interrupt, you're screwed. You could also abuse the timer interrupt as a form of timeout, it's also an interrupt.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Wed Dec 21, 2005 1:43 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5959
Location: In a galaxy, far, far away
what you have described is the "asynchronous I/O model":
Code:
    syscall(READ_SOMETHING_FROM_FILE_OR_DEVICE);
    while(syscall(DATA_NOT_AVAILABLE)) {
        do_something_else();
    }


There are of course cases where this is useful, but most of the time what you simply need is
Code:
    syscall(READ_AND_WAIT_IF_DATA_NOT_AVAILABLE);

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Wed Dec 21, 2005 4:09 pm 
Ya I should desing some system call that wait untill request is not over.
like syscall(READ_AND_WAIT_IF_DATA_NOT_AVAILABLE);

I have faced a new problem solving this stuff. My scheduler codes are running inside a timer interrupt.

timerhandler:
push_everything
call _scheduler_from_c_file
pop_everything
iret
Here when a task wants to pre-empt itself (in order to wait for IO), this timerhandler is to be called explicitly. As my _scheduler_from_c() function only exchange the stack pointers, remaining work depends on "iret" of timerhandler.

What i need is something like this

int _scheduler: ;; System call for scheduler
push_ever
call _scheduler_from_c
pop_ever
iret

timerhandler:
int _scheduler
iret

I tried this but it was not working...... Please give me some idea about relation between scheduler codes and timer handler. So that if my process say P1 wants to pre-empt, it just need to call int _scheduler and not int timerhandler.


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Wed Dec 21, 2005 4:24 pm 
hi,

I'm not sure if I understood what you, but that sysall can't be solved just via the timer interrupt. You need a seperate mechanism for syscalls (say an other interrupt like 0x80 under linux or so). So you execute an int 0x80 instruction for example and this will remove your process from the "running process"-list and will also call the scheduler to schedule an other process...

Hope that helped,
Enjoy ;)


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Thu Dec 22, 2005 1:46 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5959
Location: In a galaxy, far, far away
the problem that's likely to arise when one adds voluntary suspend to a scheduler that initially operate only from IRQ is the end-of-interrupt signal. Say you're getting out of a thread due to timer IRQ, the PIC is waiting for some EOI that is usually emitted at the end of the ISR, but the ISR doesn't end here! instead the CPU executes the resume code for some suspended process that gently returns to userlevel ... and the CPU will never get a IRQ0 anymore because the PIC is still waiting for an EOI.


The solution is fairly simple though: just make sure your IRQ0 timer acknowledges the IRQ _before_ the scheduling code is called.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Thu Dec 22, 2005 2:40 am 
Hello
Pype.. I guess what u mean is that ,i should place my scheduler code in a sys call (say interrupt 0x80) and then call this from timer handler after acknowledge it.

int 0x80: //my scheduler
.
.
iret

int timerhandler:
.
.
out 0x20 , 0x20
int 0x80
.
.
iret


Just tell me where should i place my scheduler code which swaps the stacks and do iret ?


Top
  
 
 Post subject: Re:Multitask Floppy Driver
PostPosted: Thu Dec 22, 2005 2:50 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5959
Location: In a galaxy, far, far away
more or less ... except you usually don't re-use INTxxx from an IRQ ... Instead you'll more have

Code:
; should be an INT gate in the IDT
IRQ0_handler:
    push_everything
    call update_localtime
    call update_thread_quota
    out 0x20,0x20
    jne .keep_going_on
    call schedule_me_out
.keep_going_on
    pop_everything
    iret


Code:
; should be a TRAP gate in the IDT
syscall_suspend_handler:
    push_everything
    call schedule_me_out
    pop_everything
    iret


the kernel's internal "schedule me out" function can be also called from other places such as semaphore code or whatever. It will basically turn the thread's state into "sleeping" and put it in some "synchronizing object"'s waiting queue where another thread can retrieve it, put it state back to "ready" and re-insert it in the scheduler's queue.

_________________
Image May the source be with you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group