1. 03 4月, 2018 1 次提交
    • O
      bitmap: fix memset optimization on big-endian systems · 21035965
      Omar Sandoval 提交于
      Commit 2a98dc02 ("include/linux/bitmap.h: turn bitmap_set and
      bitmap_clear into memset when possible") introduced an optimization to
      bitmap_{set,clear}() which uses memset() when the start and length are
      constants aligned to a byte.
      
      This is wrong on big-endian systems; our bitmaps are arrays of unsigned
      long, so bit n is not at byte n / 8 in memory.  This was caught by the
      Btrfs selftests, but the bitmap selftests also fail when run on a
      big-endian machine.
      
      We can still use memset if the start and length are aligned to an
      unsigned long, so do that on big-endian.  The same problem applies to
      the memcmp in bitmap_equal(), so fix it there, too.
      
      Fixes: 2a98dc02 ("include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible")
      Fixes: 2c6deb01 ("bitmap: use memcmp optimisation in more situations")
      Cc: stable@kernel.org
      Reported-by: N"Erhard F." <erhard_f@mailbox.org>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: NOmar Sandoval <osandov@fb.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      21035965
  2. 07 2月, 2018 4 次提交
    • C
      lib: optimize cpumask_next_and() · 0ade34c3
      Clement Courbet 提交于
      We've measured that we spend ~0.6% of sys cpu time in cpumask_next_and().
      It's essentially a joined iteration in search for a non-zero bit, which is
      currently implemented as a lookup join (find a nonzero bit on the lhs,
      lookup the rhs to see if it's set there).
      
      Implement a direct join (find a nonzero bit on the incrementally built
      join).  Also add generic bitmap benchmarks in the new `test_find_bit`
      module for new function (see `find_next_and_bit` in [2] and [3] below).
      
      For cpumask_next_and, direct benchmarking shows that it's 1.17x to 14x
      faster with a geometric mean of 2.1 on 32 CPUs [1].  No impact on memory
      usage.  Note that on Arm, the new pure-C implementation still outperforms
      the old one that uses a mix of C and asm (`find_next_bit`) [3].
      
      [1] Approximate benchmark code:
      
      ```
        unsigned long src1p[nr_cpumask_longs] = {pattern1};
        unsigned long src2p[nr_cpumask_longs] = {pattern2};
        for (/*a bunch of repetitions*/) {
          for (int n = -1; n <= nr_cpu_ids; ++n) {
            asm volatile("" : "+rm"(src1p)); // prevent any optimization
            asm volatile("" : "+rm"(src2p));
            unsigned long result = cpumask_next_and(n, src1p, src2p);
            asm volatile("" : "+rm"(result));
          }
        }
      ```
      
      Results:
      pattern1    pattern2     time_before/time_after
      0x0000ffff  0x0000ffff   1.65
      0x0000ffff  0x00005555   2.24
      0x0000ffff  0x00001111   2.94
      0x0000ffff  0x00000000   14.0
      0x00005555  0x0000ffff   1.67
      0x00005555  0x00005555   1.71
      0x00005555  0x00001111   1.90
      0x00005555  0x00000000   6.58
      0x00001111  0x0000ffff   1.46
      0x00001111  0x00005555   1.49
      0x00001111  0x00001111   1.45
      0x00001111  0x00000000   3.10
      0x00000000  0x0000ffff   1.18
      0x00000000  0x00005555   1.18
      0x00000000  0x00001111   1.17
      0x00000000  0x00000000   1.25
      -----------------------------
                     geo.mean  2.06
      
      [2] test_find_next_bit, X86 (skylake)
      
       [ 3913.477422] Start testing find_bit() with random-filled bitmap
       [ 3913.477847] find_next_bit: 160868 cycles, 16484 iterations
       [ 3913.477933] find_next_zero_bit: 169542 cycles, 16285 iterations
       [ 3913.478036] find_last_bit: 201638 cycles, 16483 iterations
       [ 3913.480214] find_first_bit: 4353244 cycles, 16484 iterations
       [ 3913.480216] Start testing find_next_and_bit() with random-filled
       bitmap
       [ 3913.481074] find_next_and_bit: 89604 cycles, 8216 iterations
       [ 3913.481075] Start testing find_bit() with sparse bitmap
       [ 3913.481078] find_next_bit: 2536 cycles, 66 iterations
       [ 3913.481252] find_next_zero_bit: 344404 cycles, 32703 iterations
       [ 3913.481255] find_last_bit: 2006 cycles, 66 iterations
       [ 3913.481265] find_first_bit: 17488 cycles, 66 iterations
       [ 3913.481266] Start testing find_next_and_bit() with sparse bitmap
       [ 3913.481272] find_next_and_bit: 764 cycles, 1 iterations
      
      [3] test_find_next_bit, arm (v7 odroid XU3).
      
      [  267.206928] Start testing find_bit() with random-filled bitmap
      [  267.214752] find_next_bit: 4474 cycles, 16419 iterations
      [  267.221850] find_next_zero_bit: 5976 cycles, 16350 iterations
      [  267.229294] find_last_bit: 4209 cycles, 16419 iterations
      [  267.279131] find_first_bit: 1032991 cycles, 16420 iterations
      [  267.286265] Start testing find_next_and_bit() with random-filled
      bitmap
      [  267.302386] find_next_and_bit: 2290 cycles, 8140 iterations
      [  267.309422] Start testing find_bit() with sparse bitmap
      [  267.316054] find_next_bit: 191 cycles, 66 iterations
      [  267.322726] find_next_zero_bit: 8758 cycles, 32703 iterations
      [  267.329803] find_last_bit: 84 cycles, 66 iterations
      [  267.336169] find_first_bit: 4118 cycles, 66 iterations
      [  267.342627] Start testing find_next_and_bit() with sparse bitmap
      [  267.356919] find_next_and_bit: 91 cycles, 1 iterations
      
      [courbet@google.com: v6]
        Link: http://lkml.kernel.org/r/20171129095715.23430-1-courbet@google.com
      [geert@linux-m68k.org: m68k/bitops: always include <asm-generic/bitops/find.h>]
        Link: http://lkml.kernel.org/r/1512556816-28627-1-git-send-email-geert@linux-m68k.org
      Link: http://lkml.kernel.org/r/20171128131334.23491-1-courbet@google.comSigned-off-by: NClement Courbet <courbet@google.com>
      Signed-off-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Cc: Yury Norov <ynorov@caviumnetworks.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0ade34c3
    • A
      include/linux/bitmap.h: make bitmap_fill() and bitmap_zero() consistent · 334cfa48
      Andy Shevchenko 提交于
      Behaviour of bitmap_fill() differs from bitmap_zero() in a way how bits
      behind bitmap are handed.  bitmap_zero() clears entire bitmap by unsigned
      long boundary, while bitmap_fill() mimics bitmap_set().
      
      Here we change bitmap_fill() behaviour to be consistent with bitmap_zero()
      and add a note to documentation.
      
      The change might reveal some bugs in the code where unused bits are
      handled differently and in such cases bitmap_set() has to be used.
      
      Link: http://lkml.kernel.org/r/20180109172430.87452-4-andriy.shevchenko@linux.intel.comSigned-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Suggested-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Yury Norov <ynorov@caviumnetworks.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      334cfa48
    • Y
      bitmap: replace bitmap_{from,to}_u32array · 3aa56885
      Yury Norov 提交于
      with bitmap_{from,to}_arr32 over the kernel. Additionally to it:
      * __check_eq_bitmap() now takes single nbits argument.
      * __check_eq_u32_array is not used in new test but may be used in
        future. So I don't remove it here, but annotate as __used.
      
      Tested on arm64 and 32-bit BE mips.
      
      [arnd@arndb.de: perf: arm_dsu_pmu: convert to bitmap_from_arr32]
        Link: http://lkml.kernel.org/r/20180201172508.5739-2-ynorov@caviumnetworks.com
      [ynorov@caviumnetworks.com: fix net/core/ethtool.c]
        Link: http://lkml.kernel.org/r/20180205071747.4ekxtsbgxkj5b2fz@yury-thinkpad
      Link: http://lkml.kernel.org/r/20171228150019.27953-2-ynorov@caviumnetworks.comSigned-off-by: NYury Norov <ynorov@caviumnetworks.com>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Cc: Ben Hutchings <ben@decadent.org.uk>
      Cc: David Decotigny <decot@googlers.com>,
      Cc: David S. Miller <davem@davemloft.net>,
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Heiner Kallweit <hkallweit1@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3aa56885
    • Y
      bitmap: new bitmap_copy_safe and bitmap_{from,to}_arr32 · c724f193
      Yury Norov 提交于
      This patchset replaces bitmap_{to,from}_u32array with more simple and
      standard looking copy-like functions.
      
      bitmap_from_u32array() takes 4 arguments (bitmap_to_u32array is similar):
       - unsigned long *bitmap, which is destination;
       - unsigned int nbits, the length of destination bitmap, in bits;
       - const u32 *buf, the source; and
       - unsigned int nwords, the length of source buffer in ints.
      
      In description to the function it is detailed like:
      * copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining
      * bits between nword and nbits in @bitmap (if any) are cleared.
      
      Having two size arguments looks unneeded and potentially dangerous.
      
      It is unneeded because normally user of copy-like function should take
      care of the size of destination and make it big enough to fit source
      data.
      
      And it is dangerous because function may hide possible error if user
      doesn't provide big enough bitmap, and data becomes silently dropped.
      
      That's why all copy-like functions have 1 argument for size of copying
      data, and I don't see any reason to make bitmap_from_u32array()
      different.
      
      One exception that comes in mind is strncpy() which also provides size
      of destination in arguments, but it's strongly argued by the possibility
      of taking broken strings in source.  This is not the case of
      bitmap_{from,to}_u32array().
      
      There is no many real users of bitmap_{from,to}_u32array(), and they all
      very clearly provide size of destination matched with the size of
      source, so additional functionality is not used in fact. Like this:
      bitmap_from_u32array(to->link_modes.supported,
      		__ETHTOOL_LINK_MODE_MASK_NBITS,
      		link_usettings.link_modes.supported,
      		__ETHTOOL_LINK_MODE_MASK_NU32);
      Where:
      #define __ETHTOOL_LINK_MODE_MASK_NU32 \
      	DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
      
      In this patch, bitmap_copy_safe and bitmap_{from,to}_arr32 are introduced.
      
      'Safe' in bitmap_copy_safe() stands for clearing unused bits in bitmap
      beyond last bit till the end of last word. It is useful for hardening
      API when bitmap is assumed to be exposed to userspace.
      
      bitmap_{from,to}_arr32 functions are replacements for
      bitmap_{from,to}_u32array. They don't take unneeded nwords argument, and
      so simpler in implementation and understanding.
      
      This patch suggests optimization for 32-bit systems - aliasing
      bitmap_{from,to}_arr32 to bitmap_copy_safe.
      
      Other possible optimization is aliasing 64-bit LE bitmap_{from,to}_arr32 to
      more generic function(s). But I didn't end up with the function that would
      be helpful by itself, and can be used to alias 64-bit LE
      bitmap_{from,to}_arr32, like bitmap_copy_safe() does. So I preferred to
      leave things as is.
      
      The following patch switches kernel to new API and introduces test for it.
      
      Discussion is here: https://lkml.org/lkml/2017/11/15/592
      
      [ynorov@caviumnetworks.com: rename bitmap_copy_safe to bitmap_copy_clear_tail]
        Link: http://lkml.kernel.org/r/20180201172508.5739-3-ynorov@caviumnetworks.com
      Link: http://lkml.kernel.org/r/20171228150019.27953-1-ynorov@caviumnetworks.comSigned-off-by: NYury Norov <ynorov@caviumnetworks.com>
      Cc: Ben Hutchings <ben@decadent.org.uk>
      Cc: David Decotigny <decot@googlers.com>,
      Cc: David S. Miller <davem@davemloft.net>,
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c724f193
  3. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  4. 20 10月, 2017 1 次提交
  5. 27 9月, 2017 1 次提交
  6. 09 9月, 2017 1 次提交
  7. 11 7月, 2017 3 次提交
  8. 18 8月, 2016 1 次提交
  9. 04 8月, 2016 1 次提交
  10. 13 6月, 2016 1 次提交
  11. 20 2月, 2016 1 次提交
  12. 05 8月, 2015 1 次提交
  13. 17 4月, 2015 1 次提交
  14. 16 4月, 2015 1 次提交
    • R
      linux/bitmap.h: improve BITMAP_{LAST,FIRST}_WORD_MASK · 89c1e79e
      Rasmus Villemoes 提交于
      The macro BITMAP_LAST_WORD_MASK can be implemented without a conditional,
      which will generally lead to slightly better generated code (221 bytes
      saved for allmodconfig-GCOV_KERNEL, ~2k with GCOV_KERNEL).  As a small
      bonus, this also ensures that the nbits parameter is expanded exactly
      once.
      
      In BITMAP_FIRST_WORD_MASK, if start is signed gcc is technically allowed
      to assume it is positive (or divisible by BITS_PER_LONG), and hence just
      do the simple mask.  It doesn't seem to use this, and even on an
      architecture like x86 where the shift only depends on the lower 5 or 6
      bits, and these bits are not affected by the signedness of the expression,
      gcc still generates code to compute the C99 mandated value of start %
      BITS_PER_LONG.  So just use a mask explicitly, also for consistency with
      BITMAP_LAST_WORD_MASK.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Tejun Heo <tj@kernel.org>
      Reviewed-by: NGeorge Spelvin <linux@horizon.com>
      Cc: Yury Norov <yury.norov@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      89c1e79e
  15. 14 2月, 2015 5 次提交
  16. 13 2月, 2015 5 次提交
  17. 14 12月, 2014 1 次提交
  18. 08 11月, 2014 1 次提交
  19. 07 8月, 2014 9 次提交