[v8,1/6] ip_frag: use a dynamic logtype

Message ID 20230814163125.63033-2-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Convert use of RTE_LOGTYPE_USER1 in libraries |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Aug. 14, 2023, 4:31 p.m. UTC
  DPDK libraries should not be reusing RTE_LOGTYPE_USER1 in
lieu of doing proper logtype registration.

Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Fixes: 416707812c03 ("ip_frag: refactor reassembly code into a proper library")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/ip_frag/ip_frag_common.h     | 5 ++++-
 lib/ip_frag/rte_ip_frag_common.c | 8 +++++---
 2 files changed, 9 insertions(+), 4 deletions(-)
  

Comments

David Marchand Dec. 1, 2023, 8:10 a.m. UTC | #1
On Mon, Aug 14, 2023 at 6:31 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
> @@ -52,20 +54,20 @@ rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
>         if (rte_is_power_of_2(bucket_entries) == 0 ||
>                         nb_entries > UINT32_MAX || nb_entries == 0 ||
>                         nb_entries < max_entries) {
> -               RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
> +               RTE_LOG(ERR, IPFRAG, "%s: invalid input parameter\n", __func__);
>                 return NULL;
>         }
>
>         sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
>         if ((tbl = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE,
>                         socket_id)) == NULL) {
> -               RTE_LOG(ERR, USER1,
> +               RTE_LOG(ERR, IPFRAG,
>                         "%s: allocation of %zu bytes at socket %d failed do\n",
>                         __func__, sz, socket_id);
>                 return NULL;
>         }
>
> -       RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
> +       RTE_LOG(INFO, IPFRAG, "%s: allocated of %zu bytes at socket %d\n",
>                 __func__, sz, socket_id);
>
>         tbl->max_cycles = max_cycles;
> --
> 2.39.2
>

Any reason not to use the IP_FRAG_LOG macro?
This is easy for me to fix when applying if you have no objection.
  
Konstantin Ananyev Dec. 1, 2023, 12:16 p.m. UTC | #2
Hi David,

> On Mon, Aug 14, 2023 at 6:31 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> > @@ -52,20 +54,20 @@ rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
> >         if (rte_is_power_of_2(bucket_entries) == 0 ||
> >                         nb_entries > UINT32_MAX || nb_entries == 0 ||
> >                         nb_entries < max_entries) {
> > -               RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
> > +               RTE_LOG(ERR, IPFRAG, "%s: invalid input parameter\n", __func__);
> >                 return NULL;
> >         }
> >
> >         sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
> >         if ((tbl = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE,
> >                         socket_id)) == NULL) {
> > -               RTE_LOG(ERR, USER1,
> > +               RTE_LOG(ERR, IPFRAG,
> >                         "%s: allocation of %zu bytes at socket %d failed do\n",
> >                         __func__, sz, socket_id);
> >                 return NULL;
> >         }
> >
> > -       RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
> > +       RTE_LOG(INFO, IPFRAG, "%s: allocated of %zu bytes at socket %d\n",
> >                 __func__, sz, socket_id);
> >
> >         tbl->max_cycles = max_cycles;
> > --
> > 2.39.2
> >
> 
> Any reason not to use the IP_FRAG_LOG macro?
> This is easy for me to fix when applying if you have no objection.

As I remember, IP_FRAG_LOG is disabled by default.
To enable it, user has to build it with -DRTE_LIBRTE_IP_FRAG_DEBUG or so.
Konstantin
  
David Marchand Dec. 1, 2023, 1:11 p.m. UTC | #3
Hello Konstantin,

On Fri, Dec 1, 2023 at 1:17 PM Konstantin Ananyev
<konstantin.ananyev@huawei.com> wrote:
>
> Hi David,
>
> > On Mon, Aug 14, 2023 at 6:31 PM Stephen Hemminger
> > <stephen@networkplumber.org> wrote:
> > > @@ -52,20 +54,20 @@ rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
> > >         if (rte_is_power_of_2(bucket_entries) == 0 ||
> > >                         nb_entries > UINT32_MAX || nb_entries == 0 ||
> > >                         nb_entries < max_entries) {
> > > -               RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
> > > +               RTE_LOG(ERR, IPFRAG, "%s: invalid input parameter\n", __func__);
> > >                 return NULL;
> > >         }
> > >
> > >         sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
> > >         if ((tbl = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE,
> > >                         socket_id)) == NULL) {
> > > -               RTE_LOG(ERR, USER1,
> > > +               RTE_LOG(ERR, IPFRAG,
> > >                         "%s: allocation of %zu bytes at socket %d failed do\n",
> > >                         __func__, sz, socket_id);
> > >                 return NULL;
> > >         }
> > >
> > > -       RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
> > > +       RTE_LOG(INFO, IPFRAG, "%s: allocated of %zu bytes at socket %d\n",
> > >                 __func__, sz, socket_id);
> > >
> > >         tbl->max_cycles = max_cycles;
> > > --
> > > 2.39.2
> > >
> >
> > Any reason not to use the IP_FRAG_LOG macro?
> > This is easy for me to fix when applying if you have no objection.
>
> As I remember, IP_FRAG_LOG is disabled by default.
> To enable it, user has to build it with -DRTE_LIBRTE_IP_FRAG_DEBUG or so.

Indeed, so nothing to do here, thanks.
  

Patch

diff --git a/lib/ip_frag/ip_frag_common.h b/lib/ip_frag/ip_frag_common.h
index 7d6c1aa98d98..537bce7c3b62 100644
--- a/lib/ip_frag/ip_frag_common.h
+++ b/lib/ip_frag/ip_frag_common.h
@@ -18,9 +18,12 @@ 
 #include "rte_ip_frag.h"
 #include "ip_reassembly.h"
 
+extern int ipfrag_logtype;
+#define RTE_LOGTYPE_IPFRAG	ipfrag_logtype
+
 /* logging macros. */
 #ifdef RTE_LIBRTE_IP_FRAG_DEBUG
-#define	IP_FRAG_LOG(lvl, fmt, args...)	RTE_LOG(lvl, USER1, fmt, ##args)
+#define	IP_FRAG_LOG(lvl, fmt, args...)	RTE_LOG(lvl, IPFRAG, fmt, ##args)
 #else
 #define	IP_FRAG_LOG(lvl, fmt, args...)	do {} while(0)
 #endif /* IP_FRAG_DEBUG */
diff --git a/lib/ip_frag/rte_ip_frag_common.c b/lib/ip_frag/rte_ip_frag_common.c
index c1de2e81b6d0..eed399da6bc5 100644
--- a/lib/ip_frag/rte_ip_frag_common.c
+++ b/lib/ip_frag/rte_ip_frag_common.c
@@ -7,6 +7,8 @@ 
 
 #include <rte_log.h>
 
+RTE_LOG_REGISTER_DEFAULT(ipfrag_logtype, INFO);
+
 #include "ip_frag_common.h"
 
 #define	IP_FRAG_HASH_FNUM	2
@@ -52,20 +54,20 @@  rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
 	if (rte_is_power_of_2(bucket_entries) == 0 ||
 			nb_entries > UINT32_MAX || nb_entries == 0 ||
 			nb_entries < max_entries) {
-		RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
+		RTE_LOG(ERR, IPFRAG, "%s: invalid input parameter\n", __func__);
 		return NULL;
 	}
 
 	sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
 	if ((tbl = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE,
 			socket_id)) == NULL) {
-		RTE_LOG(ERR, USER1,
+		RTE_LOG(ERR, IPFRAG,
 			"%s: allocation of %zu bytes at socket %d failed do\n",
 			__func__, sz, socket_id);
 		return NULL;
 	}
 
-	RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
+	RTE_LOG(INFO, IPFRAG, "%s: allocated of %zu bytes at socket %d\n",
 		__func__, sz, socket_id);
 
 	tbl->max_cycles = max_cycles;