while ( (l1i = ffs(l1)) != 0 ) ^^ { l1i--; l1 &= ~(1 << l1i); l2 = s->evtchn_pending[l1i] & ~s->evtchn_mask[l1i]; while ( (l2i = ffs(l2)) != 0 ) ^^ { l2i--; l2 &= ~(1 << l2i); port = (l1i << 5) + l2i; this is in: "../linux-2.4.26-xenU/arch/xen/kernel/evtchn.c" The problem is that ffs will return -1 if l1 is 0. Yeah, I know, unlikely, but if it ever happens that l1 or l2 are 0, well, you''re in for a fun time. In any event, the loop condition holds for both a valid result and an error, which may not be what you really want to do. In the plan 9 port this is: while ( (l1i = ffs(l1)) > 0 ) ^ { l1i--; l1 &= ~(1 << l1i); l2 = s->evtchn_pending[l1i] & ~s->evtchn_mask[l1i]; while ( (l2i = ffs(l2)) > 0 ) ^ { l2i--; l2 &= ~(1 << l2i); port = (l1i << 5) + l2i; A little paranoid, I realize, but mistakes happen. I can''t think of a case where this would happen, but what the heck. Maybe if l1 is 0 it should complain ... BTW my little patch for level (not edge) VIRQ_TIMER interrupts is giving me something more like what I expect from timer interrupts. I hope you''ll at least consider the idea. ron -- LANL CCS-1 email flavor: ***** Correspondence [] ***** DUSA LACSI-HW [ ] ***** DUSA LACSI-OS [x ] ***** DUSA LACSI-CS [ ] ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
Christian Limpach
2004-Aug-10 08:41 UTC
Re: [Xen-devel] question on the use of fs in evtchn.c
On Mon, Aug 09, 2004 at 10:40:10PM -0600, ron minnich wrote:> The problem is that ffs will return -1 if l1 is 0. Yeah, I know, unlikely, > but if it ever happens that l1 or l2 are 0, well, you''re in for a fun > time. In any event, the loop condition holds for both a valid result and > an error, which may not be what you really want to do.If you look at the definition of ffs in xen/include/asm-x86/bitops.h, you''ll see that we return 0 in the "error" case (i.e. input was 0).> In the plan 9 port this is: > while ( (l1i = ffs(l1)) > 0 )If your ffs indeed returns -1 if l1 is 0, shouldn''t your test be >= 0? Or does it never return 0? christian ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
On Mon, 9 Aug 2004, ron minnich wrote:> > while ( (l1i = ffs(l1)) != 0 ) > ^^never mind, I was lying down for 5 minutes and realized I''d misread the assembly (again). sorry, forget this. ron -- LANL CCS-1 email flavor: ***** Correspondence [X] ***** DUSA LACSI-HW [ ] ***** DUSA LACSI-OS [ ] ***** DUSA LACSI-CS [ ] ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
On Tue, 10 Aug 2004, Christian Limpach wrote:> > > In the plan 9 port this is: > > while ( (l1i = ffs(l1)) > 0 ) > > If your ffs indeed returns -1 if l1 is 0, shouldn''t your test be >= 0? > Or does it never return 0?no, this began as my misreading of how ffs worked (I thought it worked like the x86 instruction but it is 1, not 0- based) and proceeded to further errors on my part :-) sorry! ron -- LANL CCS-1 email flavor: ***** Correspondence [X] ***** DUSA LACSI-HW [ ] ***** DUSA LACSI-OS [ ] ***** DUSA LACSI-CS [ ] ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel