[3/7] graph: add explicit cast to allow C++ build

Message ID 20220204174209.440207-4-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Verify C++ compatibility of public headers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Feb. 4, 2022, 5:42 p.m. UTC
  C++ does not have automatic casting to/from void pointers, so need
explicit cast if header is to be included in C++ code

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/graph/rte_graph_worker.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Stephen Hemminger Feb. 4, 2022, 6:12 p.m. UTC | #1
On Fri,  4 Feb 2022 17:42:05 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:

> C++ does not have automatic casting to/from void pointers, so need
> explicit cast if header is to be included in C++ code
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/graph/rte_graph_worker.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/graph/rte_graph_worker.h b/lib/graph/rte_graph_worker.h
> index eef77f732a..0c0b9c095a 100644
> --- a/lib/graph/rte_graph_worker.h
> +++ b/lib/graph/rte_graph_worker.h
> @@ -155,7 +155,7 @@ rte_graph_walk(struct rte_graph *graph)
>  	 *	+-----+ <= cir_start + mask
>  	 */
>  	while (likely(head != graph->tail)) {
> -		node = RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
> +		node = (struct rte_node *)RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
>  		RTE_ASSERT(node->fence == RTE_GRAPH_FENCE);
>  		objs = node->objs;
>  		rte_prefetch0(objs);

Having to do this raises the other question.
Why is this code inline? It should not be in critical path.
  
Jerin Jacob Feb. 7, 2022, 9:41 a.m. UTC | #2
On Fri, Feb 4, 2022 at 11:42 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Fri,  4 Feb 2022 17:42:05 +0000
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> > C++ does not have automatic casting to/from void pointers, so need
> > explicit cast if header is to be included in C++ code
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
> >  lib/graph/rte_graph_worker.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/graph/rte_graph_worker.h b/lib/graph/rte_graph_worker.h
> > index eef77f732a..0c0b9c095a 100644
> > --- a/lib/graph/rte_graph_worker.h
> > +++ b/lib/graph/rte_graph_worker.h
> > @@ -155,7 +155,7 @@ rte_graph_walk(struct rte_graph *graph)
> >        *      +-----+ <= cir_start + mask
> >        */
> >       while (likely(head != graph->tail)) {
> > -             node = RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
> > +             node = (struct rte_node *)RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
> >               RTE_ASSERT(node->fence == RTE_GRAPH_FENCE);
> >               objs = node->objs;
> >               rte_prefetch0(objs);
>
> Having to do this raises the other question.
> Why is this code inline? It should not be in critical path.

rte_graph_walk() is a fastpath function.Slowpath and fasthpath
functions are separated by
rte_graph.h and rte_graph_worker.h

Acked-by: Jerin Jacob <jerinj@marvell.com>
  

Patch

diff --git a/lib/graph/rte_graph_worker.h b/lib/graph/rte_graph_worker.h
index eef77f732a..0c0b9c095a 100644
--- a/lib/graph/rte_graph_worker.h
+++ b/lib/graph/rte_graph_worker.h
@@ -155,7 +155,7 @@  rte_graph_walk(struct rte_graph *graph)
 	 *	+-----+ <= cir_start + mask
 	 */
 	while (likely(head != graph->tail)) {
-		node = RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
+		node = (struct rte_node *)RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
 		RTE_ASSERT(node->fence == RTE_GRAPH_FENCE);
 		objs = node->objs;
 		rte_prefetch0(objs);