DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ciara Power <ciara.power@intel.com>
To: kevin.laatz@intel.com
Cc: dev@dpdk.org, bruce.richardson@intel.com,
	stephen@networkplumber.org, thomas@monjalon.net,
	Ciara Power <ciara.power@intel.com>
Subject: [dpdk-dev] [PATCH v2] telemetry: add upper limit on connections
Date: Wed, 15 Jul 2020 16:03:00 +0100	[thread overview]
Message-ID: <20200715150300.19829-1-ciara.power@intel.com> (raw)
In-Reply-To: <20200518161232.58952-1-ciara.power@intel.com>

This patch limits the number of client connections to the new telemetry
socket. The limit is set to 10.

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 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


  parent reply	other threads:[~2020-07-15 15:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 16:12 [dpdk-dev] [PATCH 20.08] " Ciara Power
2020-05-19  0:07 ` Stephen Hemminger
2020-07-10 20:50   ` Thomas Monjalon
2020-07-13 10:22     ` Power, Ciara
2020-07-15 15:03 ` Ciara Power [this message]
2020-07-19 13:45   ` [dpdk-dev] [PATCH v2] " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200715150300.19829-1-ciara.power@intel.com \
    --to=ciara.power@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=kevin.laatz@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).