Skip to contentSkip to conversation

Add CPU utilization to packet framework

PATCH Superseded Fan Zhang 1 participant 3 messages Jan 27, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fan Zhang

author
#0 lore raw

cover Add CPU utilization to packet framework

This patchset adds CPU utilization rate computation and CLI command support to packet framework. The thread idle rate is updated once per second. User can use thread CLI command to display it.

Fan Zhang (2):
examples/ip_pipeline: CPU utilization measurement and rate computation examples/ip_pipeline: add CLI command to display CPU utilization rate

 examples/ip_pipeline/app.h       |   7 +++
 examples/ip_pipeline/init.c      |   5 ++
 examples/ip_pipeline/thread.c    |  81 +++++++++++++++++++++++++++-
 examples/ip_pipeline/thread.h    |  13 +++++
 examples/ip_pipeline/thread_fe.c | 114 +++++++++++++++++++++++++++++++++++++++
 examples/ip_pipeline/thread_fe.h |   6 +++
 6 files changed, 224 insertions(+), 2 deletions(-)
Signature · 1 line
2.5.0
author
#1 lore raw

PATCH 1/2 examples/ip_pipeline: CPU utilization measurement and

This patch adds CPU utilization measurement and rate computation to packet framework. The measurement is done by measuring the cycles spent while a thread pulls zero packet from RX queue. These cycles are treated as idle cycles (or headroom). The idle thread rate is updated once per second.

---
 examples/ip_pipeline/app.h    |  7 ++++
 examples/ip_pipeline/init.c   |  5 +++
 examples/ip_pipeline/thread.c | 81 +++++++++++++++++++++++++++++++++++++++++--
 examples/ip_pipeline/thread.h | 13 +++++++
 4 files changed, 104 insertions(+), 2 deletions(-)
