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 C3E95A06C9; Wed, 19 Oct 2022 16:29:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A64D842BC1; Wed, 19 Oct 2022 16:29:13 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C988242BB1 for ; Wed, 19 Oct 2022 16:29:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666189752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CZwbl7kUWqsXnDqyCz62jGysk39x57HgwlY/vD90DRY=; b=fmue6O9c9lUqajsHuf6SnsRZ+SZBzfFCgD/QHuIVi96fc+PnhpfUqddoalsKCYRiIPhzKV vJOCG5uHVKo8At7lhZ+WVinKb+fN1fSZY/8aEzt4uvw8rJdPIRcQdpKwp2ib3BjPUqpozS fGQRNFthnAv/RC7W5tUthVcW9cwk1fs= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-153-2OlmzkKmP8yMPmaSZDIqlA-1; Wed, 19 Oct 2022 10:29:11 -0400 X-MC-Unique: 2OlmzkKmP8yMPmaSZDIqlA-1 Received: by mail-pf1-f197.google.com with SMTP id k11-20020aa792cb000000b00558674e8e7fso9516140pfa.6 for ; Wed, 19 Oct 2022 07:29:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CZwbl7kUWqsXnDqyCz62jGysk39x57HgwlY/vD90DRY=; b=bPaUz62Fu9NA+My6Kz17QBT8pUgb5EkzfLFDrXTZOC84ahvKsj2lwAtJr84HKQZk4b Eoops38YP2J0QjsbGM6j/3KzF1lsflnPqWyCnUxXovk05E/K4kVJTZm5wiIX+3Aojfj8 tP7ydo07r83CPrGiiW//vxyZ1xKnENKXhx2P0iK675gAx2cXdhjqB0FUQkxSxavp7EJ3 5VCreYMjPhs66J7g/ZW6oX6NWNoFpEu4ET4fILJFB5jLjUlLjAk/hdjiyXJoWwrtYxlR 1p9fhruFRanCeUOy0h2sIcWXB6O7MJSW3dUlNwNw7LtkQddacYGkf0pXr7bzOIHMTumN 9MpA== X-Gm-Message-State: ACrzQf16hReBfe1qSBG4iyFha01dyHYcYj9/VbHTrcXebyG+2T2NksIy D7YreuaIUYAfUSTEArLouoaN+j3FSmEm1vwJK5SSJdhbvZ0t7+VcfJwugGPAkvfvcwgDwzZktLH 2nfFgRe4ttefb2CgLyvo= X-Received: by 2002:a17:902:bf46:b0:179:eba5:90ba with SMTP id u6-20020a170902bf4600b00179eba590bamr8741234pls.16.1666189750135; Wed, 19 Oct 2022 07:29:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OKCl8JZGq+Q+uF5m8hROVPfOkBJXsrE4O0/iVq+RUZyT6CzaDWIfTPiRx+BYRVpYMj8kwi/d1Q9YsflRI06Y= X-Received: by 2002:a17:902:bf46:b0:179:eba5:90ba with SMTP id u6-20020a170902bf4600b00179eba590bamr8741203pls.16.1666189749741; Wed, 19 Oct 2022 07:29:09 -0700 (PDT) MIME-Version: 1.0 References: <20221019073702.3948624-1-david.marchand@redhat.com> In-Reply-To: From: David Marchand Date: Wed, 19 Oct 2022 16:28:58 +0200 Message-ID: Subject: Re: [PATCH] telemetry: support boolean type To: Bruce Richardson Cc: dev@dpdk.org, mb@smartsharesystems.com, Ciara Power X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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 On Wed, Oct 19, 2022 at 3:48 PM Bruce Richardson wrote: > > On Wed, Oct 19, 2022 at 09:37:02AM +0200, David Marchand wrote: > > Add the boolean type RTE_TEL_BOOL_VAL for values in arrays and dicts. > > > > Signed-off-by: David Marchand > > --- > > This patch looks pretty good to me. Some very small comments inline below. > One thing I notice is that we are not supporting booleans except as part of > an array or dictionary. Is it likely that we will ever want to have a > telemetry command that just returns true/false alone? Don't see that being I wondered too, but then I saw that only the "simple" type string was handled and others were not. So I decided to skip. > necessary just yet, so: > > Reviewed-by: Bruce Richardson > Acked-by: Bruce Richardson > > > app/test/test_telemetry_data.c | 88 +++++++++++++++++++++++++++++++++- > > lib/telemetry/rte_telemetry.h | 36 ++++++++++++++ > > lib/telemetry/telemetry.c | 24 +++++++++- > > lib/telemetry/telemetry_data.c | 44 +++++++++++++++-- > > lib/telemetry/telemetry_data.h | 5 ++ > > lib/telemetry/telemetry_json.h | 34 +++++++++++++ > > lib/telemetry/version.map | 5 ++ > > 7 files changed, 228 insertions(+), 8 deletions(-) > > > > > > > diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h > > index a0d21d6b7f..5d74212f17 100644 > > --- a/lib/telemetry/rte_telemetry.h > > +++ b/lib/telemetry/rte_telemetry.h > > @@ -2,6 +2,7 @@ > > * Copyright(c) 2018 Intel Corporation > > */ > > > > +#include > > #include > > > > #include > > @@ -46,6 +47,7 @@ enum rte_tel_value_type { > > RTE_TEL_INT_VAL, /** a signed 32-bit int value */ > > RTE_TEL_U64_VAL, /** an unsigned 64-bit int value */ > > RTE_TEL_CONTAINER, /** a container struct */ > > + RTE_TEL_BOOL_VAL, /** a boolean value */ > > }; > > > > /** > > @@ -155,6 +157,22 @@ int > > rte_tel_data_add_array_container(struct rte_tel_data *d, > > struct rte_tel_data *val, int keep); > > > > +/** > > + * Add a boolean to an array. > > + * The array must have been started by rte_tel_data_start_array() with > > + * RTE_TEL_BOOL_VAL as the type parameter. > > + * > > + * @param d > > + * The data structure passed to the callback > > + * @param x > > + * The number to be returned in the array > > number -> boolean value > Indeed.. > > + * @return > > + * 0 on success, negative errno on error > > + */ > > +__rte_experimental > > +int > > +rte_tel_data_add_array_bool(struct rte_tel_data *d, bool x); > > + > > /** > > * Add a string value to a dictionary. > > * The dict must have been started by rte_tel_data_start_dict(). > > @@ -233,6 +251,24 @@ int > > rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name, > > struct rte_tel_data *val, int keep); > > > > +/** > > + * Add a boolean value to a dictionary. > > + * The dict must have been started by rte_tel_data_start_dict(). > > + * > > + * @param d > > + * The data structure passed to the callback > > + * @param name > > + * The name the value is to be stored under in the dict > > + * Must contain only alphanumeric characters or the symbols: '_' or '/' > > + * @param val > > + * The number to be stored in the dict > > number -> boolean value > > > + * @return > > + * 0 on success, negative errno on error, E2BIG on string truncation of name. > > + */ > > +__rte_experimental > > +int > > +rte_tel_data_add_dict_bool(struct rte_tel_data *d, const char *name, bool val); > > + > > /** > > * This telemetry callback is used when registering a telemetry command. > > * It handles getting and formatting information to be returned to telemetry > > diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c > > > diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c > > index 5b319c18fb..4f81f71e03 100644 > > --- a/lib/telemetry/telemetry_data.c > > +++ b/lib/telemetry/telemetry_data.c > > @@ -16,10 +16,11 @@ 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 */ > > + [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, > > + [RTE_TEL_BOOL_VAL] = RTE_TEL_ARRAY_BOOL, > > }; > > Really like this change! I don't remember if this form is related to some CXX standard... but I see that no compiler complained in the CI. > > > d->type = array_types[type]; > > d->data_len = 0; > > @@ -80,6 +81,17 @@ rte_tel_data_add_array_u64(struct rte_tel_data *d, uint64_t x) > > return 0; > > } > > > > +int > > +rte_tel_data_add_array_bool(struct rte_tel_data *d, bool x) > > +{ > > + if (d->type != RTE_TEL_ARRAY_BOOL) > > + return -EINVAL; > > + if (d->data_len >= RTE_TEL_MAX_ARRAY_ENTRIES) > > + return -ENOSPC; > > + d->data.array[d->data_len++].boolval = x; > > + return 0; > > +} > > + > > int > > rte_tel_data_add_array_container(struct rte_tel_data *d, > > struct rte_tel_data *val, int keep) > > > diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h > > index e3fae7c30d..c97da97366 100644 > > --- a/lib/telemetry/telemetry_json.h > > +++ b/lib/telemetry/telemetry_json.h > > @@ -7,6 +7,7 @@ > > > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -159,6 +160,21 @@ rte_tel_json_add_array_u64(char *buf, const int len, const int used, > > return ret == 0 ? used : end + ret; > > } > > > > +/* Appends a boolean into the JSON array in the provided buffer. */ > > +static inline int > > +rte_tel_json_add_array_bool(char *buf, const int len, const int used, > > + bool val) > > +{ > > + int ret, end = used - 1; /* strip off final delimiter */ > > + if (used <= 2) /* assume empty, since minimum is '[]' */ > > + return __json_snprintf(buf, len, "[%s]", > > + val ? "true" : "false"); > > + > > + ret = __json_snprintf(buf + end, len - end, ",%s]", > > + val ? "true" : "false"); > > Wonder if it's worthwhile doing a macro for this conditional, since the > same ternary-operator snippet appears 4 times in this code. Err, naming it would be hard and I don't see for now how we could reuse it. > > > + return ret == 0 ? used : end + ret; > > +} > > + > > /* > > * Add a new element with raw JSON value to the JSON array stored in the > > * provided buffer. -- David Marchand