From: Damien Millescamps Date: Fri, 21 Sep 2012 11:36:40 +0000 (+0000) Subject: timer: option --vmware-tsc-map for VMware guest X-Git-Tag: spdx-start~11249 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6286101324294f7922f0268007252d1f008c49e4;p=dpdk.git timer: option --vmware-tsc-map for VMware guest The VMWare TSC mapping uses a hook to RDPMC to read the physical TSC in the case of VMware ESXi. Signed-off-by: Damien Millescamps Acked-by: Jean-Mickael Guerin Acked-by: Olivier Matz Acked-by: Thomas Monjalon Introduce new option --vmware-tsc-map, ignored if CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set. Default is CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y. if CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is set: rte_rdtsc() selects at runtime between Vmware mapping of TSC or native TSC else rte_rdtsc() always uses native rdtsc. When running DPDK on VMware guest, enable --vmware-tsc-map to read the physical TSC. Caution: ESXi should pass monitor_control.pseudo_perfctr = TRUE othewise it results in general protection fault. Signed-off-by: Jean-Mickael Guerin Acked-by: Vincent Jardin Acked-by: Olivier Matz --- diff --git a/config/defconfig_i686-default-linuxapp-gcc b/config/defconfig_i686-default-linuxapp-gcc index a63d37a1d0..dba52897ed 100644 --- a/config/defconfig_i686-default-linuxapp-gcc +++ b/config/defconfig_i686-default-linuxapp-gcc @@ -125,6 +125,11 @@ CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y # CONFIG_RTE_LIBRTE_EAL_BAREMETAL=n +# +# Compile Environment Abstraction Layer to support Vmware TSC map +# +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y + # # Compile generic ethernet library # diff --git a/config/defconfig_i686-default-linuxapp-icc b/config/defconfig_i686-default-linuxapp-icc index cf86ba5b08..81901fd7e9 100644 --- a/config/defconfig_i686-default-linuxapp-icc +++ b/config/defconfig_i686-default-linuxapp-icc @@ -126,6 +126,11 @@ CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y # CONFIG_RTE_LIBRTE_EAL_BAREMETAL=n +# +# Compile Environment Abstraction Layer to support Vmware TSC map +# +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y + # # Compile generic ethernet library # diff --git a/config/defconfig_x86_64-default-linuxapp-gcc b/config/defconfig_x86_64-default-linuxapp-gcc index b5d3362afc..eeecfd39e1 100644 --- a/config/defconfig_x86_64-default-linuxapp-gcc +++ b/config/defconfig_x86_64-default-linuxapp-gcc @@ -126,6 +126,11 @@ CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y # CONFIG_RTE_LIBRTE_EAL_BAREMETAL=n +# +# Compile Environment Abstraction Layer to support Vmware TSC map +# +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y + # # Compile generic ethernet library # diff --git a/config/defconfig_x86_64-default-linuxapp-icc b/config/defconfig_x86_64-default-linuxapp-icc index 60f10afd16..e96c80f318 100644 --- a/config/defconfig_x86_64-default-linuxapp-icc +++ b/config/defconfig_x86_64-default-linuxapp-icc @@ -126,6 +126,11 @@ CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y # CONFIG_RTE_LIBRTE_EAL_BAREMETAL=n +# +# Compile Environment Abstraction Layer to support Vmware TSC map +# +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y + # # Compile generic ethernet library # diff --git a/lib/librte_eal/common/include/rte_cycles.h b/lib/librte_eal/common/include/rte_cycles.h index ed6b2e684c..14a7c1baca 100644 --- a/lib/librte_eal/common/include/rte_cycles.h +++ b/lib/librte_eal/common/include/rte_cycles.h @@ -31,6 +31,36 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +/* BSD LICENSE + * + * Copyright(c) 2013 6WIND. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of 6WIND S.A. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _RTE_CYCLES_H_ #define _RTE_CYCLES_H_ @@ -47,6 +77,13 @@ extern "C" { #include +#ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT +/** Global switch to use VMWARE mapping of TSC instead of RDTSC */ +extern int rte_cycles_vmware_tsc_map; +#include +#endif + + /** * Read the TSC register. * @@ -64,6 +101,17 @@ rte_rdtsc(void) }; } tsc; +#ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT + if (unlikely(rte_cycles_vmware_tsc_map)) { + /* ecx = 0x10000 corresponds to the physical TSC for VMware */ + asm volatile("rdpmc" : + "=a" (tsc.lo_32), + "=d" (tsc.hi_32) : + "c"(0x10000)); + return tsc.tsc_64; + } +#endif + asm volatile("rdtsc" : "=a" (tsc.lo_32), "=d" (tsc.hi_32)); diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index a51f86fd66..43150b14c9 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -81,6 +81,7 @@ #define OPT_PROC_TYPE "proc-type" #define OPT_NO_SHCONF "no-shconf" #define OPT_NO_HPET "no-hpet" +#define OPT_VMWARE_TSC_MAP "vmware-tsc-map" #define OPT_NO_PCI "no-pci" #define OPT_NO_HUGE "no-huge" #define OPT_FILE_PREFIX "file-prefix" @@ -134,6 +135,9 @@ struct lcore_config lcore_config[RTE_MAX_LCORE]; /* internal configuration */ struct internal_config internal_config; +/* used by rte_rdtsc() */ +int rte_cycles_vmware_tsc_map; + /* Return a pointer to the configuration structure */ struct rte_config * rte_eal_get_configuration(void) @@ -328,6 +332,8 @@ eal_usage(const char *prgname) " --"OPT_HUGE_DIR" : directory where hugetlbfs is mounted\n" " --"OPT_PROC_TYPE" : type of this process\n" " --"OPT_FILE_PREFIX": prefix for hugepage filenames\n" + " --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of " + "native RDTSC\n" "\nEAL options for DEBUG use only:\n" " --"OPT_NO_HUGE" : use malloc instead of hugetlbfs\n" " --"OPT_NO_PCI" : disable pci\n" @@ -553,6 +559,7 @@ eal_parse_args(int argc, char **argv) {OPT_NO_HUGE, 0, 0, 0}, {OPT_NO_PCI, 0, 0, 0}, {OPT_NO_HPET, 0, 0, 0}, + {OPT_VMWARE_TSC_MAP, 0, 0, 0}, {OPT_HUGE_DIR, 1, 0, 0}, {OPT_NO_SHCONF, 0, 0, 0}, {OPT_PROC_TYPE, 1, 0, 0}, @@ -584,6 +591,8 @@ eal_parse_args(int argc, char **argv) for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) internal_config.hugepage_info[i].lock_descriptor = 0; + internal_config.vmware_tsc_map = 0; + while ((opt = getopt_long(argc, argvopt, "b:c:m:n:r:v", lgopts, &option_index)) != EOF) { @@ -649,6 +658,9 @@ eal_parse_args(int argc, char **argv) else if (!strcmp(lgopts[option_index].name, OPT_NO_HPET)) { internal_config.no_hpet = 1; } + else if (!strcmp(lgopts[option_index].name, OPT_VMWARE_TSC_MAP)) { + internal_config.vmware_tsc_map = 1; + } else if (!strcmp(lgopts[option_index].name, OPT_NO_SHCONF)) { internal_config.no_shconf = 1; } @@ -807,6 +819,17 @@ rte_eal_init(int argc, char **argv) internal_config.memory = eal_get_hugepage_mem_size(); } + if (internal_config.vmware_tsc_map == 1) { +#ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT + rte_cycles_vmware_tsc_map = 1; + RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, " + "you must have monitor_control.pseudo_perfctr = TRUE\n"); +#else + RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because " + "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n"); +#endif + } + rte_srand(rte_rdtsc()); rte_config_init(); diff --git a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h index 0e5fc06077..3fc6a36c70 100644 --- a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h +++ b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h @@ -66,6 +66,8 @@ struct internal_config { volatile unsigned no_hugetlbfs; /**< true to disable hugetlbfs */ volatile unsigned no_pci; /**< true to disable PCI */ volatile unsigned no_hpet; /**< true to disable HPET */ + volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping + * instead of native TSC */ volatile unsigned no_shconf; /**< true if there is no shared config */ volatile enum rte_proc_type_t process_type; /* multi-process proc type */ /* true to try allocating memory on specific sockets */