Commit dda8f422 authored by Tejun Heo's avatar Tejun Heo Committed by Bartlomiej Zolnierkiewicz

[ide] add ide_drive_t.sleeping

ide_drive_t.sleeping field added.  0 in sleep field used to
indicate inactive sleeping but because 0 is a valid jiffy
value, though slim, there's a chance that something can go
weird.  And while at it, explicit jiffy comparisons are
converted to use time_before() macros.
Signed-off-by: default avatarTejun Heo <tj@home-tj.org>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 5e800d36
...@@ -933,6 +933,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout) ...@@ -933,6 +933,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
if (timeout > WAIT_WORSTCASE) if (timeout > WAIT_WORSTCASE)
timeout = WAIT_WORSTCASE; timeout = WAIT_WORSTCASE;
drive->sleep = timeout + jiffies; drive->sleep = timeout + jiffies;
drive->sleeping = 1;
} }
EXPORT_SYMBOL(ide_stall_queue); EXPORT_SYMBOL(ide_stall_queue);
...@@ -972,18 +973,18 @@ static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup) ...@@ -972,18 +973,18 @@ static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup)
} }
do { do {
if ((!drive->sleep || time_after_eq(jiffies, drive->sleep)) if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep))
&& !elv_queue_empty(drive->queue)) { && !elv_queue_empty(drive->queue)) {
if (!best if (!best
|| (drive->sleep && (!best->sleep || 0 < (signed long)(best->sleep - drive->sleep))) || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep)))
|| (!best->sleep && 0 < (signed long)(WAKEUP(best) - WAKEUP(drive)))) || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best))))
{ {
if (!blk_queue_plugged(drive->queue)) if (!blk_queue_plugged(drive->queue))
best = drive; best = drive;
} }
} }
} while ((drive = drive->next) != hwgroup->drive); } while ((drive = drive->next) != hwgroup->drive);
if (best && best->nice1 && !best->sleep && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
long t = (signed long)(WAKEUP(best) - jiffies); long t = (signed long)(WAKEUP(best) - jiffies);
if (t >= WAIT_MIN_SLEEP) { if (t >= WAIT_MIN_SLEEP) {
/* /*
...@@ -992,10 +993,9 @@ static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup) ...@@ -992,10 +993,9 @@ static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup)
*/ */
drive = best->next; drive = best->next;
do { do {
if (!drive->sleep if (!drive->sleeping
/* FIXME: use time_before */ && time_before(jiffies - best->service_time, WAKEUP(drive))
&& 0 < (signed long)(WAKEUP(drive) - (jiffies - best->service_time)) && time_before(WAKEUP(drive), jiffies + t))
&& 0 < (signed long)((jiffies + t) - WAKEUP(drive)))
{ {
ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP)); ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));
goto repeat; goto repeat;
...@@ -1058,14 +1058,17 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq) ...@@ -1058,14 +1058,17 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
hwgroup->busy = 1; hwgroup->busy = 1;
drive = choose_drive(hwgroup); drive = choose_drive(hwgroup);
if (drive == NULL) { if (drive == NULL) {
unsigned long sleep = 0; int sleeping = 0;
unsigned long sleep = 0; /* shut up, gcc */
hwgroup->rq = NULL; hwgroup->rq = NULL;
drive = hwgroup->drive; drive = hwgroup->drive;
do { do {
if (drive->sleep && (!sleep || 0 < (signed long)(sleep - drive->sleep))) if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) {
sleeping = 1;
sleep = drive->sleep; sleep = drive->sleep;
}
} while ((drive = drive->next) != hwgroup->drive); } while ((drive = drive->next) != hwgroup->drive);
if (sleep) { if (sleeping) {
/* /*
* Take a short snooze, and then wake up this hwgroup again. * Take a short snooze, and then wake up this hwgroup again.
* This gives other hwgroups on the same a chance to * This gives other hwgroups on the same a chance to
...@@ -1105,7 +1108,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq) ...@@ -1105,7 +1108,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
} }
hwgroup->hwif = hwif; hwgroup->hwif = hwif;
hwgroup->drive = drive; hwgroup->drive = drive;
drive->sleep = 0; drive->sleeping = 0;
drive->service_start = jiffies; drive->service_start = jiffies;
if (blk_queue_plugged(drive->queue)) { if (blk_queue_plugged(drive->queue)) {
......
...@@ -717,6 +717,7 @@ typedef struct ide_drive_s { ...@@ -717,6 +717,7 @@ typedef struct ide_drive_s {
* 3=64-bit * 3=64-bit
*/ */
unsigned scsi : 1; /* 0=default, 1=ide-scsi emulation */ unsigned scsi : 1; /* 0=default, 1=ide-scsi emulation */
unsigned sleeping : 1; /* 1=sleeping & sleep field valid */
u8 quirk_list; /* considered quirky, set for a specific host */ u8 quirk_list; /* considered quirky, set for a specific host */
u8 init_speed; /* transfer rate set at boot */ u8 init_speed; /* transfer rate set at boot */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment