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 54007A034F; Mon, 22 Feb 2021 22:25:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B956940138; Mon, 22 Feb 2021 22:25:11 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 0813A4003C for ; Mon, 22 Feb 2021 22:25:09 +0100 (CET) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 1CC9D20B6C40; Mon, 22 Feb 2021 13:25:09 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1CC9D20B6C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1614029109; bh=qenxINmGHQ7HvY2SCHHnkLxBDUYnzkEEBYnXhzb3t2Y=; h=From:To:Cc:Subject:Date:From; b=sEQBwjv+pYDeH8+ja9gmGWSzFds5JwaS48GM5e860UTyaw4WtUbtxDCxOOeAoyIqx 9ut0DdatfkLY1ihXSMj3ZxOLlVx0OnC9QIDTfC+4VC7bF97Xw+s83FoaVcfJyrPgY5 87RnC0/iuzfGtLZuopyc3kOpKw7DGVO58hE8r7sw= From: Jie To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, roretzla@linux.microsoft.com Date: Mon, 22 Feb 2021 13:25:02 -0800 Message-Id: <1614029102-30858-1-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH] rte_metrics: unconditionally export rte_metrics_tel_xxx functions 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 Sender: "dev" From: Jie Zhou This patch allows the same set of rte_metrics_tel_* functions to be exported no matter JANSSON is available or not, by doing following: 1. Leverage dpdk_conf to set configuration flag RTE_HAVE_JANSSON when Jansson dependency is found. 2. In rte_metrics_telemetry.c, leverage RTE_HAVE_JANSSON to handle the case when JANSSON is not available by adding stubs for all the instances. 3. In meson.build, per dpdk\doc\guides\rel_notes\release_20_05.rst, it is claimed that "Telemetry library is no longer dependent on the external Jansson library, which allows Telemetry be enabled by default.", thus make the deps and includes of Telemetry as not conditional anymore. Signed-off-by: Jie Zhou --- config/meson.build | 5 ++ lib/librte_metrics/meson.build | 13 +++--- lib/librte_metrics/rte_metrics_telemetry.c | 53 ++++++++++++++++++++++ lib/librte_metrics/rte_metrics_telemetry.h | 2 +- 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/config/meson.build b/config/meson.build index 3cf560b8a..892bd9677 100644 --- a/config/meson.build +++ b/config/meson.build @@ -292,6 +292,11 @@ if is_freebsd add_project_arguments('-D__BSD_VISIBLE', language: 'c') endif +jansson = dependency('jansson', required: false, method: 'pkg-config') +if jansson.found() + dpdk_conf.set('RTE_HAVE_JANSSON', 1) +endif + if is_windows # VirtualAlloc2() is available since Windows 10 / Server 2016. add_project_arguments('-D_WIN32_WINNT=0x0A00', language: 'c') diff --git a/lib/librte_metrics/meson.build b/lib/librte_metrics/meson.build index 28a8cc115..b13604c88 100644 --- a/lib/librte_metrics/meson.build +++ b/lib/librte_metrics/meson.build @@ -4,11 +4,12 @@ sources = files('rte_metrics.c') headers = files('rte_metrics.h') -jansson = dependency('jansson', required: false, method: 'pkg-config') -if jansson.found() +if dpdk_conf.has('RTE_HAVE_JANSSON') ext_deps += jansson - sources += files('rte_metrics_telemetry.c') - headers += files('rte_metrics_telemetry.h') - deps += ['ethdev', 'telemetry'] - includes += include_directories('../librte_telemetry') endif + +sources += files('rte_metrics_telemetry.c') +headers += files('rte_metrics_telemetry.h') + +deps += ['ethdev', 'telemetry'] +includes += include_directories('../librte_telemetry') diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c index b8ee56ef0..225d9ebce 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.c +++ b/lib/librte_metrics/rte_metrics_telemetry.c @@ -2,7 +2,9 @@ * Copyright(c) 2020 Intel Corporation */ +#ifdef RTE_HAVE_JANSSON #include +#endif #include #include @@ -13,6 +15,7 @@ #include "rte_metrics.h" #include "rte_metrics_telemetry.h" +#ifdef RTE_HAVE_JANSSON struct telemetry_metrics_data tel_met_data; int metrics_log_level; @@ -70,10 +73,12 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id) free(xstats_names); return ret; } +#endif int32_t rte_metrics_tel_reg_all_ethdev(int *metrics_register_done, int *reg_index_list) { +#ifdef JANSSON struct driver_index { const void *dev_ops; int reg_index; @@ -110,8 +115,15 @@ rte_metrics_tel_reg_all_ethdev(int *metrics_register_done, int *reg_index_list) } *metrics_register_done = 1; return 0; +#else + RTE_SET_USED(metrics_register_done); + RTE_SET_USED(reg_index_list); + + return -ENOTSUP; +#endif } +#ifdef RTE_HAVE_JANSSON static int32_t rte_metrics_tel_update_metrics_ethdev(uint16_t port_id, int reg_start_index) { @@ -224,11 +236,13 @@ rte_metrics_tel_format_port(uint32_t pid, json_t *ports, free(names); return ret; } +#endif int32_t rte_metrics_tel_encode_json_format(struct telemetry_encode_param *ep, char **json_buffer) { +#ifdef JANSSON json_t *root, *ports; int ret, i; @@ -276,12 +290,19 @@ rte_metrics_tel_encode_json_format(struct telemetry_encode_param *ep, *json_buffer = json_dumps(root, JSON_INDENT(2)); json_decref(root); return 0; +#else + RTE_SET_USED(ep); + RTE_SET_USED(json_buffer); + + return -ENOTSUP; +#endif } int32_t rte_metrics_tel_get_ports_stats_json(struct telemetry_encode_param *ep, int *reg_index, char **json_buffer) { +#ifdef RTE_HAVE_JANSSON int ret, i; uint32_t port_id; @@ -306,11 +327,19 @@ rte_metrics_tel_get_ports_stats_json(struct telemetry_encode_param *ep, return ret; } return 0; +#else + RTE_SET_USED(ep); + RTE_SET_USED(reg_index); + RTE_SET_USED(json_buffer); + + return -ENOTSUP; +#endif } int32_t rte_metrics_tel_get_port_stats_ids(struct telemetry_encode_param *ep) { +#ifdef RTE_HAVE_JANSSON int p, num_port_ids = 0; RTE_ETH_FOREACH_DEV(p) { @@ -327,8 +356,14 @@ rte_metrics_tel_get_port_stats_ids(struct telemetry_encode_param *ep) ep->pp.num_metric_ids = 0; ep->type = PORT_STATS; return 0; +#else + RTE_SET_USED(ep); + + return -ENOTSUP; +#endif } +#ifdef RTE_HAVE_JANSSON static int32_t rte_metrics_tel_stat_names_to_ids(const char * const *stat_names, uint32_t *stat_ids, int num_stat_names) @@ -373,10 +408,12 @@ rte_metrics_tel_stat_names_to_ids(const char * const *stat_names, free(names); return 0; } +#endif int32_t rte_metrics_tel_extract_data(struct telemetry_encode_param *ep, json_t *data) { +#ifdef RTE_HAVE_JANSSON int ret; json_t *port_ids_json = json_object_get(data, "ports"); json_t *stat_names_json = json_object_get(data, "stats"); @@ -420,8 +457,23 @@ rte_metrics_tel_extract_data(struct telemetry_encode_param *ep, json_t *data) ep->type = PORT_STATS; return 0; +#else + RTE_SET_USED(ep); + RTE_SET_USED(data); + + return -ENOTSUP; +#endif +} + +int32_t +rte_metrics_tel_get_global_stats(struct telemetry_encode_param* ep) +{ + RTE_SET_USED(ep); + + return -ENOTSUP; } +#ifdef RTE_HAVE_JANSSON static int rte_metrics_tel_initial_metrics_setup(void) { @@ -541,3 +593,4 @@ RTE_INIT(metrics_ctor) handle_ports_stats_values_by_name); #endif } +#endif diff --git a/lib/librte_metrics/rte_metrics_telemetry.h b/lib/librte_metrics/rte_metrics_telemetry.h index 5dbb32ca0..efc6b9a9e 100644 --- a/lib/librte_metrics/rte_metrics_telemetry.h +++ b/lib/librte_metrics/rte_metrics_telemetry.h @@ -2,7 +2,7 @@ * Copyright(c) 2020 Intel Corporation */ -#ifdef RTE_LIB_TELEMETRY +#ifdef RTE_HAVE_JANSSON #include #else #define json_t void * -- 2.30.0.vfs.0.2