From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 75FB6A0543; Wed, 14 Dec 2022 03:46:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1165A4021D; Wed, 14 Dec 2022 03:46:57 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 2E6654003F for ; Wed, 14 Dec 2022 03:46:56 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NX09G2QD5zlXR9; Wed, 14 Dec 2022 10:45:54 +0800 (CST) Received: from [10.67.103.231] (10.67.103.231) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 10:46:52 +0800 Message-ID: Date: Wed, 14 Dec 2022 10:46:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH V4 6/9] telemetry: refactor mapping between value and array type To: Bruce Richardson CC: , , , , , References: <20221208080540.62913-1-lihuisong@huawei.com> <20221213101512.39919-1-lihuisong@huawei.com> <20221213101512.39919-7-lihuisong@huawei.com> From: "lihuisong (C)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.103.231] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 在 2022/12/14 0:57, Bruce Richardson 写道: > On Tue, Dec 13, 2022 at 06:15:09PM +0800, Huisong Li wrote: >> Currently, use rte_tel_value_type as index of array to find the >> tel_container_types in rte_tel_data_start_array. It's not good >> for maintenance. >> >> Fixes: ed1bfad7d384 ("telemetry: add functions for returning callback data") >> Cc: stable@dpdk.org >> >> Signed-off-by: Huisong Li >> Acked-by: Morten Brørup >> Acked-by: Chengwen Feng >> --- >> lib/telemetry/telemetry_data.c | 28 ++++++++++++++++++++++------ >> 1 file changed, 22 insertions(+), 6 deletions(-) >> >> diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c >> index 34366ecee3..080d99aec9 100644 >> --- a/lib/telemetry/telemetry_data.c >> +++ b/lib/telemetry/telemetry_data.c >> @@ -15,13 +15,29 @@ >> int >> rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type) >> { >> - enum tel_container_types array_types[] = { >> - RTE_TEL_ARRAY_STRING, /* RTE_TEL_STRING_VAL = 0 */ >> - RTE_TEL_ARRAY_INT, /* RTE_TEL_INT_VAL = 1 */ >> - RTE_TEL_ARRAY_U64, /* RTE_TEL_u64_VAL = 2 */ >> - RTE_TEL_ARRAY_CONTAINER, /* RTE_TEL_CONTAINER = 3 */ >> + struct { >> + enum rte_tel_value_type value_type; >> + enum tel_container_types array_type; >> + } value2array_types_map[] = { >> + {RTE_TEL_STRING_VAL, RTE_TEL_ARRAY_STRING}, >> + {RTE_TEL_INT_VAL, RTE_TEL_ARRAY_INT}, >> + {RTE_TEL_U64_VAL, RTE_TEL_ARRAY_U64}, >> + {RTE_TEL_CONTAINER, RTE_TEL_ARRAY_CONTAINER}, >> }; >> - d->type = array_types[type]; >> + int array_types = -1; >> + uint16_t i; >> + >> + for (i = 0; i < RTE_DIM(value2array_types_map); i++) { >> + if (type == value2array_types_map[i].value_type) { >> + array_types = value2array_types_map[i].array_type; >> + break; >> + } >> + } >> + > While this may need cleanup, I don't think this particular way is the > best method to use, so NAK for this patch for now. Can you have some advice to optimize it, Bruce? > > /Bruce > .