Skip to content

Commit bf1294e

Browse files
UCP/PROTO: UCX_PROTO_INFO=used option (#11100)
1 parent a25f47e commit bf1294e

File tree

16 files changed

+242
-44
lines changed

16 files changed

+242
-44
lines changed

src/ucp/core/ucp_context.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ static ucs_config_field_t ucp_context_config_table[] = {
492492
" 'y' : Print information for all protocols\n"
493493
" 'n' : Do not print any protocol information\n"
494494
" 'auto' : Print information when UCX_LOG_LEVEL is 'debug' or higher\n"
495+
" 'used' : Print information for used protocols\n"
495496
" glob_pattern : Print information for operations matching the glob pattern.\n"
496497
" For example: '*tag*gpu*', '*put*fast*host*'",
497498
ucs_offsetof(ucp_context_config_t, proto_info), UCS_CONFIG_TYPE_STRING},
@@ -2398,6 +2399,10 @@ static ucs_status_t ucp_fill_config(ucp_context_h context,
23982399
context->config.progress_wrapper_enabled =
23992400
ucs_log_is_enabled(UCS_LOG_LEVEL_TRACE_REQ) ||
24002401
ucp_context_usage_tracker_enabled(context);
2402+
2403+
context->config.trace_used_proto_selections =
2404+
!strcasecmp(context->config.ext.proto_info, "used");
2405+
24012406
return UCS_OK;
24022407

24032408
err_free_key_list:

src/ucp/core/ucp_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ typedef struct ucp_context {
460460
/* Progress wrapper enabled */
461461
int progress_wrapper_enabled;
462462

463+
/* Indicate whether tracing for used protocol selections is enabled */
464+
int trace_used_proto_selections;
465+
463466
struct {
464467
unsigned count;
465468
size_t *sizes;

src/ucp/core/ucp_request.c

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,33 +729,87 @@ void ucp_request_purge_enqueue_cb(uct_pending_req_t *self, void *arg)
729729
ucs_queue_push(queue, (ucs_queue_elem_t*)&req->send.uct.priv);
730730
}
731731

732+
ucs_status_t ucp_request_progress_counter(uct_pending_req_t *self)
733+
{
734+
ucp_request_t *req = ucs_container_of(self, ucp_request_t,
735+
send.uct);
736+
ucp_proto_config_t *proto_config = ucs_const_cast(ucp_proto_config_t*,
737+
req->send.proto_config);
738+
const ucp_proto_t *proto = proto_config->proto;
739+
ucs_status_t status;
740+
741+
status = proto->progress[UCP_PROTO_STAGE_START](self);
742+
if (ucs_unlikely(UCS_STATUS_IS_ERR(status))) {
743+
/* NOTE: This function is only called when `progress_wrapper_enabled`
744+
* is `false`, which means that it won't be called when the log level
745+
* is TRACE_REQ or higher. Because of this, `ucs_trace` is used here
746+
* instead of `ucp_trace_req` */
747+
ucs_trace("progress protocol %s returned: %s lane %d", proto->name,
748+
ucs_status_string(status), req->send.lane);
749+
return status;
750+
}
751+
752+
++proto_config->selections;
753+
754+
return UCS_OK;
755+
}
756+
732757
ucs_status_t ucp_request_progress_wrapper(uct_pending_req_t *self)
733758
{
734759
ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct);
735-
const ucp_proto_t *proto = req->send.proto_config->proto;
760+
ucp_proto_config_t *conf = ucs_const_cast(ucp_proto_config_t *,
761+
req->send.proto_config);
762+
const ucp_proto_t *proto = conf->proto;
736763
uct_pending_callback_t progress_cb;
737764
ucs_status_t status;
738765

739766
progress_cb = proto->progress[req->send.proto_stage];
740767
ucp_trace_req(req,
741768
"progress %s {%s} ep_cfg[%d] rkey_cfg[%d] offset %zu/%zu",
742769
proto->name, ucs_debug_get_symbol_name(progress_cb),
743-
req->send.proto_config->ep_cfg_index,
744-
req->send.proto_config->rkey_cfg_index,
770+
conf->ep_cfg_index, conf->rkey_cfg_index,
745771
req->send.state.dt_iter.offset,
746772
req->send.state.dt_iter.length);
747773

748774
ucp_worker_track_ep_usage(req);
749775

750776
ucs_log_indent(1);
751777
status = progress_cb(self);
752-
if (UCS_STATUS_IS_ERR(status)) {
778+
if (ucs_unlikely(UCS_STATUS_IS_ERR(status))) {
753779
ucp_trace_req(req, "progress protocol %s returned: %s lane %d",
754780
proto->name, ucs_status_string(status), req->send.lane);
755781
} else {
782+
if (req->send.proto_stage == UCP_PROTO_STAGE_START) {
783+
++conf->selections;
784+
}
785+
756786
ucp_trace_req(req, "progress protocol %s returned: %s", proto->name,
757787
ucs_status_string(status));
758788
}
759789
ucs_log_indent(-1);
760790
return status;
761791
}
792+
793+
void ucp_request_progress_wrapper_init(ucp_worker_h worker,
794+
ucp_proto_config_t *proto_config)
795+
{
796+
uint8_t stage;
797+
798+
if (worker->context->config.progress_wrapper_enabled) {
799+
for (stage = UCP_PROTO_STAGE_START; stage < UCP_PROTO_STAGE_LAST;
800+
++stage) {
801+
proto_config->progress_wrapper[stage] =
802+
ucp_request_progress_wrapper;
803+
}
804+
return;
805+
}
806+
807+
/* Set wrappers pointing to the original protocol functions */
808+
memcpy(proto_config->progress_wrapper, proto_config->proto->progress,
809+
sizeof(proto_config->progress_wrapper));
810+
811+
if (worker->context->config.trace_used_proto_selections) {
812+
proto_config->progress_wrapper[UCP_PROTO_STAGE_START] =
813+
ucp_request_progress_counter;
814+
}
815+
}

src/ucp/core/ucp_request.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,7 @@ void ucp_request_purge_enqueue_cb(uct_pending_req_t *self, void *arg);
587587

588588
ucs_status_t ucp_request_progress_wrapper(uct_pending_req_t *self);
589589

590+
void ucp_request_progress_wrapper_init(ucp_worker_h worker,
591+
ucp_proto_config_t *proto_config);
592+
590593
#endif

src/ucp/core/ucp_worker.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,21 @@ static void ucp_worker_keepalive_reset(ucp_worker_h worker)
22722272
worker->keepalive.round_count = 0;
22732273
}
22742274

2275+
static void ucp_worker_trace_configs(ucp_worker_h worker)
2276+
{
2277+
ucp_ep_config_t *ep_config;
2278+
ucp_rkey_config_t *rkey_config;
2279+
2280+
ucs_array_for_each(ep_config, &worker->ep_config) {
2281+
ucp_proto_select_trace(worker, &ep_config->proto_select);
2282+
}
2283+
2284+
ucs_carray_for_each(rkey_config, worker->rkey_config,
2285+
worker->rkey_config_count) {
2286+
ucp_proto_select_trace(worker, &rkey_config->proto_select);
2287+
}
2288+
}
2289+
22752290
static void ucp_worker_destroy_configs(ucp_worker_h worker)
22762291
{
22772292
ucp_ep_config_t *ep_config;
@@ -2926,6 +2941,9 @@ static void ucp_worker_destroy_eps(ucp_worker_h worker,
29262941
void ucp_worker_destroy(ucp_worker_h worker)
29272942
{
29282943
ucs_debug("destroy worker %p", worker);
2944+
if (worker->context->config.trace_used_proto_selections) {
2945+
ucp_worker_trace_configs(worker);
2946+
}
29292947

29302948
UCS_ASYNC_BLOCK(&worker->async);
29312949
uct_worker_progress_unregister_safe(worker->uct, &worker->keepalive.cb_id);

src/ucp/proto/proto.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ typedef struct {
141141

142142
/* Map of used lanes */
143143
ucp_lane_map_t lane_map;
144+
145+
/* Selections count */
146+
unsigned selections;
144147
} ucp_proto_query_attr_t;
145148

146149

src/ucp/proto/proto_common.inl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ ucp_proto_request_set_stage(ucp_request_t *req, uint8_t proto_stage)
175175
req->send.proto_stage = proto_stage;
176176

177177
/* Set pointer to progress function */
178-
if (req->send.ep->worker->context->config.progress_wrapper_enabled) {
179-
req->send.uct.func = ucp_request_progress_wrapper;
180-
} else {
181-
req->send.uct.func = proto->progress[proto_stage];
182-
}
178+
req->send.uct.func = req->send.proto_config->progress_wrapper[proto_stage];
183179
}
184180

185181
/* Select protocol for the request and initialize protocol-related fields */

src/ucp/proto/proto_debug.c

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct ucp_proto_perf_node {
6464

6565
/* Protocol information table */
6666
typedef struct {
67+
char counter_str[32];
6768
char range_str[32];
6869
char desc[UCP_PROTO_DESC_STR_MAX];
6970
char config[UCP_PROTO_CONFIG_STR_MAX];
@@ -156,11 +157,16 @@ static void ucp_proto_table_row_separator(ucs_string_buffer_t *strb,
156157
}
157158

158159
static int ucp_proto_debug_is_info_enabled(ucp_context_h context,
159-
const char *select_param_str)
160+
const char *select_param_str,
161+
int show_used)
160162
{
161163
const char *proto_info_config = context->config.ext.proto_info;
162164
int bool_value;
163165

166+
if (show_used) {
167+
return context->config.trace_used_proto_selections;
168+
}
169+
164170
/* Handle "auto" - enable when log level is DEBUG or higher */
165171
if (!strcasecmp(proto_info_config, "auto")) {
166172
return ucs_log_is_enabled(UCS_LOG_LEVEL_DEBUG);
@@ -175,29 +181,74 @@ static int ucp_proto_debug_is_info_enabled(ucp_context_h context,
175181
return fnmatch(proto_info_config, select_param_str, FNM_CASEFOLD) == 0;
176182
}
177183

178-
void ucp_proto_select_elem_info(ucp_worker_h worker,
179-
ucp_worker_cfg_index_t ep_cfg_index,
180-
ucp_worker_cfg_index_t rkey_cfg_index,
181-
const ucp_proto_select_param_t *select_param,
182-
const ucp_proto_select_elem_t *select_elem,
183-
int show_all, ucs_string_buffer_t *strb)
184+
static inline int
185+
ucp_proto_select_elem_has_selections(const ucp_proto_select_elem_t *select_elem)
186+
{
187+
const ucp_proto_threshold_elem_t *thresh_elem = select_elem->thresholds;
188+
189+
do {
190+
if (thresh_elem->proto_config.selections > 0) {
191+
return 1;
192+
}
193+
} while ((thresh_elem++)->max_msg_length < SIZE_MAX);
194+
195+
return 0;
196+
}
197+
198+
static void
199+
ucp_proto_selections_dump(ucp_worker_h worker,
200+
const ucp_proto_query_attr_t *proto_attr,
201+
const ucp_proto_select_param_t *select_param,
202+
char *counter_str, size_t size, int show_used)
203+
{
204+
ucp_operation_id_t op_id;
205+
206+
if (!show_used) {
207+
*counter_str = '\0';
208+
return;
209+
}
210+
211+
/* Short active messages protocol selections are not counted */
212+
op_id = ucp_proto_select_op_id(select_param);
213+
if ((op_id == UCP_OP_ID_AM_SEND || op_id == UCP_OP_ID_AM_SEND_REPLY) &&
214+
strstr(proto_attr->desc, "short") != NULL) {
215+
ucs_assert(proto_attr->selections == 0);
216+
*counter_str = '\0';
217+
return;
218+
}
219+
220+
ucs_snprintf_safe(counter_str, size, "%u ", proto_attr->selections);
221+
}
222+
223+
void
224+
ucp_proto_select_elem_info(ucp_worker_h worker,
225+
ucp_worker_cfg_index_t ep_cfg_index,
226+
ucp_worker_cfg_index_t rkey_cfg_index,
227+
const ucp_proto_select_param_t *select_param,
228+
const ucp_proto_select_elem_t *select_elem,
229+
int show_all, int show_used, ucs_string_buffer_t *strb)
184230
{
185231
UCS_STRING_BUFFER_ONSTACK(ep_cfg_strb, UCP_PROTO_CONFIG_STR_MAX);
186232
UCS_STRING_BUFFER_ONSTACK(sel_param_strb, UCP_PROTO_CONFIG_STR_MAX);
187-
static const char *info_row_fmt = "| %*s | %-*s | %-*s |\n";
233+
static const char *info_row_fmt = "| %s%*s | %-*s | %-*s |\n";
188234
ucp_proto_info_table_t table;
189235
int hdr_col_width[2], col_width[3];
190236
ucp_proto_query_attr_t proto_attr;
191237
ucp_proto_info_row_t *row_elem;
192238
size_t range_start, range_end;
193239
int proto_valid;
194240

241+
if (show_used && !ucp_proto_select_elem_has_selections(select_elem)) {
242+
return;
243+
}
244+
195245
ucp_proto_select_param_dump(worker, ep_cfg_index, rkey_cfg_index,
196246
select_param, ucp_operation_descs, &ep_cfg_strb,
197247
&sel_param_strb);
198248
if (!show_all &&
199249
!ucp_proto_debug_is_info_enabled(
200-
worker->context, ucs_string_buffer_cstr(&sel_param_strb))) {
250+
worker->context, ucs_string_buffer_cstr(&sel_param_strb),
251+
show_used)) {
201252
return;
202253
}
203254

@@ -228,7 +279,12 @@ void ucp_proto_select_elem_info(ucp_worker_h worker,
228279
ucs_memunits_range_str(range_start, range_end, row_elem->range_str,
229280
sizeof(row_elem->range_str));
230281

231-
col_width[0] = ucs_max(col_width[0], strlen(row_elem->range_str));
282+
ucp_proto_selections_dump(worker, &proto_attr, select_param,
283+
row_elem->counter_str,
284+
sizeof(row_elem->counter_str), show_used);
285+
286+
col_width[0] = ucs_max(col_width[0], strlen(row_elem->counter_str) +
287+
strlen(row_elem->range_str));
232288
col_width[1] = ucs_max(col_width[1], strlen(row_elem->desc));
233289
col_width[2] = ucs_max(col_width[2], strlen(row_elem->config));
234290
} while (range_end != SIZE_MAX);
@@ -250,7 +306,8 @@ void ucp_proto_select_elem_info(ucp_worker_h worker,
250306
/* Print contents */
251307
ucp_proto_table_row_separator(strb, col_width, 3);
252308
ucs_array_for_each(row_elem, &table) {
253-
ucs_string_buffer_appendf(strb, info_row_fmt, col_width[0],
309+
ucs_string_buffer_appendf(strb, info_row_fmt, row_elem->counter_str,
310+
col_width[0] - strlen(row_elem->counter_str),
254311
row_elem->range_str, col_width[1],
255312
row_elem->desc, col_width[2],
256313
row_elem->config);
@@ -271,7 +328,7 @@ void ucp_proto_select_info(ucp_worker_h worker,
271328

272329
kh_foreach(proto_select->hash, key.u64, select_elem,
273330
ucp_proto_select_elem_info(worker, ep_cfg_index, rkey_cfg_index,
274-
&key.param, &select_elem, show_all,
331+
&key.param, &select_elem, show_all, 0,
275332
strb);
276333
ucs_string_buffer_appendf(strb, "\n"))
277334
}
@@ -973,7 +1030,7 @@ ucp_proto_select_write_info(ucp_worker_h worker,
9731030
ucp_operation_names, &ep_cfg_strb,
9741031
&sel_param_strb);
9751032
if (!ucp_proto_debug_is_info_enabled(
976-
worker->context, ucs_string_buffer_cstr(&sel_param_strb))) {
1033+
worker->context, ucs_string_buffer_cstr(&sel_param_strb), 0)) {
9771034
goto out;
9781035
}
9791036

@@ -1038,17 +1095,19 @@ ucp_proto_select_write_info(ucp_worker_h worker,
10381095
}
10391096

10401097
void ucp_proto_select_elem_trace(ucp_worker_h worker,
1041-
ucp_worker_cfg_index_t ep_cfg_index,
1042-
ucp_worker_cfg_index_t rkey_cfg_index,
10431098
const ucp_proto_select_param_t *select_param,
1044-
ucp_proto_select_elem_t *select_elem)
1099+
const ucp_proto_select_elem_t *select_elem,
1100+
int show_used)
10451101
{
1046-
ucs_string_buffer_t strb = UCS_STRING_BUFFER_INITIALIZER;
1102+
const ucp_proto_config_t *proto_config = &select_elem->thresholds[0].proto_config;
1103+
ucp_worker_cfg_index_t ep_cfg_index = proto_config->ep_cfg_index;
1104+
ucp_worker_cfg_index_t rkey_cfg_index = proto_config->rkey_cfg_index;
1105+
ucs_string_buffer_t strb = UCS_STRING_BUFFER_INITIALIZER;
10471106
char *line;
10481107

10491108
/* Print human-readable protocol selection table to the log */
10501109
ucp_proto_select_elem_info(worker, ep_cfg_index, rkey_cfg_index,
1051-
select_param, select_elem, 0, &strb);
1110+
select_param, select_elem, 0, show_used, &strb);
10521111
ucs_string_buffer_for_each_token(line, &strb, "\n") {
10531112
ucs_log_print_compact(line);
10541113
}

src/ucp/proto/proto_debug.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ void ucp_proto_select_elem_info(ucp_worker_h worker,
157157
ucp_worker_cfg_index_t rkey_cfg_index,
158158
const ucp_proto_select_param_t *select_param,
159159
const ucp_proto_select_elem_t *select_elem,
160-
int show_all, ucs_string_buffer_t *strb);
160+
int show_all, int show_used,
161+
ucs_string_buffer_t *strb);
161162

162163

163164
void ucp_proto_select_elem_trace(ucp_worker_h worker,
164-
ucp_worker_cfg_index_t ep_cfg_index,
165-
ucp_worker_cfg_index_t rkey_cfg_index,
166165
const ucp_proto_select_param_t *select_param,
167-
ucp_proto_select_elem_t *select_elem);
166+
const ucp_proto_select_elem_t *select_elem,
167+
int show_used);
168168

169169

170170
void ucp_proto_select_write_info(

src/ucp/proto/proto_reconfig.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static ucs_status_t ucp_proto_reconfig_select_progress(uct_pending_req_t *self)
3030
return UCS_ERR_NO_RESOURCE;
3131
}
3232

33+
/* coverity[address_free] */
3334
return req->send.uct.func(&req->send.uct);
3435
}
3536

0 commit comments

Comments
 (0)