Skip to contentSkip to conversation

Make the IDE DMA timeout modifiable

PATCH In review Suleiman Souhlal 7 participants 20 messages Feb 21, 2007 – Jul 17, 2007 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Make the IDE DMA timeout modifiable

It can be changed via /proc/ide/hd?/settings.

---
 drivers/ide/ide-dma.c |    3 ++-
 drivers/ide/ide.c     |    2 ++
 include/linux/ide.h   |    3 +++
 3 files changed, 7 insertions(+), 1 deletions(-)
drivers/ide/ide-dma.c +2 -1
index 08e7cd0..a8da725 100644
@@ -579,7 +579,8 @@ EXPORT_SYMBOL_GPL(ide_dma_setup);
 static void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
 {
 	/* issue cmd to drive */
-	ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
+	ide_execute_command(drive, command, &ide_dma_intr, drive->dma_timeout,
+	    dma_timer_expiry);
 }
 
 void ide_dma_start(ide_drive_t *drive)
drivers/ide/ide.c +2 -0
index b3c0818..ca841f2 100644
@@ -245,6 +245,7 @@ static void init_hwif_data(ide_hwif_t *h
 		drive->name[1]			= 'd';
 		drive->name[2]			= 'a' + (index * MAX_DRIVES) + unit;
 		drive->max_failures		= IDE_DEFAULT_MAX_FAILURES;
+		drive->dma_timeout		= WAIT_DMA;
 		drive->using_dma		= 0;
 		drive->vdma			= 0;
 		INIT_LIST_HEAD(&drive->list);
@@ -1197,6 +1198,7 @@ void ide_add_generic_settings (ide_drive
 	__ide_add_setting(drive,	"init_speed",		SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	70,				1,		1,		&drive->init_speed,		NULL,		0);
 	__ide_add_setting(drive,	"current_speed",	SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	70,				1,		1,		&drive->current_speed,		set_xfer_rate,	0);
 	__ide_add_setting(drive,	"number",		SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	3,				1,		1,		&drive->dn,			NULL,		0);
+	__ide_add_setting(drive,	"dma_timeout",		SETTING_RW,					-1,			-1,			TYPE_INT,	0,	2000000000,			1,		1,		&drive->dma_timeout,		NULL,		0);
 }
 
 /**
include/linux/ide.h +3 -0
index 79c0282..3861753 100644
@@ -183,6 +183,7 @@ #define WAIT_READY	(5*HZ)		/* 5sec - som
 #define WAIT_PIDENTIFY	(10*HZ)	/* 10sec  - should be less than 3ms (?), if all ATAPI CD is closed at boot */
 #define WAIT_WORSTCASE	(30*HZ)	/* 30sec  - worst case when spinning up */
 #define WAIT_CMD	(10*HZ)	/* 10sec  - maximum wait for an IRQ to happen */
+#define WAIT_DMA	(20*HZ)	/* 20sec  - maximum wait for an IRQ to happen */
 #define WAIT_MIN_SLEEP	(2*HZ/100)	/* 20msec - minimum sleep time */
 
 /*
@@ -638,6 +639,8 @@ typedef struct ide_drive_s {
 	unsigned int	drive_data;	/* use by tuneproc/selectproc */
 	unsigned int	failures;	/* current failure count */
 	unsigned int	max_failures;	/* maximum allowed failure count */
+	int		dma_timeout;	/* number of jiffies to wait for a
+					  dma to complete */
 	u64		probed_capacity;/* initial reported media capacity (ide-cd only currently) */
 
 	u64		capacity64;	/* total number of sectors */
#1 lore raw
Quoted 1 line · Suleiman Souhlal

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

BTW /proc/ide/hd?/settings is obsoleted

Quoted 65 lines
---
 drivers/ide/ide-dma.c |    3 ++-
 drivers/ide/ide.c     |    2 ++
 include/linux/ide.h   |    3 +++
 3 files changed, 7 insertions(+), 1 deletions(-)
drivers/ide/ide-dma.c +2 -1
index 08e7cd0..a8da725 100644
@@ -579,7 +579,8 @@ EXPORT_SYMBOL_GPL(ide_dma_setup);
 static void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
 {
 	/* issue cmd to drive */
-	ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
+	ide_execute_command(drive, command, &ide_dma_intr, drive->dma_timeout,
+	    dma_timer_expiry);
 }
 
 void ide_dma_start(ide_drive_t *drive)
drivers/ide/ide.c +2 -0
index b3c0818..ca841f2 100644
@@ -245,6 +245,7 @@ static void init_hwif_data(ide_hwif_t *h
 		drive->name[1]			= 'd';
 		drive->name[2]			= 'a' + (index * MAX_DRIVES) + unit;
 		drive->max_failures		= IDE_DEFAULT_MAX_FAILURES;
+		drive->dma_timeout		= WAIT_DMA;
 		drive->using_dma		= 0;
 		drive->vdma			= 0;
 		INIT_LIST_HEAD(&drive->list);
@@ -1197,6 +1198,7 @@ void ide_add_generic_settings (ide_drive
 	__ide_add_setting(drive,	"init_speed",		SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	70,				1,		1,		&drive->init_speed,		NULL,		0);
 	__ide_add_setting(drive,	"current_speed",	SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	70,				1,		1,		&drive->current_speed,		set_xfer_rate,	0);
 	__ide_add_setting(drive,	"number",		SETTING_RW,					-1,			-1,			TYPE_BYTE,	0,	3,				1,		1,		&drive->dn,			NULL,		0);
+	__ide_add_setting(drive,	"dma_timeout",		SETTING_RW,					-1,			-1,			TYPE_INT,	0,	2000000000,			1,		1,		&drive->dma_timeout,		NULL,		0);
 }
 
 /**
include/linux/ide.h +3 -0
index 79c0282..3861753 100644
@@ -183,6 +183,7 @@ #define WAIT_READY	(5*HZ)		/* 5sec - som
 #define WAIT_PIDENTIFY	(10*HZ)	/* 10sec  - should be less than 3ms (?), if all ATAPI CD is closed at boot */
 #define WAIT_WORSTCASE	(30*HZ)	/* 30sec  - worst case when spinning up */
 #define WAIT_CMD	(10*HZ)	/* 10sec  - maximum wait for an IRQ to happen */
+#define WAIT_DMA	(20*HZ)	/* 20sec  - maximum wait for an IRQ to happen */
 #define WAIT_MIN_SLEEP	(2*HZ/100)	/* 20msec - minimum sleep time */
 
 /*
@@ -638,6 +639,8 @@ typedef struct ide_drive_s {
 	unsigned int	drive_data;	/* use by tuneproc/selectproc */
 	unsigned int	failures;	/* current failure count */
 	unsigned int	max_failures;	/* maximum allowed failure count */
+	int		dma_timeout;	/* number of jiffies to wait for a
+					  dma to complete */
 	u64		probed_capacity;/* initial reported media capacity (ide-cd only currently) */
 
 	u64		capacity64;	/* total number of sectors */
#2 lore raw
Quoted 5 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line · Suleiman Souhlal

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

I've used it to test error recovery (for example).

Quoted 1 line

BTW /proc/ide/hd?/settings is obsoleted

What's the preferred way of changing such settings, these days?

-- Suleiman

#3 lore raw

Hi,

Quoted 10 lines · Suleiman Souhlal
Quoted 5 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line · Suleiman Souhlal

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

I've used it to test error recovery (for example).

Seems quite useable for developers but I would prefer not to expose it in production kernels for end users.

Quoted 3 lines
Quoted 1 line

BTW /proc/ide/hd?/settings is obsoleted

What's the preferred way of changing such settings, these days?

sysfs

ide.c:ide_dev_attrs[] for generic attributes valid for all devices

Thanks,
Bart

#4 lore raw
Quoted 4 lines · Bartlomiej Zolnierkiewicz
Quoted 3 lines · Bartlomiej Zolnierkiewicz
Quoted 2 lines · Suleiman Souhlal
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

I've used it to test error recovery (for example).

Seems quite useable for developers but I would prefer not to expose it in production kernels for end users.

It seems that I have counter example of a customer asking if this timeout
can be done configurable. :-)
BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is
not complete or interrupt pending, it may wait 10 more secs...

Quoted 2 lines

Thanks,
Bart

MBR, Sergei

#5 lore raw
Quoted 9 lines · Sergei Shtylyov
Quoted 7 lines · Bartlomiej Zolnierkiewicz
Quoted 7 lines · Bartlomiej Zolnierkiewicz
Quoted 6 lines · Suleiman Souhlal
Quoted 2 lines

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I've used it to test error recovery (for example).

Seems quite useable for developers but I would prefer not to expose it in production kernels for end users.

It seems that I have counter example of a customer asking if this timeout
can be done configurable. :-)

May I ask what was the rationale for this request?

I have no strong feelings about adding this /proc/ide/ setting but I worry that it could be (mis)used just to (unreliably) work-around problems...

Quoted 2 lines

BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is
not complete or interrupt pending, it may wait 10 more secs...

I really don't remember... :)

Maybe Mark or Alan could help with figuring this out.

Thanks,
Bart

#6 lore raw

Hello.

Quoted 10 lines · Bartlomiej Zolnierkiewicz
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines · Bartlomiej Zolnierkiewicz
Quoted 6 lines · Suleiman Souhlal
Quoted 2 lines

It can be changed via /proc/ide/hd?/settings.

Why do we need to change IDE DMA timeout dynamically?

I've used it to test error recovery (for example).

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Seems quite useable for developers but I would prefer not to expose it in production kernels for end users.

It seems that I have counter example of a customer asking if this timeout
can be done configurable. :-)

May I ask what was the rationale for this request?

Their system seems to become unschedulable for this period of time (DMA
timeouts happen from time to time) -- at least the keepalive daemon stopped replying during this period...

Quoted 9 lines

I have no strong feelings about adding this /proc/ide/ setting but I worry that it could be (mis)used just to (unreliably) work-around problems...

Quoted 2 lines

BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is
not complete or interrupt pending, it may wait 10 more secs...

