iio: dummy: evgen: use irq_sim
PATCH 1/1 iio: dummy: evgen: use irq_sim
Switch to using the recently added interrupt simulator for dummy irqs.
---
bloat-o-meter output:
add/remove: 0/3 grow/shrink: 1/5 up/down: 12/-540 (-528)
function old new delta iio_dummy_evgen_get_irq 136 148 +12 iio_evgen_release 40 36 -4 iio_dummy_evgen_get_regs 32 28 -4 iio_dummy_work_handler 20 - -20 iio_dummy_event_irqunmask 32 - -32 iio_dummy_event_irqmask 32 - -32 iio_evgen_poke 140 100 -40 init_module 376 172 -204 iio_dummy_evgen_init 376 172 -204
Total: Before=2804, After=2276, chg -18.83%
drivers/iio/dummy/Kconfig | 2 +- drivers/iio/dummy/iio_dummy_evgen.c | 91 ++++++++----------------------------- 2 files changed, 20 insertions(+), 73 deletions(-)
drivers/iio/dummy/Kconfig +1 -1
@@ -5,7 +5,7 @@ menu "IIO dummy driver" depends on IIO config IIO_DUMMY_EVGEN - select IRQ_WORK + select IRQ_SIM tristate config IIO_SIMPLE_DUMMY
drivers/iio/dummy/iio_dummy_evgen.c +19 -72
147 lines not on this page · raw message
Signature · 1 line
2.13.2
Quoted 3 lines · Bartosz Golaszewski
Switch to using the recently added interrupt simulator for dummy irqs.
Signed-off-by Bartosz Golaszewski <[email protected]>
Thanks for doing this.
[...]
Quoted 5 lines
static int
iio_dummy_evgen_create(void)
{drivers/iio/dummy/iio_dummy_evgen.c +1
-1-int ret, i; +int ret;
drivers/iio/dummy/iio_dummy_evgen.c line 59
Quoted 10 lines
drivers/iio/dummy/iio_dummy_evgen.c +2
-4iio_evgen =kzalloc (sizeof (*iio_evgen),GFP_KERNEL );if (!iio_evgen)return -ENOMEM ; - iio_evgen->base =irq_alloc_descs (-1 ,0 ,IIO_EVENTGEN_NO ,0 ); -if (iio_evgen->base <0 ) { - ret = iio_evgen->base; -kfree (iio_evgen); + ret =irq_sim_init (&iio_evgen->irq_sim,IIO_EVENTGEN_NO ); +if (ret)
What happened to the kfree(iio_evgen)?
Quoted 5 lines
drivers/iio/dummy/iio_dummy_evgen.c +0
-4return ret; - } - iio_evgen->chip.name = iio_evgen_name; - iio_evgen->chip.irq_mask = &iio_dummy_event_irqmask; - iio_evgen->chip.irq_unmask = &iio_dummy_event_irqunmask;
drivers/iio/dummy/iio_dummy_evgen.c line 62
Quoted 10 lines
drivers/iio/dummy/iio_dummy_evgen.c +2
-8-for (i =0 ; i <IIO_EVENTGEN_NO ; i++) { -irq_set_chip (iio_evgen->base + i, &iio_evgen->chip); -irq_set_handler (iio_evgen->base + i, &handle_simple_irq); -irq_modify_status (iio_evgen->base + i, -IRQ_NOREQUEST |IRQ_NOAUTOEN , -IRQ_NOPROBE ); - } -init_irq_work (&iio_evgen->handler.work, iio_dummy_work_handler); + + iio_evgen->base =irq_sim_irqnum (&iio_evgen->irq_sim,0 );
I saw you introduced irq_sim_baseirq(), to get rid of ->base. But as far as I can see the only remaining places where we need the base is to do the reverse lookup from IRQ to index. It would be nice if the irq_sim had a function for that, then we wouldn't have to know about the base at all.
Quoted 24 lines
drivers/iio/dummy/iio_dummy_evgen.c +5
-2mutex_init (&iio_evgen->lock); +return 0 ; }@@ -132,15 +79,17 @@ int iio_dummy_evgen_get_irq(void)return -ENODEV ;mutex_lock (&iio_evgen->lock); -for (i =0 ; i <IIO_EVENTGEN_NO ; i++) +for (i =0 ; i <IIO_EVENTGEN_NO ; i++) {if (!iio_evgen->inuse[i]) { - ret = iio_evgen->base + i; + ret =irq_sim_irqnum (&iio_evgen->irq_sim, i); iio_evgen->inuse[i] = true;break ; } + }mutex_unlock (&iio_evgen->lock);if (i ==IIO_EVENTGEN_NO )return -ENOMEM ; +return ret; }
2017-09-27 19:12 GMT+02:00 Lars-Peter Clausen <[email protected]>:
Quoted 17 lines · Bartosz Golaszewski
Quoted 3 lines
Switch to using the recently added interrupt simulator for dummy irqs.
Signed-off-by Bartosz Golaszewski <[email protected]>Thanks for doing this.
[...]
Quoted 9 lines
static int
iio_dummy_evgen_create(void)
{drivers/iio/dummy/iio_dummy_evgen.c +1
-1-int ret, i; +int ret; iio_evgen =kzalloc (sizeof (*iio_evgen),GFP_KERNEL );if (!iio_evgen)return -ENOMEM ;
Quoted 9 lines
drivers/iio/dummy/iio_dummy_evgen.c line 59
Quoted 6 lines
drivers/iio/dummy/iio_dummy_evgen.c +2
-4- iio_evgen->base =irq_alloc_descs (-1 ,0 ,IIO_EVENTGEN_NO ,0 ); -if (iio_evgen->base <0 ) { - ret = iio_evgen->base; -kfree (iio_evgen); + ret =irq_sim_init (&iio_evgen->irq_sim,IIO_EVENTGEN_NO ); +if (ret)What happened to the
kfree(iio_evgen)?
Oops, nice catch, thanks!
Quoted 15 lines
Quoted 5 lines
return ret;drivers/iio/dummy/iio_dummy_evgen.c +0
-4- } - iio_evgen->chip.name = iio_evgen_name; - iio_evgen->chip.irq_mask = &iio_dummy_event_irqmask; - iio_evgen->chip.irq_unmask = &iio_dummy_event_irqunmask;drivers/iio/dummy/iio_dummy_evgen.c line 62
Quoted 10 lines
drivers/iio/dummy/iio_dummy_evgen.c +2
-8-for (i =0 ; i <IIO_EVENTGEN_NO ; i++) { -irq_set_chip (iio_evgen->base + i, &iio_evgen->chip); -irq_set_handler (iio_evgen->base + i, &handle_simple_irq); -irq_modify_status (iio_evgen->base + i, -IRQ_NOREQUEST |IRQ_NOAUTOEN , -IRQ_NOPROBE ); - } -init_irq_work (&iio_evgen->handler.work, iio_dummy_work_handler); + + iio_evgen->base =irq_sim_irqnum (&iio_evgen->irq_sim,0 );
Quoted 5 lines
I saw you introduced
irq_sim_baseirq(), to get rid of ->base. But as far as I can see the only remaining places where we need the base is to do the reverse lookup from IRQ to index. It would be nice if theirq_simhad a function for that, then we wouldn't have to know about the base at all.
I'm not sure I understand. Irq sim doesn't know anything about iio data structures, so how would such a reverse lookup work in this case?
Best regards,
Bartosz Golaszewski
Quoted 15 lines · Bartosz Golaszewski
Quoted 15 lines
Quoted 15 lines
return ret;drivers/iio/dummy/iio_dummy_evgen.c +2
-12- } - iio_evgen->chip.name = iio_evgen_name; - iio_evgen->chip.irq_mask = &iio_dummy_event_irqmask; - iio_evgen->chip.irq_unmask = &iio_dummy_event_irqunmask; -for (i =0 ; i <IIO_EVENTGEN_NO ; i++) { -irq_set_chip (iio_evgen->base + i, &iio_evgen->chip); -irq_set_handler (iio_evgen->base + i, &handle_simple_irq); -irq_modify_status (iio_evgen->base + i, -IRQ_NOREQUEST |IRQ_NOAUTOEN , -IRQ_NOPROBE ); - } -init_irq_work (&iio_evgen->handler.work, iio_dummy_work_handler); + + iio_evgen->base =irq_sim_irqnum (&iio_evgen->irq_sim,0 );
Quoted 8 lines
Quoted 5 lines
I saw you introduced
irq_sim_baseirq(), to get rid of ->base. But as far as I can see the only remaining places where we need the base is to do the reverse lookup from IRQ to index. It would be nice if theirq_simhad a function for that, then we wouldn't have to know about the base at all.I'm not sure I understand. Irq sim doesn't know anything about iio data structures, so how would such a reverse lookup work in this case?
Reverse lookup in the sense of translating IRQ number to offset. All we ever do with the base in the IIO code is irq - base to get the offset. I'd hide that calculation in a helper in the irq_sim code. This nicely splits functionality and implementation, the IIO code doesn't have to know how to get offset from the IRQ.
2017-09-28 10:04 GMT+02:00 Lars-Peter Clausen <[email protected]>:
Quoted 22 lines · Bartosz Golaszewski
Quoted 21 lines
Quoted 20 lines
Quoted 5 lines
return ret;drivers/iio/dummy/iio_dummy_evgen.c +0
-4- } - iio_evgen->chip.name = iio_evgen_name; - iio_evgen->chip.irq_mask = &iio_dummy_event_irqmask; - iio_evgen->chip.irq_unmask = &iio_dummy_event_irqunmask;drivers/iio/dummy/iio_dummy_evgen.c line 62
Quoted 10 lines
drivers/iio/dummy/iio_dummy_evgen.c +2
-8-for (i =0 ; i <IIO_EVENTGEN_NO ; i++) { -irq_set_chip (iio_evgen->base + i, &iio_evgen->chip); -irq_set_handler (iio_evgen->base + i, &handle_simple_irq); -irq_modify_status (iio_evgen->base + i, -IRQ_NOREQUEST |IRQ_NOAUTOEN , -IRQ_NOPROBE ); - } -init_irq_work (&iio_evgen->handler.work, iio_dummy_work_handler); + + iio_evgen->base =irq_sim_irqnum (&iio_evgen->irq_sim,0 );I saw you introduced
irq_sim_baseirq(), to get rid of ->base. But as far as I can see the only remaining places where we need the base is to do the reverse lookup from IRQ to index. It would be nice if theirq_simhad a function for that, then we wouldn't have to know about the base at all.
Quoted 8 lines
Quoted 2 lines
I'm not sure I understand. Irq sim doesn't know anything about iio data structures, so how would such a reverse lookup work in this case?
Reverse lookup in the sense of translating IRQ number to offset. All we ever do with the base in the IIO code is
irq - baseto get the offset. I'd hide that calculation in a helper in theirq_simcode. This nicely splits functionality and implementation, the IIO code doesn't have to know how to get offset from the IRQ.
I see. Sounds like a good improvement for 4.16. In the meantime, I'll send v2 with the missing kfree() added.
Thanks,
Bartosz