OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:37 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: How to write a disk driver can serve a batch of requests?
PostPosted: Thu Jan 05, 2017 10:19 am 
Offline

Joined: Wed Sep 09, 2015 4:51 am
Posts: 2
Hey guys, I am playing with the xv6 kernel and want to improve its IDE disk driver. The xv6 doc said ''Modern disk controllers typically accept a batch of disk requests at a time", and that is my goal. But as far as I know, IDE driver uses in/out instructions to communicate with disk, as the following code shows:
Code:
  idewait(0);// wait for IDE disk to become ready.
  outb(0x3f6, 0);  // generate interrupt
  outb(0x1f2, sector_per_block);  // number of sectors
  outb(0x1f3, sector & 0xff);
  outb(0x1f4, (sector >> 8) & 0xff);
  outb(0x1f5, (sector >> 16) & 0xff);
  outb(0x1f6, 0xe0 | ((b->dev&1)<<4) | ((sector>>24)&0x0f));
  if(b->flags & B_DIRTY){
    outb(0x1f7, IDE_CMD_WRITE);
    outsl(0x1f0, b->data, BSIZE/4);
  } else {
    outb(0x1f7, IDE_CMD_READ);
  }

Based on above knowledge, I don't know how to implement an IDE driver that can issue a batch of requests(e.g., read block 3, read block 5) to disk all at once. Maybe I can use a loop to wrap all outbs in above code? I want someone to point me to the right direction, thanks.


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Thu Jan 05, 2017 10:25 am 
Offline
Member
Member

Joined: Sat Mar 28, 2015 11:23 am
Posts: 103
I'm not sure if xv6 already uses PCI DMA for the ATA driver, but if it doesn't, look into it. You can serve batches of requests by just adding another entry to the PRDTs.

_________________
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Thu Jan 05, 2017 10:32 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
You can't, the PRDT only lets you use a scatter/gather list for a single request. IDE just isn't a modern disk controller interface and allows only a single request at a time. If you want more than that, AHCI can do parallel read/writes with the NCQ commands.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Thu Jan 05, 2017 9:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 31, 2016 9:53 pm
Posts: 81
Location: San Diego, CA
Are you asking about something similar to a disk-block queue? That's what I do. (and I believe xv6 does as well)

I just add requests to a queue and then the driver responds to each request on the queue whenever an interrupt is triggered

_________________
Some of my open-source projects:
Ext2/ELF32 bootloader
Lightweight x86 assembler, designed to be portable for osdev
Scheme in under 1000 lines of C


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Fri Jan 06, 2017 8:44 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Part of the problem here is that the statement - and hence the answer - is ambiguous. What constitutes a 'modern disk controller'? IDE probably doesn't count; it is a legacy standard from the late 1980s and early 1990s. Most likely, the author was talking about controllers that implement AHCI (the implementation-independent ABI developed for the SATA physical interface standard), as Kevin said.

All compliant SATA drives should support an AHCI mode, but they usually will also emulate PATA (the retroactively-applied term for IDE and other related parallel interfaces) for legacy operating systems, and some will have an implementation-specific mode as well which exploits the specific hardware better than AHCI can. While the ideal would be to have a driver for as many of the individual drive models as possible, most low-end manufacturers don't bother to do more than AHCI does, and even for those who do, there are far too many for even Microsoft to support themselves. Even if you want to write a driver for a specific high-performance drive, the interface is probably proprietary, meaning that unless you get a driver from the manufacturer themselves you need to just use AHCI.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Fri Jan 06, 2017 9:33 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Sorry, I should have finished that but I had to go take care of something quick.

Anyway, the first question becomes, is it actually an IDE drive, or a later-model EIDE, PATA, SATA (or even SCSI, depending on the age of the drive and the controller) drive that is emulating IDE for backwards compatibility? Most true IDE and EIDE drives have long since succumbed to stiction (of which the infamous "click o' death" is the first symptom), so chances are it is a SATA drive masquerading as IDE. The drive device info in either Windows or Linux should be able to tell you, and if not, and you can open up the case, you should be able to tell just by looking at the physical connectors (the PATA style connectors are broad and narrow, about 2"/5 cm wide but about a 0.25"/6 mm thick), and usually used a ribbon cable, while the SATA connectors are about 0.4" /1 cm wide and 0.125" / 3 mm thick and use a thinner, singly clad cable).

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Sun Jan 08, 2017 8:26 am 
Offline

Joined: Wed Sep 09, 2015 4:51 am
Posts: 2
Thank you all. So the hardware, disk controller, must have a command to support receiving a batch of requests, or nothing I can do. And it seems like the old IDE(PATA) disk doesn't support this feature.


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Sun Jan 08, 2017 10:36 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Do you know the make and model of the drive, and the year it was manufactured? According to Wikipedia, the ATA-4 standard has a 'tagged queued operations' mode, meaning that PATA drives which are from 2002 or later will generally support it. As I said earlier, most drives that old or older won't even be functional anymore due to stiction - while drives made after the mid-1990s are a lot less prone to it and would run for several years longer than earlier drives, is still happens to most HDDs eventually IIUC.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Sun Jan 08, 2017 11:00 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Schol-R-LEA wrote:
According to Wikipedia, the ATA-4 standard has a 'tagged queued operations' mode, meaning that PATA drives which are from 2002 or later will generally support it.

You're jumping to conclusions. That a standard contains some optional feature doesn't mean that it gets implemented by actual hardware. If you'd read a sentence or two further in the same article: "However, support for these is extremely rare in actual parallel ATA products and device drivers because these feature sets were implemented in such a way as to maintain software compatibility with its heritage as originally an extension of the ISA bus. This implementation resulted in excessive CPU utilization which largely negated the advantages of command queuing."

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: How to write a disk driver can serve a batch of requests
PostPosted: Sun Jan 08, 2017 11:23 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
OK, I didn't read that part. I don't know why I am being so careless about things like that lately. Sorry about that.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], MichaelPetch, SemrushBot [Bot] and 153 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