Skip to content

Commit fe3941c

Browse files
committed
sentinel: fix sentinel to proc_name conversion
converting an opal_process_name_t means the loss of one bit, it was decided to restrict the local job id to 15 bits, so the useful information of an opal_process_name_t can fit in 63 bits.
1 parent 5e3f850 commit fe3941c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

ompi/proc/proc.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,42 @@ static inline bool ompi_proc_is_sentinel (ompi_proc_t *proc)
369369
return (intptr_t) proc & 0x1;
370370
}
371371

372+
/*
373+
* we assume an ompi_proc_t is at least aligned on two bytes,
374+
* so if the LSB of a pointer to an ompi_proc_t is 1, we have to handle
375+
* this pointer as a sentinel instead of a pointer.
376+
* a sentinel can be seen as a 64 bits array with the following format :
377+
* - bit 0 : 1
378+
* - bits 1-15 : local jobid
379+
* - bits 16-31 : job family
380+
* - bits 32-63 : vpid
381+
*/
372382
static inline uintptr_t ompi_proc_name_to_sentinel (opal_process_name_t name)
373383
{
374-
return (*((uintptr_t *) &name) << 1) | 0x1;
384+
uintptr_t tmp, sentinel = 0x1;
385+
/* local jobid must fit in 15 bits */
386+
assert(! (ORTE_LOCAL_JOBID(name.jobid) & 0x8000));
387+
tmp = (uintptr_t)ORTE_LOCAL_JOBID(name.jobid);
388+
sentinel |= ((tmp << 1) & 0xfffe);
389+
tmp = (uintptr_t)ORTE_JOB_FAMILY(name.jobid);
390+
sentinel |= ((tmp << 16) & 0xffff0000);
391+
tmp = (uintptr_t)name.vpid;
392+
sentinel |= ((tmp << 32) & 0xffffffff00000000);
393+
return sentinel;
375394
}
376395

377396
static inline opal_process_name_t ompi_proc_sentinel_to_name (uintptr_t sentinel)
378397
{
379-
sentinel >>= 1;
380-
return *((opal_process_name_t *) &sentinel);
398+
opal_process_name_t name;
399+
uint16_t local, family;
400+
uint32_t vpid;
401+
assert(sentinel & 0x1);
402+
local = (sentinel >> 1) & 0x7fff;
403+
family = (sentinel >> 16) & 0xffff;
404+
vpid = (sentinel >> 32) & 0xffffffff;
405+
name.jobid = ORTE_CONSTRUCT_JOBID(family,local);
406+
name.vpid = vpid;
407+
return name;
381408
}
382409

383410
END_C_DECLS

orte/util/name_fns.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ ORTE_DECLSPEC char *orte_pretty_print_timing(int64_t secs, int64_t usecs);
9797
#define ORTE_CONSTRUCT_LOCAL_JOBID(local, job) \
9898
( ((local) & 0xffff0000) | ((job) & 0x0000ffff) )
9999

100+
#define ORTE_CONSTRUCT_JOBID(family, local) \
101+
ORTE_CONSTRUCT_LOCAL_JOBID(ORTE_CONSTRUCT_JOB_FAMILY(family), local)
102+
100103
/* a macro for identifying that a proc is a daemon */
101104
#define ORTE_JOBID_IS_DAEMON(n) \
102105
!((n) & 0x0000ffff)

0 commit comments

Comments
 (0)