Skip to content

Commit

Permalink
Bump efivarfs_get_variable throughput to 50 variables/second from 33⅓
Browse files Browse the repository at this point in the history
Read the whole variable at once, then copy out the attributes
(for a description of efivarfs rate limiting, see #258)

Signed-off-by: Ahelenia Ziemiańska <[email protected]>
  • Loading branch information
nabijaczleweli committed Nov 21, 2023
1 parent f6baefa commit e371b3f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/efivarfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
__typeof__(errno) errno_value;
int ret = -1;
size_t size = 0;
uint32_t ret_attributes = 0;
uint8_t *ret_data;
int fd = -1;
char *path = NULL;
Expand All @@ -259,21 +258,23 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
goto err;
}

rc = read(fd, &ret_attributes, sizeof (ret_attributes));
rc = read_file(fd, &ret_data, &size);
if (rc < 0) {
efi_error("read failed");
efi_error("read_file failed");
goto err;
}
--size; // read_file pads out 1 extra byte to NUL

rc = read_file(fd, &ret_data, &size);
if (rc < 0) {
efi_error("read_file failed");
if (size < sizeof (*attributes)) {
efi_error("no attributes");
goto err;
}

*attributes = ret_attributes;
memcpy(attributes, ret_data, sizeof (*attributes));
memmove(ret_data, ret_data + sizeof (*attributes), size - sizeof (*attributes));

*data = ret_data;
*data_size = size - 1; // read_file pads out 1 extra byte to NUL it */
*data_size = size - sizeof (*attributes);

ret = 0;
err:
Expand Down

0 comments on commit e371b3f

Please sign in to comment.