[Sound-open-firmware] [PATCH] buffer: move buffer functions to c file
These are all functions may be called by other modules frequently, but not small enough, to reduce the elf binary size, they should not be static and inline, move the implementation to the c file buffer.c.
Example: Before applying this patch, the baytrail binary sizes as below: reef 640436 Bytes; reef-byt.ri 66361 Bytes; After applied it, they are changed to: reef 635280 Bytes; reef-byt.ri 65625 Bytes;
Signed-off-by: Keyon Jie yang.jie@linux.intel.com --- src/audio/buffer.c | 110 +++++++++++++++++++++++++++++++++++++ src/include/reef/audio/buffer.h | 117 ++++------------------------------------ 2 files changed, 120 insertions(+), 107 deletions(-)
diff --git a/src/audio/buffer.c b/src/audio/buffer.c index 0acf660..ad9d2f3 100644 --- a/src/audio/buffer.c +++ b/src/audio/buffer.c @@ -97,3 +97,113 @@ void buffer_free(struct comp_buffer *buffer) rfree(buffer->addr); rfree(buffer); } + +/* called by a component after producing data into this buffer */ +void comp_update_buffer_produce(struct comp_buffer *buffer, + uint32_t bytes) +{ + buffer->w_ptr += bytes; + + /* check for pointer wrap */ + if (buffer->w_ptr >= buffer->end_addr) + buffer->w_ptr = buffer->addr + (buffer->w_ptr - buffer->end_addr); + + /* calculate available bytes */ + if (buffer->r_ptr < buffer->w_ptr) + buffer->avail = buffer->w_ptr - buffer->r_ptr; + else if (buffer->r_ptr == buffer->w_ptr) + buffer->avail = buffer->size; /* full */ + else + buffer->avail = buffer->size - (buffer->r_ptr - buffer->w_ptr); + + /* calculate free bytes */ + buffer->free = buffer->size - buffer->avail; + + tracev_buffer("pro"); + tracev_value((buffer->avail << 16) | buffer->free); + tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer->size); + tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer->w_ptr - buffer->addr)); +} + +/* called by a component after consuming data from this buffer */ +void comp_update_buffer_consume(struct comp_buffer *buffer, + uint32_t bytes) +{ + buffer->r_ptr += bytes; + + /* check for pointer wrap */ + if (buffer->r_ptr >= buffer->end_addr) + buffer->r_ptr = buffer->addr + (buffer->r_ptr - buffer->end_addr); + + /* calculate available bytes */ + if (buffer->r_ptr < buffer->w_ptr) + buffer->avail = buffer->w_ptr - buffer->r_ptr; + else if (buffer->r_ptr == buffer->w_ptr) + buffer->avail = 0; /* empty */ + else + buffer->avail = buffer->size - (buffer->r_ptr - buffer->w_ptr); + + /* calculate free bytes */ + buffer->free = buffer->size - buffer->avail; + + tracev_buffer("con"); + tracev_value((buffer->avail << 16) | buffer->free); + tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer->size); + tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer->w_ptr - buffer->addr)); + +} + +/* get the max number of bytes that can be copied between sink and source */ +int comp_buffer_can_copy_bytes(struct comp_buffer *source, + struct comp_buffer *sink, uint32_t bytes) +{ + /* check for underrun */ + if (source->avail < bytes) + return -1; + + /* check for overrun */ + if (sink->free < bytes) + return 1; + + /* we are good to copy */ + return 0; +} + +uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source, + struct comp_buffer *sink) +{ + if (source->avail < sink->free) + return sink->free; + else + return source->avail; +} + +void buffer_reset_pos(struct comp_buffer *buffer) +{ + /* reset read and write pointer to buffer bas */ + buffer->w_ptr = buffer->r_ptr = buffer->addr; + + /* free space is buffer size */ + buffer->free = buffer->size; + + /* ther are no avail samples at reset */ + buffer->avail = 0; + + /* clear buffer contents */ + bzero(buffer->r_ptr, buffer->avail); +} + +/* set the runtime size of a buffer in bytes and improve the data cache */ +/* performance by only using minimum space needed for runtime params */ +int buffer_set_size(struct comp_buffer *buffer, uint32_t size) +{ + if (size > buffer->alloc_size) + return -ENOMEM; + if (size == 0) + return -EINVAL; + + buffer->end_addr = buffer->addr + size; + buffer->size = size; + return 0; +} + diff --git a/src/include/reef/audio/buffer.h b/src/include/reef/audio/buffer.h index 2bb2033..611857c 100644 --- a/src/include/reef/audio/buffer.h +++ b/src/include/reef/audio/buffer.h @@ -77,112 +77,15 @@ struct comp_buffer { struct comp_buffer *buffer_new(struct sof_ipc_buffer *desc); void buffer_free(struct comp_buffer *buffer);
-/* called by a component after producing data into this buffer */ -static inline void comp_update_buffer_produce(struct comp_buffer *buffer, - uint32_t bytes) -{ - buffer->w_ptr += bytes; - - /* check for pointer wrap */ - if (buffer->w_ptr >= buffer->end_addr) - buffer->w_ptr = buffer->addr + (buffer->w_ptr - buffer->end_addr); - - /* calculate available bytes */ - if (buffer->r_ptr < buffer->w_ptr) - buffer->avail = buffer->w_ptr - buffer->r_ptr; - else if (buffer->r_ptr == buffer->w_ptr) - buffer->avail = buffer->size; /* full */ - else - buffer->avail = buffer->size - (buffer->r_ptr - buffer->w_ptr); - - /* calculate free bytes */ - buffer->free = buffer->size - buffer->avail; - - tracev_buffer("pro"); - tracev_value((buffer->avail << 16) | buffer->free); - tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer->size); - tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer->w_ptr - buffer->addr)); -} - -/* called by a component after consuming data from this buffer */ -static inline void comp_update_buffer_consume(struct comp_buffer *buffer, - uint32_t bytes) -{ - buffer->r_ptr += bytes; - - /* check for pointer wrap */ - if (buffer->r_ptr >= buffer->end_addr) - buffer->r_ptr = buffer->addr + (buffer->r_ptr - buffer->end_addr); - - /* calculate available bytes */ - if (buffer->r_ptr < buffer->w_ptr) - buffer->avail = buffer->w_ptr - buffer->r_ptr; - else if (buffer->r_ptr == buffer->w_ptr) - buffer->avail = 0; /* empty */ - else - buffer->avail = buffer->size - (buffer->r_ptr - buffer->w_ptr); - - /* calculate free bytes */ - buffer->free = buffer->size - buffer->avail; - - tracev_buffer("con"); - tracev_value((buffer->avail << 16) | buffer->free); - tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer->size); - tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer->w_ptr - buffer->addr)); -} - -/* get the max number of bytes that can be copied between sink and source */ -static inline int comp_buffer_can_copy_bytes(struct comp_buffer *source, - struct comp_buffer *sink, uint32_t bytes) -{ - /* check for underrun */ - if (source->avail < bytes) - return -1; - - /* check for overrun */ - if (sink->free < bytes) - return 1; - - /* we are good to copy */ - return 0; -} - -static inline uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source, - struct comp_buffer *sink) -{ - if (source->avail < sink->free) - return sink->free; - else - return source->avail; -} - -static inline void buffer_reset_pos(struct comp_buffer *buffer) -{ - /* reset read and write pointer to buffer bas */ - buffer->w_ptr = buffer->r_ptr = buffer->addr; - - /* free space is buffer size */ - buffer->free = buffer->size; - - /* ther are no avail samples at reset */ - buffer->avail = 0; - - /* clear buffer contents */ - bzero(buffer->r_ptr, buffer->avail); -} - -/* set the runtime size of a buffer in bytes and improve the data cache */ -/* performance by only using minimum space needed for runtime params */ -static inline int buffer_set_size(struct comp_buffer *buffer, uint32_t size) -{ - if (size > buffer->alloc_size) - return -ENOMEM; - if (size == 0) - return -EINVAL; - - buffer->end_addr = buffer->addr + size; - buffer->size = size; - return 0; -} +void comp_update_buffer_produce(struct comp_buffer *buffer, + uint32_t bytes); +void comp_update_buffer_consume(struct comp_buffer *buffer, + uint32_t bytes); +int comp_buffer_can_copy_bytes(struct comp_buffer *source, + struct comp_buffer *sink, uint32_t bytes); +uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source, + struct comp_buffer *sink); +void buffer_reset_pos(struct comp_buffer *buffer); +int buffer_set_size(struct comp_buffer *buffer, uint32_t size);
#endif
On Fri, 2017-12-08 at 23:11 +0800, Keyon Jie wrote:
These are all functions may be called by other modules frequently, but not small enough, to reduce the elf binary size, they should not be static and inline, move the implementation to the c file buffer.c.
Example: Before applying this patch, the baytrail binary sizes as below: reef 640436 Bytes; reef-byt.ri 66361 Bytes; After applied it, they are changed to: reef 635280 Bytes; reef-byt.ri 65625 Bytes;
We need to inline these for use in copy() to save a function call(s) and window exceptions at the expense of slightly larger code.
Liam
Signed-off-by: Keyon Jie yang.jie@linux.intel.com
src/audio/buffer.c | 110 +++++++++++++++++++++++++++++++++++++ src/include/reef/audio/buffer.h | 117 ++++------------------------
2 files changed, 120 insertions(+), 107 deletions(-)
diff --git a/src/audio/buffer.c b/src/audio/buffer.c index 0acf660..ad9d2f3 100644 --- a/src/audio/buffer.c +++ b/src/audio/buffer.c @@ -97,3 +97,113 @@ void buffer_free(struct comp_buffer *buffer) rfree(buffer->addr); rfree(buffer); }
+/* called by a component after producing data into this buffer */ +void comp_update_buffer_produce(struct comp_buffer *buffer,
- uint32_t bytes)
+{
- buffer->w_ptr += bytes;
- /* check for pointer wrap */
- if (buffer->w_ptr >= buffer->end_addr)
buffer->w_ptr = buffer->addr + (buffer->w_ptr -
buffer->end_addr);
- /* calculate available bytes */
- if (buffer->r_ptr < buffer->w_ptr)
buffer->avail = buffer->w_ptr - buffer->r_ptr;
- else if (buffer->r_ptr == buffer->w_ptr)
buffer->avail = buffer->size; /* full */
- else
buffer->avail = buffer->size - (buffer->r_ptr -
buffer->w_ptr);
- /* calculate free bytes */
- buffer->free = buffer->size - buffer->avail;
- tracev_buffer("pro");
- tracev_value((buffer->avail << 16) | buffer->free);
- tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer-
size);
- tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer-
w_ptr - buffer->addr));
+}
+/* called by a component after consuming data from this buffer */ +void comp_update_buffer_consume(struct comp_buffer *buffer,
- uint32_t bytes)
+{
- buffer->r_ptr += bytes;
- /* check for pointer wrap */
- if (buffer->r_ptr >= buffer->end_addr)
buffer->r_ptr = buffer->addr + (buffer->r_ptr -
buffer->end_addr);
- /* calculate available bytes */
- if (buffer->r_ptr < buffer->w_ptr)
buffer->avail = buffer->w_ptr - buffer->r_ptr;
- else if (buffer->r_ptr == buffer->w_ptr)
buffer->avail = 0; /* empty */
- else
buffer->avail = buffer->size - (buffer->r_ptr -
buffer->w_ptr);
- /* calculate free bytes */
- buffer->free = buffer->size - buffer->avail;
- tracev_buffer("con");
- tracev_value((buffer->avail << 16) | buffer->free);
- tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer-
size);
- tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer-
w_ptr - buffer->addr));
+}
+/* get the max number of bytes that can be copied between sink and source */ +int comp_buffer_can_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink, uint32_t bytes)
+{
- /* check for underrun */
- if (source->avail < bytes)
return -1;
- /* check for overrun */
- if (sink->free < bytes)
return 1;
- /* we are good to copy */
- return 0;
+}
+uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink)
+{
- if (source->avail < sink->free)
return sink->free;
- else
return source->avail;
+}
+void buffer_reset_pos(struct comp_buffer *buffer) +{
- /* reset read and write pointer to buffer bas */
- buffer->w_ptr = buffer->r_ptr = buffer->addr;
- /* free space is buffer size */
- buffer->free = buffer->size;
- /* ther are no avail samples at reset */
- buffer->avail = 0;
- /* clear buffer contents */
- bzero(buffer->r_ptr, buffer->avail);
+}
+/* set the runtime size of a buffer in bytes and improve the data cache */ +/* performance by only using minimum space needed for runtime params */ +int buffer_set_size(struct comp_buffer *buffer, uint32_t size) +{
- if (size > buffer->alloc_size)
return -ENOMEM;
- if (size == 0)
return -EINVAL;
- buffer->end_addr = buffer->addr + size;
- buffer->size = size;
- return 0;
+}
diff --git a/src/include/reef/audio/buffer.h b/src/include/reef/audio/buffer.h index 2bb2033..611857c 100644 --- a/src/include/reef/audio/buffer.h +++ b/src/include/reef/audio/buffer.h @@ -77,112 +77,15 @@ struct comp_buffer { struct comp_buffer *buffer_new(struct sof_ipc_buffer *desc); void buffer_free(struct comp_buffer *buffer);
-/* called by a component after producing data into this buffer */ -static inline void comp_update_buffer_produce(struct comp_buffer *buffer,
- uint32_t bytes)
-{
- buffer->w_ptr += bytes;
- /* check for pointer wrap */
- if (buffer->w_ptr >= buffer->end_addr)
buffer->w_ptr = buffer->addr + (buffer->w_ptr -
buffer->end_addr);
- /* calculate available bytes */
- if (buffer->r_ptr < buffer->w_ptr)
buffer->avail = buffer->w_ptr - buffer->r_ptr;
- else if (buffer->r_ptr == buffer->w_ptr)
buffer->avail = buffer->size; /* full */
- else
buffer->avail = buffer->size - (buffer->r_ptr -
buffer->w_ptr);
- /* calculate free bytes */
- buffer->free = buffer->size - buffer->avail;
- tracev_buffer("pro");
- tracev_value((buffer->avail << 16) | buffer->free);
- tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer-
size);
- tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer-
w_ptr - buffer->addr));
-}
-/* called by a component after consuming data from this buffer */ -static inline void comp_update_buffer_consume(struct comp_buffer *buffer,
- uint32_t bytes)
-{
- buffer->r_ptr += bytes;
- /* check for pointer wrap */
- if (buffer->r_ptr >= buffer->end_addr)
buffer->r_ptr = buffer->addr + (buffer->r_ptr -
buffer->end_addr);
- /* calculate available bytes */
- if (buffer->r_ptr < buffer->w_ptr)
buffer->avail = buffer->w_ptr - buffer->r_ptr;
- else if (buffer->r_ptr == buffer->w_ptr)
buffer->avail = 0; /* empty */
- else
buffer->avail = buffer->size - (buffer->r_ptr -
buffer->w_ptr);
- /* calculate free bytes */
- buffer->free = buffer->size - buffer->avail;
- tracev_buffer("con");
- tracev_value((buffer->avail << 16) | buffer->free);
- tracev_value((buffer->ipc_buffer.comp.id << 16) | buffer-
size);
- tracev_value((buffer->r_ptr - buffer->addr) << 16 | (buffer-
w_ptr - buffer->addr));
-}
-/* get the max number of bytes that can be copied between sink and source */ -static inline int comp_buffer_can_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink, uint32_t bytes)
-{
- /* check for underrun */
- if (source->avail < bytes)
return -1;
- /* check for overrun */
- if (sink->free < bytes)
return 1;
- /* we are good to copy */
- return 0;
-}
-static inline uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink)
-{
- if (source->avail < sink->free)
return sink->free;
- else
return source->avail;
-}
-static inline void buffer_reset_pos(struct comp_buffer *buffer) -{
- /* reset read and write pointer to buffer bas */
- buffer->w_ptr = buffer->r_ptr = buffer->addr;
- /* free space is buffer size */
- buffer->free = buffer->size;
- /* ther are no avail samples at reset */
- buffer->avail = 0;
- /* clear buffer contents */
- bzero(buffer->r_ptr, buffer->avail);
-}
-/* set the runtime size of a buffer in bytes and improve the data cache */ -/* performance by only using minimum space needed for runtime params */ -static inline int buffer_set_size(struct comp_buffer *buffer, uint32_t size) -{
- if (size > buffer->alloc_size)
return -ENOMEM;
- if (size == 0)
return -EINVAL;
- buffer->end_addr = buffer->addr + size;
- buffer->size = size;
- return 0;
-} +void comp_update_buffer_produce(struct comp_buffer *buffer,
- uint32_t bytes);
+void comp_update_buffer_consume(struct comp_buffer *buffer,
- uint32_t bytes);
+int comp_buffer_can_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink, uint32_t bytes);
+uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source,
- struct comp_buffer *sink);
+void buffer_reset_pos(struct comp_buffer *buffer); +int buffer_set_size(struct comp_buffer *buffer, uint32_t size);
#endif
participants (2)
-
Keyon Jie
-
Liam Girdwood