Skip to contentSkip to conversation

Vhost logs fixes and improvement

PATCH Superseded David Marchand 3 participants 22 messages Jun 27, 2022 – Jul 1, 2022

lore
Share & tools
lore
#0 lore raw

cover Vhost logs fixes and improvement

Here is a series that fixes log messages (with one regression being fixed in patch 2) and changes the VHOST_LOG_* helpers to enforce that vhost log messages will always have some context/prefix to help debugging on setups with many vhost ports.

The first three patches are low risk and can probably be merged in v22.07.

Signature · 19 lines
David Marchand

David Marchand (4):
  vhost: add some trailing newline in log messages
  vhost: restore device information in log messages
  vhost: improve some datapath log messages
  vhost: prefix logs with context

 lib/vhost/iotlb.c      |  30 +-
 lib/vhost/socket.c     | 129 ++++-----
 lib/vhost/vdpa.c       |   4 +-
 lib/vhost/vhost.c      | 144 +++++-----
 lib/vhost/vhost.h      |  20 +-
 lib/vhost/vhost_user.c | 639 +++++++++++++++++++++--------------------
 lib/vhost/virtio_net.c | 258 +++++++++--------
 7 files changed, 634 insertions(+), 590 deletions(-)

-- 
2.36.1
#1 lore raw

PATCH 1/4 vhost: add some trailing newline in log messages

VHOST_LOG_* macros don't append a newline.
Add missing ones.

Fixes e623e0c6d8a5 ("vhost: add reconnect ability")
Fixes af1475918124 ("vhost: introduce API to start a specific driver")
Fixes 2dfeebe26546 ("vhost: check return of mutex initialization")
---
 lib/vhost/socket.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/vhost/socket.c +5 -5
index 7a0f63af14..24d60ca149 100644
@@ -499,7 +499,7 @@ vhost_user_reconnect_init(void)
 
 	ret = pthread_mutex_init(&reconn_list.mutex, NULL);
 	if (ret < 0) {
-		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex", __func__);
+		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex\n", __func__);
 		return ret;
 	}
 	TAILQ_INIT(&reconn_list.head);
@@ -507,9 +507,9 @@ vhost_user_reconnect_init(void)
 	ret = rte_ctrl_thread_create(&reconn_tid, "vhost_reconn", NULL,
 			     vhost_user_client_reconnect, NULL);
 	if (ret != 0) {
-		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread");
+		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread\n");
 		if (pthread_mutex_destroy(&reconn_list.mutex))
-			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect mutex", __func__);
+			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect mutex\n", __func__);
 	}
 
 	return ret;
@@ -1170,8 +1170,8 @@ rte_vhost_driver_start(const char *path)
 			"vhost-events", NULL, fdset_event_dispatch,
 			&vhost_user.fdset);
 		if (ret != 0) {
-			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset handling thread", path);
-
+			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset handling thread\n",
+				path);
 			fdset_pipe_uninit(&vhost_user.fdset);
 			return -1;
 		}
Signature · 1 line
2.36.1
Reviewed-by on v1 1/4
#2 lore raw

RE: [PATCH 1/4] vhost: add some trailing newline in log messages

Quoted 65 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, June 27, 2022 5:27 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; Yuanhan Liu <[email protected]>; Jens Freimann <[email protected]>
Subject: [PATCH 1/4] vhost: add some trailing newline in log messages

VHOST_LOG_* macros don't append a newline.
Add missing ones.

Fixes e623e0c6d8a5 ("vhost: add reconnect ability")
Fixes af1475918124 ("vhost: introduce API to start a specific driver")
Fixes 2dfeebe26546 ("vhost: check return of mutex initialization")
---
 lib/vhost/socket.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/vhost/socket.c +1 -1
index 7a0f63af14..24d60ca149 100644
@@ -499,7 +499,7 @@ vhost_user_reconnect_init(void)
 
 	ret = pthread_mutex_init(&reconn_list.mutex, NULL);
 	if (ret < 0) {
-		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex",
 __func__);
+		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex\n",
 __func__);
 		return ret;
lib/vhost/socket.c +2 -2
 	}
 	TAILQ_INIT(&reconn_list.head);
@@ -507,9 +507,9 @@ vhost_user_reconnect_init(void)
 	ret = rte_ctrl_thread_create(&reconn_tid, "vhost_reconn", NULL,
 			     vhost_user_client_reconnect, NULL);
 	if (ret != 0) {
-		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread");
+		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread\n");
 		if (pthread_mutex_destroy(&reconn_list.mutex))
-			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect
 mutex", __func__);
+			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect
 mutex\n", __func__);
 	}
lib/vhost/socket.c +2 -2
 	return ret;
@@ -1170,8 +1170,8 @@ rte_vhost_driver_start(const char *path)
 			"vhost-events", NULL, fdset_event_dispatch,
 			&vhost_user.fdset);
 		if (ret != 0) {
-			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset
 handling thread", path);
-
+			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset
 handling thread\n",
+				path);
 			fdset_pipe_uninit(&vhost_user.fdset);
lib/vhost/socket.c +0 -1
 			return -1;
 		}
--
Quoted 1 line

2.36.1

#3 lore raw

PATCH 2/4 vhost: restore device information in log messages

In reply to David Marchand

device information in the log messages was dropped.

Fixes 52ade97e3641 ("vhost: fix physical address mapping")
---
 lib/vhost/vhost_user.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +6 -3
index 2b9a3b69fa..f324f822d6 100644
@@ -144,7 +144,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 					return;
 
 				/* DMA mapping errors won't stop VHOST_USER_SET_MEM_TABLE. */
-				VHOST_LOG_CONFIG(ERR, "DMA engine map failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine map failed\n",
+					dev->ifname);
 			}
 		}
 
@@ -160,7 +161,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 				if (rte_errno == EINVAL)
 					return;
 
-				VHOST_LOG_CONFIG(ERR, "DMA engine unmap failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine unmap failed\n",
+					dev->ifname);
 			}
 		}
 	}
@@ -945,7 +947,8 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,
 					dev->max_guest_pages * sizeof(*page),
 					RTE_CACHE_LINE_SIZE);
 		if (dev->guest_pages == NULL) {
-			VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n");
+			VHOST_LOG_CONFIG(ERR, "(%s) cannot realloc guest_pages\n",
+				dev->ifname);
 			rte_free(old_pages);
 			return -1;
 		}
Signature · 1 line
2.36.1
Reviewed-by on v1 2/4
#4 lore raw

RE: [PATCH 2/4] vhost: restore device information in log messages

Hi David,

Quoted 11 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, June 27, 2022 5:27 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, YuanX <[email protected]>; Ding, Xuan <[email protected]>
Subject: [PATCH 2/4] vhost: restore device information in log messages

device information in the log messages was dropped.

Fixes 52ade97e3641 ("vhost: fix physical address mapping")

Should we add cc-stable tag in this case as it's 22.03 commit? Last time when I asked Ferruh, he said although now we don't maintain non-LTS release, we should still add this tag. Not sure this changed or not.

For the patch:

Quoted 47 lines
---
 lib/vhost/vhost_user.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +0 -0
index 2b9a3b69fa..f324f822d6 100644
@@ -144,7 +144,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 					return;
 
 				/* DMA mapping errors won't stop

VHOST_USER_SET_MEM_TABLE. */

lib/vhost/vhost_user.c +1 -1
-				VHOST_LOG_CONFIG(ERR, "DMA engine map failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine map

failed\n",

lib/vhost/vhost_user.c +3 -1
+					dev->ifname);
 			}
 		}
@@ -160,7 +161,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 				if (rte_errno == EINVAL)
 					return;
 
-				VHOST_LOG_CONFIG(ERR, "DMA engine unmap failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine unmap
 failed\n",
+					dev->ifname);
 			}
 		}
lib/vhost/vhost_user.c +2 -1
 	}
@@ -945,7 +947,8 @@ add_one_guest_page(struct virtio_net *dev, uint64_t
 guest_phys_addr,
 					dev->max_guest_pages * sizeof(*page),
 					RTE_CACHE_LINE_SIZE);
 		if (dev->guest_pages == NULL) {
-			VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n");
+			VHOST_LOG_CONFIG(ERR, "(%s) cannot realloc
 guest_pages\n",
+				dev->ifname);
 			rte_free(old_pages);
lib/vhost/vhost_user.c +0 -1
 			return -1;
 		}
--

2.36.1

#5 lore raw

Re: [PATCH 2/4] vhost: restore device information in log messages

Quoted 11 lines · Chenbo

Hi David,

Quoted 8 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, June 27, 2022 5:27 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Wang, YuanX <[email protected]>; Ding, Xuan <[email protected]>
Subject: [PATCH 2/4] vhost: restore device information in log messages

Quoted 8 lines
Quoted 3 lines

device information in the log messages was dropped.

Fixes 52ade97e3641 ("vhost: fix physical address mapping")

Should we add cc-stable tag in this case as it's 22.03 commit? Last time when I asked Ferruh, he said although now we don't maintain non-LTS release, we should still add this tag. Not sure this changed or not.

No objection for leaks and other important fixes.
Here, this patch is only fixing some log messages, so I did not see the need.

In any case, I am fine with both options and this can be added when the patch is applied by sub-tree maintainer.

Quoted 4 lines

For the patch:

Thanks Chenbo!

Signature · 1 line
David Marchand
#6 lore raw

RE: [PATCH 2/4] vhost: restore device information in log messages

Quoted 24 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, June 29, 2022 9:45 PM
To: Xia, Chenbo <[email protected]>
Cc: [email protected]; [email protected]; Wang, YuanX <[email protected]>; Ding, Xuan <[email protected]>; [email protected]
Subject: Re: [PATCH 2/4] vhost: restore device information in log messages

Quoted 8 lines · Chenbo

Hi David,

Quoted 5 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, June 27, 2022 5:27 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>;

Wang,

Quoted 5 lines
Quoted 5 lines

YuanX <[email protected]>; Ding, Xuan <[email protected]>
Subject: [PATCH 2/4] vhost: restore device information in log messages

device information in the log messages was dropped.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Fixes 52ade97e3641 ("vhost: fix physical address mapping")