examples/ip_pipeline/app.h +7 -0
index 6510d6d..2b134f1 100644
@@ -263,6 +263,11 @@ struct app_thread_data {
 
 	struct rte_ring *msgq_in;
 	struct rte_ring *msgq_out;
+
+	uint64_t time_updated;
+	uint64_t hz;
+	uint64_t headroom;
+	double headroom_rate;
 };
 
 struct app_eal_params {
@@ -421,6 +426,8 @@ struct app_eal_params {
 #define APP_MAX_CMDS                             64
 #endif
 
+#define APP_THREAD_HEADROOM_STATS_COLLECT
+
 struct app_params {
 	/* Config */
 	char app_name[APP_APPNAME_SIZE];
examples/ip_pipeline/init.c +5 -0
index 186ca03..f4c1239 100644
@@ -1379,6 +1379,11 @@ app_init_threads(struct app_params *app)
 		t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
 		t->thread_req_deadline = time + t->timer_period;
 
+		t->headroom = 0;
+		t->headroom_rate = 0.0;
+		t->time_updated = time;
+		t->hz = rte_get_tsc_hz();
+
 		t->msgq_in = app_thread_msgq_in_get(app,
 				params->socket_id,
 				params->core_id,
examples/ip_pipeline/thread.c +79 -2

118 lines not on this page · raw message

examples/ip_pipeline/thread.h +13 -0
index dc877c0..70dd98a 100644
@@ -40,6 +40,7 @@
 enum thread_msg_req_type {
 	THREAD_MSG_REQ_PIPELINE_ENABLE = 0,
 	THREAD_MSG_REQ_PIPELINE_DISABLE,
+	THREAD_MSG_REQ_HEADROOM,
 	THREAD_MSG_REQS
 };
 
@@ -81,4 +82,16 @@ struct thread_pipeline_disable_msg_rsp {
 	int status;
 };
 
+/*
+ * THREAD SHOW HEADROOM
+ */
+struct thread_show_headroom_msg_req {
+	enum thread_msg_req_type type;
+};
+struct thread_show_headroom_msg_rsp {
+	int status;
+
+	double headroom;
+};
+
 #endif /* THREAD_H_ */
Signature · 1 line
2.5.0
author
#2 lore raw

PATCH 2/2 examples/ip_pipeline: add CLI command to display CPU

In reply to Fan Zhang

This patch adds idle cycle (or headroom) rate display CLI command to packet framework. The CLI command format is shown as following:

t <thread_id> headroom

---
 examples/ip_pipeline/thread_fe.c | 114 +++++++++++++++++++++++++++++++++++++++
 examples/ip_pipeline/thread_fe.h |   6 +++
 2 files changed, 120 insertions(+)
examples/ip_pipeline/thread_fe.c +114 -0
index 95f0107..e939237 100644
@@ -170,6 +170,54 @@ app_pipeline_disable(struct app_params *app,
 	return 0;
 }
 
+int
+app_thread_headroom(struct app_params *app,
+		uint32_t socket_id,
+		uint32_t core_id,
+		uint32_t hyper_th_id)
+{
+	struct thread_show_headroom_msg_req *req;
+	struct thread_show_headroom_msg_rsp *rsp;
+	int thread_id;
+	int status;
+
+	if (app == NULL)
+		return -1;
+
+	thread_id = cpu_core_map_get_lcore_id(app->core_map,
+			socket_id,
+			core_id,
+			hyper_th_id);
+
+	if ((thread_id < 0) ||
+		((app->core_mask & (1LLU << thread_id)) == 0))
+		return -1;
+
+	req = app_msg_alloc(app);
+	if (req == NULL)
+		return -1;
+
+	req->type = THREAD_MSG_REQ_HEADROOM;
+
+	rsp = thread_msg_send_recv(app,
+		socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
+
+	if (rsp == NULL)
+		return -1;
+
+	status = rsp->status;
+
+	if (status == 0) {
+		printf("Core %u: idle CPU rate %f%%\n",
+				core_id, rsp->headroom * 100);
+	} else {
+		app_msg_free(app, rsp);
+		return -1;
+	}
+
+	return 0;
+}
+
 /*
  * pipeline enable
  */
@@ -318,9 +366,75 @@ cmdline_parse_inst_t cmd_pipeline_disable = {
 	},
 };
 
+
+/*
+ * thread headroom
+ */
+
+struct cmd_thread_headroom_result {
+	cmdline_fixed_string_t t_string;
+	cmdline_fixed_string_t t_id_string;
+	cmdline_fixed_string_t headroom_string;
+};
+
+static void
+cmd_thread_headroom_parsed(
+	void *parsed_result,
+	__rte_unused struct cmdline *cl,
+	 void *data)
+{
+	struct cmd_thread_headroom_result *params = parsed_result;
+	struct app_params *app = data;
+	int status;
+	uint32_t core_id, socket_id, hyper_th_id;
+
+	if (parse_pipeline_core(&socket_id,
+			&core_id,
+			&hyper_th_id,
+			params->t_id_string) != 0) {
+		printf("Command failed\n");
+		return;
+	}
+
+	status = app_thread_headroom(app,
+			socket_id,
+			core_id,
+			hyper_th_id);
+
+	if (status != 0)
+		printf("Command failed\n");
+}
+
+cmdline_parse_token_string_t cmd_thread_headroom_t_string =
+	TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
+		t_string, "t");
+
+cmdline_parse_token_string_t cmd_thread_headroom_t_id_string =
+	TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
+		t_id_string,
+		NULL);
+
+cmdline_parse_token_string_t cmd_thread_headroom_headroom_string =
+	TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
+		headroom_string, "headroom");
+
+cmdline_parse_inst_t cmd_thread_headroom = {
+	.f = cmd_thread_headroom_parsed,
+	.data = NULL,
+	.help_str = "Display thread headroom",
+	.tokens = {
+		(void *)&cmd_thread_headroom_t_string,
+		(void *)&cmd_thread_headroom_t_id_string,
+		(void *)&cmd_thread_headroom_headroom_string,
+		NULL,
+	},
+};
+
+
 static cmdline_parse_ctx_t thread_cmds[] = {
 	(cmdline_parse_inst_t *) &cmd_pipeline_enable,
 	(cmdline_parse_inst_t *) &cmd_pipeline_disable,
+	(cmdline_parse_inst_t *) &cmd_thread_headroom,
 	NULL,
 };
 
examples/ip_pipeline/thread_fe.h +6 -0
index 52352c1..2fd4ee8 100644
@@ -92,4 +92,10 @@ app_pipeline_disable(struct app_params *app,
 		uint32_t hyper_th_id,
 		uint32_t pipeline_id);
 
+int
+app_thread_headroom(struct app_params *app,
+		uint32_t core_id,
+		uint32_t socket_id,
+		uint32_t hyper_th_id);
+
 #endif /* THREAD_FE_H_ */
Signature · 1 line
2.5.0