diff --git a/doc/configuration.txt b/doc/configuration.txt index 830aee9e6..d4ce56657 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -14123,12 +14123,24 @@ tfo need to build HAProxy with USE_TFO=1 if your libc doesn't define TCP_FASTOPEN. -thread +thread [/] This restricts the list of threads on which this listener is allowed to run. It does not enforce any of them but eliminates those which do not match. It limits the threads allowed to process incoming connections for this listener. + + There are two numbering schemes. By default, thread numbers are absolute in + the process, comprised between 1 and the value specified in global.nbthread. + When thread groups are enabled, the number of a single desired thread group + (starting at 1) may be specified before a slash ('/') before the thread + range. In this case, the thread numbers in the range are relative to the + thread group instead, and start at 1 for each thread group. Absolute and + relative thread numbers may be used interchangeably but they must not be + mixed on a single "bind" line, as those not set will be resolved at the end + of the parsing. + For the unlikely case where several ranges are needed, this directive may be - repeated. must use the format: + repeated. It is not permitted to use different thread groups even when using + multiple directives. The specification must use the format: all | odd | even | number[-[number]] diff --git a/include/haproxy/receiver-t.h b/include/haproxy/receiver-t.h index d8f2422d9..9f14af3d3 100644 --- a/include/haproxy/receiver-t.h +++ b/include/haproxy/receiver-t.h @@ -42,6 +42,7 @@ /* All the settings that are used to configure a receiver */ struct rx_settings { unsigned long bind_thread; /* bitmask of threads allowed to use these listeners */ + uint bind_tgroup; /* thread group ID: 0=global IDs, non-zero=local IDs */ struct { /* UNIX socket permissions */ uid_t uid; /* -1 to leave unchanged */ gid_t gid; /* -1 to leave unchanged */ diff --git a/src/listener.c b/src/listener.c index a1e9edc1a..b89aa986f 100644 --- a/src/listener.c +++ b/src/listener.c @@ -1593,24 +1593,38 @@ static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct b /* parse the "thread" bind keyword */ static int bind_parse_thread(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) { - char *slash; - unsigned long thread = 0; + char *sep = NULL; + ulong thread = 0; + long tgroup = 0; - if ((slash = strchr(args[cur_arg + 1], '/')) != NULL) - *slash = 0; - - if (slash) { - *slash = '/'; - memprintf(err, "'%s': thread groups not supported", args[cur_arg+1]); - return ERR_ALERT | ERR_FATAL; + tgroup = strtol(args[cur_arg + 1], &sep, 10); + if (*sep == '/') { + /* a thread group was present */ + if (tgroup < 1 || tgroup > MAX_TGROUPS) { + memprintf(err, "'%s' thread-group number must be between 1 and %d (was %ld)", args[cur_arg + 1], MAX_TGROUPS, tgroup); + return ERR_ALERT | ERR_FATAL; + } + sep++; + } + else { + /* no thread group */ + tgroup = 0; + sep = args[cur_arg + 1]; } - if (parse_process_number(args[cur_arg+1], &thread, MAX_THREADS, NULL, err)) { - memprintf(err, "'%s' : %s", args[cur_arg+1], *err); + if ((conf->settings.bind_tgroup || conf->settings.bind_thread) && + conf->settings.bind_tgroup != tgroup) { + memprintf(err, "'%s' multiple thread-groups are not supported", args[cur_arg + 1]); + return ERR_ALERT | ERR_FATAL; + } + + if (parse_process_number(sep, &thread, MAX_THREADS, NULL, err)) { + memprintf(err, "'%s' : %s", sep, *err); return ERR_ALERT | ERR_FATAL; } conf->settings.bind_thread |= thread; + conf->settings.bind_tgroup = tgroup; return 0; }