RFCL cpuset APIs

Joel Sherrill joel.sherrill at OARcorp.com
Fri Oct 11 21:06:21 UTC 2013


Hi

We are finishing up a proposal for pthread affinity APIs. We
think we should follow the Linux API but have our own
implementation.  I am trying to use the FreeBSD cpu set code
with minimal ifdefs, but there are differences which are
adding up to the point where I have a problem. Do I put in
lots of ifdef's? Or just create our own version using
the BSD version as inspiration and code fragements?

The first difference is Linux uses cpu_set_t while
FreeBSD uses cpuset_t. This can be accounted for with
a typedef. A global search and replace or using ifdefs
will result in a file with lots of changes. Assume a
typedef is OK since it minimizes impact of that.

Then you have supporting macros.  The following summarizes
the similarities and differences.

These macros appear to be the same on Linux and FreeBSD.

  void CPU_ZERO(cpu_set_t *set);
  void CPU_SET(int cpu, cpu_set_t *set);
  void CPU_CLR(int cpu, cpu_set_t *set);
  int  CPU_ISSET(int cpu, cpu_set_t *set);

For comparing sets, Linux has CPU_EQUAL while BSD has CPU_CMP.
The signature is the same so a renaming macro would address this.

  int  CPU_EQUAL(cpu_set_t *set1, cpu_set_t *set2);

FreeBSD has these extra:

  void CPU_FILL(cpu_set_t *set)
  bool CPU_EMPTY(cpu_set_t *set) /* is empty? */
  bool CPU_SUBSET(cpu_set_t *p,cpu_set_t *c) /* is c a subset of p? */
  bool CPU_OVERLAP(cpu_set_t *p,cpu_set_t *c) /* do c and p overlap? */

And these differ between FreeBSD and Linux. The Linux API has three
parameters and is performs bitwise operations on the two sources
and puts the result in destination. FreeBSD has an "|=" or "&="
and takes destination and the set to operate with. This is the
Linux API. Just drop a parameter to get FreeBSD but that makes
them incompatible.

  void CPU_AND(cpu_set_t *destset,
     cpu_set_t *srcset1, cpu_set_t *srcset2);
  void CPU_OR(cpu_set_t *destset,
     cpu_set_t *srcset1, cpu_set_t *srcset2);
  void CPU_XOR(cpu_set_t *destset,
     cpu_set_t *srcset1, cpu_set_t *srcset2);

FreeBSD also has NAND.

Comments, suggestions, thoughts welcomed.


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985



More information about the devel mailing list