Skip to content

Commit

Permalink
spi: Reorder fields in 'struct spi_transfer'
Browse files Browse the repository at this point in the history
Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size from 144 to 128 bytes.

Turn 'timestamped' into a bitfield so that it can be easily merged with
some other bifields and move 'error'.

This should have no real impact on memory allocation because 'struct
spi_transfer' is mostly used on stack, but it can save a few cycles
when the structure is initialized or copied.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/93a051da85a895bc6003aedfb00a13e1c2fc6338.1676370870.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Christophe JAILLET authored and Mark Brown committed Feb 14, 2023
1 parent 937ca91 commit 9d77522
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ void spi_take_timestamp_post(struct spi_controller *ctlr,
/* Capture the resolution of the timestamp */
xfer->ptp_sts_word_post = progress;

xfer->timestamped = true;
xfer->timestamped = 1;
}
EXPORT_SYMBOL_GPL(spi_take_timestamp_post);

Expand Down
9 changes: 4 additions & 5 deletions include/linux/spi/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ struct spi_transfer {
void *rx_buf;
unsigned len;

#define SPI_TRANS_FAIL_NO_START BIT(0)
u16 error;

dma_addr_t tx_dma;
dma_addr_t rx_dma;
struct sg_table tx_sg;
Expand All @@ -1032,6 +1035,7 @@ struct spi_transfer {
unsigned cs_change:1;
unsigned tx_nbits:3;
unsigned rx_nbits:3;
unsigned timestamped:1;
#define SPI_NBITS_SINGLE 0x01 /* 1bit transfer */
#define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
#define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
Expand All @@ -1048,12 +1052,7 @@ struct spi_transfer {

struct ptp_system_timestamp *ptp_sts;

bool timestamped;

struct list_head transfer_list;

#define SPI_TRANS_FAIL_NO_START BIT(0)
u16 error;
};

/**
Expand Down

0 comments on commit 9d77522

Please sign in to comment.