aboutsummaryrefslogtreecommitdiffstats
path: root/nfvbenchvm/dib/elements/nfvbenchvm/finalise.d/51-add-cpu-isolation
blob: 12ffcdc16524175c566e02d6e2511160c7659537 (plain)
1
2
3
4
5
#!/bin/bash

grubby --update-kernel=ALL --args="isolcpus=1-7 rcu_nocbs=1 nohz=on nohz_full=1 nmi_watchdog=0"
grubby --update-kernel=ALL --args="default_hugepagesz=1G hugepagesz=1G hugepages=4"
grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt"
or: #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) 2010-2017 Intel Corporation
//
// 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.
*/

#include <inttypes.h>
#include <string.h>

#include <rte_launch.h>
#include <rte_cycles.h>
#include <rte_atomic.h>

#include "run.h"
#include "prox_cfg.h"
#include "prox_port_cfg.h"
#include "quit.h"
#include "commands.h"
#include "main.h"
#include "log.h"
#include "display.h"
#include "stats.h"
#include "stats_cons.h"
#include "stats_cons_log.h"
#include "stats_cons_cli.h"

#include "input.h"
#include "input_curses.h"
#include "input_conn.h"
#include "handle_master.h"

static int needs_refresh;
static uint64_t update_interval;
static int stop_prox = 0; /* set to 1 to stop prox */

void set_update_interval(uint32_t msec)
{
	update_interval = msec_to_tsc(msec);
}

void req_refresh(void)
{
	needs_refresh = 1;
}

void quit(void)
{
	static rte_atomic32_t already_leaving = RTE_ATOMIC32_INIT(0);
	if (!rte_atomic32_test_and_set(&already_leaving))
		return;

	plog_info("Leaving...\n");
	if (lcore_cfg == NULL)
		exit(EXIT_SUCCESS);
	stop_core_all(-1);
	stop_prox = 1;
}

static void update_link_states(void)
{
	struct prox_port_cfg *port_cfg;
	struct rte_eth_link link;

	for (uint8_t portid = 0; portid < PROX_MAX_PORTS; ++portid) {
		if (!prox_port_cfg[portid].active) {
			continue;
		}

		port_cfg  = &prox_port_cfg[portid];
		rte_eth_link_get_nowait(portid, &link);
		port_cfg->link_speed = link.link_speed;
		if (port_cfg->link_up != link.link_status) {
			port_cfg->link_up = link.link_status;
			plog_info("port %d: Link speed now %d Mbps\n", portid, link.link_speed);
		}
	}
}

static struct stats_cons stats_cons[8];
static size_t n_stats_cons = 0;
static uint16_t stats_cons_flags = 0;

static void stats_cons_add(struct stats_cons *sc)
{
	if (n_stats_cons == sizeof(stats_cons)/sizeof(stats_cons[0]))
		return;

	stats_cons[n_stats_cons++] = *sc;
	sc->init();
	stats_cons_flags |= sc->flags;
}

static void stats_cons_notify(void)
{
	for (size_t i = 0; i < n_stats_cons; ++i) {
		stats_cons[i].notify();
	}
}

static void stats_cons_refresh(void)
{
	for (size_t i = 0; i < n_stats_cons; ++i) {
		if (stats_cons[i].refresh)
			stats_cons[i].refresh();
	}
}

static void stats_cons_finish(void)
{
	for (size_t i = 0; i < n_stats_cons; ++i) {
		if (stats_cons[i].finish)
			stats_cons[i].finish();
	}
}

static void busy_wait_until(uint64_t deadline)
{
	while (rte_rdtsc() < deadline)
		;
}

static void multiplexed_input_stats(uint64_t deadline)
{
	if (deadline)
		input_proc_until(deadline);
	else
		input_proc();

	if (needs_refresh) {
		needs_refresh = 0;
		stats_cons_refresh();
	}

	if (rte_atomic32_read(&lsc)) {
		rte_atomic32_dec(&lsc);
		update_link_states();
		stats_cons_refresh();
	}
}

static void print_warnings(void)
{
	if (get_n_warnings() == -1) {
		plog_info("Warnings disabled\n");
	}
	else if (get_n_warnings() > 0) {
		int n_print = get_n_warnings() < 5? get_n_warnings(): 5;
		plog_info("Started with %d warnings, last %d warnings: \n", get_n_warnings(), n_print);
		for (int i = -n_print + 1; i <= 0; ++i) {
			plog_info("%s", get_warning(i));
		}
	}
	else {
		plog_info("Started without warnings\n");
	}
}

/* start main loop */
void __attribute__((noreturn)) run(uint32_t flags)
{
	uint64_t cur_tsc;
	uint64_t next_update;
	uint64_t stop_tsc = 0;
	int ret = 0;
	const uint64_t update_interval_threshold = usec_to_tsc(1);

	if (flags & DSF_LISTEN_TCP)
		PROX_PANIC(reg_input_tcp(), "Failed to start listening on TCP port 8474: %s\n", strerror(errno));
	if (flags & DSF_LISTEN_UDS)
		PROX_PANIC(reg_input_uds(), "Failed to start listening on UDS /tmp/prox.sock: %s\n", strerror(errno));

	if (prox_cfg.use_stats_logger)
		stats_cons_add(stats_cons_log_get());

	stats_init(prox_cfg.start_time, prox_cfg.duration_time);
	stats_update(STATS_CONS_F_ALL);

	switch (prox_cfg.ui) {
	case PROX_UI_CURSES:
		reg_input_curses();
		stats_cons_add(&display);
		break;
	case PROX_UI_CLI:
		stats_cons_add(stats_cons_cli_get());
		break;
	case PROX_UI_NONE:
	default:
		break;
	}

	if (flags & DSF_AUTOSTART)
		start_core_all(-1);
	else
		stop_core_all(-1);

	cur_tsc = rte_rdtsc();
	if (prox_cfg.duration_time != 0) {
		stop_tsc = cur_tsc + sec_to_tsc(prox_cfg.start_time + prox_cfg.duration_time);
	}

	stats_cons_notify();
	stats_cons_refresh();

	update_interval = str_to_tsc(prox_cfg.update_interval_str);
	next_update = cur_tsc + update_interval;

	cmd_rx_tx_info();
	print_warnings();

	struct task_master *task = (struct task_master *)lcore_cfg[prox_cfg.master].tasks_all[0];
	if (handle_ctrl_plane) {
		while (stop_prox == 0) {
			ret = 1;
			// Run ctrl plane for max 10 msec to let screen and keyboard updates
			if (prox_cfg.flags & DSF_CTRL_PLANE_ENABLED) {
				uint64_t ctrl_plane_update = rte_rdtsc() + msec_to_tsc(10);
				while ((ret) && (rte_rdtsc() < ctrl_plane_update))
					ret = handle_ctrl_plane(lcore_cfg[prox_cfg.master].tasks_all[0], NULL, 0);
			}
			multiplexed_input_stats(0);
			if (rte_rdtsc() < next_update)
				continue;
			next_update += update_interval;
			stats_update(stats_cons_flags);
			stats_cons_notify();

			if (stop_tsc && rte_rdtsc() >= stop_tsc) {
				stop_prox = 1;
			}
			if ((prox_cfg.heartbeat_tsc) && (prox_cfg.heartbeat_timeout) && (rte_rdtsc() >= prox_cfg.heartbeat_tsc)) {
				plog_info("Stopping to handle client as heartbeat timed out\n");
				stop_core_all(-1);
				stop_handling_client();
				req_refresh();
				prox_cfg.heartbeat_tsc = 0;
			}
		}
	} else {
		while (stop_prox == 0) {

			if (update_interval < update_interval_threshold)
				busy_wait_until(next_update);
			else
				multiplexed_input_stats(next_update);

			next_update += update_interval;

			stats_update(stats_cons_flags);
			stats_cons_notify();

			if (stop_tsc && rte_rdtsc() >= stop_tsc) {
				stop_prox = 1;
			}
			if ((prox_cfg.heartbeat_tsc) && (prox_cfg.heartbeat_timeout) && (rte_rdtsc() >= prox_cfg.heartbeat_tsc)) {
				plog_info("Stopping to handle client as heartbeat timed out\n");
				stop_core_all(-1);
				stop_handling_client();
				req_refresh();
				prox_cfg.heartbeat_tsc = 0;
			}
		}
	}

	stats_cons_finish();

	if (prox_cfg.flags & DSF_WAIT_ON_QUIT) {
		stop_core_all(-1);
	}

	if (prox_cfg.logbuf) {
		file_print(prox_cfg.logbuf);
	}

	display_end();
	exit(EXIT_SUCCESS);
}