Debian Codegraph @

src/mpid/ch3/channels/nemesis/include/mpid_nem_fbox.h

raw
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #ifndef MPID_NEM_FBOX_H_INCLUDED
7 #define MPID_NEM_FBOX_H_INCLUDED
8
9 typedef struct MPID_nem_fboxq_elem
10 {
11 int usage;
12 struct MPID_nem_fboxq_elem *prev;
13 struct MPID_nem_fboxq_elem *next;
14 int grank;
15 MPID_nem_fastbox_t *fbox;
16 } MPID_nem_fboxq_elem_t ;
17
18 extern MPID_nem_fboxq_elem_t *MPID_nem_fboxq_head;
19 extern MPID_nem_fboxq_elem_t *MPID_nem_fboxq_tail;
20 extern MPID_nem_fboxq_elem_t *MPID_nem_fboxq_elem_list;
21 extern MPID_nem_fboxq_elem_t *MPID_nem_fboxq_elem_list_last;
22 extern MPID_nem_fboxq_elem_t *MPID_nem_curr_fboxq_elem;
23 extern MPID_nem_fboxq_elem_t *MPID_nem_curr_fbox_all_poll;
24 extern unsigned short *MPID_nem_recv_seqno;
25 /* int MPID_nem_mpich_dequeue_fastbox (int local_rank); */
26 /* int MPID_nem_mpich_enqueue_fastbox (int local_rank); */
27
28 static inline int poll_active_fboxes(MPID_nem_cell_ptr_t *cell)
29 {
30 MPID_nem_fboxq_elem_t *orig_fboxq_elem;
31 int found = FALSE;
32
33 if (MPID_nem_fboxq_head != NULL)
34 {
35 orig_fboxq_elem = MPID_nem_curr_fboxq_elem;
36 do
37 {
38 MPID_nem_fastbox_t *fbox;
39 MPID_nem_cell_t *cell_ptr;
40
41 fbox = MPID_nem_curr_fboxq_elem->fbox;
42 MPIR_Assert(fbox != NULL);
43 cell_ptr = MPID_NEM_FBOX_TO_CELL(fbox);
44 if (MPL_atomic_acquire_load_int(&fbox->flag) &&
45 cell_ptr->header.seqno == MPID_nem_recv_seqno[MPID_nem_curr_fboxq_elem->grank])
46 {
47 ++MPID_nem_recv_seqno[MPID_nem_curr_fboxq_elem->grank];
48 *cell = cell_ptr;
49 found = TRUE;
50 goto fn_exit;
51 }
52 MPID_nem_curr_fboxq_elem = MPID_nem_curr_fboxq_elem->next;
53 if (MPID_nem_curr_fboxq_elem == NULL)
54 MPID_nem_curr_fboxq_elem = MPID_nem_fboxq_head;
55 }
56 while (MPID_nem_curr_fboxq_elem != orig_fboxq_elem);
57 }
58 *cell = NULL;
59
60 fn_exit:
61 return found;
62 }
63
64 static inline int poll_every_fbox(MPID_nem_cell_ptr_t *cell)
65 {
66 MPID_nem_fboxq_elem_t *orig_fbox_el = MPID_nem_curr_fbox_all_poll;
67 MPID_nem_fastbox_t *fbox;
68 MPID_nem_cell_t *cell_ptr;
69 int found = FALSE;
70
71 do {
72 fbox = MPID_nem_curr_fbox_all_poll->fbox;
73 cell_ptr = MPID_NEM_FBOX_TO_CELL(fbox);
74 if (fbox && MPL_atomic_acquire_load_int(&fbox->flag) &&
75 cell_ptr->header.seqno == MPID_nem_recv_seqno[MPID_nem_curr_fbox_all_poll->grank]) {
76 ++MPID_nem_recv_seqno[MPID_nem_curr_fbox_all_poll->grank];
77 *cell = cell_ptr;
78 found = TRUE;
79 break;
80 }
81 ++MPID_nem_curr_fbox_all_poll;
82 if (MPID_nem_curr_fbox_all_poll > MPID_nem_fboxq_elem_list_last)
83 MPID_nem_curr_fbox_all_poll = MPID_nem_fboxq_elem_list;
84 } while (MPID_nem_curr_fbox_all_poll != orig_fbox_el);
85
86 return found;
87 }
88
89
90 #define poll_next_fbox(_cell, do_found) \
91 do { \
92 MPID_nem_fastbox_t *fbox; \
93 MPID_nem_cell_t *cell_ptr; \
94 \
95 fbox = MPID_nem_curr_fbox_all_poll->fbox; \
96 cell_ptr = MPID_NEM_FBOX_TO_CELL(fbox); \
97 if (fbox && MPL_atomic_acquire_load_int(&fbox->flag) && \
98 cell_ptr->header.seqno == MPID_nem_recv_seqno[MPID_nem_curr_fbox_all_poll->grank]) \
99 { \
100 ++MPID_nem_recv_seqno[MPID_nem_curr_fbox_all_poll->grank]; \
101 *(_cell) = cell_ptr; \
102 do_found; \
103 } \
104 ++MPID_nem_curr_fbox_all_poll; \
105 if (MPID_nem_curr_fbox_all_poll > MPID_nem_fboxq_elem_list_last) \
106 MPID_nem_curr_fbox_all_poll = MPID_nem_fboxq_elem_list; \
107 } while(0)
108
109 #endif /* MPID_NEM_FBOX_H_INCLUDED */
110
111