include/ccKVS/inline_util.h
static inline void request_bookkeeping(bool multiget, int* pull_ptr, uint16_t qp_i, uint32_t* per_qp_buf_slots,
									   struct mica_op** next_req_ptr, uint16_t* received_messages, uint16_t* per_qp_received_messages,
									   struct wrkr_ud_req* req, uint16_t* get_i, uint16_t wr_i, struct ibv_send_wr* wr, long long* nb_tx_tot,
									   int* clt_i, uint32_t* index, uint16_t send_qp_i, struct hrd_ctrl_blk* cb, uint16_t wrkr_lid,
									   int push_ptr, uint16_t* last_measured_wr_i, uint8_t* requests_per_message)
{
	struct ibv_wc send_wc;
	if (!multiget) {
		MOD_ADD_WITH_BASE(pull_ptr[qp_i], per_qp_buf_slots[qp_i], 0);
		(*index) = pull_ptr[qp_i];
		(*next_req_ptr) = (struct mica_op *) &(req[*index].m_op);
		if (ENABLE_ASSERTIONS) assert((*next_req_ptr)->opcode == MICA_OP_GET || (*next_req_ptr)->opcode == MICA_OP_PUT);
		requests_per_message[(*received_messages)] = 1;
		(*received_messages)++;
		per_qp_received_messages[qp_i]++;
	}
	else { // if multiget
		(*get_i)++;
		if ((*get_i) > 1) { // move to the next get req
			// hrd_green_printf("Multiget is moving to get_i  %d, get_num %d\n", (*get_i), get_num );
			(*next_req_ptr) = (struct mica_op *)(req[(*index)].m_op.value + (((*get_i) - 2) * HERD_GET_REQ_SIZE));
		}
	}


	if ((ENABLE_WORKER_COALESCING == 0) || ((multiget == 0) || (*get_i == 1))) {

		if (wr_i > 0) wr[wr_i - 1].next = &wr[wr_i];
		wr[wr_i].send_flags = ((nb_tx_tot[send_qp_i] % WORKER_SS_BATCH) == 0)
							  ? IBV_SEND_SIGNALED : 0;
		if ((nb_tx_tot[send_qp_i] % WORKER_SS_BATCH) == WORKER_SS_BATCH - 1) {
			hrd_poll_cq(cb->dgram_send_cq[send_qp_i], 1, &send_wc);
		}
		if (WORKER_ENABLE_INLINING == 1) wr[wr_i].send_flags |= IBV_SEND_INLINE;
		(*clt_i) = (*next_req_ptr)->key.rem_meta.clt_gid;
		wr[wr_i].wr.ud.ah = remote_clt_qp[(*clt_i)][REMOTE_UD_QP_ID].ah;
		wr[wr_i].wr.ud.remote_qpn = remote_clt_qp[(*clt_i)][REMOTE_UD_QP_ID].qpn;

		//		green_printf("Creating a request %d for client %d\n", wr_i, *clt_i);

		if (ENABLE_ASSERTIONS)
			worker_remote_request_error_checking(pull_ptr[qp_i], per_qp_buf_slots[qp_i], *next_req_ptr,
												 wrkr_lid, qp_i, wr_i, &req[*index], nb_tx_tot[send_qp_i],
												 push_ptr, *clt_i, multiget, *get_i);
		nb_tx_tot[send_qp_i]++;
	}

	if (MEASURE_LATENCY == 1) {
		cache_meta *tmp = (cache_meta *) &(*next_req_ptr)->key.rem_meta;
		if (tmp->state != 0) {
			if ((ENABLE_WORKER_COALESCING == 0) || ((multiget == 0) || (*get_i == 1)))
				*last_measured_wr_i = wr_i;
			else
				*last_measured_wr_i = wr_i - 1;
				//			printf("I see a req for measuring from client %d, state: %d wr_i %d\n", *clt_i, tmp->state, wr_i);
			wr[*last_measured_wr_i].opcode = IBV_WR_SEND_WITH_IMM;
			wr[*last_measured_wr_i].imm_data = REMOTE_LATENCY_MARK;
			//			(*clt_i) -= CLIENT_NUM;
		}
	}

}
//do the required bookkeeping for a request
do the required bookkeeping for a request
do the required bookkeeping for a request
static inline void request_bookkeeping(bool multiget, int* pull_ptr, uint16_t qp_i, uint32_t* per_qp_buf_slots,
									   struct mica_op** next_req_ptr, uint16_t* received_messages, uint16_t* per_qp_received_messages,
									   struct wrkr_ud_req* req, uint16_t* get_i, uint16_t wr_i, struct ibv_send_wr* wr, long long* nb_tx_tot,
									   int* clt_i, uint32_t* index, uint16_t send_qp_i, struct hrd_ctrl_blk* cb, uint16_t wrkr_lid,
									   int push_ptr, uint16_t* last_measured_wr_i, uint8_t* requests_per_message)
{
	struct ibv_wc send_wc;
	if (!multiget) {
		MOD_ADD_WITH_BASE(pull_ptr[qp_i], per_qp_buf_slots[qp_i], 0);
		(*index) = pull_ptr[qp_i];
		(*next_req_ptr) = (struct mica_op *) &(req[*index].m_op);
		if (ENABLE_ASSERTIONS) assert((*next_req_ptr)->opcode == MICA_OP_GET || (*next_req_ptr)->opcode == MICA_OP_PUT);
		requests_per_message[(*received_messages)] = 1;
		(*received_messages)++;
		per_qp_received_messages[qp_i]++;
	}
	else { 
		(*get_i)++;
		if ((*get_i) > 1) { 
			(*next_req_ptr) = (struct mica_op *)(req[(*index)].m_op.value + (((*get_i) - 2) * HERD_GET_REQ_SIZE));
		}
	}
	if ((ENABLE_WORKER_COALESCING == 0) || ((multiget == 0) || (*get_i == 1))) {
		if (wr_i > 0) wr[wr_i - 1].next = &wr[wr_i];
		wr[wr_i].send_flags = ((nb_tx_tot[send_qp_i] % WORKER_SS_BATCH) == 0)
							  ? IBV_SEND_SIGNALED : 0;
		if ((nb_tx_tot[send_qp_i] % WORKER_SS_BATCH) == WORKER_SS_BATCH - 1) {
			hrd_poll_cq(cb->dgram_send_cq[send_qp_i], 1, &send_wc);
		}
		if (WORKER_ENABLE_INLINING == 1) wr[wr_i].send_flags |= IBV_SEND_INLINE;
		(*clt_i) = (*next_req_ptr)->key.rem_meta.clt_gid;
		wr[wr_i].wr.ud.ah = remote_clt_qp[(*clt_i)][REMOTE_UD_QP_ID].ah;
		wr[wr_i].wr.ud.remote_qpn = remote_clt_qp[(*clt_i)][REMOTE_UD_QP_ID].qpn;
		if (ENABLE_ASSERTIONS)
			worker_remote_request_error_checking(pull_ptr[qp_i], per_qp_buf_slots[qp_i], *next_req_ptr,
												 wrkr_lid, qp_i, wr_i, &req[*index], nb_tx_tot[send_qp_i],
												 push_ptr, *clt_i, multiget, *get_i);
		nb_tx_tot[send_qp_i]++;
	}
	if (MEASURE_LATENCY == 1) {
		cache_meta *tmp = (cache_meta *) &(*next_req_ptr)->key.rem_meta;
		if (tmp->state != 0) {
			if ((ENABLE_WORKER_COALESCING == 0) || ((multiget == 0) || (*get_i == 1)))
				*last_measured_wr_i = wr_i;
			else
				*last_measured_wr_i = wr_i - 1;
			wr[*last_measured_wr_i].opcode = IBV_WR_SEND_WITH_IMM;
			wr[*last_measured_wr_i].imm_data = REMOTE_LATENCY_MARK;
		}
	}
}
static inline void request_bookkeeping ( bool multiget , int * pull_ptr , uint16_t qp_i , uint32_t * per_qp_buf_slots , struct mica_op * * next_req_ptr , uint16_t * received_messages , uint16_t * per_qp_received_messages , struct wrkr_ud_req * req , uint16_t * get_i , uint16_t wr_i , struct ibv_send_wr * wr , long long * nb_tx_tot , int * clt_i , uint32_t * index , uint16_t send_qp_i , struct hrd_ctrl_blk * cb , uint16_t wrkr_lid , int push_ptr , uint16_t * last_measured_wr_i , uint8_t * requests_per_message ) { struct ibv_wc send_wc ; if ( ! multiget ) { MOD_ADD_WITH_BASE ( pull_ptr [ qp_i ] , per_qp_buf_slots [ qp_i ] , 0 ) ; ( * index ) = pull_ptr [ qp_i ] ; ( * next_req_ptr ) = ( struct mica_op * ) & ( req [ * index ] . m_op ) ; if ( ENABLE_ASSERTIONS ) assert ( ( * next_req_ptr ) -> opcode == MICA_OP_GET || ( * next_req_ptr ) -> opcode == MICA_OP_PUT ) ; requests_per_message [ ( * received_messages ) ] = 1 ; ( * received_messages ) ++ ; per_qp_received_messages [ qp_i ] ++ ; } else { ( * get_i ) ++ ; if ( ( * get_i ) > 1 ) { ( * next_req_ptr ) = ( struct mica_op * ) ( req [ ( * index ) ] . m_op . value + ( ( ( * get_i ) - 2 ) * HERD_GET_REQ_SIZE ) ) ; } } if ( ( ENABLE_WORKER_COALESCING == 0 ) || ( ( multiget == 0 ) || ( * get_i == 1 ) ) ) { if ( wr_i > 0 ) wr [ wr_i - 1 ] . next = & wr [ wr_i ] ; wr [ wr_i ] . send_flags = ( ( nb_tx_tot [ send_qp_i ] % WORKER_SS_BATCH ) == 0 ) ? IBV_SEND_SIGNALED : 0 ; if ( ( nb_tx_tot [ send_qp_i ] % WORKER_SS_BATCH ) == WORKER_SS_BATCH - 1 ) { hrd_poll_cq ( cb -> dgram_send_cq [ send_qp_i ] , 1 , & send_wc ) ; } if ( WORKER_ENABLE_INLINING == 1 ) wr [ wr_i ] . send_flags |= IBV_SEND_INLINE ; ( * clt_i ) = ( * next_req_ptr ) -> key . rem_meta . clt_gid ; wr [ wr_i ] . wr . ud . ah = remote_clt_qp [ ( * clt_i ) ] [ REMOTE_UD_QP_ID ] . ah ; wr [ wr_i ] . wr . ud . remote_qpn = remote_clt_qp [ ( * clt_i ) ] [ REMOTE_UD_QP_ID ] . qpn ; if ( ENABLE_ASSERTIONS ) worker_remote_request_error_checking ( pull_ptr [ qp_i ] , per_qp_buf_slots [ qp_i ] , * next_req_ptr , wrkr_lid , qp_i , wr_i , & req [ * index ] , nb_tx_tot [ send_qp_i ] , push_ptr , * clt_i , multiget , * get_i ) ; nb_tx_tot [ send_qp_i ] ++ ; } if ( MEASURE_LATENCY == 1 ) { cache_meta * tmp = ( cache_meta * ) & ( * next_req_ptr ) -> key . rem_meta ; if ( tmp -> state != 0 ) { if ( ( ENABLE_WORKER_COALESCING == 0 ) || ( ( multiget == 0 ) || ( * get_i == 1 ) ) ) * last_measured_wr_i = wr_i ; else * last_measured_wr_i = wr_i - 1 ; wr [ * last_measured_wr_i ] . opcode = IBV_WR_SEND_WITH_IMM ; wr [ * last_measured_wr_i ] . imm_data = REMOTE_LATENCY_MARK ; } } }
do the required bookkeeping for a request
do the required bookkeeping for a request
// if multiget // move to the next get req // hrd_green_printf("Multiget is moving to get_i  %d, get_num %d\n", (*get_i), get_num ); //		green_printf("Creating a request %d for client %d\n", wr_i, *clt_i); //			printf("I see a req for measuring from client %d, state: %d wr_i %d\n", *clt_i, tmp->state, wr_i); //			(*clt_i) -= CLIENT_NUM;