I really don't remember... :)

Maybe Mark or Alan could help with figuring this out.

They also have probably forgotten. :-)

Quoted 2 lines

Thanks,
Bart

MBR, Sergei

#7 lore raw

O> >> BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

not complete or interrupt pending, it may wait 10 more secs...

I really don't remember... :)

Maybe Mark or Alan could help with figuring this out.

They also have probably forgotten. :-)

Because that value seemed to work ok. Mark set the timeouts way back in history and I never touched most of them.

#8 lore raw
Quoted 8 lines · Alan Cox

O> >> BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

not complete or interrupt pending, it may wait 10 more secs...

I really don't remember... :)
Maybe Mark or Alan could help with figuring this out.

They also have probably forgotten. :-)

Because that value seemed to work ok. Mark set the timeouts way back in history and I never touched most of them.

I've lost the original question from this thread, but the idea of the longish timeouts was that drive *may* be spun down ("standby"), and thus have to spin up again to complete media commands. Back then, drives were much slower at spinning up than nowadays, and the ATA spec says to allow up to 30 seconds.

So..

#9 lore raw

Hello.

Quoted 7 lines · Mark Lord
Quoted 6 lines

O> >> BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

not complete or interrupt pending, it may wait 10 more secs...

I really don't remember... :)
Maybe Mark or Alan could help with figuring this out.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

They also have probably forgotten. :-)

Because that value seemed to work ok. Mark set the timeouts way back in history and I never touched most of them.

I've lost the original question from this thread, but the idea of the

The original question concerned specifically the DMA command timeout which
is twice more than the usual one, WAIT_CMD (10 seconds).

Quoted 4 lines

longish
timeouts was that drive *may* be spun down ("standby"), and thus have to spin up again to complete media commands. Back then, drives were much slower at spinning up than nowadays, and the ATA spec says to allow up to 30 seconds.

Well, that doesn't explain the DMA case.

MBR, Sergei

#10 lore raw
Quoted 3 lines · Sergei Shtylyov
Quoted 1 line · Mark Lord
Quoted 1 line

O> >> BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is not complete or interrupt pending, it may wait 10 more secs...

..

Quoted 11 lines
Quoted 1 line

I've lost the original question from this thread, but the idea of the

The original question concerned specifically the DMA command timeout
which is twice more than the usual one, WAIT_CMD (10 seconds).

Quoted 4 lines

longish
timeouts was that drive *may* be spun down ("standby"), and thus have to spin up again to complete media commands. Back then, drives were much slower at spinning up than nowadays, and the ATA spec says to allow up to 30 seconds.

Well, that doesn't explain the DMA case.

When a drive is in standby, we don't send it anything special to wake up. So even DMA commands have to have a long enough timeout to allow for spinning up.

Cheers

#11 lore raw
Quoted 10 lines · Mark Lord
Quoted 9 lines
Quoted 1 line

I've lost the original question from this thread, but the idea of the

The original question concerned specifically the DMA command
timeout which is twice more than the usual one, WAIT_CMD (10 seconds).

Quoted 4 lines

longish
timeouts was that drive *may* be spun down ("standby"), and thus have to spin up again to complete media commands. Back then, drives were much slower at spinning up than nowadays, and the ATA spec says to allow up to 30 seconds.

Quoted 5 lines
Quoted 1 line

Well, that doesn't explain the DMA case.

When a drive is in standby, we don't send it anything special to wake up. So even DMA commands have to have a long enough timeout to allow for spinning up.

Yes, but why *twice* as long as the others?

Quoted 1 line

Cheers

MBR, Sergei

#12 lore raw
Quoted 4 lines · Sergei Shtylyov
Quoted 2 lines · Mark Lord
Quoted 2 lines

The original question concerned specifically the DMA command
timeout which is twice more than the usual one, WAIT_CMD (10 seconds).

..

Quoted 5 lines
Quoted 3 lines

When a drive is in standby, we don't send it anything special to wake up. So even DMA commands have to have a long enough timeout to allow for spinning up.

Yes, but why *twice* as long as the others?

I would guess simply because DMA has to transfer up to 256 sectors of data, possibly with sector reallocations, in addition to waiting for the drive to spin up. Other commands don't.

At the time that was coded (?), I suspect that PIO READ/WRITE commands were fed data as it became available to/from the drive. This may or may not still be the case, but it does imply that they don't need to hang around as long on the timeouts as do DMA commands (which have to wait for *everything* to be transferred).

I'm guessing that this was the original concern of mine, way back in 1994 or whenever it was.

Cheers

#13 lore raw
Quoted 7 lines · Mark Lord
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

The original question concerned specifically the DMA command
timeout which is twice more than the usual one, WAIT_CMD (10 seconds)...

When a drive is in standby, we don't send it anything special to wake up. So even DMA commands have to have a long enough timeout to allow for spinning up.

Quoted 5 lines
Quoted 1 line

Yes, but why *twice* as long as the others?

I would guess simply because DMA has to transfer up to 256 sectors of data, possibly with sector reallocations, in addition to waiting for the drive to spin up. Other commands don't.

What?! PIO commands don't have to do this as well? :-)

Quoted 2 lines

At the time that was coded (?), I suspect that PIO READ/WRITE commands were fed data as it became available to/from the drive. This may or may

I don't see *any* difference with the DMA commands here -- the drive has
always been free to assert and deassert DMARQ at its well.

Quoted 3 lines

not still be the case, but it does imply that they don't need to hang around as long on the timeouts as do DMA commands (which have to wait for *everything* to be transferred).

Ah, that makes sense -- during PIO interrupts happen a lot more often.
20 secs still seem to be too much.

Quoted 1 line

Cheers

MBR, Sergei

