Message ID | 20220123183925.1052919-30-yury.norov@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | None | expand |
On Sun, Jan 23, 2022 at 10:39:00AM -0800, Yury Norov wrote: > drivers/iio calls bitmap_weight() to compare the weight of bitmap with > a given number. We can do it more efficiently with bitmap_weight_{eq, gt} > because conditional bitmap_weight may stop traversing the bitmap earlier, > as soon as condition is met. ... > int i, j; > > for (i = 0, j = 0; > - i < bitmap_weight(indio_dev->active_scan_mask, > - indio_dev->masklength); > + bitmap_weight_gt(indio_dev->active_scan_mask, > + indio_dev->masklength, i); > i++, j++) { > j = find_next_bit(indio_dev->active_scan_mask, > indio_dev->masklength, j); This smells like room for improvement. Have you checked this deeply?
On Mon, 24 Jan 2022 14:46:43 +0200 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Sun, Jan 23, 2022 at 10:39:00AM -0800, Yury Norov wrote: > > drivers/iio calls bitmap_weight() to compare the weight of bitmap with > > a given number. We can do it more efficiently with bitmap_weight_{eq, gt} > > because conditional bitmap_weight may stop traversing the bitmap earlier, > > as soon as condition is met. > > ... > > > int i, j; > > > > for (i = 0, j = 0; > > - i < bitmap_weight(indio_dev->active_scan_mask, > > - indio_dev->masklength); > > + bitmap_weight_gt(indio_dev->active_scan_mask, > > + indio_dev->masklength, i); > > i++, j++) { > > j = find_next_bit(indio_dev->active_scan_mask, > > indio_dev->masklength, j); > > This smells like room for improvement. Have you checked this deeply? > I have no idea what I was smoking that day. It was near 10 years ago, so I'll blame my younger self ;) Jonathan
diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c index d81c2b2dad82..670997301e47 100644 --- a/drivers/iio/dummy/iio_simple_dummy_buffer.c +++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c @@ -71,8 +71,8 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) int i, j; for (i = 0, j = 0; - i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); + bitmap_weight_gt(indio_dev->active_scan_mask, + indio_dev->masklength, i); i++, j++) { j = find_next_bit(indio_dev->active_scan_mask, indio_dev->masklength, j); diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index f504ed351b3e..98c54022fecf 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -331,7 +331,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig, { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(pf->indio_dev); bool no_other_users = - bitmap_weight(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER) == 1; + bitmap_weight_eq(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER, 1); int ret = 0; if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
drivers/iio calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_{eq, gt} because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is met. Signed-off-by: Yury Norov <yury.norov@gmail.com> --- drivers/iio/dummy/iio_simple_dummy_buffer.c | 4 ++-- drivers/iio/industrialio-trigger.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)