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 BBECAA0547; Wed, 15 Jul 2020 17:07:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7BD4A4C7B; Wed, 15 Jul 2020 17:07:36 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 2C8732C58 for ; Wed, 15 Jul 2020 17:07:34 +0200 (CEST) IronPort-SDR: JmRzTJRWrqktHgsSotFHVGOPNu0+svPCPG3171xHywLUf0Ir/fk/y3hPaXsD9WCUNvzV3zD6fi b/yBnO9FwL8w== X-IronPort-AV: E=McAfee;i="6000,8403,9683"; a="210706467" X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="210706467" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 08:07:32 -0700 IronPort-SDR: 3O6tf0RcpcCUVYwXQYsNA1zxxj9NVXO5COus9wMcQFfyt/YJNr7zDW1J6UBQFc3TbtseD8iTQI OhVEyV9y/6yg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="308279353" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by fmsmga004.fm.intel.com with ESMTP; 15 Jul 2020 08:07:31 -0700 From: Ciara Power To: kevin.laatz@intel.com Cc: dev@dpdk.org, bruce.richardson@intel.com, stephen@networkplumber.org, thomas@monjalon.net, Ciara Power Date: Wed, 15 Jul 2020 16:03:00 +0100 Message-Id: <20200715150300.19829-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518161232.58952-1-ciara.power@intel.com> References: <20200518161232.58952-1-ciara.power@intel.com> Subject: [dpdk-dev] [PATCH v2] 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 to 10. Signed-off-by: Ciara Power --- lib/librte_telemetry/telemetry.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c index e7e3d861d..025228273 100644 --- a/lib/librte_telemetry/telemetry.c +++ b/lib/librte_telemetry/telemetry.c @@ -23,6 +23,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 +38,7 @@ struct socket { int sock; char path[sizeof(((struct sockaddr_un *)0)->sun_path)]; handler fn; + uint16_t *num_clients; }; static struct socket v2_socket; /* socket for v2 telemetry */ static struct socket v1_socket; /* socket for v1 telemetry */ @@ -46,6 +48,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 uint16_t v2_clients; int rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help) @@ -263,6 +266,7 @@ client_handler(void *sock_id) bytes = read(s, buffer, sizeof(buffer) - 1); } close(s); + __atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED); return NULL; } @@ -279,6 +283,16 @@ socket_listener(void *socket) "Error with accept, telemetry thread quitting"); return NULL; } + if (s->num_clients != NULL) { + uint16_t conns = __atomic_load_n(s->num_clients, + __ATOMIC_RELAXED); + if (conns >= MAX_CONNECTIONS) { + close(s_accepted); + continue; + } + __atomic_add_fetch(s->num_clients, 1, + __ATOMIC_RELAXED); + } pthread_create(&th, NULL, s->fn, (void *)(uintptr_t)s_accepted); pthread_detach(th); } @@ -373,6 +387,7 @@ telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset) { pthread_t t_new; + v2_socket.num_clients = &v2_clients; rte_telemetry_register_cmd("/", list_commands, "Returns list of available commands, Takes no parameters"); rte_telemetry_register_cmd("/info", json_info, -- 2.17.1