Should we add cc-stable tag in this case as it's 22.03 commit? Last time when I asked Ferruh, he said although now we don't maintain non-LTS release, we should still add this tag. Not sure this changed or not.

No objection for leaks and other important fixes.

Good to know we are aligned :)

Quoted 2 lines

Here, this patch is only fixing some log messages, so I did not see the need.

OK. Make sense to me

Thanks,
Chenbo

Quoted 14 lines

In any case, I am fine with both options and this can be added when the patch is applied by sub-tree maintainer.

Quoted 4 lines

For the patch:

Thanks Chenbo!

--
David Marchand

#7 lore raw

PATCH 3/4 vhost: improve some datapath log messages

In reply to David Marchand

Those messages were missed when adding socket context. Fix this.

---
 lib/vhost/vhost.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vhost/vhost.h +3 -3
index 4ebcb7448a..810bc71c9d 100644
@@ -652,7 +652,7 @@ extern int vhost_data_log_level;
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DATA(DEBUG, "%s", packet); \
+	VHOST_LOG_DATA(DEBUG, "(%s) %s", device->ifname, packet); \
 } while (0)
 #else
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
@@ -866,8 +866,8 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
-			__func__,
+		VHOST_LOG_DATA(DEBUG, "(%s) %s: used_event_idx=%d, old=%d, new=%d\n",
+			dev->ifname, __func__,
 			vhost_used_event(vq),
 			old, new);
 
Signature · 1 line
2.36.1
#9 lore raw

PATCH 4/4 vhost: prefix logs with context

In reply to David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
 lib/vhost/iotlb.c      |  30 +-
 lib/vhost/socket.c     | 129 ++++-----
 lib/vhost/vdpa.c       |   4 +-
 lib/vhost/vhost.c      | 144 ++++-----
 lib/vhost/vhost.h      |  20 +-
 lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
 lib/vhost/virtio_net.c | 258 +++++++++--------
 7 files changed, 634 insertions(+), 593 deletions(-)
lib/vhost/iotlb.c +15 -15
index 5a5ba8b82a..35b4193606 100644
@@ -70,18 +70,18 @@ vhost_user_iotlb_pending_insert(struct virtio_net *dev, struct vhost_virtqueue *
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for pending insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for pending insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_pending_list))
 			vhost_user_iotlb_pending_remove_all(vq);
 		else
 			vhost_user_iotlb_cache_random_evict(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, pending insertion failure\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, pending insertion failure\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -169,18 +169,18 @@ vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for cache insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for cache insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_list))
 			vhost_user_iotlb_cache_random_evict(vq);
 		else
 			vhost_user_iotlb_pending_remove_all(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, cache insertion failed\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, cache insertion failed\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -320,7 +320,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 
 	snprintf(pool_name, sizeof(pool_name), "iotlb_%u_%d_%d",
 			getpid(), dev->vid, vq_index);
-	VHOST_LOG_CONFIG(DEBUG, "(%s) IOTLB cache name: %s\n", dev->ifname, pool_name);
+	VHOST_LOG_CONFIG(dev->ifname, DEBUG, "IOTLB cache name: %s\n", pool_name);
 
 	/* If already created, free it and recreate */
 	vq->iotlb_pool = rte_mempool_lookup(pool_name);
@@ -332,8 +332,8 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 			RTE_MEMPOOL_F_NO_CACHE_ALIGN |
 			RTE_MEMPOOL_F_SP_PUT);
 	if (!vq->iotlb_pool) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Failed to create IOTLB cache pool %s\n",
-				dev->ifname, pool_name);
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to create IOTLB cache pool %s\n",
+			pool_name);
 		return -1;
 	}
 
lib/vhost/socket.c +60 -69

356 lines not on this page · raw message

lib/vhost/vdpa.c +2 -2
index 8fa2153023..b2a2919fc0 100644
@@ -81,8 +81,8 @@ rte_vdpa_register_device(struct rte_device *rte_dev,
 			!ops->get_protocol_features || !ops->dev_conf ||
 			!ops->dev_close || !ops->set_vring_state ||
 			!ops->set_features) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Some mandatory vDPA ops aren't implemented\n",
-				rte_dev->name);
+		VHOST_LOG_CONFIG(rte_dev->name, ERR,
+			"Some mandatory vDPA ops aren't implemented\n");
 		return NULL;
 	}
 
lib/vhost/vhost.c +76 -68

333 lines not on this page · raw message

lib/vhost/vhost.h +9 -11
index 810bc71c9d..310aaf88ff 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
 extern int vhost_config_log_level;
 extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)			\
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)		\
 	rte_log(RTE_LOG_ ## level, vhost_config_log_level,	\
-		"VHOST_CONFIG: " fmt, ##args)
+		"VHOST_CONFIG: (%s): " fmt, prefix, ##args)
 
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)		\
 	(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?	\
 	 rte_log(RTE_LOG_ ## level,  vhost_data_log_level,	\
-		"VHOST_DATA : " fmt, ##args) :			\
+		"VHOST_DATA: (%s):" fmt, prefix, ##args) :	\
 	 0)
 
 #ifdef RTE_LIBRTE_VHOST_DEBUG
@@ -652,7 +652,7 @@ extern int vhost_data_log_level;
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DATA(DEBUG, "(%s) %s", device->ifname, packet); \
+	VHOST_LOG_DATA(device->ifname, DEBUG, "%s", packet); \
 } while (0)
 #else
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
@@ -777,8 +777,7 @@ get_device(int vid)
 	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
