Skip to contentSkip to conversation

Bitmap patches for v5.19-rc1

GIT PULL Yury Norov 2 participants 3 messages May 27, 2022 – Jun 1, 2022

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

Hi Linus,

The following changes since commit ce522ba9ef7e2d9fb22a39eb3371c0c64e2a433e:

Linux 5.18-rc2 (2022-04-10 14:21:36 -1000)

are available in the Git repository at:

https://github.com/norov/linux.git/ tags/bitmap-for-5.19-rc1

for you to fetch changes up to db7b4edf37fe9872bec4d1537d67c4c9f95810b6:

nodemask: Fix return values to be unsigned (2022-05-23 13:17:07 -0700)

----------------------------------------------------------------
Bitmap patches for 5.19-rc1

This series includes the following patch-sets:
- bitmap: optimize bitmap_weight() usage, from me;
- lib/bitmap.c make bitmap_print_bitmask_to_buf parseable, from Mauro Carvalho Chehab;
- include/linux/find: Fix documentation, from Anna-Maria Behnsen;
- bitmap: fix conversion from/to fix-sized arrays, from me;
- bitmap: Fix return values to be unsigned, from Kees Cook.

It has been in linux-next for at least a week with no problems.

----------------------------------------------------------------
Anna-Maria Behnsen (1):
include/linux/find: Fix documentation

Kees Cook (2):
bitmap: Fix return values to be unsigned
nodemask: Fix return values to be unsigned

Mauro Carvalho Chehab (1):
lib/bitmap.c make bitmap_print_bitmask_to_buf parseable

Yury Norov (51):
net: dsa: don't use bitmap_weight() in b53_arl_read()
net: systemport: don't use bitmap_weight() in bcm_sysport_rule_set()
net: mellanox: fix open-coded for_each_set_bit()
iio: fix opencoded for_each_set_bit()
qed: rework qed_rdma_bmap_free()
KVM: x86: replace bitmap_weight with bitmap_empty where appropriate
octeontx2-pf: replace bitmap_weight with bitmap_empty where appropriate
qed: replace bitmap_weight with bitmap_empty in qed_roce_stop() arch/alpha: replace cpumask_weight with cpumask_empty where appropriate arch/ia64: replace cpumask_weight with cpumask_empty where appropriate arch/x86: replace cpumask_weight with cpumask_empty where appropriate drm/i915/pmu: replace cpumask_weight with cpumask_empty where appropriate
irq: mips: replace cpumask_weight with cpumask_empty where appropriate genirq/affinity: replace cpumask_weight with cpumask_empty where appropriate
clocksource: replace cpumask_weight with cpumask_empty in clocksource.c mm/vmstat: replace cpumask_weight with cpumask_empty where appropriate arch/x86: replace nodes_weight with nodes_empty where appropriate
bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions arch/x86: replace bitmap_weight with bitmap_weight_{eq,gt,ge,lt,le} where appropriate
iio: replace bitmap_weight() with bitmap_weight_{eq,gt} where appropriate
memstick: replace bitmap_weight with bitmap_weight_eq where appropriate
ixgbe: replace bitmap_weight with bitmap_weight_eq
octeontx2-pf: replace bitmap_weight with bitmap_weight_{eq,gt}
mlx4: replace bitmap_weight with bitmap_weight_{eq,gt,ge,lt,le}
perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2
media: tegra-video: replace bitmap_weight with bitmap_weight_le
cpumask: add cpumask_weight_{eq,gt,ge,lt,le}
arch/ia64: replace cpumask_weight with cpumask_weight_eq in mm/tlb.c arch/mips: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate arch/powerpc: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate
firmware: psci: replace cpumask_weight with cpumask_weight_eq RDMA/hfi1: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate
scsi: lpfc: replace cpumask_weight with cpumask_weight_gt
soc/qman: replace cpumask_weight with cpumask_weight_lt
nodemask: add nodemask_weight_{eq,gt,ge,lt,le}
ACPI: replace nodes__weight with nodes_weight_ge for numa mm/mempolicy: replace nodes_weight with nodes_weight_eq
nodemask: add num_node_state_eq()
tools: bitmap: sync bitmap_weight
MAINTAINERS: add cpumask and nodemask files to BITMAP_API
lib/bitmap: extend comment for bitmap_(from,to)_arr32()
lib: add bitmap_{from,to}_arr64
lib/bitmap: add test for bitmap_{from,to}_arr64
KVM: s390: replace bitmap_copy with bitmap_{from,to}_arr64 where appropriate drm/amd/pm: use bitmap_{from,to}_arr32 where appropriate
ia64: cleanup remove_siblinginfo()
cpufreq: use cpumask_weight_gt() in policy_is_shared()
KVM: x86: hyper-v: fix type of valid_bank_mask
KVM: x86: hyper-v: replace bitmap_weight() with hweight64()
risc-v: replace bitmap_weight with bitmap_empty in riscv_fill_hwcap()

 MAINTAINERS                                        |   4 +
 arch/alpha/kernel/process.c                        |   2 +-
 arch/ia64/kernel/setup.c                           |   2 +-
 arch/ia64/kernel/smpboot.c                         |   4 -
 arch/ia64/mm/tlb.c                                 |   2 +-
 arch/mips/cavium-octeon/octeon-irq.c               |   4 +-
 arch/mips/kernel/crash.c                           |   2 +-
 arch/powerpc/kernel/smp.c                          |   2 +-
 arch/powerpc/kernel/watchdog.c                     |   2 +-
 arch/powerpc/xmon/xmon.c                           |   4 +-
 arch/riscv/kernel/cpufeature.c                     |   7 +-
 arch/s390/kernel/perf_cpum_cf.c                    |   2 +-
 arch/s390/kvm/kvm-s390.c                           |  10 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c             |  16 +--
 arch/x86/kvm/hyperv.c                              |  14 +--
 arch/x86/mm/amdtopology.c                          |   2 +-
 arch/x86/mm/mmio-mod.c                             |   2 +-
 arch/x86/mm/numa_emulation.c                       |   4 +-
 arch/x86/platform/uv/uv_nmi.c                      |   2 +-
 drivers/acpi/numa/srat.c                           |   2 +-
 drivers/firmware/psci/psci_checker.c               |   2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c     |   2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c     |   2 +-
 drivers/gpu/drm/i915/i915_pmu.c                    |   2 +-
 drivers/iio/dummy/iio_simple_dummy_buffer.c        |  48 +++----
 drivers/iio/industrialio-trigger.c                 |   2 +-
 drivers/infiniband/hw/hfi1/affinity.c              |   9 +-
 drivers/infiniband/hw/qib/qib_file_ops.c           |   2 +-
 drivers/infiniband/hw/qib/qib_iba7322.c            |   2 +-
 drivers/irqchip/irq-bcm6345-l1.c                   |   2 +-
 drivers/memstick/core/ms_block.c                   |   4 +-
 drivers/net/dsa/b53/b53_common.c                   |   6 +-
 drivers/net/ethernet/broadcom/bcmsysport.c         |   6 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c     |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_flows.c    |   8 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |   2 +-
 drivers/net/ethernet/mellanox/mlx4/cmd.c           |  33 ++---
 drivers/net/ethernet/mellanox/mlx4/eq.c            |   4 +-
 drivers/net/ethernet/mellanox/mlx4/fw.c            |   4 +-
 drivers/net/ethernet/mellanox/mlx4/main.c          |   2 +-
 drivers/net/ethernet/qlogic/qed/qed_rdma.c         |  45 +++----
 drivers/net/ethernet/qlogic/qed/qed_roce.c         |   2 +-
 drivers/perf/thunderx2_pmu.c                       |   4 +-
 drivers/scsi/lpfc/lpfc_init.c                      |   2 +-
 drivers/soc/fsl/qbman/qman_test_stash.c            |   2 +-
 drivers/staging/media/tegra-video/vi.c             |   2 +-
 include/linux/bitmap.h                             | 139 ++++++++++++++++++---
 include/linux/cpufreq.h                            |   2 +-
 include/linux/cpumask.h                            |  50 ++++++++
 include/linux/find.h                               |   6 +-
 include/linux/nodemask.h                           |  78 +++++++++---
 kernel/irq/affinity.c                              |   2 +-
 kernel/time/clocksource.c                          |   2 +-
 lib/bitmap.c                                       | 138 +++++++++++++++-----
 lib/nodemask.c                                     |   4 +-
 lib/test_bitmap.c                                  |  25 ++++
 mm/mempolicy.c                                     |   2 +-
 mm/page_alloc.c                                    |   2 +-
 mm/vmstat.c                                        |   4 +-
 tools/include/linux/bitmap.h                       |  60 +++++++--
 tools/lib/bitmap.c                                 |  40 ++++--
 tools/perf/util/pmu.c                              |   2 +-
 63 files changed, 578 insertions(+), 270 deletions(-)
