* [PATCH] hash_readwrite_autotest: fix printf parameters @ 2025-03-06 20:03 Andre Muezerie 2025-03-07 9:01 ` Bruce Richardson 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie 0 siblings, 2 replies; 13+ messages in thread From: Andre Muezerie @ 2025-03-06 20:03 UTC (permalink / raw) To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin Cc: dev, Andre Muezerie Compiling with MSVC logs the warnings below, which result in build error: ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : unknown type field character ''' in format specifier ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : too many arguments passed for format string ../app/test/test_hash_readwrite.c(75): note: placeholders and their parameters expect 2 variadic arguments, but 4 were provided Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> --- app/test/test_hash_readwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/test_hash_readwrite.c b/app/test/test_hash_readwrite.c index 1867376ade..dc07df709a 100644 --- a/app/test/test_hash_readwrite.c +++ b/app/test/test_hash_readwrite.c @@ -70,7 +70,7 @@ test_hash_readwrite_worker(__rte_unused void *arg) } offset = tbl_rw_test_param.num_insert * i; - printf("Core #%d inserting and reading %d: %'"PRId64" - %'"PRId64"\n", + printf("Core #%d inserting and reading %d: %" PRId64 " - %" PRId64 "\n", lcore_id, tbl_rw_test_param.num_insert, offset, offset + tbl_rw_test_param.num_insert - 1); -- 2.48.1.vfs.0.0 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-06 20:03 [PATCH] hash_readwrite_autotest: fix printf parameters Andre Muezerie @ 2025-03-07 9:01 ` Bruce Richardson 2025-03-07 22:34 ` Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie 1 sibling, 1 reply; 13+ messages in thread From: Bruce Richardson @ 2025-03-07 9:01 UTC (permalink / raw) To: Andre Muezerie; +Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > Compiling with MSVC logs the warnings below, which result in > build error: > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : > unknown type field character ''' in format specifier > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : > too many arguments passed for format string > ../app/test/test_hash_readwrite.c(75): note: placeholders and > their parameters expect 2 variadic arguments, but 4 were provided > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > --- > app/test/test_hash_readwrite.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > IF the "'" character is not supported, is there some other method to do thousands grouping in MSVC? /Bruce ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-07 9:01 ` Bruce Richardson @ 2025-03-07 22:34 ` Andre Muezerie 2025-03-10 10:51 ` Bruce Richardson 0 siblings, 1 reply; 13+ messages in thread From: Andre Muezerie @ 2025-03-07 22:34 UTC (permalink / raw) To: Bruce Richardson; +Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote: > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > > Compiling with MSVC logs the warnings below, which result in > > build error: > > > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : > > unknown type field character ''' in format specifier > > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : > > too many arguments passed for format string > > ../app/test/test_hash_readwrite.c(75): note: placeholders and > > their parameters expect 2 variadic arguments, but 4 were provided > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > --- > > app/test/test_hash_readwrite.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > IF the "'" character is not supported, is there some other method to do > thousands grouping in MSVC? > > /Bruce The problem exists with all compilers I tried on Windows: 1) MSVC logs the error I mentioned above 2) GCC and Clang don't complain at compile time, but don't honor the "'" as a special character. As an example, printf("%'d\n", 1024); results in 'd It seems that for this syntax to work as you would expect, support needs to exist in both the compiler and the libraries used. Back to your question: there's no equivalent syntax on Windows that provides the thousands grouping. If really needed (and I understand it is useful for large numbers), we could get the same result by calling a helper function that would convert the number in the formatted string and use that in the printf statement. There is a Win32 API that does that. It takes a string as input though: GetNumberFormatA. (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getnumberformata) We could use ifdefs to keep the old logic on Linux and use new logic on Windows (for all compilers). Let me know if this is something that would need to be done, or if the current output without thousands grouping is good enough. -- Andre Muezerie ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-07 22:34 ` Andre Muezerie @ 2025-03-10 10:51 ` Bruce Richardson 2025-03-10 15:36 ` Stephen Hemminger 0 siblings, 1 reply; 13+ messages in thread From: Bruce Richardson @ 2025-03-10 10:51 UTC (permalink / raw) To: Andre Muezerie; +Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev On Fri, Mar 07, 2025 at 02:34:01PM -0800, Andre Muezerie wrote: > On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote: > > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > > > Compiling with MSVC logs the warnings below, which result in > > > build error: > > > > > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : > > > unknown type field character ''' in format specifier > > > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : > > > too many arguments passed for format string > > > ../app/test/test_hash_readwrite.c(75): note: placeholders and > > > their parameters expect 2 variadic arguments, but 4 were provided > > > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > > --- > > > app/test/test_hash_readwrite.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > IF the "'" character is not supported, is there some other method to do > > thousands grouping in MSVC? > > > > /Bruce > > The problem exists with all compilers I tried on Windows: > > 1) MSVC logs the error I mentioned above > > 2) GCC and Clang don't complain at compile time, but don't honor the "'" as a special > character. As an example, > printf("%'d\n", 1024); > results in > 'd > > It seems that for this syntax to work as you would expect, support needs to exist in both the > compiler and the libraries used. > > Back to your question: there's no equivalent syntax on Windows that provides the thousands grouping. > If really needed (and I understand it is useful for large numbers), we could get the same result > by calling a helper function that would convert the number in the formatted string and use that > in the printf statement. > > There is a Win32 API that does that. It takes a string as input though: GetNumberFormatA. > (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getnumberformata) > > We could use ifdefs to keep the old logic on Linux and use new logic on Windows (for all compilers). > > Let me know if this is something that would need to be done, or if the current output > without thousands grouping is good enough. > -- The thousands grouping is incredibly helpful when working with large numbers, but given the lack of support for this on Windows, we'll just have to go without, I think. /Bruce ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-10 10:51 ` Bruce Richardson @ 2025-03-10 15:36 ` Stephen Hemminger 2025-03-11 14:39 ` Andre Muezerie 0 siblings, 1 reply; 13+ messages in thread From: Stephen Hemminger @ 2025-03-10 15:36 UTC (permalink / raw) To: Bruce Richardson Cc: Andre Muezerie, Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev On Mon, 10 Mar 2025 10:51:51 +0000 Bruce Richardson <bruce.richardson@intel.com> wrote: > On Fri, Mar 07, 2025 at 02:34:01PM -0800, Andre Muezerie wrote: > > On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote: > > > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > > > > Compiling with MSVC logs the warnings below, which result in > > > > build error: > > > > > > > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : > > > > unknown type field character ''' in format specifier > > > > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : > > > > too many arguments passed for format string > > > > ../app/test/test_hash_readwrite.c(75): note: placeholders and > > > > their parameters expect 2 variadic arguments, but 4 were provided > > > > > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > > > --- > > > > app/test/test_hash_readwrite.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > IF the "'" character is not supported, is there some other method to do > > > thousands grouping in MSVC? > > > > > > /Bruce > > > > The problem exists with all compilers I tried on Windows: > > > > 1) MSVC logs the error I mentioned above > > > > 2) GCC and Clang don't complain at compile time, but don't honor the "'" as a special > > character. As an example, > > printf("%'d\n", 1024); > > results in > > 'd > > > > It seems that for this syntax to work as you would expect, support needs to exist in both the > > compiler and the libraries used. > > > > Back to your question: there's no equivalent syntax on Windows that provides the thousands grouping. > > If really needed (and I understand it is useful for large numbers), we could get the same result > > by calling a helper function that would convert the number in the formatted string and use that > > in the printf statement. > > > > There is a Win32 API that does that. It takes a string as input though: GetNumberFormatA. > > (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getnumberformata) > > > > We could use ifdefs to keep the old logic on Linux and use new logic on Windows (for all compilers). > > > > Let me know if this is something that would need to be done, or if the current output > > without thousands grouping is good enough. > > -- > The thousands grouping is incredibly helpful when working with large > numbers, but given the lack of support for this on Windows, we'll just have > to go without, I think. > > /Bruce Maybe some variation of the pretty printing code that iproute2 has (see print_num) would be useful. Feel free to reuse it. I wrote the initial version. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-10 15:36 ` Stephen Hemminger @ 2025-03-11 14:39 ` Andre Muezerie 2025-03-11 15:01 ` Morten Brørup 0 siblings, 1 reply; 13+ messages in thread From: Andre Muezerie @ 2025-03-11 14:39 UTC (permalink / raw) To: Stephen Hemminger Cc: Bruce Richardson, Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev On Mon, Mar 10, 2025 at 08:36:40AM -0700, Stephen Hemminger wrote: > On Mon, 10 Mar 2025 10:51:51 +0000 > Bruce Richardson <bruce.richardson@intel.com> wrote: > > > On Fri, Mar 07, 2025 at 02:34:01PM -0800, Andre Muezerie wrote: > > > On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote: > > > > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > > > > > Compiling with MSVC logs the warnings below, which result in > > > > > build error: > > > > > > > > > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : > > > > > unknown type field character ''' in format specifier > > > > > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : > > > > > too many arguments passed for format string > > > > > ../app/test/test_hash_readwrite.c(75): note: placeholders and > > > > > their parameters expect 2 variadic arguments, but 4 were provided > > > > > > > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > > > > --- > > > > > app/test/test_hash_readwrite.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > IF the "'" character is not supported, is there some other method to do > > > > thousands grouping in MSVC? > > > > > > > > /Bruce > > > > > > The problem exists with all compilers I tried on Windows: > > > > > > 1) MSVC logs the error I mentioned above > > > > > > 2) GCC and Clang don't complain at compile time, but don't honor the "'" as a special > > > character. As an example, > > > printf("%'d\n", 1024); > > > results in > > > 'd > > > > > > It seems that for this syntax to work as you would expect, support needs to exist in both the > > > compiler and the libraries used. > > > > > > Back to your question: there's no equivalent syntax on Windows that provides the thousands grouping. > > > If really needed (and I understand it is useful for large numbers), we could get the same result > > > by calling a helper function that would convert the number in the formatted string and use that > > > in the printf statement. > > > > > > There is a Win32 API that does that. It takes a string as input though: GetNumberFormatA. > > > (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getnumberformata) > > > > > > We could use ifdefs to keep the old logic on Linux and use new logic on Windows (for all compilers). > > > > > > Let me know if this is something that would need to be done, or if the current output > > > without thousands grouping is good enough. > > > -- > > The thousands grouping is incredibly helpful when working with large > > numbers, but given the lack of support for this on Windows, we'll just have > > to go without, I think. > > > > /Bruce > > Maybe some variation of the pretty printing code that iproute2 has > (see print_num) would be useful. Feel free to reuse it. > I wrote the initial version. That's an interesting suggestion. I'll use that. ^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [PATCH] hash_readwrite_autotest: fix printf parameters 2025-03-11 14:39 ` Andre Muezerie @ 2025-03-11 15:01 ` Morten Brørup 0 siblings, 0 replies; 13+ messages in thread From: Morten Brørup @ 2025-03-11 15:01 UTC (permalink / raw) To: Andre Muezerie, Stephen Hemminger, Bruce Richardson Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev > From: Andre Muezerie [mailto:andremue@linux.microsoft.com] > Sent: Tuesday, 11 March 2025 15.40 > > On Mon, Mar 10, 2025 at 08:36:40AM -0700, Stephen Hemminger wrote: > > On Mon, 10 Mar 2025 10:51:51 +0000 > > Bruce Richardson <bruce.richardson@intel.com> wrote: > > > > > On Fri, Mar 07, 2025 at 02:34:01PM -0800, Andre Muezerie wrote: > > > > On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote: > > > > > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote: > > > > > > Compiling with MSVC logs the warnings below, which result in > > > > > > build error: > > > > > > > > > > > > ../app/test/test_hash_readwrite.c(73): warning C4476: > 'printf' : > > > > > > unknown type field character ''' in format specifier > > > > > > ../app/test/test_hash_readwrite.c(75): warning C4474: > 'printf' : > > > > > > too many arguments passed for format string > > > > > > ../app/test/test_hash_readwrite.c(75): note: placeholders and > > > > > > their parameters expect 2 variadic arguments, but 4 were > provided > > > > > > > > > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > > > > > --- > > > > > > app/test/test_hash_readwrite.c | 2 +- > > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > > IF the "'" character is not supported, is there some other > method to do > > > > > thousands grouping in MSVC? > > > > > > > > > > /Bruce > > > > > > > > The problem exists with all compilers I tried on Windows: > > > > > > > > 1) MSVC logs the error I mentioned above > > > > > > > > 2) GCC and Clang don't complain at compile time, but don't honor > the "'" as a special > > > > character. As an example, > > > > printf("%'d\n", 1024); > > > > results in > > > > 'd > > > > > > > > It seems that for this syntax to work as you would expect, > support needs to exist in both the > > > > compiler and the libraries used. > > > > > > > > Back to your question: there's no equivalent syntax on Windows > that provides the thousands grouping. > > > > If really needed (and I understand it is useful for large > numbers), we could get the same result > > > > by calling a helper function that would convert the number in the > formatted string and use that > > > > in the printf statement. > > > > > > > > There is a Win32 API that does that. It takes a string as input > though: GetNumberFormatA. > > > > (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf- > winnls-getnumberformata) > > > > > > > > We could use ifdefs to keep the old logic on Linux and use new > logic on Windows (for all compilers). > > > > > > > > Let me know if this is something that would need to be done, or > if the current output > > > > without thousands grouping is good enough. > > > > -- > > > The thousands grouping is incredibly helpful when working with > large > > > numbers, but given the lack of support for this on Windows, we'll > just have > > > to go without, I think. > > > > > > /Bruce > > > > Maybe some variation of the pretty printing code that iproute2 has > > (see print_num) would be useful. Feel free to reuse it. > > I wrote the initial version. > > That's an interesting suggestion. I'll use that. Often "123 M" is better than "123123123", but sometimes seeing the last digit move is important, e.g. when looking at packet counters. Just mentioning, so you consider which format is better every time you use it. ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/3] eal: add function rte_size_to_str 2025-03-06 20:03 [PATCH] hash_readwrite_autotest: fix printf parameters Andre Muezerie 2025-03-07 9:01 ` Bruce Richardson @ 2025-03-11 15:33 ` Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie ` (3 more replies) 1 sibling, 4 replies; 13+ messages in thread From: Andre Muezerie @ 2025-03-11 15:33 UTC (permalink / raw) To: andremue Cc: bruce.richardson, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang It's common to use %' in the printf format specifier to make large numbers more easily readable by having the thousands grouped. However, this grouping does not work on Windows. Therefore, a function is needed to make uint64_t numbers more easily readable. There are at least two tests that can benefit from this new function. Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> --- lib/eal/common/eal_common_string_fns.c | 44 ++++++++++++++++++++++++++ lib/eal/include/rte_common.h | 21 ++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/eal/common/eal_common_string_fns.c b/lib/eal/common/eal_common_string_fns.c index 9ca2045b18..b658d68eac 100644 --- a/lib/eal/common/eal_common_string_fns.c +++ b/lib/eal/common/eal_common_string_fns.c @@ -4,6 +4,7 @@ #include <ctype.h> #include <errno.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -87,6 +88,12 @@ rte_str_to_size(const char *str) endptr++; /* allow 1 space gap */ switch (*endptr) { + case 'E': case 'e': + size *= 1024; /* fall-through */ + case 'P': case 'p': + size *= 1024; /* fall-through */ + case 'T': case 't': + size *= 1024; /* fall-through */ case 'G': case 'g': size *= 1024; /* fall-through */ case 'M': case 'm': @@ -98,3 +105,40 @@ rte_str_to_size(const char *str) } return size; } + +int +rte_size_to_str(char *buf, int buf_size, + uint64_t count, bool use_iec) +{ + const char *prefix = "kMGTPE"; + const unsigned int base = use_iec ? 1024 : 1000; + uint64_t powi = 1; + uint16_t powj = 1; + uint8_t precision = 2; + + if (count < base) + return snprintf(buf, buf_size, "%"PRIu64" ", count); + + /* increase value by a factor of 1000/1024 and store + * if result is something a human can read + */ + for (;;) { + powi *= base; + if (count / base < powi) + break; + + if (!prefix[1]) + break; + ++prefix; + } + + /* try to guess a good number of digits for precision */ + for (; precision > 0; precision--) { + powj *= 10; + if (count / powi < powj) + break; + } + + return snprintf(buf, buf_size, "%.*f%c%s", precision, + (double)count / powi, *prefix, use_iec ? "i" : ""); +} diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 386f11ae40..81fa4d3c34 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -14,6 +14,7 @@ #include <assert.h> #include <limits.h> +#include <stdbool.h> #include <stdint.h> #include <stdalign.h> @@ -919,6 +920,26 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; uint64_t rte_str_to_size(const char *str); +/** + * Converts the uint64_t value provided to a human-readable string. + * It null-terminates the string, truncating the data if needed. + * + * @param buf + * Buffer to write the string to. + * @param buf_size + * Size of the buffer. + * @param count + * Number to convert. + * @param use_iec + * If true, use IEC units (1024-based), otherwise use SI units (1000-based). + * @return + * Number of characters written (not including the null-terminator), + * or that would have been required when the buffer is too small. + */ +int +rte_size_to_str(char *buf, int buf_size, + uint64_t count, bool use_iec); + /** * Function to terminate the application immediately, printing an error * message and returning the exit_code back to the shell. -- 2.48.1.vfs.0.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie @ 2025-03-11 15:33 ` Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 3/3] hash_readwrite_autotest: " Andre Muezerie ` (2 subsequent siblings) 3 siblings, 0 replies; 13+ messages in thread From: Andre Muezerie @ 2025-03-11 15:33 UTC (permalink / raw) To: andremue Cc: bruce.richardson, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang Compiling with MSVC logs the warnings below, which result in build error: ../app/test/test_hash_multiwriter.c(71): warning C4476: 'printf' : unknown type field character ''' in format specifier ../app/test/test_hash_multiwriter.c(73): warning C4474: 'printf' : too many arguments passed for format string ../app/test/test_hash_multiwriter.c(73): note: placeholders and their parameters expect 2 variadic arguments, but 4 were provided Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> --- app/test/test_hash_multiwriter.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/test/test_hash_multiwriter.c b/app/test/test_hash_multiwriter.c index 33d3147bd8..5c1dd4c195 100644 --- a/app/test/test_hash_multiwriter.c +++ b/app/test/test_hash_multiwriter.c @@ -32,6 +32,8 @@ #define RTE_APP_TEST_HASH_MULTIWRITER_FAILED 0 +#define OFFSET_STR_LEN 16 + struct { uint32_t *keys; uint32_t *found; @@ -51,11 +53,14 @@ static int use_htm; static int test_hash_multiwriter_worker(void *arg) { + char offset_start[OFFSET_STR_LEN]; + char offset_end[OFFSET_STR_LEN]; uint64_t i, offset; uint16_t pos_core; uint32_t lcore_id = rte_lcore_id(); uint64_t begin, cycles; uint16_t *enabled_core_ids = (uint16_t *)arg; + const bool use_iec = true; for (pos_core = 0; pos_core < rte_lcore_count(); pos_core++) { if (enabled_core_ids[pos_core] == lcore_id) @@ -68,10 +73,12 @@ test_hash_multiwriter_worker(void *arg) */ offset = pos_core * tbl_multiwriter_test_params.nb_tsx_insertion; - printf("Core #%d inserting %d: %'"PRId64" - %'"PRId64"\n", + rte_size_to_str(offset_start, sizeof(offset_start), offset, use_iec); + rte_size_to_str(offset_end, sizeof(offset_end), + offset + tbl_multiwriter_test_params.nb_tsx_insertion - 1, use_iec); + printf("Core #%u inserting %u: %s - %s\n", lcore_id, tbl_multiwriter_test_params.nb_tsx_insertion, - offset, - offset + tbl_multiwriter_test_params.nb_tsx_insertion - 1); + offset_start, offset_end); begin = rte_rdtsc_precise(); -- 2.48.1.vfs.0.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 3/3] hash_readwrite_autotest: fix printf parameters 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie @ 2025-03-11 15:33 ` Andre Muezerie 2025-03-11 15:49 ` [PATCH v2 1/3] eal: add function rte_size_to_str Stephen Hemminger 2025-03-11 16:21 ` Morten Brørup 3 siblings, 0 replies; 13+ messages in thread From: Andre Muezerie @ 2025-03-11 15:33 UTC (permalink / raw) To: andremue Cc: bruce.richardson, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang Compiling with MSVC logs the warnings below, which result in build error: ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' : unknown type field character ''' in format specifier ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' : too many arguments passed for format string ../app/test/test_hash_readwrite.c(75): note: placeholders and their parameters expect 2 variadic arguments, but 4 were provided Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> --- app/test/test_hash_readwrite.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/test/test_hash_readwrite.c b/app/test/test_hash_readwrite.c index 1867376ade..3fa7003bfb 100644 --- a/app/test/test_hash_readwrite.c +++ b/app/test/test_hash_readwrite.c @@ -25,6 +25,8 @@ #define NUM_TEST 3 unsigned int core_cnt[NUM_TEST] = {2, 4, 8}; +#define OFFSET_STR_LEN 16 + unsigned int worker_core_ids[RTE_MAX_LCORE]; struct perf { uint32_t single_read; @@ -57,10 +59,13 @@ static RTE_ATOMIC(uint64_t) gwrites; static int test_hash_readwrite_worker(__rte_unused void *arg) { + char offset_start[OFFSET_STR_LEN]; + char offset_end[OFFSET_STR_LEN]; uint64_t i, offset; uint32_t lcore_id = rte_lcore_id(); uint64_t begin, cycles; int *ret; + const bool use_iec = true; ret = rte_malloc(NULL, sizeof(int) * tbl_rw_test_param.num_insert, 0); @@ -70,9 +75,13 @@ test_hash_readwrite_worker(__rte_unused void *arg) } offset = tbl_rw_test_param.num_insert * i; - printf("Core #%d inserting and reading %d: %'"PRId64" - %'"PRId64"\n", + rte_size_to_str(offset_start, sizeof(offset_start), offset, use_iec); + rte_size_to_str(offset_end, sizeof(offset_end), + offset + tbl_rw_test_param.num_insert - 1, use_iec); + + printf("Core #%u inserting and reading %u: %s - %s\n", lcore_id, tbl_rw_test_param.num_insert, - offset, offset + tbl_rw_test_param.num_insert - 1); + offset_start, offset_end); begin = rte_rdtsc_precise(); -- 2.48.1.vfs.0.1 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] eal: add function rte_size_to_str 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 3/3] hash_readwrite_autotest: " Andre Muezerie @ 2025-03-11 15:49 ` Stephen Hemminger 2025-03-11 15:51 ` Bruce Richardson 2025-03-11 16:21 ` Morten Brørup 3 siblings, 1 reply; 13+ messages in thread From: Stephen Hemminger @ 2025-03-11 15:49 UTC (permalink / raw) To: Andre Muezerie Cc: bruce.richardson, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang On Tue, 11 Mar 2025 08:33:13 -0700 Andre Muezerie <andremue@linux.microsoft.com> wrote: > It's common to use %' in the printf format specifier to make large numbers > more easily readable by having the thousands grouped. However, this > grouping does not work on Windows. Therefore, a function is needed to make > uint64_t numbers more easily readable. There are at least two tests that > can benefit from this new function. > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > --- > lib/eal/common/eal_common_string_fns.c | 44 ++++++++++++++++++++++++++ > lib/eal/include/rte_common.h | 21 ++++++++++++ > 2 files changed, 65 insertions(+) > > diff --git a/lib/eal/common/eal_common_string_fns.c b/lib/eal/common/eal_common_string_fns.c > index 9ca2045b18..b658d68eac 100644 > --- a/lib/eal/common/eal_common_string_fns.c > +++ b/lib/eal/common/eal_common_string_fns.c > @@ -4,6 +4,7 @@ > > #include <ctype.h> > #include <errno.h> > +#include <inttypes.h> > #include <stdio.h> > #include <stdlib.h> > > @@ -87,6 +88,12 @@ rte_str_to_size(const char *str) > endptr++; /* allow 1 space gap */ > > switch (*endptr) { > + case 'E': case 'e': > + size *= 1024; /* fall-through */ > + case 'P': case 'p': > + size *= 1024; /* fall-through */ > + case 'T': case 't': > + size *= 1024; /* fall-through */ > case 'G': case 'g': > size *= 1024; /* fall-through */ > case 'M': case 'm': > @@ -98,3 +105,40 @@ rte_str_to_size(const char *str) > } > return size; > } > + Is this right? Looks like existing code is not using correct multiple The standard for communication is K = 1000 and the standard for storage is K = 1024. That is why iproute2 has the use_iec flag. https://en.wikipedia.org/wiki/Data-rate_units ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] eal: add function rte_size_to_str 2025-03-11 15:49 ` [PATCH v2 1/3] eal: add function rte_size_to_str Stephen Hemminger @ 2025-03-11 15:51 ` Bruce Richardson 0 siblings, 0 replies; 13+ messages in thread From: Bruce Richardson @ 2025-03-11 15:51 UTC (permalink / raw) To: Stephen Hemminger Cc: Andre Muezerie, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang On Tue, Mar 11, 2025 at 08:49:05AM -0700, Stephen Hemminger wrote: > On Tue, 11 Mar 2025 08:33:13 -0700 > Andre Muezerie <andremue@linux.microsoft.com> wrote: > > > It's common to use %' in the printf format specifier to make large numbers > > more easily readable by having the thousands grouped. However, this > > grouping does not work on Windows. Therefore, a function is needed to make > > uint64_t numbers more easily readable. There are at least two tests that > > can benefit from this new function. > > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com> > > --- > > lib/eal/common/eal_common_string_fns.c | 44 ++++++++++++++++++++++++++ > > lib/eal/include/rte_common.h | 21 ++++++++++++ > > 2 files changed, 65 insertions(+) > > > > diff --git a/lib/eal/common/eal_common_string_fns.c b/lib/eal/common/eal_common_string_fns.c > > index 9ca2045b18..b658d68eac 100644 > > --- a/lib/eal/common/eal_common_string_fns.c > > +++ b/lib/eal/common/eal_common_string_fns.c > > @@ -4,6 +4,7 @@ > > > > #include <ctype.h> > > #include <errno.h> > > +#include <inttypes.h> > > #include <stdio.h> > > #include <stdlib.h> > > > > @@ -87,6 +88,12 @@ rte_str_to_size(const char *str) > > endptr++; /* allow 1 space gap */ > > > > switch (*endptr) { > > + case 'E': case 'e': > > + size *= 1024; /* fall-through */ > > + case 'P': case 'p': > > + size *= 1024; /* fall-through */ > > + case 'T': case 't': > > + size *= 1024; /* fall-through */ > > case 'G': case 'g': > > size *= 1024; /* fall-through */ > > case 'M': case 'm': > > @@ -98,3 +105,40 @@ rte_str_to_size(const char *str) > > } > > return size; > > } > > + > > Is this right? Looks like existing code is not using correct multiple > > The standard for communication is K = 1000 and the standard for storage is K = 1024. > That is why iproute2 has the use_iec flag. > > https://en.wikipedia.org/wiki/Data-rate_units > Ideally, we should have that flag, but I believe this current function is for things like memory sizes, which means that using 1024 is correct. /Bruce ^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [PATCH v2 1/3] eal: add function rte_size_to_str 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie ` (2 preceding siblings ...) 2025-03-11 15:49 ` [PATCH v2 1/3] eal: add function rte_size_to_str Stephen Hemminger @ 2025-03-11 16:21 ` Morten Brørup 3 siblings, 0 replies; 13+ messages in thread From: Morten Brørup @ 2025-03-11 16:21 UTC (permalink / raw) To: Andre Muezerie Cc: bruce.richardson, dev, sameh.gobriel, vladimir.medvedkin, yipeng1.wang, Stephen Hemminger > + return snprintf(buf, buf_size, "%.*f%c%s", precision, > + (double)count / powi, *prefix, use_iec ? "i" : ""); I prefer a space between the number and the postfix (if a postfix is present), e.g. "1.23 M", so when followed by the unit, it becomes "1.23 Mbit/s" rather than "1.23M bit/s". > +/** > + * Converts the uint64_t value provided to a human-readable string. > + * It null-terminates the string, truncating the data if needed. Please add some examples showing the output formatting. E.g.: "123 M", "12.3 M", "12 M", " 12 M" or "12.0 M", "1.00 ", " 1.00", or " 1", or something else? > + * > + * @param buf > + * Buffer to write the string to. > + * @param buf_size > + * Size of the buffer. > + * @param count > + * Number to convert. > + * @param use_iec > + * If true, use IEC units (1024-based), otherwise use SI units > (1000-based). > + * @return > + * Number of characters written (not including the null- > terminator), > + * or that would have been required when the buffer is too small. > + */ > +int > +rte_size_to_str(char *buf, int buf_size, > + uint64_t count, bool use_iec); > + ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-03-11 16:21 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-03-06 20:03 [PATCH] hash_readwrite_autotest: fix printf parameters Andre Muezerie 2025-03-07 9:01 ` Bruce Richardson 2025-03-07 22:34 ` Andre Muezerie 2025-03-10 10:51 ` Bruce Richardson 2025-03-10 15:36 ` Stephen Hemminger 2025-03-11 14:39 ` Andre Muezerie 2025-03-11 15:01 ` Morten Brørup 2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie 2025-03-11 15:33 ` [PATCH v2 3/3] hash_readwrite_autotest: " Andre Muezerie 2025-03-11 15:49 ` [PATCH v2 1/3] eal: add function rte_size_to_str Stephen Hemminger 2025-03-11 15:51 ` Bruce Richardson 2025-03-11 16:21 ` Morten Brørup
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).