On 24 Apr 2024, at 21:53, Adrian Moreno wrote:

> Add a cache entry type for psample objects.
> Store both the dpif_psample reference and the collector_set_id so we can
> quickly find the particular exporter.
>
> Using that mechanism, account for packet and byte statistics.

See comments inline.

//Eelco

> Signed-off-by: Adrian Moreno <[email protected]>
> ---
>  ofproto/ofproto-dpif-psample.c     | 20 ++++++++++++++++++++
>  ofproto/ofproto-dpif-psample.h     |  4 ++++
>  ofproto/ofproto-dpif-xlate-cache.c | 11 ++++++++++-
>  ofproto/ofproto-dpif-xlate-cache.h |  6 ++++++
>  ofproto/ofproto-dpif-xlate.c       |  9 +++++++++
>  ofproto/ofproto-dpif.c             |  1 +
>  6 files changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/ofproto/ofproto-dpif-psample.c b/ofproto/ofproto-dpif-psample.c
> index 1e4f4bf48..ea4926eb2 100644
> --- a/ofproto/ofproto-dpif-psample.c
> +++ b/ofproto/ofproto-dpif-psample.c
> @@ -17,6 +17,7 @@
>  #include <config.h>
>  #include "ofproto-dpif-psample.h"
>
> +#include "dpif.h"
>  #include "hash.h"
>  #include "ofproto.h"
>  #include "openvswitch/hmap.h"
> @@ -30,6 +31,8 @@ static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
>  struct psample_exporter {
>      uint32_t group_id;
>      uint32_t collector_set_id;
> +    uint64_t n_packets;
> +    uint64_t n_bytes;
>  };
>
>  struct psample_exporter_map_node {
> @@ -145,6 +148,23 @@ dpif_psample_get_group_id(struct dpif_psample *ps, 
> uint32_t collector_set_id,
>      return found;
>  }
>
> +void
> +dpif_psample_credit_stats(struct dpif_psample *ps, uint32_t collector_set_id,
> +                          const struct dpif_flow_stats *stats)
> +OVS_EXCLUDED(mutex)
> +{
> +    struct psample_exporter_map_node *node;
> +
> +    ovs_mutex_lock(&mutex);
> +    node = dpif_psample_find_exporter_node(ps, collector_set_id);
> +    if (node) {
> +        node->exporter.n_packets += stats->n_packets;
> +        node->exporter.n_bytes += stats->n_bytes;

A global mutex seems far from optimal for increasing stats.

> +    }
> +    ovs_mutex_unlock(&mutex);
> +}
> +
> +
>  /* Creation and destruction. */
>  struct dpif_psample *
>  dpif_psample_create(void)
> diff --git a/ofproto/ofproto-dpif-psample.h b/ofproto/ofproto-dpif-psample.h
> index b9f2584af..763fbd30b 100644
> --- a/ofproto/ofproto-dpif-psample.h
> +++ b/ofproto/ofproto-dpif-psample.h
> @@ -20,6 +20,7 @@
>  #include <stdbool.h>
>  #include <stdint.h>
>
> +struct dpif_flow_stats;
>  struct dpif_psample;
>  struct ovs_list;
>
> @@ -31,4 +32,7 @@ bool dpif_psample_set_options(struct dpif_psample *, const 
> struct ovs_list *);
>
>  bool dpif_psample_get_group_id(struct dpif_psample *, uint32_t, uint32_t *);
>
> +void dpif_psample_credit_stats(struct dpif_psample *, uint32_t,

Please add a name for this uint32_t parameter.

> +                               const struct dpif_flow_stats *);
> +
>  #endif // OFPROTO_DPIF_PSAMPLE_H
> diff --git a/ofproto/ofproto-dpif-xlate-cache.c 
> b/ofproto/ofproto-dpif-xlate-cache.c
> index 2e1fcb3a6..0fe76e5fa 100644
> --- a/ofproto/ofproto-dpif-xlate-cache.c
> +++ b/ofproto/ofproto-dpif-xlate-cache.c
> @@ -35,9 +35,10 @@
>  #include "learn.h"
>  #include "mac-learning.h"
>  #include "netdev-vport.h"
> +#include "ofproto/ofproto-dpif.h"
>  #include "ofproto/ofproto-dpif-mirror.h"
> +#include "ofproto/ofproto-dpif-psample.h"
>  #include "ofproto/ofproto-dpif-xlate.h"
> -#include "ofproto/ofproto-dpif.h"
>  #include "ofproto/ofproto-provider.h"
>  #include "openvswitch/dynamic-string.h"
>  #include "openvswitch/vlog.h"
> @@ -162,6 +163,11 @@ xlate_push_stats_entry(struct xc_entry *entry,
>          }
>
>          break;
> +    case XC_PSAMPLE:
> +        dpif_psample_credit_stats(entry->psample.psample,
> +                                  entry->psample.collector_set_id,
> +                                  stats);
> +        break;
>      default:
>          OVS_NOT_REACHED();
>      }
> @@ -245,6 +251,9 @@ xlate_cache_clear_entry(struct xc_entry *entry)
>          break;
>      case XC_TUNNEL_HEADER:
>          break;
> +    case XC_PSAMPLE:
> +        dpif_psample_unref(entry->psample.psample);
> +        break;
>      default:
>          OVS_NOT_REACHED();
>      }
> diff --git a/ofproto/ofproto-dpif-xlate-cache.h 
> b/ofproto/ofproto-dpif-xlate-cache.h
> index 0fc6d2ea6..fa707889d 100644
> --- a/ofproto/ofproto-dpif-xlate-cache.h
> +++ b/ofproto/ofproto-dpif-xlate-cache.h
> @@ -29,6 +29,7 @@
>  struct bfd;
>  struct bond;
>  struct dpif_flow_stats;
> +struct dpif_psample;
>  struct flow;
>  struct group_dpif;
>  struct mbridge;
> @@ -53,6 +54,7 @@ enum xc_type {
>      XC_GROUP,
>      XC_TNL_NEIGH,
>      XC_TUNNEL_HEADER,
> +    XC_PSAMPLE,
>  };
>
>  /* xlate_cache entries hold enough information to perform the side effects of
> @@ -126,6 +128,10 @@ struct xc_entry {
>              } operation;
>              uint16_t hdr_size;
>          } tunnel_hdr;
> +        struct {
> +            struct dpif_psample *psample;
> +            uint32_t collector_set_id;
> +        } psample;
>      };
>  };
>
> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
> index 1dcf86856..a9856e358 100644
> --- a/ofproto/ofproto-dpif-xlate.c
> +++ b/ofproto/ofproto-dpif-xlate.c
> @@ -5989,6 +5989,15 @@ xlate_sample_action(struct xlate_ctx *ctx,
>                         sizeof(os->obs_domain_id));
>              ofpbuf_put(&psample_args->cookie, &os->obs_point_id,
>                         sizeof(os->obs_point_id));
> +
> +            if (ctx->xin->xcache) {
> +                struct xc_entry *entry;
> +
> +                entry = xlate_cache_add_entry(ctx->xin->xcache, XC_PSAMPLE);
> +                entry->psample.psample = dpif_psample_ref(psample);
> +                entry->psample.collector_set_id = os->collector_set_id;
> +            }
> +
>          }
>      }
>
> diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
> index 64c06322e..f1efdd482 100644
> --- a/ofproto/ofproto-dpif.c
> +++ b/ofproto/ofproto-dpif.c
> @@ -5167,6 +5167,7 @@ ofproto_dpif_xcache_execute(struct ofproto_dpif 
> *ofproto,
>          case XC_GROUP:
>          case XC_TNL_NEIGH:
>          case XC_TUNNEL_HEADER:
> +        case XC_PSAMPLE:
>              xlate_push_stats_entry(entry, stats, false);
>              break;
>          default:
> -- 
> 2.44.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to