[PATCH] lib: fwts_acpi_tables: speed up table loading on 64 bit systems

Keng-Yu Lin kengyu at canonical.com
Mon Jan 14 07:45:01 UTC 2013


On Sat, Jan 5, 2013 at 1:12 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at 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 at 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 at canonical.com>



More information about the fwts-devel mailing list