From b73b9fcb1dad0e4edd13b6d1423c27acf4c4f312 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Sat, 13 Mar 2021 18:10:12 +0000 Subject: [PATCH] cksum: add --debug to diagnose which implementation used * src/cksum.c: (main): Use getopt_long to parse options, and handle the new --debug option. (pclmul_supported): Diagnose various failures and attempts. * NEWS: Mention the new option. --- NEWS | 4 +++- src/cksum.c | 55 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index aad05df6db..89f60d28fe 100644 --- a/NEWS +++ b/NEWS @@ -70,7 +70,9 @@ GNU coreutils NEWS -*- outline -*- cat --show-ends will now show \r\n as ^M$. Previously the \r was taken literally, thus overwriting the first character in the line with '$'. - cksum is now up to 4 times faster by using a slice by 8 algorithm. + cksum is now up to 4 times faster by using a slice by 8 algorithm, + and at least 8 times faster where pclmul instructions are supported. + A new --debug option will indicate if pclmul is being used. df now recognizes these file systems as remote: acfs, coda, fhgfs, gpfs, ibrix, ocfs2, and vxfs. diff --git a/src/cksum.c b/src/cksum.c index a38f03ca86..f3d41666bd 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -39,6 +39,7 @@ #define AUTHORS proper_name ("Q. Frank Xia") +#include #include #include #include @@ -141,7 +142,6 @@ main (void) #else /* !CRCTAB */ -# include "long-options.h" # include "die.h" # include "error.h" @@ -153,6 +153,21 @@ main (void) /* Number of bytes to read at once. */ # define BUFLEN (1 << 16) +static bool debug; + +enum +{ + DEBUG_PROGRAM_OPTION = CHAR_MAX + 1, +}; + +static struct option const longopts[] = +{ + {"debug", no_argument, NULL, DEBUG_PROGRAM_OPTION}, + {GETOPT_HELP_OPTION_DECL}, + {GETOPT_VERSION_OPTION_DECL}, + {NULL, 0, NULL, 0}, +}; + /* Nonzero if any of the files read were the standard input. */ static bool have_read_stdin; @@ -173,13 +188,21 @@ pclmul_supported (void) unsigned int edx = 0; if (! __get_cpuid (1, &eax, &ebx, &ecx, &edx)) - return false; + { + if (debug) + error (0, 0, "%s", _("failed to get cpuid")); + return false; + } - if (! (ecx & bit_PCLMUL)) - return false; + if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX)) + { + if (debug) + error (0, 0, "%s", _("pclmul support not detected")); + return false; + } - if (! (ecx & bit_AVX)) - return false; + if (debug) + error (0, 0, "%s", _("using pclmul hardware support")); return true; } @@ -330,7 +353,7 @@ Print CRC checksum and byte counts of each FILE.\n\ int main (int argc, char **argv) { - int i; + int i, c; bool ok; initialize_main (&argc, &argv); @@ -345,8 +368,22 @@ main (int argc, char **argv) so that processes running in parallel do not intersperse their output. */ setvbuf (stdout, NULL, _IOLBF, 0); - parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE, Version, - true, usage, AUTHORS, (char const *) NULL); + while ((c = getopt_long (argc, argv, "", longopts, NULL)) != -1) + { + switch (c) + { + case DEBUG_PROGRAM_OPTION: + debug = true; + break; + + case_GETOPT_HELP_CHAR; + + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + + default: + usage (EXIT_FAILURE); + } + } have_read_stdin = false; -- 2.47.2