This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thoughts on CPU set manipulation functions


On Mon, Mar 24, 2008 at 5:33 PM, Ulrich Drepper <drepper@redhat.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>
>  Bert Wesarg wrote:
>  > * a copy function (which is faster than CPU_OR(dest, src, src))
>
>  memcpy is available.
From the manual:

  The type `cpu_set_t' should be considered opaque; all manipulation
  should happen via the next four macros.


>
>
>
>  > * the 'd = s1 & ~s2' operator
>
>  Justification needed.
Really? Ok, if you need one:

Sure you can get the result by:

  cpu_set_t tmp;
  CPU_COMPLEMENT(tmp, s2);

Oops, there is no CPU_COMPLEMENT()!

Hmm, ok we have an CPU_XOR(), unlucky us we don't have something to
set all bits (ie CPU_ONES())...

Hmm, sorry I'm out of options.

If you need a justification for the operation itself, ie. for what I
need this op, honestly, the andnot operation is a very common bit
manipulation operation, if you need an example, see CPU_CLR().

By the way, its really only a two-liner:

# define CPU_ANDNOT(destset, srcset1, srcset2) \
  __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, & ~)
# define CPU_ANDNOT_S(setsize, destset, srcset1, srcset2) \
  __CPU_OP_S (setsize, destset, srcset1, srcset2, & ~)


>  > As a second point I want to suggest to include some kind of iterator
>  > functionality for the API, either as a complete opaque for loop, or a
>  > iterator function pair first_bit_set/next_bit_set.
>
>  That's not easy to do cleanly in a form which is widely applicable.
>  Make a suggestion.
I know, here is one:

-- Macro: int CPU_FIRST_SET (cpu_set_t *SET)
     This macro returns the first CPU (ie. the CPU with the smallest
id) that is in
     the CPU set SET. If no CPU is in the set, CPU_SETSIZE will be returned.

-- Macro: int CPU_NEXT_SET(cpu_set_t *SET, int CPU)
     This macro returns the CPU which has a greater id than CPU in the
CPU set SET. If no
     such CPU is in the set, CPU_SETSIZE will be returned.

These two macros can be used to iterate over all CPUs from a set:

  cpu_set_t set;
  int cpu;
  :
  for (cpu = CPU_FIRST_SET(&set);
       cpu < CPU_SETSIZE;
       cpu = CPU_NEXT_SET(&set, cpu)) {
       assert(CPU_ISSET(cpu, &set);
  }
  :

Bert
>
>  - --
>  â Ulrich Drepper â Red Hat, Inc. â 444 Castro St â Mountain View, CA â

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]