Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/6600/?format=api
https://patches.dpdk.org/api/patches/6600/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1437958594-29468-3-git-send-email-thomas.monjalon@6wind.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1437958594-29468-3-git-send-email-thomas.monjalon@6wind.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1437958594-29468-3-git-send-email-thomas.monjalon@6wind.com", "date": "2015-07-27T00:56:33", "name": "[dpdk-dev,v10,2/3] eal: deduplicate timer functions", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "13baeeb0f54fb5dc1c1ffaa9248b4ac3344130b5", "submitter": { "id": 1, "url": "https://patches.dpdk.org/api/people/1/?format=api", "name": "Thomas Monjalon", "email": "thomas.monjalon@6wind.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1437958594-29468-3-git-send-email-thomas.monjalon@6wind.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/6600/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/6600/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 4EC84C4FE;\n\tMon, 27 Jul 2015 02:57:59 +0200 (CEST)", "from mail-wi0-f175.google.com (mail-wi0-f175.google.com\n\t[209.85.212.175]) by dpdk.org (Postfix) with ESMTP id 3E77BC4FA\n\tfor <dev@dpdk.org>; Mon, 27 Jul 2015 02:57:57 +0200 (CEST)", "by wicmv11 with SMTP id mv11so119776836wic.0\n\tfor <dev@dpdk.org>; Sun, 26 Jul 2015 17:57:57 -0700 (PDT)", "from localhost.localdomain (136-92-190-109.dsl.ovh.fr.\n\t[109.190.92.136]) by smtp.gmail.com with ESMTPSA id\n\tdz4sm10733801wib.17.2015.07.26.17.57.55\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tSun, 26 Jul 2015 17:57:56 -0700 (PDT)" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=8PdQ3sxx1YRbgV2SvjTjgjiLgmaAdHNLN6hsEMpbL+o=;\n\tb=Jy5UuLa2SkKJRCBWhJJUT9Anzn2r3b0dAy9dUJMI2xlVAedoB0dnwXnk3UjB+9vu7P\n\tC7LgGtJqgJXZZcGVbYhjhRQClnOBOkFGKGBINdsUnboj46RJu5dP5xIT+nsqJeOHQy9U\n\t14H4y3gy46K33JNQGx2myA11JB4jUe9tVtZDbQbsBMeEhAhJ/sr2XDor+0VXvrLRyEio\n\tjw01HyQZVWh12tf8TTYDCAdAx3b1EaRxHn8yLcZH9YdgpqPplAp3CplYOgl1LZGhnRRZ\n\tsJjEHxIPIeI31h9ve5cCM0TurVOhz3Nm4rfRDEyzV5qO++q4Op0pnDZxYopcul819sn1\n\tDhmw==", "X-Gm-Message-State": "ALoCoQmrorQFgrCWPdiyd5DEV5vuOHlitRaiV6Z6Ncil4lbF3suB5W078R2f/X4teTRdJs4oM3OH", "X-Received": "by 10.194.184.140 with SMTP id\n\teu12mr48022783wjc.78.1437958677022; \n\tSun, 26 Jul 2015 17:57:57 -0700 (PDT)", "From": "Thomas Monjalon <thomas.monjalon@6wind.com>", "To": "david.marchand@6wind.com", "Date": "Mon, 27 Jul 2015 02:56:33 +0200", "Message-Id": "<1437958594-29468-3-git-send-email-thomas.monjalon@6wind.com>", "X-Mailer": "git-send-email 2.4.2", "In-Reply-To": "<1437958594-29468-1-git-send-email-thomas.monjalon@6wind.com>", "References": "<1437852868-6031-1-git-send-email-rkerur@gmail.com>\n\t<1437958594-29468-1-git-send-email-thomas.monjalon@6wind.com>", "Cc": "dev@dpdk.org", "Subject": "[dpdk-dev] [PATCH v10 2/3] eal: deduplicate timer functions", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "From: Ravi Kerur <rkerur@gmail.com>\n\nMove common functions from BSD/Linux to eal_common_timer.c.\nBSD uses sysctl and Linux uses CLOCK_MONOTIC_RAW to calibrate TSC.\nHPET is specific to Linux and not integrated in the common init.\n\nSigned-off-by: Ravi Kerur <rkerur@gmail.com>\nSigned-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>\n---\n lib/librte_eal/bsdapp/eal/Makefile | 1 +\n lib/librte_eal/bsdapp/eal/eal_timer.c | 58 ++--------------\n .../eal/eal_timer.c => common/eal_common_timer.c} | 79 +++-------------------\n lib/librte_eal/common/eal_private.h | 14 ++++\n lib/librte_eal/linuxapp/eal/Makefile | 1 +\n lib/librte_eal/linuxapp/eal/eal_timer.c | 60 ++--------------\n 6 files changed, 39 insertions(+), 174 deletions(-)\n copy lib/librte_eal/{bsdapp/eal/eal_timer.c => common/eal_common_timer.c} (57%)", "diff": "diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile\nindex 24733ae..a969435 100644\n--- a/lib/librte_eal/bsdapp/eal/Makefile\n+++ b/lib/librte_eal/bsdapp/eal/Makefile\n@@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c\n \n # from common dir\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c\ndiff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/bsdapp/eal/eal_timer.c\nindex 7147abe..f12d9bd 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_timer.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_timer.c\n@@ -55,29 +55,12 @@\n \n enum timer_source eal_timer_source = EAL_TIMER_TSC;\n \n-/* The frequency of the RDTSC timer resolution */\n-static uint64_t eal_tsc_resolution_hz = 0;\n-\n-void\n-rte_delay_us(unsigned us)\n-{\n-\tconst uint64_t start = rte_get_timer_cycles();\n-\tconst uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;\n-\twhile ((rte_get_timer_cycles() - start) < ticks)\n-\t\trte_pause();\n-}\n-\n uint64_t\n-rte_get_tsc_hz(void)\n-{\n-\treturn eal_tsc_resolution_hz;\n-}\n-\n-static int\n-set_tsc_freq_from_sysctl(void)\n+get_tsc_freq(void)\n {\n \tsize_t sz;\n \tint tmp;\n+\tuint64_t tsc_hz;\n \n \tsz = sizeof(tmp);\n \ttmp = 0;\n@@ -94,42 +77,13 @@ set_tsc_freq_from_sysctl(void)\n \telse if (tmp != 1)\n \t\tRTE_LOG(WARNING, EAL, \"TSC is not invariant\\n\");\n \n-\tsz = sizeof(eal_tsc_resolution_hz);\n-\tif (sysctlbyname(\"machdep.tsc_freq\", &eal_tsc_resolution_hz, &sz, NULL, 0)) {\n+\tsz = sizeof(tsc_hz);\n+\tif (sysctlbyname(\"machdep.tsc_freq\", &tsc_hz, &sz, NULL, 0)) {\n \t\tRTE_LOG(WARNING, EAL, \"%s\\n\", strerror(errno));\n-\t\treturn -1;\n+\t\treturn 0;\n \t}\n \n-\treturn 0;\n-}\n-\n-static void\n-set_tsc_freq_fallback(void)\n-{\n-\tRTE_LOG(WARNING, EAL, \"WARNING: clock_gettime cannot use \"\n-\t\t\t\"CLOCK_MONOTONIC_RAW and HPET is not available\"\n-\t\t\t\" - clock timings may be less accurate.\\n\");\n-\t/* assume that the sleep(1) will sleep for 1 second */\n-\tuint64_t start = rte_rdtsc();\n-\tsleep(1);\n-\teal_tsc_resolution_hz = rte_rdtsc() - start;\n-}\n-\n-/*\n- * This function measures the TSC frequency. It uses a variety of approaches.\n- *\n- * 1. Read the TSC frequency value provided by the kernel\n- * 2. If above does not work, just sleep for 1 second and tune off that,\n- * printing a warning about inaccuracy of timing\n- */\n-static void\n-set_tsc_freq(void)\n-{\n-\tif (set_tsc_freq_from_sysctl() < 0)\n-\t\tset_tsc_freq_fallback();\n-\n-\tRTE_LOG(INFO, EAL, \"TSC frequency is ~%\"PRIu64\" KHz\\n\",\n-\t\t\teal_tsc_resolution_hz/1000);\n+\treturn tsc_hz;\n }\n \n int\ndiff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/common/eal_common_timer.c\nsimilarity index 57%\ncopy from lib/librte_eal/bsdapp/eal/eal_timer.c\ncopy to lib/librte_eal/common/eal_common_timer.c\nindex 7147abe..2956703 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_timer.c\n+++ b/lib/librte_eal/common/eal_common_timer.c\n@@ -30,6 +30,7 @@\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n+\n #include <string.h>\n #include <stdio.h>\n #include <unistd.h>\n@@ -41,22 +42,11 @@\n #include <rte_common.h>\n #include <rte_log.h>\n #include <rte_cycles.h>\n-#include <rte_memory.h>\n-#include <rte_memzone.h>\n-#include <rte_eal.h>\n-#include <rte_debug.h>\n \n #include \"eal_private.h\"\n-#include \"eal_internal_cfg.h\"\n-\n-#ifdef RTE_LIBEAL_USE_HPET\n-#warning HPET is not supported in FreeBSD\n-#endif\n-\n-enum timer_source eal_timer_source = EAL_TIMER_TSC;\n \n /* The frequency of the RDTSC timer resolution */\n-static uint64_t eal_tsc_resolution_hz = 0;\n+static uint64_t eal_tsc_resolution_hz;\n \n void\n rte_delay_us(unsigned us)\n@@ -73,68 +63,21 @@ rte_get_tsc_hz(void)\n \treturn eal_tsc_resolution_hz;\n }\n \n-static int\n-set_tsc_freq_from_sysctl(void)\n+static uint64_t\n+estimate_tsc_freq(void)\n {\n-\tsize_t sz;\n-\tint tmp;\n-\n-\tsz = sizeof(tmp);\n-\ttmp = 0;\n-\n-\tif (sysctlbyname(\"kern.timecounter.smp_tsc\", &tmp, &sz, NULL, 0))\n-\t\tRTE_LOG(WARNING, EAL, \"%s\\n\", strerror(errno));\n-\telse if (tmp != 1)\n-\t\tRTE_LOG(WARNING, EAL, \"TSC is not safe to use in SMP mode\\n\");\n-\n-\ttmp = 0;\n-\n-\tif (sysctlbyname(\"kern.timecounter.invariant_tsc\", &tmp, &sz, NULL, 0))\n-\t\tRTE_LOG(WARNING, EAL, \"%s\\n\", strerror(errno));\n-\telse if (tmp != 1)\n-\t\tRTE_LOG(WARNING, EAL, \"TSC is not invariant\\n\");\n-\n-\tsz = sizeof(eal_tsc_resolution_hz);\n-\tif (sysctlbyname(\"machdep.tsc_freq\", &eal_tsc_resolution_hz, &sz, NULL, 0)) {\n-\t\tRTE_LOG(WARNING, EAL, \"%s\\n\", strerror(errno));\n-\t\treturn -1;\n-\t}\n-\n-\treturn 0;\n-}\n-\n-static void\n-set_tsc_freq_fallback(void)\n-{\n-\tRTE_LOG(WARNING, EAL, \"WARNING: clock_gettime cannot use \"\n-\t\t\t\"CLOCK_MONOTONIC_RAW and HPET is not available\"\n-\t\t\t\" - clock timings may be less accurate.\\n\");\n+\tRTE_LOG(WARNING, EAL, \"WARNING: TSC frequency estimated roughly\"\n+\t\t\" - clock timings may be less accurate.\\n\");\n \t/* assume that the sleep(1) will sleep for 1 second */\n \tuint64_t start = rte_rdtsc();\n \tsleep(1);\n-\teal_tsc_resolution_hz = rte_rdtsc() - start;\n+\treturn rte_rdtsc() - start;\n }\n \n-/*\n- * This function measures the TSC frequency. It uses a variety of approaches.\n- *\n- * 1. Read the TSC frequency value provided by the kernel\n- * 2. If above does not work, just sleep for 1 second and tune off that,\n- * printing a warning about inaccuracy of timing\n- */\n-static void\n+void\n set_tsc_freq(void)\n {\n-\tif (set_tsc_freq_from_sysctl() < 0)\n-\t\tset_tsc_freq_fallback();\n-\n-\tRTE_LOG(INFO, EAL, \"TSC frequency is ~%\"PRIu64\" KHz\\n\",\n-\t\t\teal_tsc_resolution_hz/1000);\n-}\n-\n-int\n-rte_eal_timer_init(void)\n-{\n-\tset_tsc_freq();\n-\treturn 0;\n+\tuint64_t freq = get_tsc_freq() || estimate_tsc_freq();\n+\tRTE_LOG(INFO, EAL, \"TSC frequency is ~%\" PRIu64 \" KHz\\n\", freq / 1000);\n+\teal_tsc_resolution_hz = freq;\n }\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex 8505b05..f8e8869 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -314,4 +314,18 @@ unsigned eal_cpu_core_id(unsigned lcore_id);\n */\n int eal_cpu_detected(unsigned lcore_id);\n \n+/**\n+ * Set TSC frequency from precise value or estimation\n+ *\n+ * This function is private to the EAL.\n+ */\n+void set_tsc_freq(void);\n+\n+/**\n+ * Get precise TSC frequency from system\n+ *\n+ * This function is private to the EAL.\n+ */\n+uint64_t get_tsc_freq(void);\n+\n #endif /* _EAL_PRIVATE_H_ */\ndiff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile\nindex f4f8cdf..376d275 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -71,6 +71,7 @@ endif\n \n # from common dir\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c\nindex 94909ed..76a8a65 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_timer.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_timer.c\n@@ -57,9 +57,6 @@\n \n enum timer_source eal_timer_source = EAL_TIMER_HPET;\n \n-/* The frequency of the RDTSC timer resolution */\n-static uint64_t eal_tsc_resolution_hz = 0;\n-\n #ifdef RTE_LIBEAL_USE_HPET\n \n #define DEV_HPET \"/dev/hpet\"\n@@ -160,23 +157,6 @@ rte_get_hpet_cycles(void)\n \n #endif\n \n-\n-void\n-rte_delay_us(unsigned us)\n-{\n-\tconst uint64_t start = rte_get_timer_cycles();\n-\tconst uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;\n-\twhile ((rte_get_timer_cycles() - start) < ticks)\n-\t\trte_pause();\n-}\n-\n-uint64_t\n-rte_get_tsc_hz(void)\n-{\n-\treturn eal_tsc_resolution_hz;\n-}\n-\n-\n #ifdef RTE_LIBEAL_USE_HPET\n /*\n * Open and mmap /dev/hpet (high precision event timer) that will\n@@ -275,8 +255,8 @@ check_tsc_flags(void)\n \tfclose(stream);\n }\n \n-static int\n-set_tsc_freq_from_clock(void)\n+uint64_t\n+get_tsc_freq(void)\n {\n #ifdef CLOCK_MONOTONIC_RAW\n #define NS_PER_SEC 1E9\n@@ -284,6 +264,7 @@ set_tsc_freq_from_clock(void)\n \tstruct timespec sleeptime = {.tv_nsec = 5E8 }; /* 1/2 second */\n \n \tstruct timespec t_start, t_end;\n+\tuint64_t tsc_hz;\n \n \tif (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) {\n \t\tuint64_t ns, end, start = rte_rdtsc();\n@@ -294,40 +275,11 @@ set_tsc_freq_from_clock(void)\n \t\tns += (t_end.tv_nsec - t_start.tv_nsec);\n \n \t\tdouble secs = (double)ns/NS_PER_SEC;\n-\t\teal_tsc_resolution_hz = (uint64_t)((end - start)/secs);\n-\t\treturn 0;\n+\t\ttsc_hz = (uint64_t)((end - start)/secs);\n+\t\treturn tsc_hz;\n \t}\n #endif\n-\treturn -1;\n-}\n-\n-static void\n-set_tsc_freq_fallback(void)\n-{\n-\tRTE_LOG(WARNING, EAL, \"WARNING: clock_gettime cannot use \"\n-\t\t\t\"CLOCK_MONOTONIC_RAW and HPET is not available\"\n-\t\t\t\" - clock timings may be less accurate.\\n\");\n-\t/* assume that the sleep(1) will sleep for 1 second */\n-\tuint64_t start = rte_rdtsc();\n-\tsleep(1);\n-\teal_tsc_resolution_hz = rte_rdtsc() - start;\n-}\n-/*\n- * This function measures the TSC frequency. It uses a variety of approaches.\n- *\n- * 1. If kernel provides CLOCK_MONOTONIC_RAW we use that to tune the TSC value\n- * 2. If kernel does not provide that, and we have HPET support, tune using HPET\n- * 3. Lastly, if neither of the above can be used, just sleep for 1 second and\n- * tune off that, printing a warning about inaccuracy of timing\n- */\n-static void\n-set_tsc_freq(void)\n-{\n-\tif (set_tsc_freq_from_clock() < 0)\n-\t\tset_tsc_freq_fallback();\n-\n-\tRTE_LOG(INFO, EAL, \"TSC frequency is ~%\"PRIu64\" KHz\\n\",\n-\t\t\teal_tsc_resolution_hz/1000);\n+\treturn 0;\n }\n \n int\n", "prefixes": [ "dpdk-dev", "v10", "2/3" ] }{ "id": 6600, "url": "