Skip to contentSkip to conversation

swsusp: clean up reading

PATCH Pavel Machek 2 participants 2 messages Sep 10, 2004 – Sep 11, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!

This removes one-line functions so that code is readable again. Test is added so that we do not ignore I/O errors. It also turns io_schedule() into yield() as suggested by Andrea. Please apply,

Pavel

kernel/power/swsusp.c +8 -15
@@ -994,24 +978,14 @@
 
 static atomic_t io_done = ATOMIC_INIT(0);
 
-static void start_io(void)
-{
-	atomic_set(&io_done,1);
-}
-
 static int end_io(struct bio * bio, unsigned int num, int err)
 {
-	atomic_set(&io_done,0);
+	if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
+		panic("I/O error reading memory image");
+	atomic_set(&io_done, 0);
 	return 0;
 }
 
-static void wait_io(void)
-{
-	while(atomic_read(&io_done))
-		io_schedule();
-}
-
-
 static struct block_device * resume_bdev;
 
 /**
@@ -1046,9 +1020,12 @@
 
 	if (rw == WRITE)
 		bio_set_pages_dirty(bio);
-	start_io();
+
+	atomic_set(&io_done, 1);
 	submit_bio(rw | (1 << BIO_RW_SYNC), bio);
-	wait_io();
+	while (atomic_read(&io_done))
+		yield();
+
  Done:
 	bio_put(bio);
 	return error;
#1 lore raw
Quoted 10 lines · Pavel Machek

-static void wait_io(void)
-{
- while(atomic_read(&io_done))
- io_schedule();
-}
-
-
static struct block_device * resume_bdev;

Quoted 5 lines

...

- wait_io();
+ while (atomic_read(&io_done))
+ yield();

This doesn't seem to be much of an improvement, really. It still runs the risk that the caller might have SCHIED_FIFO policy and we end up in a spinloop until I/O completion.

Why not stick a `struct completion' at bio->bi_private, do complete() in the end_io handler and wait_for_completion() in the caller?

I'll add the current patch to -mm for now, thanks.