aboutsummaryrefslogtreecommitdiffstats
path: root/csit.infra.vagrant/Vagrantfile
blob: f951425e86323cbcabcd851a693cd86c5891f767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { c
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

    # Configure cached packages to be shared between instances of the
    # same base box.
    if Vagrant.has_plugin?("vagrant-cachier")
        config.cache.scope = :box
    end

    # Configure proxy if needed.
    if Vagrant.has_plugin?("vagrant-proxyconf")
        config.proxy.http     = "http://192.168.0.2:3128/"
        config.proxy.https    = "http://192.168.0.2:3128/"
        config.proxy.ftp      = "http://192.168.0.2:3128/"
        config.proxy.no_proxy = "localhost,127.0.0.1"
    end

    # Configure testing network interfaces (tg).
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link1", nic_type: "82545em", mac: "0800270fe04d"
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link2", nic_type: "82545em", mac: "08002761f7ad"
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link3", nic_type: "82545em", mac: "080027dc5da4"

    # Configure testing network interfaces (sut).
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link1", nic_type: "82545em", mac: "080027385e58"
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link2", nic_type: "82545em", mac: "080027e3f542"
    config.vm.network :private_network, type: "dhcp", auto_config: false, virtualbox__intnet: "link3", nic_type: "82545em", mac: "0800274f7c63"

    config.vm.synced_folder "../", "/vagrant/csit"

    # Provision the box using ansible local (no Ansible installation needed
    # on host).
    config.vm.provision "ansible_local" do |ansible|
        ansible.version = "latest"
        ansible.become = true
        ansible.verbose = false
        ansible.limit = "vagrant"
        ansible.inventory_path = "csit/fdio.infra.ansible/inventories/vagrant_inventory/hosts"
        ansible.playbook = "csit/fdio.infra.ansible/site.yaml"
    end

    config.vm.post_up_message = <<-MESSAGE
    Your virtual machine is configured!

    Login to the box using command:
        vagrant ssh

    To run some tests use the VPP Device bootstrap script, eg:
        cd /home/vagrant/csit/resources/libraries/bash/entry
        ./bootstrap_vpp_device.sh csit-vpp-device-master-ubuntu2004-1n-vbox

    To run only selected tests based on TAGS, export environment variables
    before running the test suite:
        export GERRIT_EVENT_TYPE="comment-added"
        export GERRIT_EVENT_COMMENT_TEXT="devicetest memif"
        ./bootstrap_vpp_device.sh csit-vpp-device-master-ubuntu2004-1n-vbox

    For more information please visit:
        https://docs.fd.io/csit/master/report/
        https://docs.fd.io/csit/master/trending/

    MESSAGE

    config.vm.define "focal", primary: true do |focal|
        # Base box definition, currently using
        #  Official Ubuntu 20.04 LTS (Focal) Daily Build
        focal.vm.box = "ubuntu/focal64"
        focal.vm.box_version = "20210415.0.0"
        focal.vm.box_check_update = false

        # Virtualbox machine configuration
        focal.vm.provider "virtualbox" do |vb|
            vb.name = "vppdevice-focal"
            vb.gui = false
            vb.memory = "8192"
            vb.cpus = "4"
            vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
            vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"]
            vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"]
            vb.customize ["modifyvm", :id, "--nicpromisc5", "allow-all"]
            vb.customize ["modifyvm", :id, "--nicpromisc6", "allow-all"]
            vb.customize ["modifyvm", :id, "--nicpromisc7", "allow-all"]
        end
    end
end
read_shared_counter (void *arg) { f64 *time = vec_new (f64, 1); *time = 0; rwlock_test_main_t *rtm = arg; uword cnt_cpy = 0, exp = rtm->increment_per_thread * rtm->write_cores * rtm->threads_per_core; /* Wait for all threads to be created */ while (!clib_atomic_load_acq_n (&all_threads_online)); f64 start = clib_cpu_time_now (); while (cnt_cpy < exp) { clib_rwlock_reader_lock (&rtm->rwlock); cnt_cpy = rtm->shared_count; clib_rwlock_reader_unlock (&rtm->rwlock); } *time = clib_cpu_time_now () - start; return time; } unsigned test_rwlock (rwlock_test_main_t * rtm, f64 * elapse_time) { int error = 0, total_threads = (rtm->read_cores + rtm->write_cores) * rtm->threads_per_core; pthread_t pthread[total_threads]; cpu_set_t cpuset; unsigned cores_set = 0, cpu_id = 0; /* Spawn reader (consumer) threads */ for (unsigned cpu_mask = rtm->cpu_mask_read; cpu_mask; cpu_mask >>= 1) { if (!(cpu_mask & 1)) { cpu_id++; continue; } CPU_ZERO (&cpuset); CPU_SET (cpu_id, &cpuset); for (uword t_num = 0; t_num < rtm->threads_per_core; t_num++) { uword t_index = cores_set * rtm->threads_per_core + t_num; if ((error = pthread_create (&pthread[t_index], NULL, &read_shared_counter, rtm))) clib_unix_warning ("pthread_create failed with %d", error); if ((error = pthread_setaffinity_np (pthread[t_index], sizeof (cpu_set_t), &cpuset))) clib_unix_warning ("pthread_set_affinity_np failed with %d", error); } cores_set++; cpu_id++; } /* Spawn writer (producer) threads */ cpu_id = 0; for (unsigned cpu_mask = rtm->cpu_mask_write; cpu_mask; cpu_mask >>= 1) { if (!(cpu_mask & 1)) { cpu_id++; continue; } CPU_ZERO (&cpuset); CPU_SET (cpu_id, &cpuset); for (uword t_num = 0; t_num < rtm->threads_per_core; t_num++) { uword t_index = cores_set * rtm->threads_per_core + t_num; if ((error = pthread_create (&pthread[t_index], NULL, &write_shared_counter, rtm))) clib_unix_warning ("pthread_create failed with %d", error); if ((error = pthread_setaffinity_np (pthread[t_index], sizeof (cpu_set_t), &cpuset))) clib_unix_warning ("pthread_set_affinity_np failed with %d", error); } cores_set++; cpu_id++; } /* Launch all threads */ clib_atomic_store_rel_n (&all_threads_online, 1); for (uword thread_num = 0; thread_num < total_threads; thread_num++) { f64 *time; if ((error = pthread_join (pthread[thread_num], (void *) &time))) clib_unix_warning ("pthread_join failed with %d", error); *elapse_time += *time; vec_free (time); } fformat (stdout, "Time elapsed: %.4e\n", *elapse_time); return rtm->shared_count; } uword num_cores_in_cpu_mask (uword mask) { uword num_cores = 0; for (uword cpu_mask = mask; cpu_mask; cpu_mask >>= 1) num_cores += (cpu_mask & 1); return num_cores; } int test_rwlock_main (unformat_input_t * i) { rwlock_test_main_t _rtm, *rtm = &_rtm; clib_memset (rtm, 0, sizeof (rwlock_test_main_t)); while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (0 == unformat (i, "threads/core %d", &rtm->threads_per_core) && 0 == unformat (i, "cpu_mask_read %x", &rtm->cpu_mask_read) && 0 == unformat (i, "cpu_mask_write %x", &rtm->cpu_mask_write) && 0 == unformat (i, "increment %d", &rtm->increment_per_thread) && 0 == unformat (i, "iterations %d", &rtm->iterations)) { clib_unix_warning ("unknown input '%U'", format_unformat_error, i); return 1; } } rtm->read_cores = num_cores_in_cpu_mask (rtm->cpu_mask_read); rtm->write_cores = num_cores_in_cpu_mask (rtm->cpu_mask_write); uword total_increment = rtm->threads_per_core * rtm->write_cores * rtm->increment_per_thread; clib_rwlock_init (&rtm->rwlock); f64 average_time = 0; for (uword trial = 0; trial < rtm->iterations; trial++) { rtm->shared_count = 0; f64 elapse_time = 0; if (test_rwlock (rtm, &elapse_time) != total_increment) { clib_rwlock_free (&rtm->rwlock); fformat (stdout, "FAILED: expected count: %d, actual count: %d\n", total_increment, rtm->shared_count); return 1; } fformat (stdout, "Trial %d SUCCESS: %d = %d\n", trial, rtm->shared_count, total_increment); average_time = (average_time * trial + elapse_time) / (trial + 1); fformat (stdout, "Average lock/unlock cycles: %.4e\n", average_time); } clib_rwlock_free (&rtm->rwlock); return 0; } #ifdef CLIB_UNIX /** Launches a number of writer threads to simultaneously increment a global counter and a number of reader threads to continuously poll the counter, and records timestamps for rwlock performance benchmarking @param "threads/core [# threads/core]" - number of threads per core @param "cpu_mask_read [cpu_mask]" - reader thread cpu string e.g. input ff sets cpus 0 - 7 @param "cpu_mask_write [cpu_mask]" - writer thread cpu string @param "increment [# increments]" - number of increments per writer thread @param "iterations [# iterations]" - number of iterations @returns exit code */ int main (int argc, char *argv[]) { unformat_input_t i; i32 ret; clib_time_t time; clib_mem_init (0, 3ULL << 30); clib_time_init (&time); unformat_init_command_line (&i, argv); ret = test_rwlock_main (&i); unformat_free (&i); return ret; } #endif /* CLIB_UNIX */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */