diff mbox series

[API-NEXT,v1,5/8] api: pool: remove union from params

Message ID 1508158805-5932-6-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [API-NEXT,v1,1/8] api: pool: relax packet pool param num | expand

Commit Message

Github ODP bot Oct. 16, 2017, 1 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Remove anonymous union from pool parameter structure.
Union makes it impossible to initialize parameters per
pool type (use other values than all zeros). This change
is not visible to applications (union was anonymous).

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 234 (psavol:next-pool-param)
 ** https://github.com/Linaro/odp/pull/234
 ** Patch: https://github.com/Linaro/odp/pull/234.patch
 ** Base sha: afeda4d14bb6f449cb269680cdbd56b26726eedf
 ** Merge commit sha: 54f5fc670a7c125b6b0098e34e68fe3b45875069
 **/
 include/odp/api/spec/pool.h | 215 ++++++++++++++++++++++----------------------
 1 file changed, 109 insertions(+), 106 deletions(-)

Comments

Bill Fischofer Oct. 16, 2017, 11:15 p.m. UTC | #1
On Mon, Oct 16, 2017 at 8:00 AM, Github ODP bot <odpbot@yandex.ru> wrote:
> From: Petri Savolainen <petri.savolainen@linaro.org>

>

> Remove anonymous union from pool parameter structure.

> Union makes it impossible to initialize parameters per

> pool type (use other values than all zeros). This change

> is not visible to applications (union was anonymous).


The reason for the union was to reduce the size of the
odp_pool_param_t. I'm not sure I understand the remark about making
initializations impossible. Pool parameters are initialized to their
default values via the odp_pool_param_init() API. Failure to use this
API exposes the application to portability issues as different
implementations may have different default values. If the use of
anonymous unions discourages attempts to have static copies of
odp_pool_param_t variables, so much the better.

>

> Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

> ---

> /** Email created from pull request 234 (psavol:next-pool-param)

>  ** https://github.com/Linaro/odp/pull/234

>  ** Patch: https://github.com/Linaro/odp/pull/234.patch

>  ** Base sha: afeda4d14bb6f449cb269680cdbd56b26726eedf

>  ** Merge commit sha: 54f5fc670a7c125b6b0098e34e68fe3b45875069

>  **/

>  include/odp/api/spec/pool.h | 215 ++++++++++++++++++++++----------------------

>  1 file changed, 109 insertions(+), 106 deletions(-)

>

> diff --git a/include/odp/api/spec/pool.h b/include/odp/api/spec/pool.h

> index 7c9bee8ee..7b1e2d467 100644

> --- a/include/odp/api/spec/pool.h

> +++ b/include/odp/api/spec/pool.h

> @@ -195,112 +195,115 @@ typedef struct odp_pool_param_t {

>         /** Pool type */

>         int type;

>

> -       /** Variant parameters for different pool types */

> -       union {

> -               /** Parameters for buffer pools */

> -               struct {

> -                       /** Number of buffers in the pool */

> -                       uint32_t num;

> -

> -                       /** Buffer size in bytes. The maximum number of bytes

> -                           application will store in each buffer. */

> -                       uint32_t size;

> -

> -                       /** Minimum buffer alignment in bytes. Valid values are

> -                           powers of two. Use 0 for default alignment.

> -                           Default will always be a multiple of 8. */

> -                       uint32_t align;

> -               } buf;

> -

> -               /** Parameters for packet pools */

> -               struct {

> -                       /** Minimum number of 'len' byte packets.

> -                        *

> -                        *  The pool must contain at least this many packets

> -                        *  that are 'len' bytes or smaller. An implementation

> -                        *  may round up the value, as long as the 'max_num'

> -                        *  parameter below is not violated. The maximum value

> -                        *  for this field is defined by pool capability

> -                        *  pkt.max_num.

> -                        */

> -                       uint32_t num;

> -

> -                       /** Maximum number of packets.

> -                        *

> -                        *  This is the maximum number of packets of any length

> -                        *  that can be allocated from the pool. The maximum

> -                        *  value is defined by pool capability pkt.max_num.

> -                        *  Use 0 when there's no requirement for the maximum

> -                        *  number of packets. The default value is 0.

> -                        */

> -                       uint32_t max_num;

> -

> -                       /** Minimum length of 'num' packets.

> -                        *

> -                        *  The pool must contain at least 'num' packets up to

> -                        *  this packet length (1 ... 'len' bytes). The maximum

> -                        *  value for this field is defined by pool capability

> -                        *  pkt.max_len. Use 0 for default.

> -                        */

> -                       uint32_t len;

> -

> -                       /** Maximum packet length that will be allocated from

> -                           the pool. The maximum value is defined by pool

> -                           capability pkt.max_len. Use 0 for default (the

> -                           pool maximum). */

> -                       uint32_t max_len;

> -

> -                       /** Minimum number of packet data bytes that are stored

> -                           in the first segment of a packet. The maximum value

> -                           is defined by pool capability pkt.max_seg_len.

> -                           Use 0 for default. */

> -                       uint32_t seg_len;

> -

> -                       /** User area size in bytes. The maximum value is

> -                           defined by pool capability pkt.max_uarea_size.

> -                           Specify as 0 if no user area is needed. */

> -                       uint32_t uarea_size;

> -

> -                       /** Minimum Headroom size in bytes. Each newly allocated

> -                           packet from the pool must have at least this much

> -                           headroom. The maximum value is defined by pool

> -                           capability pkt.max_headroom.

> -                           Use zero if headroom is not needed. */

> -                       uint32_t headroom;

> -

> -                       /** Number of subparameters

> -                        *

> -                        *  The number of subparameter table entries used.

> -                        *  The maximum value is defined by pool

> -                        *  capability pkt.max_num_sub. The default value is 0.

> -                        */

> -                       uint8_t num_sub;

> -

> -                       /** Subparameter table

> -                        *

> -                        *  Subparameters continue pool configuration with

> -                        *  additional packet length requirements. The first

> -                        *  table entry follows the num/len specification above.

> -                        *  So that, sub[0].len > 'len', and sub[0].num refers

> -                        *  to packet lengths between 'len' + 1 and sub[0].len.

> -                        *  Similarly, sub[1] follows sub[0] specification, and

> -                        *  so on.

> -                        *

> -                        *  Each requirement is supported separately and may be

> -                        *  rounded up, as long as the 'max_num' parameter is

> -                        *  not violated. It's implementation specific if some

> -                        *  requirements are supported simultaneously (e.g.

> -                        *  due to subpool design).

> -                        */

> -                       odp_pool_pkt_subparam_t sub[ODP_POOL_MAX_SUBPARAMS];

> -               } pkt;

> -

> -               /** Parameters for timeout pools */

> -               struct {

> -                       /** Number of timeouts in the pool */

> -                       uint32_t num;

> -               } tmo;

> -       };

> +       /** Parameters for buffer pools */

> +       struct {

> +               /** Number of buffers in the pool */

> +               uint32_t num;

> +

> +               /** Buffer size in bytes. The maximum number of bytes

> +                *  application will store in each buffer.

> +                */

> +               uint32_t size;

> +

> +               /** Minimum buffer alignment in bytes. Valid values are

> +                *  powers of two. Use 0 for default alignment.

> +                *  Default will always be a multiple of 8.

> +                */

> +               uint32_t align;

> +       } buf;

> +

> +       /** Parameters for packet pools */

> +       struct {

> +               /** Minimum number of 'len' byte packets.

> +                *

> +                *  The pool must contain at least this many packets

> +                *  that are 'len' bytes or smaller. An implementation

> +                *  may round up the value, as long as the 'max_num'

> +                *  parameter below is not violated. The maximum value

> +                *  for this field is defined by pool capability

> +                *  pkt.max_num.

> +                */

> +               uint32_t num;

> +

> +               /** Maximum number of packets.

> +                *

> +                *  This is the maximum number of packets of any length

> +                *  that can be allocated from the pool. The maximum

> +                *  value is defined by pool capability pkt.max_num.

> +                *  Use 0 when there's no requirement for the maximum

> +                *  number of packets. The default value is 0.

> +                */

> +               uint32_t max_num;

> +

> +               /** Minimum length of 'num' packets.

> +                *

> +                *  The pool must contain at least 'num' packets up to

> +                *  this packet length (1 ... 'len' bytes). The maximum

> +                *  value for this field is defined by pool capability

> +                *  pkt.max_len. Use 0 for default.

> +                */

> +               uint32_t len;

> +

> +               /** Maximum packet length that will be allocated from

> +                *  the pool. The maximum value is defined by pool

> +                *  capability pkt.max_len. Use 0 for default (the

> +                *  pool maximum).

> +                */

> +               uint32_t max_len;

> +

> +               /** Minimum number of packet data bytes that are stored

> +                *  in the first segment of a packet. The maximum value

> +                *  is defined by pool capability pkt.max_seg_len.

> +                *  Use 0 for default.

> +                */

> +               uint32_t seg_len;

> +

> +               /** User area size in bytes. The maximum value is

> +                *  defined by pool capability pkt.max_uarea_size.

> +                *  Specify as 0 if no user area is needed.

> +                */

> +               uint32_t uarea_size;

> +

> +               /** Minimum Headroom size in bytes. Each newly allocated

> +                *  packet from the pool must have at least this much

> +                *  headroom. The maximum value is defined by pool

> +                *  capability pkt.max_headroom.

> +                *  Use zero if headroom is not needed.

> +                */

> +               uint32_t headroom;

> +

> +               /** Number of subparameters

> +                *

> +                *  The number of subparameter table entries used.

> +                *  The maximum value is defined by pool

> +                *  capability pkt.max_num_sub. The default value is 0.

> +                */

> +               uint8_t num_sub;

> +

> +               /** Subparameter table

> +                *

> +                *  Subparameters continue pool configuration with

> +                *  additional packet length requirements. The first

> +                *  table entry follows the num/len specification above.

> +                *  So that, sub[0].len > 'len', and sub[0].num refers

> +                *  to packet lengths between 'len' + 1 and sub[0].len.

> +                *  Similarly, sub[1] follows sub[0] specification, and

> +                *  so on.

> +                *

> +                *  Each requirement is supported separately and may be

> +                *  rounded up, as long as the 'max_num' parameter is

> +                *  not violated. It's implementation specific if some

> +                *  requirements are supported simultaneously (e.g.

> +                *  due to subpool design).

> +                */

> +               odp_pool_pkt_subparam_t sub[ODP_POOL_MAX_SUBPARAMS];

> +       } pkt;

> +

> +       /** Parameters for timeout pools */

> +       struct {

> +               /** Number of timeouts in the pool */

> +               uint32_t num;

> +       } tmo;

>  } odp_pool_param_t;

