mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Suspend2][ 00/13] Compression support.
@ 2006-06-27  4:37 Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 01/13] [Suspend2] Compression File Header Nigel Cunningham
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel


Patches which implement support for compressing the image. We use
cryptoapi. A separate patch adds an LZF compression module, which
is much faster than gzip.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 01/13] [Suspend2] Compression File Header
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 02/13] [Suspend2] Allocate compression buffers Nigel Cunningham
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

This is the header of the suspend2 modules that implements compression
support, using cryptoapi.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
new file mode 100644
index 0000000..72075d7
--- /dev/null
+++ b/kernel/power/compression.c
@@ -0,0 +1,41 @@
+/*
+ * kernel/power/compression.c
+ *
+ * Copyright (C) 2003-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * This file is released under the GPLv2.
+ *
+ * This file contains data compression routines for suspend,
+ * using cryptoapi.
+ *
+ */
+
+#include <linux/suspend.h>
+#include <linux/module.h>
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+#include <linux/crypto.h>
+
+#include "suspend2.h"
+#include "modules.h"
+#include "proc.h"
+#include "suspend2_common.h"
+#include "io.h"
+
+#define S2C_WRITE 0
+#define S2C_READ 1
+
+static int suspend_expected_compression = 0;
+
+static struct suspend_module_ops suspend_compression_ops;
+static struct suspend_module_ops *next_driver;
+
+static char suspend_compressor_name[32];
+static struct crypto_tfm *suspend_compressor_transform;
+
+static u8 *local_buffer = NULL;
+static u8 *page_buffer = NULL;
+static unsigned int bufofs;
+
+static int position = 0;
+       

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 02/13] [Suspend2] Allocate compression buffers.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 01/13] [Suspend2] Compression File Header Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 03/13] [Suspend2] Compression cryptoapi initialisation and cleanup Nigel Cunningham
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

The compression module uses a couple of local buffers to cache partially
filled output pages, and to receive the cryptoapi output. These routines
are responsible for allocating and freeing those buffers.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   53 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 72075d7..3d222b3 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -39,3 +39,56 @@ static unsigned int bufofs;
 
 static int position = 0;
        
+/* ---- Local buffer management ---- */
+
+/* 
+ * suspend_compress_allocate_local_buffer
+ *
+ * Allocates a page of memory for buffering output.
+ * Int: Zero if successful, -ENONEM otherwise.
+ */
+static int suspend_compress_allocate_local_buffer(void)
+{
+	if (!local_buffer) {
+		local_buffer = (char *) get_zeroed_page(GFP_ATOMIC);
+	
+		if (!local_buffer) {
+			printk(KERN_ERR
+				"Failed to allocate the local buffer for "
+				"suspend2 compression driver.\n");
+			return -ENOMEM;
+		}
+	}
+
+	if (!page_buffer) {
+		page_buffer = (char *) get_zeroed_page(GFP_ATOMIC);
+	
+		if (!page_buffer) {
+			printk(KERN_ERR
+				"Failed to allocate the page buffer for "
+				"suspend2 compression driver.\n");
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
+/* 
+ * suspend_compress_free_local_buffer
+ *
+ * Frees memory allocated for buffering output.
+ */
+static inline void suspend_compress_free_local_buffer(void)
+{
+	if (local_buffer)
+		free_page((unsigned long) local_buffer);
+
+	local_buffer = NULL;
+
+	if (page_buffer)
+		free_page((unsigned long) page_buffer);
+
+	page_buffer = NULL;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 03/13] [Suspend2] Compression cryptoapi initialisation and cleanup.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 01/13] [Suspend2] Compression File Header Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 02/13] [Suspend2] Allocate compression buffers Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 04/13] [Suspend2] Compression initialise & cleanup routines Nigel Cunningham
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Add the routines for preparing cryptoapi for suspend2 use and cleaning it
up.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 3d222b3..470644f 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -92,3 +92,40 @@ static inline void suspend_compress_free
 	page_buffer = NULL;
 }
 
+/* 
+ * suspend_compress_cleanup
+ *
+ * Frees memory allocated for our labours.
+ */
+static void suspend_compress_cleanup(void)
+{
+	if (suspend_compressor_transform) {
+		crypto_free_tfm(suspend_compressor_transform);
+		suspend_compressor_transform = NULL;
+	}
+}
+
+/* 
+ * suspend_crypto_prepare
+ *
+ * Prepare to do some work by allocating buffers and transforms.
+ * Returns: Int: Zero. Even if we can't set up compression, we still
+ * seek to suspend.
+ */
+static int suspend_compress_crypto_prepare(void)
+{
+	if (!*suspend_compressor_name) {
+		printk("Suspend2: Compression enabled but no compressor name set.\n");
+		suspend_compression_ops.disabled = 1;
+		return 0;
+	}
+
+	if (!(suspend_compressor_transform = crypto_alloc_tfm(suspend_compressor_name, 0))) {
+		printk("Suspend2: Failed to initialise the %s compression transform.\n",
+				suspend_compressor_name);
+		return 1;
+	}
+
+	return 0;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 04/13] [Suspend2] Compression initialise & cleanup routines.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (2 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 03/13] [Suspend2] Compression cryptoapi initialisation and cleanup Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 05/13] [Suspend2] Compression write routines Nigel Cunningham
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

These routines handle the initialisation and cleanup for compression,
invoking the buffer allocation and cryptoapi setup routines.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 470644f..44d46be 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -129,3 +129,62 @@ static int suspend_compress_crypto_prepa
 	return 0;
 }
 
+/* 
+ * suspend_compress_write_cleanup(): Write unflushed data and free workspace.
+ * 
+ * Returns: Result of writing last page.
+ */
+static int suspend_compress_rw_cleanup(int rw)
+{
+	int ret = 0;
+	
+	if (rw == WRITE && suspend_compressor_transform)
+		ret = next_driver->write_chunk(virt_to_page(local_buffer));
+
+	suspend_compress_cleanup();
+	suspend_compress_free_local_buffer();
+
+	return ret;
+}
+
+/* 
+ * suspend_compress_rw_init()
+ * @stream_number:	Ignored.
+ *
+ * Allocate buffers and prepare to compress data.
+ * Returns: Zero on success, -ENOMEM if unable to vmalloc.
+ */
+static int suspend_compress_rw_init(int rw, int stream_number)
+{
+	int result;
+	
+	next_driver = suspend_get_next_filter(&suspend_compression_ops);
+
+	if (!next_driver) {
+		printk("Compression Driver: Argh! Nothing follows me in"
+				" the pipeline!");
+		return -ECHILD;
+	}
+
+	if ((result = suspend_compress_crypto_prepare() ||
+	     suspend_compression_ops.disabled))
+		return result;
+	
+	if ((result = suspend_compress_allocate_local_buffer()))
+		return result;
+
+	if (rw == READ)
+		bufofs = PAGE_SIZE;
+	else {
+		/* Only reset the stats if starting to write an image */
+		if (stream_number == 2)
+			bytes_in = bytes_out = 0;
+	
+		bufofs = 0;
+	}
+
+	position = 0;
+
+	return 0;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 05/13] [Suspend2] Compression write routines.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (3 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 04/13] [Suspend2] Compression initialise & cleanup routines Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 06/13] [Suspend2] Compression read routines Nigel Cunningham
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Add routines used in compressing pages and passing them to the next module.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   87 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 44d46be..db3bca3 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -188,3 +188,90 @@ static int suspend_compress_rw_init(int 
 	return 0;
 }
 
+/* 
+ * suspend_compress_write()
+ * @u8*:		Output buffer to be written.
+ * @unsigned int:	Length of buffer.
+ *
+ * Helper function for write_chunk. Write the compressed data.
+ * Return: Int.	Result to be passed back to caller.
+ */
+static int suspend_compress_write (u8 *buffer, unsigned int len)
+{
+	int ret;
+
+	bytes_out += len;
+
+	while (len + bufofs > PAGE_SIZE) {
+		unsigned int chunk = PAGE_SIZE - bufofs;
+		memcpy (local_buffer + bufofs, buffer, chunk);
+		buffer += chunk;
+		len -= chunk;
+		bufofs = 0;
+		if ((ret = next_driver->write_chunk(virt_to_page(local_buffer))) < 0)
+			return ret;
+	}
+	memcpy (local_buffer + bufofs, buffer, len);
+	bufofs += len;
+	return 0;
+}
+
+/* 
+ * suspend_compress_write_chunk()
+ *
+ * Compress a page of data, buffering output and passing on filled
+ * pages to the next module in the pipeline.
+ * 
+ * Buffer_page:	Pointer to a buffer of size PAGE_SIZE, containing
+ * data to be compressed.
+ *
+ * Returns:	0 on success. Otherwise the error is that returned by later
+ * 		modules, -ECHILD if we have a broken pipeline or -EIO if
+ * 		zlib errs.
+ */
+static int suspend_compress_write_chunk(struct page *buffer_page)
+{
+	int ret; 
+	unsigned int len;
+	u16 len_written;
+	char *buffer_start;
+	
+	if (!suspend_compressor_transform)
+		return next_driver->write_chunk(buffer_page);
+
+	buffer_start = kmap(buffer_page);
+
+	bytes_in += PAGE_SIZE;
+
+	len = PAGE_SIZE;
+
+	ret = crypto_comp_compress(suspend_compressor_transform,
+			buffer_start, PAGE_SIZE,
+			page_buffer, &len);
+	
+	if (ret) {
+		printk("Compression failed.\n");
+		goto failure;
+	}
+	
+	len_written = (u16) len;
+		
+	if ((ret = suspend_compress_write((u8 *)&len_written, 2)) >= 0) {
+		if ((ret = suspend_compress_write((u8 *) &position, sizeof(position))))
+			return -EIO;
+		if (len < PAGE_SIZE) { /* some compression */
+			position += len;
+			ret = suspend_compress_write(page_buffer, len);
+		} else {
+			ret = suspend_compress_write(buffer_start, PAGE_SIZE);
+			position += PAGE_SIZE;
+		}
+	}
+	position += 2 + sizeof(int);
+
+
+failure:
+	kunmap(buffer_page);
+	return ret;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 06/13] [Suspend2] Compression read routines.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (4 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 05/13] [Suspend2] Compression write routines Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 07/13] [Suspend2] Compression debug stats Nigel Cunningham
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Routines used to obtain data from the next module, decompress it and return
a page full to the caller.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |  100 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index db3bca3..5193423 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -275,3 +275,103 @@ failure:
 	return ret;
 }
 
+/* 
+ * suspend_compress_read()
+ * @buffer: u8 *. Address of the buffer.
+ * @len: unsigned int. Length.
+ *
+ * Description:	Read data into compression buffer.
+ * Returns:	int:		Result of reading the image chunk.
+ */
+static int suspend_compress_read (u8 *buffer, unsigned int len)
+{
+	int ret;
+
+	while (len + bufofs > PAGE_SIZE) {
+		unsigned int chunk = PAGE_SIZE - bufofs;
+		memcpy(buffer, local_buffer + bufofs, chunk);
+		buffer += chunk;
+		len -= chunk;
+		bufofs = 0;
+		if ((ret = next_driver->read_chunk(
+				virt_to_page(local_buffer), SUSPEND_SYNC)) < 0) {
+			return ret;
+		}
+	}
+	memcpy (buffer, local_buffer + bufofs, len);
+	bufofs += len;
+	return 0;
+}
+
+/* 
+ * suspend_compress_read_chunk()
+ * @buffer_page: struct page *. Pointer to a buffer of size PAGE_SIZE.
+ * @sync:	int. Whether the previous module (or core) wants its data synchronously.
+ *
+ * Retrieve data from later modules and decompress it until the input buffer
+ * is filled.
+ * Zero if successful. Error condition from me or from downstream on failure.
+ */
+static int suspend_compress_read_chunk(struct page *buffer_page, int sync)
+{
+	int ret, position_saved; 
+	unsigned int len;
+	u16 len_written;
+	char *buffer_start;
+
+	if (!suspend_compressor_transform)
+		return next_driver->read_chunk(buffer_page, SUSPEND_ASYNC);
+
+	/* 
+	 * All our reads must be synchronous - we can't decompress
+	 * data that hasn't been read yet.
+	 */
+
+	buffer_start = kmap(buffer_page);
+
+	if ((ret = suspend_compress_read ((u8 *)&len_written, 2)) >= 0) {
+		len = (unsigned int) len_written;
+		ret = suspend_compress_read((u8 *) &position_saved, sizeof(position_saved));
+		if (ret)
+			return ret;
+
+		if (position != position_saved) {
+			printk("Position saved (%d) != position I'm at now (%d).\n",
+					position_saved, position);
+			BUG_ON(1);
+		}
+		if (len >= PAGE_SIZE) { /* uncompressed */
+			ret = suspend_compress_read(buffer_start, PAGE_SIZE);
+			if (ret)
+				return ret;
+
+			position += PAGE_SIZE;
+		} else { /* compressed */
+			if ((ret = suspend_compress_read(page_buffer, len)) >= 0) {
+				int outlen = PAGE_SIZE;
+				/* Important note.
+				 *
+				 * For Deflate, decompression return values may represent
+				 * errors. Deflate complains when everything is alright, so
+				 * we ignore the errors unless the number of output bytes is
+				 * not PAGE_SIZE.
+				 */
+				crypto_comp_decompress(suspend_compressor_transform, 
+						page_buffer, len,
+						buffer_start, &outlen);
+				if (outlen != PAGE_SIZE) {
+					printk("Decompression yielded %d bytes instead of %ld.\n", outlen, PAGE_SIZE);
+					ret = -EIO;
+				} else
+					ret = 0;
+			}
+			position += len;
+		}
+		position += 2 + sizeof(int);
+	} else
+		printk("Compress_read returned %d.", ret);
+	kunmap(buffer_page);
+	return ret;
+}
+
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 07/13] [Suspend2] Compression debug stats.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (5 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 06/13] [Suspend2] Compression read routines Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 08/13] [Suspend2] Compression memory and storage usage routines Nigel Cunningham
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Fill a buffer with debugging information about whether compression was
enabled and (if so) what ratio was achieved.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 5193423..6578e8c 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -374,4 +374,29 @@ static int suspend_compress_read_chunk(s
 	return ret;
 }
 
