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 6765EA0524; Thu, 6 May 2021 10:28:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E349A410DB; Thu, 6 May 2021 10:28:09 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 675F740040 for ; Thu, 6 May 2021 10:28:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620289687; 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: content-transfer-encoding:content-transfer-encoding; bh=GVUKdlzQJzJeginQ2gwBlPnvv5cHLLd0XC4bqXIhJ7U=; b=HM5X0uOxClCLdudYakKM6RxnhesHCreUQgN8rXCnimLPi9KbH4mzLMLkLaN6PqG6y3JHMF f5fNi/CNptM587mNyn9grHGrlVG1uhRRPM/riGxFP0Wd89L07YjA9GvjFE5hhPZK/931wD f7CLbdmw5PVSnYWkP4n89I24z0UUJQU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-Hs1z1w_3OGCUyZYhJUGKPw-1; Thu, 06 May 2021 04:28:03 -0400 X-MC-Unique: Hs1z1w_3OGCUyZYhJUGKPw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA81E107ACCD; Thu, 6 May 2021 08:28:02 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9274260CD0; Thu, 6 May 2021 08:28:01 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Ciara Power Date: Thu, 6 May 2021 10:27:54 +0200 Message-Id: <20210506082754.2843-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH] telemetry: remove static limit on callbacks count 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" This code is not performance sensitive and can be switched to dynamic allocations. Signed-off-by: David Marchand --- lib/telemetry/rte_telemetry.h | 2 +- lib/telemetry/telemetry.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h index c08146e142..8776998b54 100644 --- a/lib/telemetry/rte_telemetry.h +++ b/lib/telemetry/rte_telemetry.h @@ -283,7 +283,7 @@ typedef void * (*handler)(void *sock_id); * @return * -EINVAL for invalid parameters failure. * @return - * -ENOENT if max callbacks limit has been reached. + * -ENOMEM for mem allocation failure. */ __rte_experimental int diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index f8b0d1157b..6baba57ec2 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -27,9 +27,6 @@ #define MAX_OUTPUT_LEN (1024 * 16) #define MAX_CONNECTIONS 10 -/** Maximum number of telemetry callbacks. */ -#define TELEMETRY_MAX_CALLBACKS 64 - #ifndef RTE_EXEC_ENV_WINDOWS static void * client_handler(void *socket); @@ -62,7 +59,7 @@ static uint32_t logtype; rte_log_ptr(RTE_LOG_ ## l, logtype, "TELEMETRY: " __VA_ARGS__) /* list of command callbacks, with one command registered by default */ -static struct cmd_callback callbacks[TELEMETRY_MAX_CALLBACKS]; +static struct cmd_callback *callbacks; static int num_callbacks; /* How many commands are registered */ /* Used when accessing or modifying list of command callbacks */ static rte_spinlock_t callback_sl = RTE_SPINLOCK_INITIALIZER; @@ -73,15 +70,21 @@ static uint16_t v2_clients; int rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help) { + struct cmd_callback *new_callbacks; int i = 0; if (strlen(cmd) >= MAX_CMD_LEN || fn == NULL || cmd[0] != '/' || strlen(help) >= MAX_HELP_LEN) return -EINVAL; - if (num_callbacks >= TELEMETRY_MAX_CALLBACKS) - return -ENOENT; rte_spinlock_lock(&callback_sl); + new_callbacks = realloc(callbacks, sizeof(callbacks[0]) * (num_callbacks + 1)); + if (new_callbacks == NULL) { + rte_spinlock_unlock(&callback_sl); + return -ENOMEM; + } + callbacks = new_callbacks; + while (i < num_callbacks && strcmp(cmd, callbacks[i].cmd) > 0) i++; if (i != num_callbacks) -- 2.23.0