[Barrelfish-users] Is coremask code correct?

Kornilios Kourtis kornilios.kourtis at inf.ethz.ch
Tue Jun 11 12:15:59 CEST 2013


Hi,

On Sun, Jun 09, 2013 at 11:42:44AM +0800, Wang Nan wrote:
> Hi,
> 
> in include/barrelfish/types.h:
> 
> 
> // MAX_COREID is 255
> typedef uint64_t _coremask_word_t;
> #define _COREMASK_BITS_PER_WORD (sizeof(_coremask_word_t) * NBBY)
> #define _COREMASK_WORDS DIVIDE_ROUND_UP(MAX_COREID, _COREMASK_BITS_PER_WORD)
> 
> typedef struct {
>     _coremask_word_t bits[_COREMASK_WORDS];
> } coremask_t;
> 
> _COREMASK_WORDS is 4
> 
> 
> in lib/barrelfish/coreset.c:
> 
> errval_t coreset_to_coremask(struct coreset *set, coremask_t *mask)
> {
>     memset(mask->bits, 0, sizeof(mask->bits));
> 
>     for (int i = 0; i < MAX_COREID; i++) {
>         if (coreset_test(set, i)) {
>             mask->bits[i % _COREMASK_BITS_PER_WORD]
>                 |= (_coremask_word_t)1 << (i / _COREMASK_BITS_PER_WORD);
>         }
>     }
> 
>     return SYS_ERR_OK;
> }
> 
> if i larger than 4, setting mask->bits causes problem.
> 
> should we enlarge coremask_t or fix setting of mask->bits (swap index
> and value)?

Thanks for spotting this. I didn't write the code, but I think that the
original intention was  to use _COREMASK_WORDS instead of
_COREMASK_BITS_PER_WORD in the above code.

So something like:
|   for (int i = 0; i < MAX_COREID; i++) {
|       if (coreset_test(set, i)) {
|           int div = i / _COREMASK_WORDS;
|           int mod = i % _COREMASK_WORDS;
|           mask->bits[mod] |= (_coremask_word_t)1 << div;
|       }
|   }

This seems a somewhat unorthodox encoding, but AFAICT it should work.
coreset_from_coremask(), coreset_{add,remove,test} have the same problem
as well.

cheers,
Kornilios.

-- 
Kornilios Kourtis



More information about the Barrelfish-users mailing list