-		VHOST_LOG_CONFIG(ERR,
-			"(%d) device not found.\n", vid);
+		VHOST_LOG_CONFIG("device", ERR, "(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -866,10 +865,9 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DATA(DEBUG, "(%s) %s: used_event_idx=%d, old=%d, new=%d\n",
-			dev->ifname, __func__,
-			vhost_used_event(vq),
-			old, new);
+		VHOST_LOG_DATA(dev->ifname, DEBUG,
+			"%s: used_event_idx=%d, old=%d, new=%d\n",
+			__func__, vhost_used_event(vq), old, new);
 
 		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
 					(vq->callfd >= 0)) ||
lib/vhost/vhost_user.c +335 -307

1,333 lines not on this page · raw message

lib/vhost/virtio_net.c +137 -121

589 lines not on this page · raw message

Signature · 1 line
2.36.1
#10 lore raw

Re: [PATCH 4/4] vhost: prefix logs with context

Hi David,

Quoted 38 lines · David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
  lib/vhost/iotlb.c      |  30 +-
  lib/vhost/socket.c     | 129 ++++-----
  lib/vhost/vdpa.c       |   4 +-
  lib/vhost/vhost.c      | 144 ++++-----
  lib/vhost/vhost.h      |  20 +-
  lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
  lib/vhost/virtio_net.c | 258 +++++++++--------
  7 files changed, 634 insertions(+), 593 deletions(-)
lib/vhost/vhost.h +1 -1
index 810bc71c9d..310aaf88ff 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
  extern int vhost_config_log_level;
  extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)			\
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)		\
  	rte_log(RTE_LOG_ ## level, vhost_config_log_level,	\

lib/vhost/vhost.h vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 636

Quoted 10 lines
lib/vhost/vhost.h +3 -3
-		"VHOST_CONFIG: " fmt, ##args)
+		"VHOST_CONFIG: (%s): " fmt, prefix, ##args)
 
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)		\
  	(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?	\
  	 rte_log(RTE_LOG_ ## level,  vhost_data_log_level,	\
-		"VHOST_DATA : " fmt, ##args) :			\
+		"VHOST_DATA: (%s):" fmt, prefix, ##args) :	\
  	 0)

As discussed off-list, adding the function will break OVS tests once again. I propose to pick the first 3 patches for now.

Thanks,
Maxime

#11 lore raw

Re: [PATCH 4/4] vhost: prefix logs with context

Quoted 42 lines · Maxime Coquelin
Quoted 41 lines · David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
  lib/vhost/iotlb.c      |  30 +-
  lib/vhost/socket.c     | 129 ++++-----
  lib/vhost/vdpa.c       |   4 +-
  lib/vhost/vhost.c      | 144 ++++-----
  lib/vhost/vhost.h      |  20 +-
  lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
  lib/vhost/virtio_net.c | 258 +++++++++--------
  7 files changed, 634 insertions(+), 593 deletions(-)
lib/vhost/vhost.h +2 -2
index 810bc71c9d..310aaf88ff 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
  extern int vhost_config_log_level;
  extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)                        \
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)                \
      rte_log(RTE_LOG_ ## level, vhost_config_log_level,      \
-             "VHOST_CONFIG: " fmt, ##args)
+             "VHOST_CONFIG: (%s): " fmt, prefix, ##args)
 
Quoted 10 lines

lib/vhost/vhost.h vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 636

Quoted 7 lines
lib/vhost/vhost.h +2 -2
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)          \
      (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?        \
       rte_log(RTE_LOG_ ## level,  vhost_data_log_level,      \
-             "VHOST_DATA : " fmt, ##args) :                  \
+             "VHOST_DATA: (%s):" fmt, prefix, ##args) :      \
       0)

As discussed off-list, adding the function will break OVS tests once again. I propose to pick the first 3 patches for now.

The issue with OVS tests is that they match the log message content, and this current patch changes the format.

For example, before we have:
VHOST_CONFIG: (vhost0.sock) vhost-user server: socket created, fd: 57
VHOST_CONFIG: (vhost0.sock) binding succeeded
After:
VHOST_CONFIG: (vhost0.sock): vhost-user server: socket created, fd: 56
VHOST_CONFIG: (vhost0.sock): binding succeeded

I can respin, removing the extra ':' in VHOST_* macros. WDYT?

Signature · 1 line
David Marchand
#12 lore raw

Re: [PATCH 4/4] vhost: prefix logs with context

Quoted 65 lines · David Marchand
Quoted 42 lines · Maxime Coquelin
Quoted 41 lines · David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
   lib/vhost/iotlb.c      |  30 +-
   lib/vhost/socket.c     | 129 ++++-----
   lib/vhost/vdpa.c       |   4 +-
   lib/vhost/vhost.c      | 144 ++++-----
   lib/vhost/vhost.h      |  20 +-
   lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
   lib/vhost/virtio_net.c | 258 +++++++++--------
   7 files changed, 634 insertions(+), 593 deletions(-)
lib/vhost/vhost.h +2 -2
index 810bc71c9d..310aaf88ff 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
   extern int vhost_config_log_level;
   extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)                        \
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)                \
       rte_log(RTE_LOG_ ## level, vhost_config_log_level,      \
-             "VHOST_CONFIG: " fmt, ##args)
+             "VHOST_CONFIG: (%s): " fmt, prefix, ##args)
 
Quoted 10 lines

lib/vhost/vhost.h vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 636

Quoted 7 lines
lib/vhost/vhost.h +2 -2
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)          \
       (void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?        \
        rte_log(RTE_LOG_ ## level,  vhost_data_log_level,      \
-             "VHOST_DATA : " fmt, ##args) :                  \
+             "VHOST_DATA: (%s):" fmt, prefix, ##args) :      \
        0)

As discussed off-list, adding the function will break OVS tests once again. I propose to pick the first 3 patches for now.

The issue with OVS tests is that they match the log message content, and this current patch changes the format.

For example, before we have:
VHOST_CONFIG: (vhost0.sock) vhost-user server: socket created, fd: 57
VHOST_CONFIG: (vhost0.sock) binding succeeded
After:
VHOST_CONFIG: (vhost0.sock): vhost-user server: socket created, fd: 56
VHOST_CONFIG: (vhost0.sock): binding succeeded

Quoted 2 lines

I can respin, removing the extra ':' in VHOST_* macros. WDYT?

Sounds good!

Thanks,
Maxime

#13 lore raw

v2 cover Vhost logs fixes and improvement

In reply to David Marchand

Here is a series that fixes log messages (with one regression being fixed in patch 2) and changes the VHOST_LOG_* helpers to enforce that vhost log messages will always have some context/prefix to help debugging on setups with many vhost ports.

The first three patches are low risk and can probably be merged in v22.07.

Changes since v1:
- fixed log formats in patch4,

Signature · 19 lines
David Marchand

David Marchand (4):
  vhost: add some trailing newline in log messages
  vhost: restore device information in log messages
  vhost: improve some datapath log messages
  vhost: prefix logs with context

 lib/vhost/iotlb.c      |  30 +-
 lib/vhost/socket.c     | 129 ++++-----
 lib/vhost/vdpa.c       |   4 +-
 lib/vhost/vhost.c      | 144 +++++-----
 lib/vhost/vhost.h      |  20 +-
 lib/vhost/vhost_user.c | 639 +++++++++++++++++++++--------------------
 lib/vhost/virtio_net.c | 258 +++++++++--------
 7 files changed, 634 insertions(+), 590 deletions(-)

-- 
2.36.1
#14 lore raw

PATCH v2 1/4 vhost: add some trailing newline in log messages

VHOST_LOG_* macros don't append a newline.
Add missing ones.

Fixes e623e0c6d8a5 ("vhost: add reconnect ability")
Fixes af1475918124 ("vhost: introduce API to start a specific driver")
Fixes 2dfeebe26546 ("vhost: check return of mutex initialization")
---
 lib/vhost/socket.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/vhost/socket.c +5 -5
index 7a0f63af14..24d60ca149 100644
@@ -499,7 +499,7 @@ vhost_user_reconnect_init(void)
 
 	ret = pthread_mutex_init(&reconn_list.mutex, NULL);
 	if (ret < 0) {
-		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex", __func__);
+		VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex\n", __func__);
 		return ret;
 	}
 	TAILQ_INIT(&reconn_list.head);
@@ -507,9 +507,9 @@ vhost_user_reconnect_init(void)
 	ret = rte_ctrl_thread_create(&reconn_tid, "vhost_reconn", NULL,
 			     vhost_user_client_reconnect, NULL);
 	if (ret != 0) {
-		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread");
+		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread\n");
 		if (pthread_mutex_destroy(&reconn_list.mutex))
-			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect mutex", __func__);
+			VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect mutex\n", __func__);
 	}
 
 	return ret;
@@ -1170,8 +1170,8 @@ rte_vhost_driver_start(const char *path)
 			"vhost-events", NULL, fdset_event_dispatch,
 			&vhost_user.fdset);
 		if (ret != 0) {
-			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset handling thread", path);
-
+			VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset handling thread\n",
+				path);
 			fdset_pipe_uninit(&vhost_user.fdset);
 			return -1;
 		}
Signature · 1 line
2.36.1
#15 lore raw

PATCH v2 2/4 vhost: restore device information in log messages

In reply to David Marchand

device information in the log messages was dropped.

Fixes 52ade97e3641 ("vhost: fix physical address mapping")
---
 lib/vhost/vhost_user.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/vhost/vhost_user.c +6 -3
index 2b9a3b69fa..f324f822d6 100644
@@ -144,7 +144,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 					return;
 
 				/* DMA mapping errors won't stop VHOST_USER_SET_MEM_TABLE. */
-				VHOST_LOG_CONFIG(ERR, "DMA engine map failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine map failed\n",
+					dev->ifname);
 			}
 		}
 
@@ -160,7 +161,8 @@ async_dma_map(struct virtio_net *dev, bool do_map)
 				if (rte_errno == EINVAL)
 					return;
 
-				VHOST_LOG_CONFIG(ERR, "DMA engine unmap failed\n");
+				VHOST_LOG_CONFIG(ERR, "(%s) DMA engine unmap failed\n",
+					dev->ifname);
 			}
 		}
 	}
@@ -945,7 +947,8 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,
 					dev->max_guest_pages * sizeof(*page),
 					RTE_CACHE_LINE_SIZE);
 		if (dev->guest_pages == NULL) {
-			VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n");
+			VHOST_LOG_CONFIG(ERR, "(%s) cannot realloc guest_pages\n",
+				dev->ifname);
 			rte_free(old_pages);
 			return -1;
 		}
Signature · 1 line
2.36.1
#16 lore raw

PATCH v2 3/4 vhost: improve some datapath log messages

In reply to David Marchand

Those messages were missed when adding socket context. Fix this.

---
 lib/vhost/vhost.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vhost/vhost.h +3 -3
index 4ebcb7448a..810bc71c9d 100644
@@ -652,7 +652,7 @@ extern int vhost_data_log_level;
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DATA(DEBUG, "%s", packet); \
+	VHOST_LOG_DATA(DEBUG, "(%s) %s", device->ifname, packet); \
 } while (0)
 #else
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
@@ -866,8 +866,8 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
-			__func__,
+		VHOST_LOG_DATA(DEBUG, "(%s) %s: used_event_idx=%d, old=%d, new=%d\n",
+			dev->ifname, __func__,
 			vhost_used_event(vq),
 			old, new);
 
Signature · 1 line
2.36.1
#17 lore raw

PATCH v2 4/4 vhost: prefix logs with context

In reply to David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
Changes since v1:
- preserved original format for logs (removing extra ':'),

---
 lib/vhost/iotlb.c      |  30 +-
 lib/vhost/socket.c     | 129 ++++-----
 lib/vhost/vdpa.c       |   4 +-
 lib/vhost/vhost.c      | 144 ++++-----
 lib/vhost/vhost.h      |  20 +-
 lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
 lib/vhost/virtio_net.c | 258 +++++++++--------
 7 files changed, 634 insertions(+), 593 deletions(-)
lib/vhost/iotlb.c +15 -15
index 5a5ba8b82a..35b4193606 100644
@@ -70,18 +70,18 @@ vhost_user_iotlb_pending_insert(struct virtio_net *dev, struct vhost_virtqueue *
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for pending insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for pending insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_pending_list))
 			vhost_user_iotlb_pending_remove_all(vq);
 		else
 			vhost_user_iotlb_cache_random_evict(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, pending insertion failure\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, pending insertion failure\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -169,18 +169,18 @@ vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for cache insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for cache insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_list))
 			vhost_user_iotlb_cache_random_evict(vq);
 		else
 			vhost_user_iotlb_pending_remove_all(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, cache insertion failed\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, cache insertion failed\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -320,7 +320,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 
 	snprintf(pool_name, sizeof(pool_name), "iotlb_%u_%d_%d",
 			getpid(), dev->vid, vq_index);
-	VHOST_LOG_CONFIG(DEBUG, "(%s) IOTLB cache name: %s\n", dev->ifname, pool_name);
+	VHOST_LOG_CONFIG(dev->ifname, DEBUG, "IOTLB cache name: %s\n", pool_name);
 
 	/* If already created, free it and recreate */
 	vq->iotlb_pool = rte_mempool_lookup(pool_name);
@@ -332,8 +332,8 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 			RTE_MEMPOOL_F_NO_CACHE_ALIGN |
 			RTE_MEMPOOL_F_SP_PUT);
 	if (!vq->iotlb_pool) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Failed to create IOTLB cache pool %s\n",
-				dev->ifname, pool_name);
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to create IOTLB cache pool %s\n",
+			pool_name);
 		return -1;
 	}
 
lib/vhost/socket.c +60 -69

356 lines not on this page · raw message

lib/vhost/vdpa.c +2 -2
index 8fa2153023..b2a2919fc0 100644
@@ -81,8 +81,8 @@ rte_vdpa_register_device(struct rte_device *rte_dev,
 			!ops->get_protocol_features || !ops->dev_conf ||
 			!ops->dev_close || !ops->set_vring_state ||
 			!ops->set_features) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Some mandatory vDPA ops aren't implemented\n",
-				rte_dev->name);
+		VHOST_LOG_CONFIG(rte_dev->name, ERR,
+			"Some mandatory vDPA ops aren't implemented\n");
 		return NULL;
 	}
 
lib/vhost/vhost.c +76 -68

333 lines not on this page · raw message

lib/vhost/vhost.h +9 -11
index 810bc71c9d..40fac3b7c6 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
 extern int vhost_config_log_level;
 extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)			\
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)		\
 	rte_log(RTE_LOG_ ## level, vhost_config_log_level,	\
-		"VHOST_CONFIG: " fmt, ##args)
+		"VHOST_CONFIG: (%s) " fmt, prefix, ##args)
 
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)		\
 	(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?	\
 	 rte_log(RTE_LOG_ ## level,  vhost_data_log_level,	\
-		"VHOST_DATA : " fmt, ##args) :			\
+		"VHOST_DATA: (%s) " fmt, prefix, ##args) :	\
 	 0)
 
 #ifdef RTE_LIBRTE_VHOST_DEBUG
@@ -652,7 +652,7 @@ extern int vhost_data_log_level;
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DATA(DEBUG, "(%s) %s", device->ifname, packet); \
+	VHOST_LOG_DATA(device->ifname, DEBUG, "%s", packet); \
 } while (0)
 #else
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
@@ -777,8 +777,7 @@ get_device(int vid)
 	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
-		VHOST_LOG_CONFIG(ERR,
-			"(%d) device not found.\n", vid);
+		VHOST_LOG_CONFIG("device", ERR, "(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -866,10 +865,9 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DATA(DEBUG, "(%s) %s: used_event_idx=%d, old=%d, new=%d\n",
-			dev->ifname, __func__,
-			vhost_used_event(vq),
-			old, new);
+		VHOST_LOG_DATA(dev->ifname, DEBUG,
+			"%s: used_event_idx=%d, old=%d, new=%d\n",
+			__func__, vhost_used_event(vq), old, new);
 
 		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
 					(vq->callfd >= 0)) ||
lib/vhost/vhost_user.c +335 -307

1,333 lines not on this page · raw message

lib/vhost/virtio_net.c +137 -121

589 lines not on this page · raw message

Signature · 1 line
2.36.1
Reviewed-by on v2 4/4
#18 lore raw

Re: [PATCH v2 4/4] vhost: prefix logs with context

Quoted 20 lines · David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
Changes since v1:
- preserved original format for logs (removing extra ':'),

Quoted 10 lines
---
  lib/vhost/iotlb.c      |  30 +-
  lib/vhost/socket.c     | 129 ++++-----
  lib/vhost/vdpa.c       |   4 +-
  lib/vhost/vhost.c      | 144 ++++-----
  lib/vhost/vhost.h      |  20 +-
  lib/vhost/vhost_user.c | 642 +++++++++++++++++++++--------------------
  lib/vhost/virtio_net.c | 258 +++++++++--------
  7 files changed, 634 insertions(+), 593 deletions(-)

Thanks,
Maxime

#19 lore raw

PATCH v3 1/1 vhost: prefix logs with context

In reply to David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
Changes since v2:
- rebased on next-virtio,

Changes since v1:
- preserved original format for logs (removing extra ':'),

---
 lib/vhost/iotlb.c      |  30 +-
 lib/vhost/socket.c     | 129 ++++-----
 lib/vhost/vdpa.c       |   4 +-
 lib/vhost/vhost.c      | 146 +++++-----
 lib/vhost/vhost.h      |  20 +-
 lib/vhost/vhost_user.c | 644 +++++++++++++++++++++--------------------
 lib/vhost/virtio_net.c | 258 +++++++++--------
 7 files changed, 636 insertions(+), 595 deletions(-)
lib/vhost/iotlb.c +15 -15
index 5a5ba8b82a..35b4193606 100644
@@ -70,18 +70,18 @@ vhost_user_iotlb_pending_insert(struct virtio_net *dev, struct vhost_virtqueue *
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for pending insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for pending insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_pending_list))
 			vhost_user_iotlb_pending_remove_all(vq);
 		else
 			vhost_user_iotlb_cache_random_evict(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, pending insertion failure\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, pending insertion failure\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -169,18 +169,18 @@ vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 	if (ret) {
-		VHOST_LOG_CONFIG(DEBUG,
-				"(%s) IOTLB pool %s empty, clear entries for cache insertion\n",
-				dev->ifname, vq->iotlb_pool->name);
+		VHOST_LOG_CONFIG(dev->ifname, DEBUG,
+			"IOTLB pool %s empty, clear entries for cache insertion\n",
+			vq->iotlb_pool->name);
 		if (!TAILQ_EMPTY(&vq->iotlb_list))
 			vhost_user_iotlb_cache_random_evict(vq);
 		else
 			vhost_user_iotlb_pending_remove_all(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 		if (ret) {
-			VHOST_LOG_CONFIG(ERR,
-					"(%s) IOTLB pool %s still empty, cache insertion failed\n",
-					dev->ifname, vq->iotlb_pool->name);
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"IOTLB pool %s still empty, cache insertion failed\n",
+				vq->iotlb_pool->name);
 			return;
 		}
 	}
@@ -320,7 +320,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 
 	snprintf(pool_name, sizeof(pool_name), "iotlb_%u_%d_%d",
 			getpid(), dev->vid, vq_index);
-	VHOST_LOG_CONFIG(DEBUG, "(%s) IOTLB cache name: %s\n", dev->ifname, pool_name);
+	VHOST_LOG_CONFIG(dev->ifname, DEBUG, "IOTLB cache name: %s\n", pool_name);
 
 	/* If already created, free it and recreate */
 	vq->iotlb_pool = rte_mempool_lookup(pool_name);
@@ -332,8 +332,8 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 			RTE_MEMPOOL_F_NO_CACHE_ALIGN |
 			RTE_MEMPOOL_F_SP_PUT);
 	if (!vq->iotlb_pool) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Failed to create IOTLB cache pool %s\n",
-				dev->ifname, pool_name);
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to create IOTLB cache pool %s\n",
+			pool_name);
 		return -1;
 	}
 
lib/vhost/socket.c +60 -69

356 lines not on this page · raw message

lib/vhost/vdpa.c +2 -2
index 8fa2153023..b2a2919fc0 100644
@@ -81,8 +81,8 @@ rte_vdpa_register_device(struct rte_device *rte_dev,
 			!ops->get_protocol_features || !ops->dev_conf ||
 			!ops->dev_close || !ops->set_vring_state ||
 			!ops->set_features) {
-		VHOST_LOG_CONFIG(ERR, "(%s) Some mandatory vDPA ops aren't implemented\n",
-				rte_dev->name);
+		VHOST_LOG_CONFIG(rte_dev->name, ERR,
+			"Some mandatory vDPA ops aren't implemented\n");
 		return NULL;
 	}
 
lib/vhost/vhost.c +77 -69

338 lines not on this page · raw message

lib/vhost/vhost.h +9 -11
index 810bc71c9d..40fac3b7c6 100644
@@ -625,14 +625,14 @@ vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,
 extern int vhost_config_log_level;
 extern int vhost_data_log_level;
 
-#define VHOST_LOG_CONFIG(level, fmt, args...)			\
+#define VHOST_LOG_CONFIG(prefix, level, fmt, args...)		\
 	rte_log(RTE_LOG_ ## level, vhost_config_log_level,	\
-		"VHOST_CONFIG: " fmt, ##args)
+		"VHOST_CONFIG: (%s) " fmt, prefix, ##args)
 
-#define VHOST_LOG_DATA(level, fmt, args...) \
+#define VHOST_LOG_DATA(prefix, level, fmt, args...)		\
 	(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?	\
 	 rte_log(RTE_LOG_ ## level,  vhost_data_log_level,	\
-		"VHOST_DATA : " fmt, ##args) :			\
+		"VHOST_DATA: (%s) " fmt, prefix, ##args) :	\
 	 0)
 
 #ifdef RTE_LIBRTE_VHOST_DEBUG
@@ -652,7 +652,7 @@ extern int vhost_data_log_level;
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DATA(DEBUG, "(%s) %s", device->ifname, packet); \
+	VHOST_LOG_DATA(device->ifname, DEBUG, "%s", packet); \
 } while (0)
 #else
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
@@ -777,8 +777,7 @@ get_device(int vid)
 	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
-		VHOST_LOG_CONFIG(ERR,
-			"(%d) device not found.\n", vid);
+		VHOST_LOG_CONFIG("device", ERR, "(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -866,10 +865,9 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DATA(DEBUG, "(%s) %s: used_event_idx=%d, old=%d, new=%d\n",
-			dev->ifname, __func__,
-			vhost_used_event(vq),
-			old, new);
+		VHOST_LOG_DATA(dev->ifname, DEBUG,
+			"%s: used_event_idx=%d, old=%d, new=%d\n",
+			__func__, vhost_used_event(vq), old, new);
 
 		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
 					(vq->callfd >= 0)) ||
lib/vhost/vhost_user.c +336 -308

1,341 lines not on this page · raw message

lib/vhost/virtio_net.c +137 -121

589 lines not on this page · raw message

Signature · 1 line
2.36.1
#20 lore raw

Re: [PATCH v3] vhost: prefix logs with context

Quoted 24 lines · David Marchand

We recently improved the log messages in the vhost library, adding some context that helps filtering for a given vhost-user device. However, some parts of the code were missed, and some later code changes broke this new convention (fixes were sent previous to this patch).

Change the VHOST_LOG_CONFIG/DATA helpers and always ask for a string used as context. This should help limit regressions on this topic.

Most of the time, the context is the vhost-user device socket path. For the rest when a vhost-user device can not be related, generic names were chosen:
- "dma", for vhost-user async DMA operations,
- "device", for vhost-user device creation and lookup,
- "thread", for threads management,

---
Changes since v2:
- rebased on next-virtio,

Changes since v1:
- preserved original format for logs (removing extra ':'),

Quoted 10 lines
---
  lib/vhost/iotlb.c      |  30 +-
  lib/vhost/socket.c     | 129 ++++-----
  lib/vhost/vdpa.c       |   4 +-
  lib/vhost/vhost.c      | 146 +++++-----
  lib/vhost/vhost.h      |  20 +-
  lib/vhost/vhost_user.c | 644 +++++++++++++++++++++--------------------
  lib/vhost/virtio_net.c | 258 +++++++++--------
  7 files changed, 636 insertions(+), 595 deletions(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime

#21 lore raw
In reply to David Marchand
Quoted 5 lines · David Marchand

Here is a series that fixes log messages (with one regression being fixed in patch 2) and changes the VHOST_LOG_* helpers to enforce that vhost log messages will always have some context/prefix to help debugging on setups with many vhost ports.

Quoted 7 lines

The first three patches are low risk and can probably be merged in v22.07.

Changes since v1:
- fixed log formats in patch4,

Applied first 3 patches to dpdk-next-virtio/main.

Thanks,
Maxime