Skip to content

Commit dc3b66a

Browse files
Gioh Kimjgunthorpe
authored andcommitted
RDMA/rtrs-clt: Add a minimum latency multipath policy
This patch adds new multipath policy: min-latency. Client checks the latency of each path when it sends the heart-beat. And it sends IO to the path with the minimum latency. Link: https://lore.kernel.org/r/20210407113444.150961-2-gi-oh.kim@ionos.com Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com> Signed-off-by: Jack Wang <jinpu.wang@ionos.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent fe73f96 commit dc3b66a

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ static ssize_t mpath_policy_show(struct device *dev,
101101
case MP_POLICY_MIN_INFLIGHT:
102102
return sysfs_emit(page, "min-inflight (MI: %d)\n",
103103
clt->mp_policy);
104+
case MP_POLICY_MIN_LATENCY:
105+
return sysfs_emit(page, "min-latency (ML: %d)\n",
106+
clt->mp_policy);
104107
default:
105108
return sysfs_emit(page, "Unknown (%d)\n", clt->mp_policy);
106109
}
@@ -114,22 +117,32 @@ static ssize_t mpath_policy_store(struct device *dev,
114117
struct rtrs_clt *clt;
115118
int value;
116119
int ret;
120+
size_t len = 0;
117121

118122
clt = container_of(dev, struct rtrs_clt, dev);
119123

120124
ret = kstrtoint(buf, 10, &value);
121125
if (!ret && (value == MP_POLICY_RR ||
122-
value == MP_POLICY_MIN_INFLIGHT)) {
126+
value == MP_POLICY_MIN_INFLIGHT ||
127+
value == MP_POLICY_MIN_LATENCY)) {
123128
clt->mp_policy = value;
124129
return count;
125130
}
126131

132+
/* distinguish "mi" and "min-latency" with length */
133+
len = strnlen(buf, NAME_MAX);
134+
if (buf[len - 1] == '\n')
135+
len--;
136+
127137
if (!strncasecmp(buf, "round-robin", 11) ||
128-
!strncasecmp(buf, "rr", 2))
138+
(len == 2 && !strncasecmp(buf, "rr", 2)))
129139
clt->mp_policy = MP_POLICY_RR;
130140
else if (!strncasecmp(buf, "min-inflight", 12) ||
131-
!strncasecmp(buf, "mi", 2))
141+
(len == 2 && !strncasecmp(buf, "mi", 2)))
132142
clt->mp_policy = MP_POLICY_MIN_INFLIGHT;
143+
else if (!strncasecmp(buf, "min-latency", 11) ||
144+
(len == 2 && !strncasecmp(buf, "ml", 2)))
145+
clt->mp_policy = MP_POLICY_MIN_LATENCY;
133146
else
134147
return -EINVAL;
135148

drivers/infiniband/ulp/rtrs/rtrs-clt.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ static void rtrs_clt_rdma_done(struct ib_cq *cq, struct ib_wc *wc)
628628
} else if (imm_type == RTRS_HB_ACK_IMM) {
629629
WARN_ON(con->c.cid);
630630
sess->s.hb_missed_cnt = 0;
631+
sess->s.hb_cur_latency =
632+
ktime_sub(ktime_get(), sess->s.hb_last_sent);
631633
if (sess->flags & RTRS_MSG_NEW_RKEY_F)
632634
return rtrs_clt_recv_done(con, wc);
633635
} else {
@@ -826,6 +828,57 @@ static struct rtrs_clt_sess *get_next_path_min_inflight(struct path_it *it)
826828
return min_path;
827829
}
828830

831+
/**
832+
* get_next_path_min_latency() - Returns path with minimal latency.
833+
* @it: the path pointer
834+
*
835+
* Return: a path with the lowest latency or NULL if all paths are tried
836+
*
837+
* Locks:
838+
* rcu_read_lock() must be hold.
839+
*
840+
* Related to @MP_POLICY_MIN_LATENCY
841+
*
842+
* This DOES skip an already-tried path.
843+
* There is a skip-list to skip a path if the path has tried but failed.
844+
* It will try the minimum latency path and then the second minimum latency
845+
* path and so on. Finally it will return NULL if all paths are tried.
846+
* Therefore the caller MUST check the returned
847+
* path is NULL and trigger the IO error.
848+
*/
849+
static struct rtrs_clt_sess *get_next_path_min_latency(struct path_it *it)
850+
{
851+
struct rtrs_clt_sess *min_path = NULL;
852+
struct rtrs_clt *clt = it->clt;
853+
struct rtrs_clt_sess *sess;
854+
ktime_t min_latency = INT_MAX;
855+
ktime_t latency;
856+
857+
list_for_each_entry_rcu(sess, &clt->paths_list, s.entry) {
858+
if (unlikely(READ_ONCE(sess->state) != RTRS_CLT_CONNECTED))
859+
continue;
860+
861+
if (unlikely(!list_empty(raw_cpu_ptr(sess->mp_skip_entry))))
862+
continue;
863+
864+
latency = sess->s.hb_cur_latency;
865+
866+
if (latency < min_latency) {
867+
min_latency = latency;
868+
min_path = sess;
869+
}
870+
}
871+
872+
/*
873+
* add the path to the skip list, so that next time we can get
874+
* a different one
875+
*/
876+
if (min_path)
877+
list_add(raw_cpu_ptr(min_path->mp_skip_entry), &it->skip_list);
878+
879+
return min_path;
880+
}
881+
829882
static inline void path_it_init(struct path_it *it, struct rtrs_clt *clt)
830883
{
831884
INIT_LIST_HEAD(&it->skip_list);
@@ -834,8 +887,10 @@ static inline void path_it_init(struct path_it *it, struct rtrs_clt *clt)
834887

835888
if (clt->mp_policy == MP_POLICY_RR)
836889
it->next_path = get_next_path_rr;
837-
else
890+
else if (clt->mp_policy == MP_POLICY_MIN_INFLIGHT)
838891
it->next_path = get_next_path_min_inflight;
892+
else
893+
it->next_path = get_next_path_min_latency;
839894
}
840895

841896
static inline void path_it_deinit(struct path_it *it)

drivers/infiniband/ulp/rtrs/rtrs-clt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum rtrs_clt_state {
2929
enum rtrs_mp_policy {
3030
MP_POLICY_RR,
3131
MP_POLICY_MIN_INFLIGHT,
32+
MP_POLICY_MIN_LATENCY,
3233
};
3334

3435
/* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */

drivers/infiniband/ulp/rtrs/rtrs-pri.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ struct rtrs_sess {
112112
unsigned int hb_interval_ms;
113113
unsigned int hb_missed_cnt;
114114
unsigned int hb_missed_max;
115+
ktime_t hb_last_sent;
116+
ktime_t hb_cur_latency;
115117
};
116118

117119
/* rtrs information unit */

drivers/infiniband/ulp/rtrs/rtrs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ static void hb_work(struct work_struct *work)
337337
schedule_hb(sess);
338338
return;
339339
}
340+
341+
sess->hb_last_sent = ktime_get();
342+
340343
imm = rtrs_to_imm(RTRS_HB_MSG_IMM, 0);
341344
err = rtrs_post_rdma_write_imm_empty(usr_con, sess->hb_cqe, imm,
342345
0, NULL);

0 commit comments

Comments
 (0)