include/ccKVS/inline_util.h
static inline enum control_flow_directive handle_lack_of_credits_for_remotes(struct extended_cache_op* ops, struct extended_cache_op* next_ops, struct mica_resp* resp,
																			 struct mica_resp* next_resp, struct key_home* key_homes, struct key_home* next_key_homes,
																			 uint16_t* op_i, uint16_t* next_op_i, uint16_t local_client_id, struct ibv_send_wr* rem_send_wr,
																			 uint16_t* wn, uint16_t* worker_id, uint16_t rm_id, uint8_t* per_worker_outstanding, uint16_t wr_i,
																			 uint32_t outstanding_rem_reqs, struct latency_flags* latency_info)
{
	uint16_t i;
	per_worker_outstanding[(*worker_id)]--;
	if ((outstanding_rem_reqs + wr_i) >= MAX_OUTSTANDING_REQS) { //   the client has no credits at all
		rem_send_wr[wr_i - 1].next = NULL;
		copy_op_to_next_op(ops, next_ops, resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
		(*op_i)++;
		return break_;
	}
	else {
		if (BALANCE_REQS == 1) { // option 1: send to an alternative worker TODO test this!
			//			printf(" %d %d\n", outstanding_rem_reqs + wr_i + 1, MAX_OUTSTANDING_REQS);
			//			if (ENABLE_ASSERTIONS == 1) assert(outstanding_rem_reqs + wr_i > MAX_OUTSTANDING_REQS);
			for (i = 0; i < WORKERS_PER_MACHINE; i++) {
				if (per_worker_outstanding[rm_id * WORKERS_PER_MACHINE + i] < WS_PER_WORKER) {
					//					printf("previous worker %d, new worker %d \n", (*wn), i);
					(*wn) = i;
					break;
				}
			}
			(*worker_id) = rm_id * WORKERS_PER_MACHINE + (*wn);
			per_worker_outstanding[(*worker_id)]++;
			//			printf("new worker id %d\n", (*worker_id));
			return no_cf_change;
		}
		else if (FINISH_BATCH_ON_MISSING_CREDIT == 1) { //option 2: finish the batch
			rem_send_wr[wr_i - 1].next = NULL; /* Make sure to end the batch on the last WR*/
			copy_op_to_next_op(ops, next_ops,resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
			(*op_i)++;
			return break_;
		}
		else { // option 3: skip this request
			copy_op_to_next_op(ops, next_ops, resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
			(*op_i)++;
			return continue_;
		}
	}
}
/* Handle the lack of credits for a remote request by either breaking,
 going to the next req, or picking another receipient */
Handle the lack of credits for a remote request by either breaking,
going to the next req, or picking another receipient
Handle the lack of credits for a remote request by either breaking going to the next req or picking another receipient
static inline enum control_flow_directive handle_lack_of_credits_for_remotes(struct extended_cache_op* ops, struct extended_cache_op* next_ops, struct mica_resp* resp,
																			 struct mica_resp* next_resp, struct key_home* key_homes, struct key_home* next_key_homes,
																			 uint16_t* op_i, uint16_t* next_op_i, uint16_t local_client_id, struct ibv_send_wr* rem_send_wr,
																			 uint16_t* wn, uint16_t* worker_id, uint16_t rm_id, uint8_t* per_worker_outstanding, uint16_t wr_i,
																			 uint32_t outstanding_rem_reqs, struct latency_flags* latency_info)
{
	uint16_t i;
	per_worker_outstanding[(*worker_id)]--;
	if ((outstanding_rem_reqs + wr_i) >= MAX_OUTSTANDING_REQS) { 
		rem_send_wr[wr_i - 1].next = NULL;
		copy_op_to_next_op(ops, next_ops, resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
		(*op_i)++;
		return break_;
	}
	else {
		if (BALANCE_REQS == 1) { 
			for (i = 0; i < WORKERS_PER_MACHINE; i++) {
				if (per_worker_outstanding[rm_id * WORKERS_PER_MACHINE + i] < WS_PER_WORKER) {
					(*wn) = i;
					break;
				}
			}
			(*worker_id) = rm_id * WORKERS_PER_MACHINE + (*wn);
			per_worker_outstanding[(*worker_id)]++;
			return no_cf_change;
		}
		else if (FINISH_BATCH_ON_MISSING_CREDIT == 1) { 
			rem_send_wr[wr_i - 1].next = NULL; 
			copy_op_to_next_op(ops, next_ops,resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
			(*op_i)++;
			return break_;
		}
		else { 
			copy_op_to_next_op(ops, next_ops, resp, next_resp, key_homes, next_key_homes, (*op_i), next_op_i, latency_info, NULL);
			(*op_i)++;
			return continue_;
		}
	}
}
static inline enum control_flow_directive handle_lack_of_credits_for_remotes ( struct extended_cache_op * ops , struct extended_cache_op * next_ops , struct mica_resp * resp , struct mica_resp * next_resp , struct key_home * key_homes , struct key_home * next_key_homes , uint16_t * op_i , uint16_t * next_op_i , uint16_t local_client_id , struct ibv_send_wr * rem_send_wr , uint16_t * wn , uint16_t * worker_id , uint16_t rm_id , uint8_t * per_worker_outstanding , uint16_t wr_i , uint32_t outstanding_rem_reqs , struct latency_flags * latency_info ) { uint16_t i ; per_worker_outstanding [ ( * worker_id ) ] -- ; if ( ( outstanding_rem_reqs + wr_i ) >= MAX_OUTSTANDING_REQS ) { rem_send_wr [ wr_i - 1 ] . next = NULL ; copy_op_to_next_op ( ops , next_ops , resp , next_resp , key_homes , next_key_homes , ( * op_i ) , next_op_i , latency_info , NULL ) ; ( * op_i ) ++ ; return break_ ; } else { if ( BALANCE_REQS == 1 ) { for ( i = 0 ; i < WORKERS_PER_MACHINE ; i ++ ) { if ( per_worker_outstanding [ rm_id * WORKERS_PER_MACHINE + i ] < WS_PER_WORKER ) { ( * wn ) = i ; break ; } } ( * worker_id ) = rm_id * WORKERS_PER_MACHINE + ( * wn ) ; per_worker_outstanding [ ( * worker_id ) ] ++ ; return no_cf_change ; } else if ( FINISH_BATCH_ON_MISSING_CREDIT == 1 ) { rem_send_wr [ wr_i - 1 ] . next = NULL ; copy_op_to_next_op ( ops , next_ops , resp , next_resp , key_homes , next_key_homes , ( * op_i ) , next_op_i , latency_info , NULL ) ; ( * op_i ) ++ ; return break_ ; } else { copy_op_to_next_op ( ops , next_ops , resp , next_resp , key_homes , next_key_homes , ( * op_i ) , next_op_i , latency_info , NULL ) ; ( * op_i ) ++ ; return continue_ ; } } }
Handle the lack of credits for a remote request by either breaking,
going to the next req, or picking another receipient
Handle the lack of credits for a remote request by either breaking going to the next req or picking another receipient
//   the client has no credits at all // option 1: send to an alternative worker TODO test this! //			printf(" %d %d\n", outstanding_rem_reqs + wr_i + 1, MAX_OUTSTANDING_REQS); //			if (ENABLE_ASSERTIONS == 1) assert(outstanding_rem_reqs + wr_i > MAX_OUTSTANDING_REQS); //					printf("previous worker %d, new worker %d \n", (*wn), i); //			printf("new worker id %d\n", (*worker_id)); //option 2: finish the batch /* Make sure to end the batch on the last WR*/ // option 3: skip this request