summaryrefslogtreecommitdiffstats
path: root/src/plugins/perfmon
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2019-12-16 15:26:49 +0100
committerDamjan Marion <dmarion@me.com>2019-12-17 17:53:07 +0000
commit7176b800fa5570a14d9d403183131f5115158baf (patch)
tree89cd45e23a73165a95690f9ab241d27f85b7d0df /src/plugins/perfmon
parente11dce20c99775884877ad6dcf879e8995c78ebf (diff)
perfmon: fix per-worker data initialization
When perfmon_init is called at initialization time worker threads are not created yet and vec_len(vlib_mains) returns 1. Initialize per-worker data when the number of workers is known, when enabling data collection instead. Type: fix Change-Id: I36887cc7b2a3e88d9728d3cd7262d9b1c968dd3c Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/plugins/perfmon')
-rw-r--r--src/plugins/perfmon/perfmon.c6
-rw-r--r--src/plugins/perfmon/perfmon_periodic.c17
2 files changed, 14 insertions, 9 deletions
diff --git a/src/plugins/perfmon/perfmon.c b/src/plugins/perfmon/perfmon.c
index 552c88757f7..7e276c30810 100644
--- a/src/plugins/perfmon/perfmon.c
+++ b/src/plugins/perfmon/perfmon.c
@@ -110,14 +110,8 @@ perfmon_init (vlib_main_t * vm)
/* Default data collection interval */
pm->timeout_interval = 2.0; /* seconds */
vec_validate (pm->pm_fds, 1);
- vec_validate (pm->pm_fds[0], vec_len (vlib_mains) - 1);
- vec_validate (pm->pm_fds[1], vec_len (vlib_mains) - 1);
vec_validate (pm->perf_event_pages, 1);
- vec_validate (pm->perf_event_pages[0], vec_len (vlib_mains) - 1);
- vec_validate (pm->perf_event_pages[1], vec_len (vlib_mains) - 1);
vec_validate (pm->rdpmc_indices, 1);
- vec_validate (pm->rdpmc_indices[0], vec_len (vlib_mains) - 1);
- vec_validate (pm->rdpmc_indices[1], vec_len (vlib_mains) - 1);
pm->page_size = getpagesize ();
pm->perfmon_table = 0;
diff --git a/src/plugins/perfmon/perfmon_periodic.c b/src/plugins/perfmon/perfmon_periodic.c
index ac68c42c219..8498419f36f 100644
--- a/src/plugins/perfmon/perfmon_periodic.c
+++ b/src/plugins/perfmon/perfmon_periodic.c
@@ -130,6 +130,10 @@ enable_current_events (perfmon_main_t * pm)
for (i = 0; i < limit; i++)
{
+ vec_validate (pm->pm_fds[i], vec_len (vlib_mains) - 1);
+ vec_validate (pm->perf_event_pages[i], vec_len (vlib_mains) - 1);
+ vec_validate (pm->rdpmc_indices[i], vec_len (vlib_mains) - 1);
+
c = vec_elt_at_index (pm->single_events_to_collect,
pm->current_event + i);
@@ -169,6 +173,7 @@ enable_current_events (perfmon_main_t * pm)
close (fd);
return;
}
+ CLIB_MEM_UNPOISON (p, pm->page_size);
}
else
p = 0;
@@ -239,12 +244,18 @@ disable_events (perfmon_main_t * pm)
clib_unix_warning ("disable ioctl");
if (pm->perf_event_pages[i][my_thread_index])
- if (munmap (pm->perf_event_pages[i][my_thread_index],
- pm->page_size) < 0)
- clib_unix_warning ("munmap");
+ {
+ if (munmap (pm->perf_event_pages[i][my_thread_index],
+ pm->page_size) < 0)
+ clib_unix_warning ("munmap");
+ CLIB_MEM_POISON (pm->perf_event_pages[i][my_thread_index],
+ pm->page_size);
+ pm->perf_event_pages[i][my_thread_index] = 0;
+ }
(void) close (pm->pm_fds[i][my_thread_index]);
pm->pm_fds[i][my_thread_index] = 0;
+
}
}
hlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * ip/ip6_pg: IP v4 packet-generator interface
 *
 * Copyright (c) 2008 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <vnet/ip/ip.h>
#include <vnet/pg/pg.h>

static void
ip6_pg_edit_function (pg_main_t * pg,
		      pg_stream_t * s,
		      pg_edit_group_t * g, u32 * packets, u32 n_packets)
{
  vlib_main_t *vm = vlib_get_main ();
  u32 ip_header_offset = g->start_byte_offset;

  while (n_packets >= 2)
    {
      u32 pi0, pi1;
      vlib_buffer_t *p0, *p1;
      ip6_header_t *ip0, *ip1;

      pi0 = packets[0];
      pi1 = packets[1];
      p0 = vlib_get_buffer (vm, pi0);
      p1 = vlib_get_buffer (vm, pi1);
      n_packets -= 2;
      packets += 2;

      ip0 = (void *) (p0->data + ip_header_offset);
      ip1 = (void *) (p1->data + ip_header_offset);

      ip0->payload_length =
	clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
			      ip_header_offset - sizeof (ip0[0]));
      ip1->payload_length =
	clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p1) -
			      ip_header_offset - sizeof (ip1[0]));
    }

  while (n_packets >= 1)
    {
      u32 pi0;
      vlib_buffer_t *p0;
      ip6_header_t *ip0;

      pi0 = packets[0];
      p0 = vlib_get_buffer (vm, pi0);
      n_packets -= 1;
      packets += 1;

      ip0 = (void *) (p0->data + ip_header_offset);

      ip0->payload_length =
	clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, p0) -
			      ip_header_offset - sizeof (ip0[0]));
    }
}

typedef struct
{
  pg_edit_t ip_version;
  pg_edit_t traffic_class;
  pg_edit_t flow_label;
  pg_edit_t payload_length;
  pg_edit_t protocol;
  pg_edit_t hop_limit;
  pg_edit_t src_address, dst_address;
} pg_ip6_header_t;

static inline void
pg_ip6_header_init (pg_ip6_header_t * p)
{
  /* Initialize fields that are not bit fields in the IP header. */
#define _(f) pg_edit_init (&p->f, ip6_header_t, f);
  _(payload_length);
  _(hop_limit);
  _(protocol);
  _(src_address);
  _(dst_address);
#undef _

  /* Initialize bit fields. */
  pg_edit_init_bitfield (&p->ip_version, ip6_header_t,
			 ip_version_traffic_class_and_flow_label, 28, 4);
  pg_edit_init_bitfield (&p->traffic_class, ip6_header_t,
			 ip_version_traffic_class_and_flow_label, 20, 8);
  pg_edit_init_bitfield (&p->flow_label, ip6_header_t,
			 ip_version_traffic_class_and_flow_label, 0, 20);
}

uword
unformat_pg_ip6_header (unformat_input_t * input, va_list * args)
{
  pg_stream_t *s = va_arg (*args, pg_stream_t *);
  pg_ip6_header_t *p;
  u32 group_index;

  p = pg_create_edit_group (s, sizeof (p[0]), sizeof (ip6_header_t),
			    &group_index);
  pg_ip6_header_init (p);

  /* Defaults. */
  pg_edit_set_fixed (&p->ip_version, 6);
  pg_edit_set_fixed (&p->traffic_class, 0);
  pg_edit_set_fixed (&p->flow_label, 0);
  pg_edit_set_fixed (&p->hop_limit, 64);

  p->payload_length.type = PG_EDIT_UNSPECIFIED;

  if (!unformat (input, "%U: %U -> %U",
		 unformat_pg_edit,
		 unformat_ip_protocol, &p->protocol,
		 unformat_pg_edit,
		 unformat_ip6_address, &p->src_address,
		 unformat_pg_edit, unformat_ip6_address, &p->dst_address))
    goto error;

  /* Parse options. */
  while (1)
    {
      if (unformat (input, "version %U",
		    unformat_pg_edit, unformat_pg_number, &p->ip_version))
	;

      else if (unformat (input, "traffic-class %U",
			 unformat_pg_edit,
			 unformat_pg_number, &p->traffic_class))
	;

      else if (unformat (input, "length %U",
			 unformat_pg_edit,
			 unformat_pg_number, &p->payload_length))
	;

      else if (unformat (input, "hop-limit %U",
			 unformat_pg_edit, unformat_pg_number, &p->hop_limit))
	;

      /* Can't parse input: try next protocol level. */
      else
	break;
    }

  {
    ip_main_t *im = &ip_main;
    ip_protocol_t protocol;
    ip_protocol_info_t *pi;

    pi = 0;
    if (p->protocol.type == PG_EDIT_FIXED)
      {
	protocol = pg_edit_get_value (&p->protocol, PG_EDIT_LO);
	pi = ip_get_protocol_info (im, protocol);
      }

    if (pi && pi->unformat_pg_edit
	&& unformat_user (input, pi->unformat_pg_edit, s))
      ;

    else if (!unformat_user (input, unformat_pg_payload, s))
      goto error;

    if (p->payload_length.type == PG_EDIT_UNSPECIFIED
	&& s->min_packet_bytes == s->max_packet_bytes
	&& group_index + 1 < vec_len (s->edit_groups))
      {
	pg_edit_set_fixed (&p->payload_length,
			   pg_edit_group_n_bytes (s,
						  group_index) -
			   sizeof (ip6_header_t));
      }

    p = pg_get_edit_group (s, group_index);
    if (p->payload_length.type == PG_EDIT_UNSPECIFIED)
      {
	pg_edit_group_t *g = pg_stream_get_group (s, group_index);
	g->edit_function = ip6_pg_edit_function;
      }

    return 1;
  }

error:
  /* Free up any edits we may have added. */
  pg_free_edit_group (s);
  return 0;
}


/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */