include/ccKVS/inline_util.h
static inline void post_credit_recvs_and_batch_bcasts_to_NIC(uint16_t br_i, struct hrd_ctrl_blk *cb, struct ibv_send_wr *coh_send_wr,
															 struct ibv_recv_wr *credit_recv_wr, uint16_t *credit_recv_counter,
															 int protocol)
{
	uint16_t j;
	int ret;
	struct ibv_send_wr *bad_send_wr;
	struct ibv_recv_wr *bad_recv_wr;
	uint32_t max_credit_recvs;
	if (protocol == LINEARIZABILITY) max_credit_recvs = MAX_CREDIT_RECVS;
	else if (protocol == SEQUENTIAL_CONSISTENCY) max_credit_recvs = SC_MAX_CREDIT_RECVS;
	else if (ENABLE_ASSERTIONS) assert(false);
	if (*credit_recv_counter > 0) { // Must post receives for credits
		if (ENABLE_ASSERTIONS == 1) assert ((*credit_recv_counter) * (MACHINE_NUM - 1) <= max_credit_recvs);
		for (j = 0; j < (MACHINE_NUM - 1) * (*credit_recv_counter); j++) {
			credit_recv_wr[j].next = (j == ((MACHINE_NUM - 1) * (*credit_recv_counter)) - 1) ?	NULL : &credit_recv_wr[j + 1];
		}
		ret = ibv_post_recv(cb->dgram_qp[FC_UD_QP_ID], &credit_recv_wr[0], &bad_recv_wr);
		CPE(ret, "ibv_post_recv error: posting recvs for credits before broadcasting", ret);
		*credit_recv_counter = 0;
	}
	// Batch the broadcasts to the NIC
	if (br_i > 0) {
		coh_send_wr[(br_i * MESSAGES_IN_BCAST) - 1].next = NULL;
		ret = ibv_post_send(cb->dgram_qp[BROADCAST_UD_QP_ID], &coh_send_wr[0], &bad_send_wr);
		CPE(ret, "Broadcast ibv_post_send error", ret);
		if (CLIENT_ENABLE_INLINING == 1) coh_send_wr[0].send_flags = IBV_SEND_INLINE;
		else if (!CLIENT_ENABLE_INLINING && protocol == SEQUENTIAL_CONSISTENCY) coh_send_wr[0].send_flags = 0;
	}
}
// Broadcast logic uses this function to post appropriate number of credit recvs before sending broadcasts
Broadcast logic uses this function to post appropriate number of credit recvs before sending broadcasts
Broadcast logic uses this function to post appropriate number of credit recvs before sending broadcasts
static inline void post_credit_recvs_and_batch_bcasts_to_NIC(uint16_t br_i, struct hrd_ctrl_blk *cb, struct ibv_send_wr *coh_send_wr,
															 struct ibv_recv_wr *credit_recv_wr, uint16_t *credit_recv_counter,
															 int protocol)
{
	uint16_t j;
	int ret;
	struct ibv_send_wr *bad_send_wr;
	struct ibv_recv_wr *bad_recv_wr;
	uint32_t max_credit_recvs;
	if (protocol == LINEARIZABILITY) max_credit_recvs = MAX_CREDIT_RECVS;
	else if (protocol == SEQUENTIAL_CONSISTENCY) max_credit_recvs = SC_MAX_CREDIT_RECVS;
	else if (ENABLE_ASSERTIONS) assert(false);
	if (*credit_recv_counter > 0) { 
		if (ENABLE_ASSERTIONS == 1) assert ((*credit_recv_counter) * (MACHINE_NUM - 1) <= max_credit_recvs);
		for (j = 0; j < (MACHINE_NUM - 1) * (*credit_recv_counter); j++) {
			credit_recv_wr[j].next = (j == ((MACHINE_NUM - 1) * (*credit_recv_counter)) - 1) ?	NULL : &credit_recv_wr[j + 1];
		}
		ret = ibv_post_recv(cb->dgram_qp[FC_UD_QP_ID], &credit_recv_wr[0], &bad_recv_wr);
		CPE(ret, "ibv_post_recv error: posting recvs for credits before broadcasting", ret);
		*credit_recv_counter = 0;
	}
	if (br_i > 0) {
		coh_send_wr[(br_i * MESSAGES_IN_BCAST) - 1].next = NULL;
		ret = ibv_post_send(cb->dgram_qp[BROADCAST_UD_QP_ID], &coh_send_wr[0], &bad_send_wr);
		CPE(ret, "Broadcast ibv_post_send error", ret);
		if (CLIENT_ENABLE_INLINING == 1) coh_send_wr[0].send_flags = IBV_SEND_INLINE;
		else if (!CLIENT_ENABLE_INLINING && protocol == SEQUENTIAL_CONSISTENCY) coh_send_wr[0].send_flags = 0;
	}
}
static inline void post_credit_recvs_and_batch_bcasts_to_NIC ( uint16_t br_i , struct hrd_ctrl_blk * cb , struct ibv_send_wr * coh_send_wr , struct ibv_recv_wr * credit_recv_wr , uint16_t * credit_recv_counter , int protocol ) { uint16_t j ; int ret ; struct ibv_send_wr * bad_send_wr ; struct ibv_recv_wr * bad_recv_wr ; uint32_t max_credit_recvs ; if ( protocol == LINEARIZABILITY ) max_credit_recvs = MAX_CREDIT_RECVS ; else if ( protocol == SEQUENTIAL_CONSISTENCY ) max_credit_recvs = SC_MAX_CREDIT_RECVS ; else if ( ENABLE_ASSERTIONS ) assert ( false ) ; if ( * credit_recv_counter > 0 ) { if ( ENABLE_ASSERTIONS == 1 ) assert ( ( * credit_recv_counter ) * ( MACHINE_NUM - 1 ) <= max_credit_recvs ) ; for ( j = 0 ; j < ( MACHINE_NUM - 1 ) * ( * credit_recv_counter ) ; j ++ ) { credit_recv_wr [ j ] . next = ( j == ( ( MACHINE_NUM - 1 ) * ( * credit_recv_counter ) ) - 1 ) ? NULL : & credit_recv_wr [ j + 1 ] ; } ret = ibv_post_recv ( cb -> dgram_qp [ FC_UD_QP_ID ] , & credit_recv_wr [ 0 ] , & bad_recv_wr ) ; CPE ( ret , " " , ret ) ; * credit_recv_counter = 0 ; } if ( br_i > 0 ) { coh_send_wr [ ( br_i * MESSAGES_IN_BCAST ) - 1 ] . next = NULL ; ret = ibv_post_send ( cb -> dgram_qp [ BROADCAST_UD_QP_ID ] , & coh_send_wr [ 0 ] , & bad_send_wr ) ; CPE ( ret , " " , ret ) ; if ( CLIENT_ENABLE_INLINING == 1 ) coh_send_wr [ 0 ] . send_flags = IBV_SEND_INLINE ; else if ( ! CLIENT_ENABLE_INLINING && protocol == SEQUENTIAL_CONSISTENCY ) coh_send_wr [ 0 ] . send_flags = 0 ; } }
Broadcast logic uses this function to post appropriate number of credit recvs before sending broadcasts
Broadcast logic uses this function to post appropriate number of credit recvs before sending broadcasts
// Must post receives for credits // Batch the broadcasts to the NIC