From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:23 +0000 (-0700) Subject: lib/poll: Trim PollClassSet X-Git-Tag: stable-10.2.0~363 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4a8aecf2d148ce11afbad939beb7b629a8970263;p=thirdparty%2Fopen-vm-tools.git lib/poll: Trim PollClassSet We no longer need per-VCPU poll classes, trim PollClassSet down to a non-array size. Tweak a few pollInt.h algorithms so that compile-time-constant PollClass values can be constant-folded. --- diff --git a/open-vm-tools/lib/include/poll.h b/open-vm-tools/lib/include/poll.h index 75d221a09..67297ede2 100644 --- a/open-vm-tools/lib/include/poll.h +++ b/open-vm-tools/lib/include/poll.h @@ -108,7 +108,7 @@ typedef enum PollClass { POLL_CLASS_MKS, POLL_FIXED_CLASSES, /* Size enum to maximum */ - POLL_MAX_CLASSES = 540, + POLL_MAX_CLASSES = 31, } PollClass; @@ -117,16 +117,14 @@ typedef enum PollClass { */ typedef struct PollClassSet { - /* Type is uintptr_t to give best 32/64-bit code. */ -#define _POLL_ELEMSIZE (sizeof (uintptr_t) * 8) - uintptr_t bits[CEILING(POLL_MAX_CLASSES, _POLL_ELEMSIZE)]; + uintptr_t bits; } PollClassSet; /* An empty PollClassSet. */ static INLINE PollClassSet PollClassSet_Empty(void) { - PollClassSet set = { { 0 } }; + PollClassSet set = { 0 }; return set; } @@ -136,12 +134,10 @@ PollClassSet_Singleton(PollClass c) { PollClassSet s = PollClassSet_Empty(); - ASSERT_ON_COMPILE(sizeof s.bits[0] * 8 == _POLL_ELEMSIZE); /* Size correct */ - ASSERT_ON_COMPILE((_POLL_ELEMSIZE & (_POLL_ELEMSIZE - 1)) == 0); /* power of 2 */ - ASSERT_ON_COMPILE(POLL_MAX_CLASSES <= ARRAYSIZE(s.bits) * _POLL_ELEMSIZE); + ASSERT_ON_COMPILE(POLL_MAX_CLASSES < sizeof s.bits * 8); ASSERT(c < POLL_MAX_CLASSES); - s.bits[c / _POLL_ELEMSIZE] = CONST3264U(1) << (c % _POLL_ELEMSIZE); + s.bits = CONST3264U(1) << c; return s; } @@ -149,13 +145,9 @@ PollClassSet_Singleton(PollClass c) static INLINE PollClassSet PollClassSet_Union(PollClassSet lhs, PollClassSet rhs) { - PollClassSet u; - unsigned i; - - for (i = 0; i < ARRAYSIZE(u.bits); i++) { - u.bits[i] = lhs.bits[i] | rhs.bits[i]; - } - return u; + PollClassSet set; + set.bits = lhs.bits | rhs.bits; + return set; } /* Add single class to PollClassSet. */ diff --git a/open-vm-tools/lib/include/pollImpl.h b/open-vm-tools/lib/include/pollImpl.h index 2a5b1edfa..366f8a2ea 100644 --- a/open-vm-tools/lib/include/pollImpl.h +++ b/open-vm-tools/lib/include/pollImpl.h @@ -45,6 +45,7 @@ #include "includeCheck.h" #include "poll.h" +#include "vm_basic_asm.h" #if defined(__cplusplus) extern "C" { @@ -84,22 +85,14 @@ void Poll_InitWithImpl(const PollImpl *impl); static INLINE Bool PollClassSet_IsMember(PollClassSet set, PollClass c) { - ASSERT(c < POLL_MAX_CLASSES); - return ((set.bits[c / _POLL_ELEMSIZE] >> (c % _POLL_ELEMSIZE)) & 0x1) != 0; + return (set.bits & PollClassSet_Singleton(c).bits) != 0; } /* Compare two PollClassSets. */ static INLINE Bool PollClassSet_Equals(PollClassSet lhs, PollClassSet rhs) { - unsigned i; - - for (i = 0; i < ARRAYSIZE(lhs.bits); i++) { - if (lhs.bits[i] != rhs.bits[i]) { - return FALSE; - } - } - return TRUE; + return lhs.bits == rhs.bits; } /* Verifies if the class set is empty. */ @@ -113,27 +106,15 @@ PollClassSet_IsEmpty(PollClassSet cs) static INLINE void PollClassSet_Remove(PollClassSet *set, PollClass c) { - ASSERT(c < POLL_MAX_CLASSES); - set->bits[c / _POLL_ELEMSIZE] &= ~(CONST3264U(1) << (c % _POLL_ELEMSIZE)); + set->bits &= ~PollClassSet_Singleton(c).bits; } /* Find first set. POLL_MAX_CLASSES for none set. */ static INLINE PollClass PollClassSet_FFS(PollClassSet *set) { - unsigned i, j; - - /* XXX TODO: use lssbPtr */ - for (i = 0; i < ARRAYSIZE(set->bits); i++) { - if (set->bits[i] != 0) { - for (j = 0; j < _POLL_ELEMSIZE; j++) { - if ((set->bits[i] & (CONST3264U(1) << j)) != 0) { - PollClass c = (PollClass)(i * _POLL_ELEMSIZE + j); - ASSERT(c < POLL_MAX_CLASSES); - return c; - } - } - } + if (set->bits != 0) { + return lssbPtr_0(set->bits); } return POLL_MAX_CLASSES; }