#1 lore raw
Quoted 2 lines · Yury Norov

bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions

So honestly, I pulled this, looked at the code, and then unpulled it again.

This is not helping.

Making changes like this:

-       if (mm != current->active_mm || cpumask_weight(mm_cpumask(mm)) != 1) {
+       if (mm != current->active_mm || !cpumask_weight_eq(mm_cpumask(mm), 1)) {

only makes the code harder to understand.

And it gets worse:

- if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu)))
+ if (cpumask_weight_gt(mask, cpumask_weight(sibling_mask(cpu))))

is just disgusting. That original line is simple to read and makes sense. That new replacement really makes you do "Whaa?"

Now, I understand that these kinds of helper functions could make for slightly more efficient code in that you can break out of the bitmap scanning early when you have found enough bits set. I get it.

BUT.

(a) code legibility is really really important

(b) the places I found this weren't that performance-critical.

(c) in most cases, the bitmaps in question are one single word

so I'm unpulling this again.

Now, some other parts of the pull were clear improvements. For example, the hyperv changes like this:

- if (hc->var_cnt != bitmap_weight((unsigned long
*)&valid_bank_mask, 64))
+ if (hc->var_cnt != hweight64(valid_bank_mask))

were clear improvements where the old code was disgusting, and clearly improved by the change.

But the "bitmap_weight_cmp()" functions (and the cpumask_weight_cmp() ones) are just not a direction we want to go.

The special case of zero (ie "cpumask_weight() == 0" -> "bitmap_empty()") is one thing: making that kind of change tends to keep the code legible or even make it more understandable. So I didn't mind that. But I do mind the pointlessly complex new arbitrary weight comparisons, and the kind of mental cost they have.

There are people in the CS world that think "abstractions are always good". Those people are very very wrong.

Linus

author
#2 lore raw
Quoted 50 lines · Linus Torvalds
Quoted 2 lines · Yury Norov

bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions

So honestly, I pulled this, looked at the code, and then unpulled it again.

This is not helping.

Making changes like this:

(quoted diff) +1 -1
-       if (mm != current->active_mm || cpumask_weight(mm_cpumask(mm)) != 1) {
+       if (mm != current->active_mm || !cpumask_weight_eq(mm_cpumask(mm), 1)) {

only makes the code harder to understand.

And it gets worse:

(quoted diff) +1 -1
-               if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu)))
+               if (cpumask_weight_gt(mask, cpumask_weight(sibling_mask(cpu))))

is just disgusting. That original line is simple to read and makes sense. That new replacement really makes you do "Whaa?"

Now, I understand that these kinds of helper functions could make for slightly more efficient code in that you can break out of the bitmap scanning early when you have found enough bits set. I get it.

BUT.

(a) code legibility is really really important

(b) the places I found this weren't that performance-critical.

(c) in most cases, the bitmaps in question are one single word

so I'm unpulling this again.

Now, some other parts of the pull were clear improvements. For example, the hyperv changes like this:

- if (hc->var_cnt != bitmap_weight((unsigned long
*)&valid_bank_mask, 64))
+ if (hc->var_cnt != hweight64(valid_bank_mask))

were clear improvements where the old code was disgusting, and clearly improved by the change.

But the "bitmap_weight_cmp()" functions (and the cpumask_weight_cmp() ones) are just not a direction we want to go.

Quoted 8 lines

The special case of zero (ie "cpumask_weight() == 0" -> "bitmap_empty()") is one thing: making that kind of change tends to keep the code legible or even make it more understandable. So I didn't mind that. But I do mind the pointlessly complex new arbitrary weight comparisons, and the kind of mental cost they have.

There are people in the CS world that think "abstractions are always good". Those people are very very wrong.

Ok, I'll send a new pull with all but bitmap_weight_cmp() patches.