Message ID | 20211218212014.1315894-2-yury.norov@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | lib/bitmap: optimize bitmap_weight() usage | expand |
On Sat, Dec 18, 2021 at 01:19:57PM -0800, Yury Norov wrote: > Don't call bitmap_weight() if the following code can get by > without it. > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > --- > drivers/net/dsa/b53/b53_common.c | 6 +----- > drivers/net/ethernet/broadcom/bcmsysport.c | 6 +----- > drivers/thermal/intel/intel_powerclamp.c | 9 +++------ > 3 files changed, 5 insertions(+), 16 deletions(-) [...] Looks good, but I think this needs to be split per subsystem. Best Regards Michał Mirosław
On Sat, Dec 18, 2021 at 2:16 PM Michał Mirosław <mirq-linux@rere.qmqm.pl> wrote: > > On Sat, Dec 18, 2021 at 01:19:57PM -0800, Yury Norov wrote: > > Don't call bitmap_weight() if the following code can get by > > without it. > > > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > > --- > > drivers/net/dsa/b53/b53_common.c | 6 +----- > > drivers/net/ethernet/broadcom/bcmsysport.c | 6 +----- > > drivers/thermal/intel/intel_powerclamp.c | 9 +++------ > > 3 files changed, 5 insertions(+), 16 deletions(-) > [...] > > Looks good, Does it mean Acked-by, Reviewed-by, or something else? > but I think this needs to be split per subsystem. What you ask breaks rules: Documentation/process/submitting-patches.rst: Separate each **logical change** into a separate patch. For example, if your changes include both bug fixes and performance enhancements for a single driver, separate those changes into two or more patches. If your changes include an API update, and a new driver which uses that new API, separate those into two patches. On the other hand, if you make a single change to numerous files, group those changes into a single patch. Thus a single logical change is contained within a single patch. This is not a dead rule, refer for example the 96d4f267e40f9 ("Remove 'type' argument from access_ok() functioin.") Or this: https://lkml.org/lkml/2021/6/14/1736 Thanks, Yury
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 3867f3d4545f..9a10d80125d9 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1620,12 +1620,8 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, return 0; } - if (bitmap_weight(free_bins, dev->num_arl_bins) == 0) - return -ENOSPC; - *idx = find_first_bit(free_bins, dev->num_arl_bins); - - return -ENOENT; + return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT; } static int b53_arl_op(struct b53_device *dev, int op, int port, diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 40933bf5a710..241696fdc6c7 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2177,13 +2177,9 @@ static int bcm_sysport_rule_set(struct bcm_sysport_priv *priv, if (nfc->fs.ring_cookie != RX_CLS_FLOW_WAKE) return -EOPNOTSUPP; - /* All filters are already in use, we cannot match more rules */ - if (bitmap_weight(priv->filters, RXCHK_BRCM_TAG_MAX) == - RXCHK_BRCM_TAG_MAX) - return -ENOSPC; - index = find_first_zero_bit(priv->filters, RXCHK_BRCM_TAG_MAX); if (index >= RXCHK_BRCM_TAG_MAX) + /* All filters are already in use, we cannot match more rules */ return -ENOSPC; /* Location is the classification ID, and index is the position diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c index 14256421d98c..c841ab37e7c6 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -556,12 +556,9 @@ static void end_power_clamp(void) * stop faster. */ clamping = false; - if (bitmap_weight(cpu_clamping_mask, num_possible_cpus())) { - for_each_set_bit(i, cpu_clamping_mask, num_possible_cpus()) { - pr_debug("clamping worker for cpu %d alive, destroy\n", - i); - stop_power_clamp_worker(i); - } + for_each_set_bit(i, cpu_clamping_mask, num_possible_cpus()) { + pr_debug("clamping worker for cpu %d alive, destroy\n", i); + stop_power_clamp_worker(i); } }
Don't call bitmap_weight() if the following code can get by without it. Signed-off-by: Yury Norov <yury.norov@gmail.com> --- drivers/net/dsa/b53/b53_common.c | 6 +----- drivers/net/ethernet/broadcom/bcmsysport.c | 6 +----- drivers/thermal/intel/intel_powerclamp.c | 9 +++------ 3 files changed, 5 insertions(+), 16 deletions(-)