Skip to content

Commit 237fa96

Browse files
author
Khang Nguyen
committed
mctpd: Add timeout overriding using program arguments
Currently, the timeout is hardcoded with the value of 250ms. However, when developing, we may want to make the timeout longer to make sure we do not miss any messages due to other reasons. This commit adds timeout overriding using program arguments. This makes tweaking the timeout at runtime possible. Tested: 1. Send a request to a non-existent endpoint. It should timeout in 250ms by default. root@mtmitchell:~# time busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp \ > au.com.CodeConstruct.MCTP SetupEndpoint say mctppcie0 2 0xCA 0xFE Call failed: MCTP Endpoint did not respond real 0m0.344s user 0m0.016s sys 0m0.000s 2. Change mctpd.service to use longer timeout, 10 seconds for example. ExecStart=/usr/sbin/mctpd -t 10000000 3. Resend the request. It should timeout in 10 seconds. root@mtmitchell:~# time busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp \ > au.com.CodeConstruct.MCTP SetupEndpoint say mctppcie0 2 0xCA 0xFE Call failed: MCTP Endpoint did not respond real 0m10.083s user 0m0.015s sys 0m0.001s Signed-off-by: Khang Nguyen <[email protected]>
1 parent a591ad8 commit 237fa96

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/mctpd.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -3074,9 +3074,10 @@ static int setup_testing(ctx *ctx) {
30743074

30753075
static void print_usage(ctx *ctx)
30763076
{
3077-
fprintf(stderr, "mctpd [-v] [-N]\n");
3077+
fprintf(stderr, "mctpd [-v] [-N] [-t usecs]\n");
30783078
fprintf(stderr, " -v verbose\n");
30793079
fprintf(stderr, " -N testing mode. Not safe for production\n");
3080+
fprintf(stderr, " -t timeout in usecs\n");
30803081
}
30813082

30823083
static int parse_args(ctx *ctx, int argc, char **argv)
@@ -3085,12 +3086,16 @@ static int parse_args(ctx *ctx, int argc, char **argv)
30853086
{ .name = "help", .has_arg = no_argument, .val = 'h' },
30863087
{ .name = "verbose", .has_arg = no_argument, .val = 'v' },
30873088
{ .name = "testing", .has_arg = no_argument, .val = 'N' },
3089+
{ .name = "timeout", .has_arg = required_argument, .val = 't' },
30883090
{ 0 },
30893091
};
30903092
int c;
30913093

3094+
// default values
3095+
ctx->mctp_timeout = 250000; // 250ms
3096+
30923097
for (;;) {
3093-
c = getopt_long(argc, argv, "+hvN", options, NULL);
3098+
c = getopt_long(argc, argv, "+hvNt:", options, NULL);
30943099
if (c == -1)
30953100
break;
30963101

@@ -3101,6 +3106,13 @@ static int parse_args(ctx *ctx, int argc, char **argv)
31013106
case 'v':
31023107
ctx->verbose = true;
31033108
break;
3109+
case 't':
3110+
ctx->mctp_timeout = strtoull(optarg, NULL, 10);
3111+
if (ctx->mctp_timeout == 0) {
3112+
warnx("Timeout must be a non-zero u64");
3113+
return errno;
3114+
}
3115+
break;
31043116
case 'h':
31053117
default:
31063118
print_usage(ctx);
@@ -3138,7 +3150,6 @@ static int setup_config(ctx *ctx)
31383150
{
31393151
int rc;
31403152
// TODO: this will go in a config file or arguments.
3141-
ctx->mctp_timeout = 250000; // 250ms
31423153
ctx->bus_owner = true;
31433154
rc = fill_uuid(ctx);
31443155
if (rc < 0)

0 commit comments

Comments
 (0)