PS: Your mail server still keeps bouncing me off. :-(

#14 lore raw
Quoted 7 lines · Sergei Shtylyov

Mark Lord wrote:
..

Quoted 3 lines

I would guess simply because DMA has to transfer up to 256 sectors of data, possibly with sector reallocations, in addition to waiting for the drive to spin up. Other commands don't.

What?! PIO commands don't have to do this as well? :-)

"Other commands" don't have to transfer up to 256 sectors before interrupting.

Quoted 5 lines
Quoted 2 lines

At the time that was coded (?), I suspect that PIO READ/WRITE commands were fed data as it became available to/from the drive. This may or may

I don't see *any* difference with the DMA commands here -- the drive
has always been free to assert and deassert DMARQ at its well.

Yeah, but that's not what our software timeout is for.
The timeout is for the next interrupt, which will only be given (for DMA) once the drive completes *all* transfers.

Quoted 6 lines
Quoted 3 lines

not still be the case, but it does imply that they don't need to hang around as long on the timeouts as do DMA commands (which have to wait for *everything* to be transferred).

Ah, that makes sense -- during PIO interrupts happen a lot more often.
20 secs still seem to be too much.

I don't think so, even for modern drives.
Figure 8-10 seconds max for spin-up,
plus 6-9 seconds to do a sector re-assignment
or retries on a bad block (a measured *real-life* value).

That adds up to 14-19 seconds, so 20 seconds is probably good.

Still, this does need to be adjustable for faster (CF) devices, and slower (optical/tape) devices, rather than just a single set of fixed timeout values.

Cheers

Quoted 1 line

PS: Your mail server still keeps bouncing me off. :-(

PS: your mail server still looks like a spammer, because it is
(1) missing a reverse DNS entry for 63.81.120.155, and (2) is not RFC compliant on the SMTP "HELO" message (bad hostname given there).

#15 lore raw
Quoted 8 lines · Mark Lord
Quoted 2 lines

Ah, that makes sense -- during PIO interrupts happen a lot more often.
20 secs still seem to be too much.

I don't think so, even for modern drives.
Figure 8-10 seconds max for spin-up,
plus 6-9 seconds to do a sector re-assignment
or retries on a bad block (a measured *real-life* value).

Quoted 5 lines

That adds up to 14-19 seconds, so 20 seconds is probably good.

Still, this does need to be adjustable for faster (CF) devices, and slower (optical/tape) devices, rather than just a single set of fixed timeout values.

In real life, with real bad blocks on real harddrives, some harddrives take more than the DMA TIMEOUT time to read a single block, even without having to spin up.

The current code then resets the drive, on which the drive reports "busy, not ready for command", and things go downhill from there.

Roger.

Signature · 6 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2600998 **
**    Delftechpark 26 2628 XH  Delft, The Netherlands. KVK: 27239233    **
*-- BitWizard writes Linux device drivers for any device you may have! --*
Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement. 
Does it sit on the couch all day? Is it unemployed? Please be specific! 
Define 'it' and what it isn't doing. --------- Adapted from lxrbot FAQ
#16 lore raw

Hello.

Quoted 10 lines · Rogier Wolff
Quoted 9 lines
Quoted 2 lines

Ah, that makes sense -- during PIO interrupts happen a lot more often.
20 secs still seem to be too much.

I don't think so, even for modern drives.
Figure 8-10 seconds max for spin-up,
plus 6-9 seconds to do a sector re-assignment
or retries on a bad block (a measured *real-life* value).

That adds up to 14-19 seconds, so 20 seconds is probably good.

Quoted 7 lines
Quoted 3 lines

Still, this does need to be adjustable for faster (CF) devices, and slower (optical/tape) devices, rather than just a single set of fixed timeout values.

In real life, with real bad blocks on real harddrives, some harddrives take more than the DMA TIMEOUT time to read a single block, even without having to spin up.

Yeah, "shit happens".

Quoted 2 lines

The current code then resets the drive, on which the drive reports "busy, not ready for command", and things go downhill from there.

You are clearly mixing things: this message is a result of retrying
command in PIO mode (that fails because the drive is still busy), and then the drives are actually reset. If they keep being busy *after* that, all I'd say is dump them ASAP. ;-)

Quoted 1 line

Roger.

MBR, Sergei

#17 lore raw
In reply to Mark Lord
Quoted 9 lines · Mark Lord
Quoted 1 line
Quoted 1 line
Quoted 1 line

O> >> BTW, why the timeout is so damn long? 2*WAIT_CMD is 20 secs, and if DMA is not complete or interrupt pending, it may wait 10 more secs...

..

Quoted 4 lines
Quoted 1 line

I've lost the original question from this thread, but the idea of the

The original question concerned specifically the DMA command
timeout which is twice more than the usual one, WAIT_CMD (10 seconds).

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

longish
timeouts was that drive *may* be spun down ("standby"), and thus have to spin up again to complete media commands. Back then, drives were much slower at spinning up than nowadays, and the ATA spec says to allow up to 30 seconds.

Well, that doesn't explain the DMA case.

When a drive is in standby, we don't send it anything special to wake up.

Wait, aren't we sending IDLE on resume step 2 -- looking at
ide-io.cide_start_power_step()?

Quoted 1 line

Cheers

MBR, Sergei

#18 lore raw
Quoted 1 line · Sergei Shtylyov

Mark Lord wrote:

..

Quoted 4 lines
Quoted 1 line

When a drive is in standby, we don't send it anything special to wake up.

Wait, aren't we sending IDLE on resume step 2 -- looking at
ide-io.cide_start_power_step()?

Sure, for RESUME.

But now for a drive that just happens to have put itself into standby due to expiration of the standby timer (hdparm -S).

Cheers

#19 lore raw
Quoted 5 lines · Mark Lord
Quoted 1 line · Sergei Shtylyov

Mark Lord wrote:

..

Quoted 2 lines
Quoted 1 line

When a drive is in standby, we don't send it anything special to wake up.

Quoted 7 lines
Quoted 2 lines

Wait, aren't we sending IDLE on resume step 2 -- looking at
ide-io.cide_start_power_step()?

Sure, for RESUME.

But now for a drive that just happens to have put itself into standby due to expiration of the standby timer (hdparm -S).

That should have said:

But *not* for a drive ...