Skip to content

Commit

Permalink
Add startup script with worker core support
Browse files Browse the repository at this point in the history
Non-empty value of VPP_USE_WORKER_CORE env var enables the use of the
worker core. In this case, exactly 2 logical cores must be allocated
for the VPP container via the cpuset cgroup controller.
  • Loading branch information
ivan4th committed Feb 18, 2021
1 parent 572ac43 commit b736a69
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=private \
python python-cffi python-cffi-backend python-ipaddress \
python2-minimal python-ply python-pycparser python2.7 python2.7-minimal \
python3 python3-minimal python3.6 python3-minimal \
python3-cffi python3-cffi-backend && \
python3-cffi python3-cffi-backend dumb-init && \
apt-get install -yy clang-9

# TODO: add more packages above that are VPP deps
Expand All @@ -43,4 +43,8 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=private \
/debs/libvppinfra_*.deb \
/debs/vpp-api-python_*.deb

ENTRYPOINT /usr/bin/vpp
COPY start.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/start.sh

ENTRYPOINT ["dumb-init", "--"]
CMD ["/usr/local/bin/start.sh"]
8 changes: 6 additions & 2 deletions Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=private \
python python-cffi python-cffi-backend python-ipaddress \
python2-minimal python-ply python-pycparser python2.7 python2.7-minimal \
python3 python3-minimal python3.6 python3-minimal \
python3-cffi python3-cffi-backend && \
python3-cffi python3-cffi-backend dumb-init && \
apt-get install -yy clang-9

# TODO: add more packages above that are VPP deps
Expand All @@ -45,4 +45,8 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=private \
/debs/libvppinfra-dev_*.deb \
/debs/vpp-api-python_*.deb

ENTRYPOINT /usr/bin/vpp
COPY start.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/start.sh

ENTRYPOINT ["dumb-init", "--"]
CMD ["/usr/local/bin/start.sh"]
45 changes: 45 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash -x
# TODO: remove -x above !
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace

trap "sleep 10" EXIT

sysctl kernel.core_pattern="/tmp/coredump/core.%t.%e.%p"
cp /etc/vpp/startup.conf /tmp/startup.conf

echo "cpu {" >>/tmp/startup.conf
if [[ ${VPP_USE_WORKER_CORE:-} ]]; then
# this expands ranges like 10-12,42 in the cpuset core list
# into an array by using eval and {x..y} brace expansion
cores=($(eval "echo $(sed 's/\([0-9]*\)-\([0-9]*\)/{\1..\2}/g;s/,/ /g' /sys/fs/cgroup/cpuset/cpuset.cpus)"))
if (( ${#cores[@]} < 2 )); then
echo >&2 "ERROR: need at least 2 cores"
exit 1
fi
main_core=${cores[0]}
# try to pick a non-sibling core from the rest of the list
for ((i = 1; i < ${#cores[@]}; i++)); do
worker_core="${cores[${i}]}"
if ! grep -qE "\b(${main_core},${worker_core}|${worker_core},${main_core})\b" \
/sys/devices/system/cpu/cpu*/topology/thread_siblings_list; then
break
fi
done
if (( ${i} == ${#cores[@]} )); then
echo >&2 "ERROR: couldn't find enough cores"
echo >&2 "ERROR: the main core ${main_core} and the worker core ${worker_core} are HT siblings!"
if [[ ! ${VPP_TOLERATE_HT_SIBLING_CORES:-} ]]; then
exit 1
fi
fi
echo " main-core ${main_core}" >>/tmp/startup.conf
echo " corelist-workers ${worker_core}" >>/tmp/startup.conf
else
echo " workers 0" >>/tmp/startup.conf
fi
echo "}" >>/tmp/startup.conf

/usr/bin/vpp -c /tmp/startup.conf

0 comments on commit b736a69

Please sign in to comment.