Patchwork lib: fwts_acpi_tables: speed up table loading on 64 bit systems

login
register
mail settings
Submitter Colin King
Date Jan. 4, 2013, 5:12 p.m.
Message ID <1357319521-23034-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/209492/
State Accepted
Headers show

Comments

Colin King - Jan. 4, 2013, 5:12 p.m.
From: Colin Ian King <colin.king@canonical.com>

When loading tables from an apcidump fwts_acpi_load_table_from_acpidump()
will load in 16 byte chunks at a time and re-allocate the buffer each
time using the low 32 bit memory allocator. This allocator is really slow on
64 bit systems that don't support MAP_32BIT and generally far slower
than malloc on systems that do support MAP_32BIT.  So, instead, use plain
old realloc() to read in the table, and use the low 32 bit allocator for
the table once we know how big it is.

This noticeably speeds up table loads when testing against my database
of known problematic ACPI tables.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_acpi_tables.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
Keng-Yu Lin - Jan. 14, 2013, 7:45 a.m.
On Sat, Jan 5, 2013 at 1:12 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> When loading tables from an apcidump fwts_acpi_load_table_from_acpidump()
> will load in 16 byte chunks at a time and re-allocate the buffer each
> time using the low 32 bit memory allocator. This allocator is really slow on
> 64 bit systems that don't support MAP_32BIT and generally far slower
> than malloc on systems that do support MAP_32BIT.  So, instead, use plain
> old realloc() to read in the table, and use the low 32 bit allocator for
> the table once we know how big it is.
>
> This noticeably speeds up table loads when testing against my database
> of known problematic ACPI tables.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_acpi_tables.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 876a6f5..b23efa7 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -327,7 +327,8 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>         uint32_t offset;
>         uint8_t  data[16];
>         char buffer[128];
> -       uint8_t *table = NULL;
> +       uint8_t *table;
> +       uint8_t *tmp = NULL;
>         char *ptr = buffer;
>         size_t len = 0;
>         unsigned long long table_addr;
> @@ -381,12 +382,19 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>                         break;
>
>                 len += (n - 1);
> -               table = fwts_low_realloc(table, len);
> -               if (table == NULL)
> +               if ((tmp = realloc(tmp, len)) == NULL)
>                         return NULL;
> -               memcpy(table + offset, data, n-1);
> +               memcpy(tmp + offset, data, n-1);
>         }
>
> +       /* Allocate the table using low 32 bit memory */
> +       if ((table = fwts_low_malloc(len)) == NULL) {
> +               free(tmp);
> +               return NULL;
> +       }
> +       memcpy(table, tmp, len);
> +       free(tmp);
> +
>         if (table_addr == 0)
>                 table_addr = fwts_fake_physical_addr(len);
>
> --
> 1.8.0
>
>


Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - Jan. 14, 2013, 9:50 a.m.
On 01/05/2013 01:12 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> When loading tables from an apcidump fwts_acpi_load_table_from_acpidump()
> will load in 16 byte chunks at a time and re-allocate the buffer each
> time using the low 32 bit memory allocator. This allocator is really slow on
> 64 bit systems that don't support MAP_32BIT and generally far slower
> than malloc on systems that do support MAP_32BIT.  So, instead, use plain
> old realloc() to read in the table, and use the low 32 bit allocator for
> the table once we know how big it is.
>
> This noticeably speeds up table loads when testing against my database
> of known problematic ACPI tables.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_acpi_tables.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 876a6f5..b23efa7 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -327,7 +327,8 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>   	uint32_t offset;
>   	uint8_t  data[16];
>   	char buffer[128];
> -	uint8_t *table = NULL;
> +	uint8_t *table;
> +	uint8_t *tmp = NULL;
>   	char *ptr = buffer;
>   	size_t len = 0;
>   	unsigned long long table_addr;
> @@ -381,12 +382,19 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>   			break;
>
>   		len += (n - 1);
> -		table = fwts_low_realloc(table, len);
> -		if (table == NULL)
> +		if ((tmp = realloc(tmp, len)) == NULL)
>   			return NULL;
> -		memcpy(table + offset, data, n-1);
> +		memcpy(tmp + offset, data, n-1);
>   	}
>
> +	/* Allocate the table using low 32 bit memory */
> +	if ((table = fwts_low_malloc(len)) == NULL) {
> +		free(tmp);
> +		return NULL;
> +	}
> +	memcpy(table, tmp, len);
> +	free(tmp);
> +
>   	if (table_addr == 0)
>   		table_addr = fwts_fake_physical_addr(len);
>
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 876a6f5..b23efa7 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -327,7 +327,8 @@  static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
 	uint32_t offset;
 	uint8_t  data[16];
 	char buffer[128];
-	uint8_t *table = NULL;
+	uint8_t *table;
+	uint8_t *tmp = NULL;
 	char *ptr = buffer;
 	size_t len = 0;
 	unsigned long long table_addr;
@@ -381,12 +382,19 @@  static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
 			break;
 
 		len += (n - 1);
-		table = fwts_low_realloc(table, len);
-		if (table == NULL)
+		if ((tmp = realloc(tmp, len)) == NULL)
 			return NULL;
-		memcpy(table + offset, data, n-1);
+		memcpy(tmp + offset, data, n-1);
 	}
 
+	/* Allocate the table using low 32 bit memory */
+	if ((table = fwts_low_malloc(len)) == NULL) {
+		free(tmp);
+		return NULL;
+	}
+	memcpy(table, tmp, len);
+	free(tmp);
+
 	if (table_addr == 0)
 		table_addr = fwts_fake_physical_addr(len);