>

>  /** Packet pool*/

>
diff mbox series

Patch

diff --git a/include/odp/api/spec/pool.h b/include/odp/api/spec/pool.h
index 7c9bee8ee..7b1e2d467 100644
--- a/include/odp/api/spec/pool.h
+++ b/include/odp/api/spec/pool.h
@@ -195,112 +195,115 @@  typedef struct odp_pool_param_t {
 	/** Pool type */
 	int type;
 
-	/** Variant parameters for different pool types */
-	union {
-		/** Parameters for buffer pools */
-		struct {
-			/** Number of buffers in the pool */
-			uint32_t num;
-
-			/** Buffer size in bytes. The maximum number of bytes
-			    application will store in each buffer. */
-			uint32_t size;
-
-			/** Minimum buffer alignment in bytes. Valid values are
-			    powers of two. Use 0 for default alignment.
-			    Default will always be a multiple of 8. */
-			uint32_t align;
-		} buf;
-
-		/** Parameters for packet pools */
-		struct {
-			/** Minimum number of 'len' byte packets.
-			 *
-			 *  The pool must contain at least this many packets
-			 *  that are 'len' bytes or smaller. An implementation
-			 *  may round up the value, as long as the 'max_num'
-			 *  parameter below is not violated. The maximum value
-			 *  for this field is defined by pool capability
-			 *  pkt.max_num.
-			 */
-			uint32_t num;
-
-			/** Maximum number of packets.
-			 *
-			 *  This is the maximum number of packets of any length
-			 *  that can be allocated from the pool. The maximum
-			 *  value is defined by pool capability pkt.max_num.
-			 *  Use 0 when there's no requirement for the maximum
-			 *  number of packets. The default value is 0.
-			 */
-			uint32_t max_num;
-
-			/** Minimum length of 'num' packets.
-			 *
-			 *  The pool must contain at least 'num' packets up to
-			 *  this packet length (1 ... 'len' bytes). The maximum
-			 *  value for this field is defined by pool capability
-			 *  pkt.max_len. Use 0 for default.
-			 */
-			uint32_t len;
-
-			/** Maximum packet length that will be allocated from
-			    the pool. The maximum value is defined by pool
-			    capability pkt.max_len. Use 0 for default (the
-			    pool maximum). */
-			uint32_t max_len;
-
-			/** Minimum number of packet data bytes that are stored
-			    in the first segment of a packet. The maximum value
-			    is defined by pool capability pkt.max_seg_len.
-			    Use 0 for default. */
-			uint32_t seg_len;
-
-			/** User area size in bytes. The maximum value is
-			    defined by pool capability pkt.max_uarea_size.
-			    Specify as 0 if no user area is needed. */
-			uint32_t uarea_size;
-
-			/** Minimum Headroom size in bytes. Each newly allocated
-			    packet from the pool must have at least this much
-			    headroom. The maximum value is defined by pool
-			    capability pkt.max_headroom.
-			    Use zero if headroom is not needed. */
-			uint32_t headroom;
-
-			/** Number of subparameters
-			 *
-			 *  The number of subparameter table entries used.
-			 *  The maximum value is defined by pool
-			 *  capability pkt.max_num_sub. The default value is 0.
-			 */
-			uint8_t num_sub;
-
-			/** Subparameter table
-			 *
-			 *  Subparameters continue pool configuration with
-			 *  additional packet length requirements. The first
-			 *  table entry follows the num/len specification above.
-			 *  So that, sub[0].len > 'len', and sub[0].num refers
-			 *  to packet lengths between 'len' + 1 and sub[0].len.
-			 *  Similarly, sub[1] follows sub[0] specification, and
-			 *  so on.
-			 *
-			 *  Each requirement is supported separately and may be
-			 *  rounded up, as long as the 'max_num' parameter is
-			 *  not violated. It's implementation specific if some
-			 *  requirements are supported simultaneously (e.g.
-			 *  due to subpool design).
-			 */
-			odp_pool_pkt_subparam_t sub[ODP_POOL_MAX_SUBPARAMS];
-		} pkt;
-
-		/** Parameters for timeout pools */
-		struct {
-			/** Number of timeouts in the pool */
-			uint32_t num;
-		} tmo;
-	};
+	/** Parameters for buffer pools */
+	struct {
+		/** Number of buffers in the pool */
+		uint32_t num;
+
+		/** Buffer size in bytes. The maximum number of bytes
+		 *  application will store in each buffer.
+		 */
+		uint32_t size;
+
+		/** Minimum buffer alignment in bytes. Valid values are
+		 *  powers of two. Use 0 for default alignment.
+		 *  Default will always be a multiple of 8.
+		 */
+		uint32_t align;
+	} buf;
+
+	/** Parameters for packet pools */
+	struct {
+		/** Minimum number of 'len' byte packets.
+		 *
+		 *  The pool must contain at least this many packets
+		 *  that are 'len' bytes or smaller. An implementation
+		 *  may round up the value, as long as the 'max_num'
+		 *  parameter below is not violated. The maximum value
+		 *  for this field is defined by pool capability
+		 *  pkt.max_num.
+		 */
+		uint32_t num;
+
+		/** Maximum number of packets.
+		 *
+		 *  This is the maximum number of packets of any length
+		 *  that can be allocated from the pool. The maximum
+		 *  value is defined by pool capability pkt.max_num.
+		 *  Use 0 when there's no requirement for the maximum
+		 *  number of packets. The default value is 0.
+		 */
+		uint32_t max_num;
+
+		/** Minimum length of 'num' packets.
+		 *
+		 *  The pool must contain at least 'num' packets up to
+		 *  this packet length (1 ... 'len' bytes). The maximum
+		 *  value for this field is defined by pool capability
+		 *  pkt.max_len. Use 0 for default.
+		 */
+		uint32_t len;
+
+		/** Maximum packet length that will be allocated from
+		 *  the pool. The maximum value is defined by pool
+		 *  capability pkt.max_len. Use 0 for default (the
+		 *  pool maximum).
+		 */
+		uint32_t max_len;
+
+		/** Minimum number of packet data bytes that are stored
+		 *  in the first segment of a packet. The maximum value
+		 *  is defined by pool capability pkt.max_seg_len.
+		 *  Use 0 for default.
+		 */
+		uint32_t seg_len;
+
+		/** User area size in bytes. The maximum value is
+		 *  defined by pool capability pkt.max_uarea_size.
+		 *  Specify as 0 if no user area is needed.
+		 */
+		uint32_t uarea_size;
+
+		/** Minimum Headroom size in bytes. Each newly allocated
+		 *  packet from the pool must have at least this much
+		 *  headroom. The maximum value is defined by pool
+		 *  capability pkt.max_headroom.
+		 *  Use zero if headroom is not needed.
+		 */
+		uint32_t headroom;
+
+		/** Number of subparameters
+		 *
+		 *  The number of subparameter table entries used.
+		 *  The maximum value is defined by pool
+		 *  capability pkt.max_num_sub. The default value is 0.
+		 */
+		uint8_t num_sub;
+
+		/** Subparameter table
+		 *
+		 *  Subparameters continue pool configuration with
+		 *  additional packet length requirements. The first
+		 *  table entry follows the num/len specification above.
+		 *  So that, sub[0].len > 'len', and sub[0].num refers
+		 *  to packet lengths between 'len' + 1 and sub[0].len.
+		 *  Similarly, sub[1] follows sub[0] specification, and
+		 *  so on.
+		 *
+		 *  Each requirement is supported separately and may be
+		 *  rounded up, as long as the 'max_num' parameter is
+		 *  not violated. It's implementation specific if some
+		 *  requirements are supported simultaneously (e.g.
+		 *  due to subpool design).
+		 */
+		odp_pool_pkt_subparam_t sub[ODP_POOL_MAX_SUBPARAMS];
+	} pkt;
+
+	/** Parameters for timeout pools */
+	struct {
+		/** Number of timeouts in the pool */
+		uint32_t num;
+	} tmo;
 } odp_pool_param_t;
 
 /** Packet pool*/