+/* 
+ * suspend_compress_print_debug_stats
+ * @buffer: Pointer to a buffer into which the debug info will be printed.
+ * @size: Size of the buffer.
+ *
+ * Print information to be recorded for debugging purposes into a buffer.
+ * Returns: Number of characters written to the buffer.
+ */
+
+static int suspend_compress_print_debug_stats(char *buffer, int size)
+{
+	int pages_in = bytes_in >> PAGE_SHIFT, 
+		pages_out = bytes_out >> PAGE_SHIFT;
+	int len;
+	
+	/* Output the compression ratio achieved. */
+	len = snprintf_used(buffer, size, "- Compressor %s enabled.\n",
+			suspend_compressor_name);
+	if (pages_in)
+		len+= snprintf_used(buffer+len, size - len,
+		  "  Compressed %ld bytes into %ld (%d percent compression).\n",
+		  bytes_in, bytes_out, (pages_in - pages_out) * 100 / pages_in);
+	return len;
+}
+
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 08/13] [Suspend2] Compression memory and storage usage routines.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (6 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 07/13] [Suspend2] Compression debug stats Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 09/13] [Suspend2] Serialisation of compressor configuration in image header Nigel Cunningham
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Routines to tell the core how much memory and space in the image header is
required for the compression support.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 6578e8c..b8005c7 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -399,4 +399,21 @@ static int suspend_compress_print_debug_
 	return len;
 }
 
+/* 
+ * suspend_compress_compression_memory_needed
+ *
+ * Tell the caller how much memory we need to operate during suspend/resume.
+ * Returns: Unsigned long. Maximum number of bytes of memory required for
+ * operation.
+ */
+static unsigned long suspend_compress_memory_needed(void)
+{
+	return 2 * PAGE_SIZE;
+}
+
+static unsigned long suspend_compress_storage_needed(void)
+{
+	return 4 * sizeof(unsigned long) + strlen(suspend_compressor_name) + 1;
+}
+
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 09/13] [Suspend2] Serialisation of compressor configuration in image header.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (7 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 08/13] [Suspend2] Compression memory and storage usage routines Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 10/13] [Suspend2] Get expected compression ratio Nigel Cunningham
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Routines for storing and reloading the compression configuration in an
image header.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index b8005c7..1398dc5 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -416,4 +416,47 @@ static unsigned long suspend_compress_st
 	return 4 * sizeof(unsigned long) + strlen(suspend_compressor_name) + 1;
 }
 
+/* 
+ * suspend_compress_save_config_info
+ * @buffer: Pointer to a buffer of size PAGE_SIZE.
+ *
+ * Save informaton needed when reloading the image at resume time.
+ * Returns: Number of bytes used for saving our data.
+ */
+static int suspend_compress_save_config_info(char *buffer)
+{
+	int namelen = strlen(suspend_compressor_name) + 1;
+	int total_len;
+	
+	*((unsigned long *) buffer) = bytes_in;
+	*((unsigned long *) (buffer + 1 * sizeof(unsigned long))) = bytes_out;
+	*((unsigned long *) (buffer + 2 * sizeof(unsigned long))) =
+		suspend_expected_compression;
+	*((unsigned long *) (buffer + 3 * sizeof(unsigned long))) = namelen;
+	strncpy(buffer + 4 * sizeof(unsigned long), suspend_compressor_name, 
+								namelen);
+	total_len = 4 * sizeof(unsigned long) + namelen;
+	return total_len;
+}
+
+/* suspend_compress_load_config_info
+ * @buffer: Pointer to the start of the data.
+ * @size: Number of bytes that were saved.
+ *
+ * Description:	Reload information needed for decompressing the image at
+ * resume time.
+ */
+static void suspend_compress_load_config_info(char *buffer, int size)
+{
+	int namelen;
+	
+	bytes_in = *((unsigned long *) buffer);
+	bytes_out = *((unsigned long *) (buffer + 1 * sizeof(unsigned long)));
+	suspend_expected_compression = *((unsigned long *) (buffer + 2 *
+				sizeof(unsigned long)));
+	namelen = *((unsigned long *) (buffer + 3 * sizeof(unsigned long)));
+	strncpy(suspend_compressor_name, buffer + 4 * sizeof(unsigned long),
+			namelen);
+	return;
+}
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 10/13] [Suspend2] Get expected compression ratio.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (8 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 09/13] [Suspend2] Serialisation of compressor configuration in image header Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 11/13] [Suspend2] Compression proc entry data Nigel Cunningham
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Return the expected compression ratio, set by the user.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 1398dc5..924d507 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -460,3 +460,20 @@ static void suspend_compress_load_config
 	return;
 }
 
+/* 
+ * suspend_expected_compression_ratio
+ * 
+ * Description:	Returns the expected ratio between data passed into this module
+ * 		and the amount of data output when writing.
+ * Returns:	100 if the module is disabled. Otherwise the value set by the
+ * 		user via our proc entry.
+ */
+
+int suspend_expected_compression_ratio(void)
+{
+	if (suspend_compression_ops.disabled)
+		return 100;
+	else
+		return 100 - suspend_expected_compression;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 11/13] [Suspend2] Compression proc entry data.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (9 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 10/13] [Suspend2] Get expected compression ratio Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:37 ` [Suspend2][ 12/13] [Suspend2] Compression operations structure Nigel Cunningham
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

This patch adds the suspend_proc_data structure that allows the user to
configure compression support.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 924d507..54d54a9 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -477,3 +477,46 @@ int suspend_expected_compression_ratio(v
 		return 100 - suspend_expected_compression;
 }
 
+/*
+ * data for our proc entries.
+ */
+static struct suspend_proc_data proc_params[] = {
+{
+	.filename			= "expected_compression",
+	.permissions			= PROC_RW,
+	.type				= SUSPEND_PROC_DATA_INTEGER,
+	.data = {
+		.integer = {
+			.variable	= &suspend_expected_compression,
+			.minimum	= 0,
+			.maximum	= 99,
+		}
+	}
+},
+
+{
+	.filename			= "disable_compression",
+	.permissions			= PROC_RW,
+	.type				= SUSPEND_PROC_DATA_INTEGER,
+	.data = {
+		.integer = {
+			.variable	= &suspend_compression_ops.disabled,
+			.minimum	= 0,
+			.maximum	= 1,
+		}
+	}
+},
+
+{
+	.filename			= "compressor",
+	.permissions			= PROC_RW,
+	.type				= SUSPEND_PROC_DATA_STRING,
+	.data = {
+		.string = {
+			.variable	= suspend_compressor_name,
+			.max_length	= 31,
+		}
+	},
+}
+};
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 12/13] [Suspend2] Compression operations structure.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (10 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 11/13] [Suspend2] Compression proc entry data Nigel Cunningham
@ 2006-06-27  4:37 ` Nigel Cunningham
  2006-06-27  4:38 ` [Suspend2][ 13/13] [Suspend2] Compression (un)load routines Nigel Cunningham
  2006-06-27 13:59 ` [Suspend2][ 00/13] Compression support Pavel Machek
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:37 UTC (permalink / raw)
  To: linux-kernel

Add the compression ops structure, which provides the core (or previous
module in the pipeline) with access to the compression functions.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 54d54a9..4f0f82e 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -520,3 +520,23 @@ static struct suspend_proc_data proc_par
 }
 };
 
+/*
+ * Ops structure.
+ */
+static struct suspend_module_ops suspend_compression_ops = {
+	.type			= FILTER_MODULE,
+	.name			= "Suspend2 Compressor",
+	.module			= THIS_MODULE,
+	.memory_needed 		= suspend_compress_memory_needed,
+	.print_debug_info	= suspend_compress_print_debug_stats,
+	.save_config_info	= suspend_compress_save_config_info,
+	.load_config_info	= suspend_compress_load_config_info,
+	.storage_needed		= suspend_compress_storage_needed,
+	
+	.rw_init		= suspend_compress_rw_init,
+	.rw_cleanup		= suspend_compress_rw_cleanup,
+
+	.write_chunk		= suspend_compress_write_chunk,
+	.read_chunk		= suspend_compress_read_chunk,
+};
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Suspend2][ 13/13] [Suspend2] Compression (un)load routines.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (11 preceding siblings ...)
  2006-06-27  4:37 ` [Suspend2][ 12/13] [Suspend2] Compression operations structure Nigel Cunningham
@ 2006-06-27  4:38 ` Nigel Cunningham
  2006-06-27 13:59 ` [Suspend2][ 00/13] Compression support Pavel Machek
  13 siblings, 0 replies; 15+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:38 UTC (permalink / raw)
  To: linux-kernel

Add routines to register the compression support and proc file entries on
load.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/compression.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 4f0f82e..726518c 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -540,3 +540,36 @@ static struct suspend_module_ops suspend
 	.read_chunk		= suspend_compress_read_chunk,
 };
 
+/* ---- Registration ---- */
+
+static __init int suspend_compress_load(void)
+{
+	int result;
+	int i, numfiles = sizeof(proc_params) / sizeof(struct suspend_proc_data);
+
+	printk("Suspend2 Compression Driver loading.\n");
+	if (!(result = suspend_register_module(&suspend_compression_ops))) {
+		for (i=0; i< numfiles; i++)
+			suspend_register_procfile(&proc_params[i]);
+	} else
+		printk("Suspend2 Compression Driver unable to register!\n");
+	return result;
+}
+
+#ifdef MODULE
+static __exit void suspend_compress_unload(void)
+{
+	printk("Suspend2 Compression Driver unloading.\n");
+	for (i=0; i< numfiles; i++)
+		suspend_unregister_procfile(&proc_params[i]);
+	suspend_unregister_module(&suspend_compression_ops);
+}
+
+module_init(suspend_compress_load);
+module_exit(suspend_compress_unload);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Nigel Cunningham");
+MODULE_DESCRIPTION("Compression Support for Suspend2");
+#else
+late_initcall(suspend_compress_load);
+#endif

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Suspend2][ 00/13] Compression support.
  2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
                   ` (12 preceding siblings ...)
  2006-06-27  4:38 ` [Suspend2][ 13/13] [Suspend2] Compression (un)load routines Nigel Cunningham
@ 2006-06-27 13:59 ` Pavel Machek
  13 siblings, 0 replies; 15+ messages in thread
From: Pavel Machek @ 2006-06-27 13:59 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-kernel

Hi!

> Patches which implement support for compressing the image. We use
> cryptoapi. A separate patch adds an LZF compression module, which
> is much faster than gzip.

This is diffstat of compression/encryption patches:

 b/kernel/power/compression.c |   43 +++
 b/kernel/power/encryption.c  |   49 +++
 kernel/power/compression.c   |  559 +++++++++++++++++++++++++++++++++++++++++--
 kernel/power/encryption.c    |  517 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 1115 insertions(+), 53 deletions(-)

..so we add 1000 lines of code for feature that can very well live in
userspace. All the filewriters/etc can live in userspace, too.

Could we improve suspend.sf.net code instead of trying to merge awful
lot of code that does not really belong into kernel?

I counted over 300 patches in this series....
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-06-27 14:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-27  4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 01/13] [Suspend2] Compression File Header Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 02/13] [Suspend2] Allocate compression buffers Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 03/13] [Suspend2] Compression cryptoapi initialisation and cleanup Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 04/13] [Suspend2] Compression initialise & cleanup routines Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 05/13] [Suspend2] Compression write routines Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 06/13] [Suspend2] Compression read routines Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 07/13] [Suspend2] Compression debug stats Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 08/13] [Suspend2] Compression memory and storage usage routines Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 09/13] [Suspend2] Serialisation of compressor configuration in image header Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 10/13] [Suspend2] Get expected compression ratio Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 11/13] [Suspend2] Compression proc entry data Nigel Cunningham
2006-06-27  4:37 ` [Suspend2][ 12/13] [Suspend2] Compression operations structure Nigel Cunningham
2006-06-27  4:38 ` [Suspend2][ 13/13] [Suspend2] Compression (un)load routines Nigel Cunningham
2006-06-27 13:59 ` [Suspend2][ 00/13] Compression support Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome