summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-01-27 18:08:25 -0800
committerDave Barach <openvpp@barachs.net>2021-01-28 15:57:33 +0000
commit80b742592bd227cedb22362abb6286838977ba4f (patch)
treeca87e72c58df443744cc6b50a65feaf947ef36de /src/svm
parentb13ba133fbdb3a66a6c3ddf19a2bc80525b92606 (diff)
svm vcl: add helper fn that discovers mqs in segment
Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I1b083ee793a7cf91b1001bfe88353fa5e6515c42
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/fifo_segment.c33
-rw-r--r--src/svm/fifo_segment.h9
-rw-r--r--src/svm/fifo_types.h1
3 files changed, 43 insertions, 0 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 3e9aecb9dc8..76cc046efec 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -301,6 +301,7 @@ fifo_segment_init (fifo_segment_t * fs)
fsh->max_log2_fifo_size = min_log2 (max_fifo);
fsh->n_cached_bytes = 0;
fsh->n_reserved_bytes = fsh->byte_index;
+ fsh->start_byte_index = fsh->byte_index;
ASSERT (fsh->max_byte_index <= sh->ssvm_size - offset);
fs->max_byte_index = fsh->max_byte_index;
@@ -1054,6 +1055,38 @@ fifo_segment_msg_q_attach (fifo_segment_t *fs, uword offset, u32 mq_index)
return mq;
}
+void
+fifo_segment_msg_qs_discover (fifo_segment_t *fs, int *fds, u32 n_fds)
+{
+ svm_msg_q_shared_t *smq;
+ u32 n_mqs, size, i;
+ uword offset = 0, n_alloced;
+ svm_msg_q_t *mq;
+
+ n_mqs = fs->h->n_mqs;
+ if (n_fds && n_mqs != n_fds)
+ {
+ clib_warning ("expected %u fds got %u", n_mqs, n_fds);
+ return;
+ }
+
+ vec_validate (fs->mqs, n_mqs - 1);
+ n_alloced = fs->h->n_reserved_bytes - fs->h->start_byte_index;
+ ASSERT (n_alloced % n_mqs == 0);
+ size = n_alloced / n_mqs;
+
+ offset = fs->h->start_byte_index;
+ for (i = 0; i < n_mqs; i++)
+ {
+ mq = vec_elt_at_index (fs->mqs, i);
+ smq = (svm_msg_q_shared_t *) ((u8 *) fs->h + offset);
+ svm_msg_q_attach (mq, smq);
+ if (n_fds)
+ svm_msg_q_set_eventfd (mq, fds[i]);
+ offset += size;
+ }
+}
+
uword
fifo_segment_msg_q_offset (fifo_segment_t *fs, u32 mq_index)
{
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h
index 268b48b39f6..9d2ab281034 100644
--- a/src/svm/fifo_segment.h
+++ b/src/svm/fifo_segment.h
@@ -167,6 +167,15 @@ svm_msg_q_t *fifo_segment_msg_q_attach (fifo_segment_t *fs, uword offset,
u32 mq_index);
/**
+ * Discover mqs on mq only segment
+ *
+ * @param fs fifo segment for mq
+ * @param fds array of fds is mqs use eventfds
+ * @param n_fds number of fds
+ */
+void fifo_segment_msg_qs_discover (fifo_segment_t *fs, int *fds, u32 n_fds);
+
+/**
* Message queue offset on segment
*
* @param fs fifo segment for mq
diff --git a/src/svm/fifo_types.h b/src/svm/fifo_types.h
index 03adbd33c2c..7b844f00bfe 100644
--- a/src/svm/fifo_types.h
+++ b/src/svm/fifo_types.h
@@ -150,6 +150,7 @@ struct fifo_segment_header_
CLIB_CACHE_LINE_ALIGN_MARK (allocator);
uword byte_index;
uword max_byte_index;
+ uword start_byte_index;
CLIB_CACHE_LINE_ALIGN_MARK (slice);
fifo_segment_slice_t slices[0]; /** Fixed array of slices */
};
ht .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.
 */
/*
  Copyright (c) 2012 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.
*/

#ifndef included_clib_elf_self_h
#define included_clib_elf_self_h

#include <vppinfra/elf.h>
#include <vppinfra/hash.h>

#define CLIB_ELF_SECTION_DATA_ALIGN 32

#define CLIB_ELF_SECTION_ADD_PREFIX(n) "clib_elf_section_" n

/* Attribute used is so that static registrations work even if
   variable is not referenced. */
#define CLIB_ELF_SECTION(SECTION)					\
   __attribute__ ((used,						\
		   aligned (CLIB_ELF_SECTION_DATA_ALIGN),		\
		   section (CLIB_ELF_SECTION_ADD_PREFIX (SECTION))))

/* Given pointer to previous data A get next pointer.  EXTRA gives extra
   space beyond A + 1 used in object. */
#define clib_elf_section_data_next(a,extra)				\
  uword_to_pointer (round_pow2 (pointer_to_uword (a + 1) + (extra),	\
				CLIB_ELF_SECTION_DATA_ALIGN),		\
		    void *)

typedef struct
{
  void *lo, *hi;
} clib_elf_section_bounds_t;

typedef struct
{
  /* Vector of bounds for this section.  Multiple shared objects may have instances
     of the same sections. */
  clib_elf_section_bounds_t *bounds;

  /* Name of ELF section (e.g. .text). */
  u8 *name;
} clib_elf_section_t;

typedef struct
{
  /* Vector of sections. */
  clib_elf_section_t *sections;

  /* Hash map of name to section index. */
  uword *section_by_name;

  /* Unix path that we were exec()ed with. */
  char *exec_path;

  elf_main_t *elf_mains;
} clib_elf_main_t;

always_inline void
clib_elf_main_free (clib_elf_main_t * m)
{
  clib_elf_section_t *s;
  vec_foreach (s, m->sections)
  {
    vec_free (s->bounds);
    vec_free (s->name);
  }
  vec_free (m->sections);
  hash_free (m->section_by_name);

  {
    elf_main_t *em;
    vec_foreach (em, m->elf_mains)
    {
      elf_main_free (em);
    }
    vec_free (m->elf_mains);
  }
}

/* Call with exec_path equal to argv[0] from C main. */
void clib_elf_main_init (char *exec_path);

clib_elf_section_bounds_t *clib_elf_get_section_bounds (char *name);

typedef struct
{
  /* The symbol. */
  elf64_symbol_t symbol;

  /* elf_main_t where symbol came from. */
  u32 elf_main_index;

  /* Symbol table in elf_main_t where this symbol came from. */
  u32 symbol_table_index;
} clib_elf_symbol_t;

/* Returns 1 if found; otherwise zero. */
uword clib_elf_symbol_by_name (char *name, clib_elf_symbol_t * result);
uword clib_elf_symbol_by_address (uword address, clib_elf_symbol_t * result);

format_function_t format_clib_elf_symbol, format_clib_elf_symbol_with_address;

#endif /* included_clib_elf_self_h */

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