From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 973E0A0093; Mon, 18 May 2020 18:15:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 667681D426; Mon, 18 May 2020 18:15:10 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 3248E1D418 for ; Mon, 18 May 2020 18:15:07 +0200 (CEST) IronPort-SDR: ORegfGgT+gQkXzvsAA9bwf/mgk+9KKjCF6dAZnQWPCUV0mQYhYW6BdWR882+d5uYYzznK9qeu2 avI6EolHRRJQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 09:15:06 -0700 IronPort-SDR: C5cSzUkmN1S3kbdDQKBBtOZXGRzTm1tJZqf2Aq0rR7qJJkUTeUG+ZuThSk37PG5/KWAx0Fbhiy aRXplSJujD/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,407,1583222400"; d="scan'208";a="342843642" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by orsmga001.jf.intel.com with ESMTP; 18 May 2020 09:15:05 -0700 From: Ciara Power To: kevin.laatz@intel.com Cc: dev@dpdk.org, Ciara Power Date: Mon, 18 May 2020 17:12:32 +0100 Message-Id: <20200518161232.58952-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH 20.08] telemetry: add upper limit on connections 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch limits the number of client connections to the new telemetry socket. The limit is set at 10. Signed-off-by: Ciara Power --- lib/librte_telemetry/telemetry.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c index 56a2fed3f5..5c9d7983e3 100644 --- a/lib/librte_telemetry/telemetry.c +++ b/lib/librte_telemetry/telemetry.c @@ -7,6 +7,7 @@ #include #include #include +#include /* we won't link against libbsd, so just always use DPDKs-specific strlcpy */ #undef RTE_USE_LIBBSD @@ -23,6 +24,7 @@ #define MAX_CMD_LEN 56 #define MAX_HELP_LEN 64 #define MAX_OUTPUT_LEN (1024 * 16) +#define MAX_CONNECTIONS 10 static void * client_handler(void *socket); @@ -37,6 +39,7 @@ struct socket { int sock; char path[sizeof(((struct sockaddr_un *)0)->sun_path)]; handler fn; + sem_t *limit; }; static struct socket v2_socket; /* socket for v2 telemetry */ static struct socket v1_socket; /* socket for v1 telemetry */ @@ -46,6 +49,7 @@ static struct cmd_callback callbacks[TELEMETRY_MAX_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; +static sem_t v2_limit; int rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help) @@ -263,6 +267,7 @@ client_handler(void *sock_id) bytes = read(s, buffer, sizeof(buffer) - 1); } close(s); + sem_post(&v2_limit); return NULL; } @@ -272,6 +277,8 @@ socket_listener(void *socket) while (1) { pthread_t th; struct socket *s = (struct socket *)socket; + if (s->limit != NULL) + sem_wait(s->limit); int s_accepted = accept(s->sock, NULL, NULL); if (s_accepted < 0) { snprintf(telemetry_log_error, @@ -372,6 +379,9 @@ telemetry_v2_init(const char *runtime_dir) { pthread_t t_new; + RTE_BUILD_BUG_ON(_SC_SEM_VALUE_MAX < MAX_CONNECTIONS); + (void)sem_init(&v2_limit, 0, MAX_CONNECTIONS); + v2_socket.limit = &v2_limit; rte_telemetry_register_cmd("/", list_commands, "Returns list of available commands, Takes no parameters"); rte_telemetry_register_cmd("/info", json_info, -- 2.17.1