From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id 91FB21B1BB for ; Thu, 5 Oct 2017 11:49:28 +0200 (CEST) Received: by mail-wm0-f48.google.com with SMTP id f4so1051061wme.0 for ; Thu, 05 Oct 2017 02:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OSJcX6Gc4v7Z9E0Y/sLUWqWpUcfINuAV3jqkdH2kbNo=; b=HQ7ICsmpZc1dCvDfSGjr4G3Xi7l42cnT1UUPfkCF5aa1L6A5Szbj+C0PNUYbJ9/dim 8/oJA+cJdX3bYJIkg+jyNGW3stKk3DLUaG/5X4vXU+O5tbBrMnqnVxszcX0nw4FMKHv7 H4Wz7qnCTToFTtGLVkldAVOAJ/RHfeGPyrUr8FZlQDrevqa3WXGEkcfaoFGE8YTmOf9u PhcspypZFNHAMJHmXVBIgxi2mSlxJCofzeKmeinyacslntdITngol9tjfmVEg9pTso12 9U/IDVG/xd6CWk7ai+5GphNhccEdlXI7kLbRlPN0FxaEhjptOXGpU/69rLRbVow+PEXh XEyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OSJcX6Gc4v7Z9E0Y/sLUWqWpUcfINuAV3jqkdH2kbNo=; b=j9pYMr3peg7hRMEEs8TPZe7vHIigVm0YzqG1vwbfYDJgptJVHWwITL6qIe6pLPy7QH aM42qzjCVj3SsOcNfq8P2uAmPVScvJIsrCBJIBQr2qbsRy9e6GBIiwHpVW/9e5u7LGwz AdA6Zjm/AgtByJKWkfIzCLpiaOH/izL2vA7uZduSI0V2EGJf/klGlzPC6sRNzKfovxvA QRC7TxYDoaRd6yOhdBNBO9CuScXkVSqrhY6AIiY4K4v+4gjMUJEvfVLm8id3sjCUPr4k amyvcJB6B5bJi7DzuzlACRWfpkhMqNR1ybmgVWtiNyWJh2CTcofN1V17S86tCHOiA7rM lbdQ== X-Gm-Message-State: AHPjjUgBDLbTqpEYk1u7+3dUphBJ8/PlvSQjdz9mhiu+QmiAdS+InDob vx0yhrjkrTep0N04z/fbejvxkA== X-Google-Smtp-Source: AOwi7QAkAyljmV4VwtdU6JL5tjTFU1kbBpzSHizsYCh9tTvCEGknIVIZXzkbUM+i2dGHacV2Wh2r/A== X-Received: by 10.80.146.35 with SMTP id i32mr33158580eda.10.1507196967913; Thu, 05 Oct 2017 02:49:27 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id k8sm15277552ede.91.2017.10.05.02.49.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 02:49:26 -0700 (PDT) From: Adrien Mazarguil To: Ferruh Yigit , Gaetan Rivet Cc: dev@dpdk.org Date: Thu, 5 Oct 2017 11:49:07 +0200 Message-Id: <1c2bcd3d1e44dd94d9c992315bfab9d75776cc20.1507193186.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 6/7] ethdev: generate flow API conversion header X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Oct 2017 09:49:28 -0000 Add script and build target to generate rte_flow_conv.h (used by rte_flow_conv()) from rte_flow.h. Although the resulting header file is internal and not public, this is not done automatically since it is versioned in the source tree. Developers can update it after making changes to rte_flow.h by running: make lib/librte_ether_sub RTE_MAKE_SUBTARGET=rte_flow_conv.h Signed-off-by: Adrien Mazarguil --- MAINTAINERS | 1 + buildtools/gen-rte_flow_conv-h.sh | 264 +++++++++++++++++++++++++++++++++ lib/librte_ether/Makefile | 10 ++ 3 files changed, 275 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9eec984..002b54e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -253,6 +253,7 @@ F: devtools/test-null.sh Flow API M: Adrien Mazarguil +F: buildtools/gen-rte_flow_conv-h.sh F: lib/librte_ether/rte_flow* Traffic Management API - EXPERIMENTAL diff --git a/buildtools/gen-rte_flow_conv-h.sh b/buildtools/gen-rte_flow_conv-h.sh new file mode 100755 index 0000000..482e733 --- /dev/null +++ b/buildtools/gen-rte_flow_conv-h.sh @@ -0,0 +1,264 @@ +#!/bin/sh -e +# +# BSD LICENSE +# +# Copyright 2017 6WIND S.A. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of 6WIND S.A. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This script generates an internal flow API header file needed by +# conversion function rte_flow_conv(). +# +# This is done by feeding rte_flow.h to the C preprocessor and transforming +# its output into a different C header file whose name is provided as a +# command-line argument. +# +# CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the +# environment. + +# Check command-line parameters and environment. +: ${CC:=cc} +output=${1:?missing output file name} + +# Generate pattern for C punctuators. +punctuators=$(printf '%s' \ +'[ ] ( ) { } . -> +++ -- & * + - ~ ! +/ % << >> < > <= >= == != ^ | && || +? : ; ... += *= /= %= += -= <<= >>= &= ^= |= +, # ## +<: :> <% %> %: %: %:' | + tr '\n' ' ' | + sed -ne 's/[[/.*\?]/\\&/g' -e 's/[[:space:]]\+/\\|/gp') + +# Generate include guard. +guard=$(printf '%s_' "${output##*/}" | + tr [[:lower:]] [[:upper:]] | + sed -e 's/[^A-Z0-9]/_/g' -e 's/^.\{,4\}$//') + +# Retrieve C preprocessor output and expand it to one token per line. +preprocess () +{ + { + temp=/tmp/${0##*/}.$$.c + printf '#include "rte_flow.h"' > "$temp" + ${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \ + ${CFLAGS} ${EXTRA_CFLAGS} -E "$temp" + rm -f "$temp" + } | + sed -e ' +/^[[:space:]]*#/d +s/[[:space:]]\+/\n/g +s/'"$punctuators"'/\n&\n/g +' | + sed -e '/^[[:space:]]*$/d' +} + +# Retrieve defined pattern items and actions. +items='' +actions='' +while read -r type name dummy +do + case "$type" in + ITEM) + items="$items $name" + ;; + ACTION) + actions="$actions $name" + ;; + esac +done < "${output}" || +exit + +# Reuse license header from this script. +sed -ne ' +/^#.*BSD LICENSE/{ + i\ +/*- + :a + /^#/!{ + i\ + */ + q + } + s/^#/ */ + p + n + ba +} +' "$0" + +# Output includes and structure definitions. +printf ' +/** + * @file + * RTE generic flow API (internal) + * + * This file exports resources needed by rte_flow_conv(). + * + * DO NOT EDIT THIS FILE. + * + * It was generated from rte_flow.h, run %s to update it. + */ + +#ifndef %s +#define %s + +#include + +#include "rte_flow.h" + +/** + * This structure describes either a pattern item or an action as well as + * their associated specification or configuration structure. + */ +struct rte_flow_conv_res { + const char *name; /**< Object name. */ + const void *mask; /**< Default mask for structure if relevant. */ + size_t size; /**< Associated structure size. */ + size_t flex_len_type; /**< Length field type for flexible array. */ + size_t flex_len_off; /**< Length field offset for flexible array. */ + size_t flex_elt_size; /**< Flexible array element size. */ + size_t flex_off; /**< Flexible array field offset. */ +}; +' \ + "${0##*/}" \ + "$guard" \ + "$guard" + +# Pattern items/actions arrays generator. +generate () +{ + type=${1:?missing type} + desc=${2:?missing description} + lc_type=$(printf '%s' "$type" | tr [:upper:] [:lower:]) + : ${lc_type:?cannot convert type to lower case} + shift 2 + objects=${@:?missing objects} + printf ' +/** %s description table. */ +static const struct rte_flow_conv_res rte_flow_conv_res_%s[] = {' \ + "$desc" "$lc_type" + for object in $objects + do + lc_object=$(printf '%s' "$object" | tr [:upper:] [:lower:]) || + break + set -- $(preprocess | + sed -ne ' +/^struct$/{ + n + /^rte_flow_'"$lc_type"'_'"$lc_object"'$/{ + :a + p + /^{$/{ + H + n + ba + } + /^}$/{ + x + s/\n{$// + /^$/q + x + } + n + ba + } +}' | + tr '\n' ' ' | + sed -ne ' +s/ /\n/ +P +s/^.* \([^ ]\+\) ; [^ ]\+ \([^ ]\+\) \[ ] ; } $/\1 \2/p') + size=${1:+"sizeof(struct $1)"} + : ${size:=0} + flex_len_type=${2:+"sizeof(((struct $1 *)0)->$2)"} + : ${flex_len_type:=0} + flex_len_off=${2:+"offsetof(struct $1, $2)"} + : ${flex_len_off:=0} + flex_elt_size=${2:+"sizeof(((struct $1 *)0)->$3[0])"} + : ${flex_elt_size:=0} + flex_off=${3:+"offsetof(struct $1, $3)"} + : ${flex_off:=0} + printf ' + [RTE_FLOW_'"$type"'_TYPE_%s] = { + .name = "%s", + .size = %s, + .flex_len_type = %s, + .flex_len_off = %s, + .flex_elt_size = %s, + .flex_off = %s, + },' \ + "$object" \ + "$lc_object" \ + "$size" \ + "$flex_len_type" \ + "$flex_len_off" \ + "$flex_elt_size" \ + "$flex_off" + done + printf ' +}; +' +} + +# Generate pattern items/actions arrays. +generate ITEM "Pattern items" $items && +generate ACTION "Actions" $actions || +exit + +# Output footer. +printf ' +#endif /* %s */ +' \ + "$guard" diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile index 5f65d05..0b3f77e 100644 --- a/lib/librte_ether/Makefile +++ b/lib/librte_ether/Makefile @@ -61,4 +61,14 @@ SYMLINK-y-include += rte_flow_driver.h SYMLINK-y-include += rte_tm.h SYMLINK-y-include += rte_tm_driver.h +# +# This file is versioned thus not built automatically. +# To re-generate it, run: +# +# make lib/librte_ether_sub RTE_MAKE_SUBTARGET=rte_flow_conv.h +# +rte_flow_conv.h: rte_flow.h + @$(if $V,,echo " GEN $(@F)") + $Q sh -- $(RTE_SDK)/buildtools/gen-rte_flow_conv-h.sh "$(