2004-09-10 09:33:11

by Pavel Machek

[permalink] [raw]
Subject: swsusp: progress in percent

Hi!

swsusp currently has very poor progress indication. Thanks to Erik
Rigtorp <[email protected]>, we have percentages there, so people know
how long wait to expect. Please apply,

[I'd prefer this to be start of "next batch" of changes to linus. It
would be nice if linus could pull previous version from power tree...]

From: Erik Rigtorp <[email protected]>
Signed-off-by: Pavel Machek <[email protected]>

Pavel

--- clean-mm/kernel/power/disk.c 2004-09-07 21:12:33.000000000 +0200
+++ linux-mm/kernel/power/disk.c 2004-09-08 22:47:41.000000000 +0200
@@ -91,10 +91,20 @@

static void free_some_memory(void)
{
- printk("Freeing memory: ");
- while (shrink_all_memory(10000))
- printk(".");
- printk("|\n");
+ unsigned int i = 0;
+ unsigned int tmp;
+ unsigned long pages = 0;
+ char *p = "-\\|/";
+
+ printk("Freeing memory... ");
+ while ((tmp = shrink_all_memory(10000))) {
+ pages += tmp;
+ printk("\b%c", p[i]);
+ i++;
+ if (i > 3)
+ i = 0;
+ }
+ printk("\bdone (%li pages freed)\n", pages);
}


--- clean-mm/kernel/power/swsusp.c 2004-09-07 21:12:33.000000000 +0200
+++ linux-mm/kernel/power/swsusp.c 2004-09-09 08:56:20.000000000 +0200
@@ -296,15 +292,19 @@
{
int error = 0;
int i;
-
- printk( "Writing data to swap (%d pages): ", nr_copy_pages );
+ unsigned int mod = nr_copy_pages / 100;
+
+ if (!mod)
+ mod = 1;
+
+ printk( "Writing data to swap (%d pages)... ", nr_copy_pages );
for (i = 0; i < nr_copy_pages && !error; i++) {
- if (!(i%100))
- printk( "." );
+ if (!(i%mod))
+ printk( "\b\b\b\b%3d%%", i / mod );
error = write_page((pagedir_nosave+i)->address,
&((pagedir_nosave+i)->swap_address));
}
- printk(" %d Pages done.\n",i);
+ printk("\b\b\b\bdone\n");
return error;
}

@@ -1153,14 +1120,18 @@
struct pbe * p;
int error;
int i;
-
+ int mod = nr_copy_pages / 100;
+
+ if (!mod)
+ mod = 1;
+
if ((error = swsusp_pagedir_relocate()))
return error;

- printk( "Reading image data (%d pages): ", nr_copy_pages );
+ printk( "Reading image data (%d pages): ", nr_copy_pages );
for(i = 0, p = pagedir_nosave; i < nr_copy_pages && !error; i++, p++) {
- if (!(i%100))
- printk( "." );
+ if (!(i%mod))
+ printk( "\b\b\b\b%3d%%", i / mod );
error = bio_read_page(swp_offset(p->swap_address),
(void *)p->address);
}



2004-09-11 13:05:28

by Tonnerre

[permalink] [raw]
Subject: Re: swsusp: progress in percent

Salut,

On Fri, Sep 10, 2004 at 10:47:04AM +0200, Pavel Machek wrote:
> --- clean-mm/kernel/power/disk.c 2004-09-07 21:12:33.000000000 +0200
> +++ linux-mm/kernel/power/disk.c 2004-09-08 22:47:41.000000000 +0200
> @@ -91,10 +91,20 @@
>
> static void free_some_memory(void)
> {
> - printk("Freeing memory: ");
> - while (shrink_all_memory(10000))
> - printk(".");
> - printk("|\n");
> + unsigned int i = 0;
> + unsigned int tmp;
> + unsigned long pages = 0;
> + char *p = "-\\|/";
> +
> + printk("Freeing memory... ");
> + while ((tmp = shrink_all_memory(10000))) {
> + pages += tmp;
printk("\b%c", p[(i++)%4]); ?
> + }
> + printk("\bdone (%li pages freed)\n", pages);
> }
>
>
> --- clean-mm/kernel/power/swsusp.c 2004-09-07 21:12:33.000000000 +0200
> +++ linux-mm/kernel/power/swsusp.c 2004-09-09 08:56:20.000000000 +0200
> @@ -296,15 +292,19 @@
> {
> int error = 0;
> int i;
> -
> - printk( "Writing data to swap (%d pages): ", nr_copy_pages );
> + unsigned int mod = nr_copy_pages / 100;
> +
> + if (!mod)
> + mod = 1;
> +
> + printk( "Writing data to swap (%d pages)... ", nr_copy_pages );
> for (i = 0; i < nr_copy_pages && !error; i++) {
> - if (!(i%100))
> - printk( "." );
> + if (!(i%mod))
> + printk( "\b\b\b\b%3d%%", i / mod );
> error = write_page((pagedir_nosave+i)->address,
> &((pagedir_nosave+i)->swap_address));
> }
> - printk(" %d Pages done.\n",i);
> + printk("\b\b\b\bdone\n");

Didn't we say we want the page count here?

> return error;
> }
>
> @@ -1153,14 +1120,18 @@
> struct pbe * p;
> int error;
> int i;
> -
> + int mod = nr_copy_pages / 100;
> +
> + if (!mod)
> + mod = 1;
> +
> if ((error = swsusp_pagedir_relocate()))
> return error;
>
> - printk( "Reading image data (%d pages): ", nr_copy_pages );
> + printk( "Reading image data (%d pages): ", nr_copy_pages );
> for(i = 0, p = pagedir_nosave; i < nr_copy_pages && !error; i++, p++) {
> - if (!(i%100))
> - printk( "." );
> + if (!(i%mod))
> + printk( "\b\b\b\b%3d%%", i / mod );
> error = bio_read_page(swp_offset(p->swap_address),
> (void *)p->address);
> }
>
>

Thanks for enlightenment.

Tonnerre


Attachments:
(No filename) (2.13 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments

2004-09-11 17:05:43

by Stefan Seyfried

[permalink] [raw]
Subject: Re: swsusp: progress in percent

Tonnerre wrote:

>>- printk(" %d Pages done.\n",i);
>>+ printk("\b\b\b\bdone\n");
>
> Didn't we say we want the page count here?

well, you usually won't see it anyway since after writing the pages to
swap the machine should power off pretty soon :-)
Changing it to

printk("\b\b\b%d Pages done.\n",i);

is no big deal though.

Stefan