All modifications to the watchdog_inuse_map happen with d->watchdog_lock held, so there are no concurrency problems to deal with.
Furthermore, there is no need to use a loop to locate the next available watchdog. As the bitmap is currently 2 bits wide and is stored in a uint32_t, the next available timer can be located in O(1) time using bit-scanning instructions. No change in behaviour, but should have less cache-coherency impact. Signed-off-by: Andrew Cooper <andrew.coop...@citrix.com> --- CC: Jan Beulich <jbeul...@suse.com> CC: Wei Liu <wei.l...@citrix.com> CC: Roger Pau Monné <roger....@citrix.com> CC: Stefano Stabellini <sstabell...@kernel.org> CC: Julien Grall <julien.gr...@arm.com> CC: George Dunlap <george.dun...@eu.citrix.com> CC: Edwin Török <edvin.to...@citrix.com> CC: Christian Lindig <christian.lin...@citrix.com> CC: Pau Ruiz Safont <pau.saf...@citrix.com> --- xen/common/schedule.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 89aba88..98c2c35 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1068,17 +1068,15 @@ static long domain_watchdog(struct domain *d, uint32_t id, uint32_t timeout) } else /* Allocate the next available timer. */ { - for ( id = 0; id < NR_DOMAIN_WATCHDOG_TIMERS; id++ ) - { - if ( test_and_set_bit(id, &d->watchdog_inuse_map) ) - continue; - break; - } - if ( id == NR_DOMAIN_WATCHDOG_TIMERS ) + id = ffs(~d->watchdog_inuse_map) - 1; + + if ( unlikely(id >= NR_DOMAIN_WATCHDOG_TIMERS) ) { rc = -ENOSPC; goto unlock; } + + __set_bit(id, &d->watchdog_inuse_map); rc = id + 1; } @@ -1086,7 +1084,7 @@ static long domain_watchdog(struct domain *d, uint32_t id, uint32_t timeout) if ( unlikely(timeout == 0) ) { stop_timer(&d->watchdog_timer[id]); - clear_bit(id, &d->watchdog_inuse_map); + __clear_bit(id, &d->watchdog_inuse_map); } else set_timer(&d->watchdog_timer[id], NOW() + SECONDS(timeout)); -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel