]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move parsing of workers / threads into scheduler
authorAlan T. DeKok <aland@freeradius.org>
Tue, 17 Dec 2019 16:01:33 +0000 (11:01 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 17 Dec 2019 16:13:01 +0000 (11:13 -0500)
src/bin/radiusd.c
src/lib/io/schedule.c
src/lib/io/schedule.h
src/lib/server/main_config.c
src/lib/server/main_config.h

index f66b776cb78ef742c2c1481f5b8e4e2345a7ce87..cb1ea33225c9cab7a5c1c912dd29fe9734260731 100644 (file)
@@ -757,8 +757,6 @@ int main(int argc, char *argv[])
         *      Start the network / worker threads.
         */
        {
-               int networks = config->num_networks;
-               int workers = config->num_workers;
                fr_event_list_t *el = NULL;
 
                /*
@@ -767,13 +765,10 @@ int main(int argc, char *argv[])
                 *      it's own event list.
                 */
                if (!config->spawn_workers) {
-                       networks = 0;
-                       workers = 0;
                        el = main_loop_event_list();
                }
 
                sc = fr_schedule_create(NULL, el, &default_log, fr_debug_lvl,
-                                       networks, workers,
                                        thread_instantiate,
                                        cf_section_find(config->root_cs, "thread", CF_IDENT_ANY));
                if (!sc) {
index 99b029ef719b91f785a1d9298d7c5f95952fd1ec..73e62e5baa5902f422f974e4d3213262fbc3b748 100644 (file)
@@ -124,8 +124,9 @@ struct fr_schedule_s {
        fr_log_t        *log;                   //!< log destination
        fr_log_lvl_t    lvl;                    //!< log level
 
-       unsigned int    max_networks;           //!< number of network threads
-       unsigned int    max_workers;            //!< max number of worker threads
+
+       uint32_t        max_networks;           //!< number of network threads
+       uint32_t        max_workers;            //!< number of network threads
 
        unsigned int    num_workers_exited;     //!< number of exited workers
 
@@ -363,20 +364,64 @@ int fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *a
        return 0;
 }
 
-static const CONF_PARSER schedule_config[] = {
+static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent,
+                             CONF_ITEM *ci, CONF_PARSER const *rule)
+{
+       int             ret;
+       uint32_t        value;
+
+       if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
+
+       memcpy(&value, out, sizeof(value));
+
+       if (value != 1) value = 1;
+
+       memcpy(out, &value, sizeof(value));
+
+       return 0;
+}
+
+static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent,
+                            CONF_ITEM *ci, CONF_PARSER const *rule)
+{
+       int             ret;
+       uint32_t        value;
+
+       if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
+
+       memcpy(&value, out, sizeof(value));
+
+       if (value < 1) value = 1;
+       if (value > 64) value = 64;
+
+       memcpy(out, &value, sizeof(value));
+
+       return 0;
+}
+
+static const CONF_PARSER scheduler_config[] = {
        { FR_CONF_OFFSET("stats_interval", FR_TYPE_TIME_DELTA, fr_schedule_t, stats_interval), },
 
        CONF_PARSER_TERMINATOR
 };
 
+static const CONF_PARSER thread_config[] = {
+       { FR_CONF_OFFSET("num_networks", FR_TYPE_UINT32, fr_schedule_t, max_networks), .dflt = STRINGIFY(1),
+         .func = num_networks_parse },
+       { FR_CONF_OFFSET("num_workers", FR_TYPE_UINT32, fr_schedule_t, max_workers), .dflt = STRINGIFY(4),
+         .func = num_workers_parse },
+
+       { FR_CONF_POINTER("scheduler", FR_TYPE_SUBSECTION, NULL), .subcs = (void const *) scheduler_config },
+
+       CONF_PARSER_TERMINATOR
+};
+
 /** Create a scheduler and spawn the child threads.
  *
  * @param[in] ctx              talloc context.
  * @param[in] el               event list, only for single-threaded mode.
  * @param[in] logger           destination for all logging messages.
  * @param[in] lvl              log level.
- * @param[in] max_networks     number of network threads.
- * @param[in] max_workers      number of worker threads.
  * @param[in] worker_thread_instantiate                callback for new worker threads.
  * @param[in] cs               "thread pool" configuration section
  * @return
@@ -385,33 +430,12 @@ static const CONF_PARSER schedule_config[] = {
  */
 fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el,
                                  fr_log_t *logger, fr_log_lvl_t lvl,
-                                 int max_networks, int max_workers,
                                  fr_schedule_thread_instantiate_t worker_thread_instantiate,
                                  CONF_SECTION *cs)
 {
        unsigned int i;
        fr_schedule_worker_t *sw, *next;
        fr_schedule_t *sc;
-       CONF_SECTION *subcs;
-
-       /*
-        *      Single-threaded mode MUST have event list, and zero
-        *      networks or workers
-        */
-       if (el && (max_networks || max_workers)) {
-               fr_strerror_printf("Cannot specify event list and networks or workers");
-               return NULL;
-       }
-
-       /*
-        *      Multi-threaded mode must NOT have an event list, and
-        *      non-zero networks and workers.
-        */
-       if (!el && (!max_networks || !max_workers)) {
-               fr_strerror_printf("Must specify the number of networks (%d >= 0) and workers (%d >= 0)",
-                       max_networks, max_workers);
-               return NULL;
-       }
 
        sc = talloc_zero(ctx, fr_schedule_t);
        if (!sc) {
@@ -421,26 +445,10 @@ fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el,
 
        sc->cs = cs;
        sc->el = el;
-       sc->max_networks = max_networks;
-       sc->max_workers = max_workers;
        sc->log = logger;
        sc->lvl = lvl;
 
-       /*
-        *      Parse any scheduler-specific configuration.
-        */
-       subcs = cf_section_find(cs, "scheduler", NULL);
-       if (subcs) {
-               cf_section_rule_push(subcs, schedule_config);
-               if (cf_section_parse(sc, sc, subcs) < 0) {
-                       talloc_free(sc);
-                       fr_strerror_printf("Failed parsing scheduler configuration");
-                       return NULL;
-               }
-       }
-
        sc->worker_thread_instantiate = worker_thread_instantiate;
-
        sc->running = true;
 
        /*
@@ -465,6 +473,8 @@ fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el,
                 *      Parent thread-specific data from the single_worker
                 */
                if (sc->worker_thread_instantiate) {
+                       CONF_SECTION *subcs;
+
                        subcs = cf_section_find(sc->cs, "worker", "0");
                        if (!subcs) subcs = cf_section_find(sc->cs, "worker", NULL);
 
@@ -490,6 +500,26 @@ fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el,
                return sc;
        }
 
+       /*
+        *      Parse any scheduler-specific configuration.
+        */
+       if (!cs) {
+               sc->max_networks = 1;
+               sc->max_workers = 4;
+       } else {
+               cf_section_rules_push(cs, thread_config);
+               if (cf_section_parse(sc, sc, cs) < 0) {
+                       talloc_free(sc);
+                       fr_strerror_printf("Failed parsing scheduler configuration");
+                       return NULL;
+               }
+
+               if (sc->max_networks != 1) sc->max_networks = 1;
+               if (sc->max_workers < 1) sc->max_workers = 1;
+               if (sc->max_workers > 64) sc->max_workers = 64;
+
+       }
+
        /*
         *      Create the list which holds the workers.
         */
index 3bdb4006d816c8d3d09a1b36a6fc303b16004e01..7b7818812fb0dcf5812510dc923ed371d85a7f7c 100644 (file)
@@ -58,7 +58,6 @@ int                   fr_schedule_worker_id(void);
 
 int                    fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *arg);
 fr_schedule_t          *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *log, fr_log_lvl_t lvl,
-                                           int max_inputs, int max_workers,
                                            fr_schedule_thread_instantiate_t worker_thread_instantiate,
                                            CONF_SECTION *root_cs) CC_HINT(nonnull(3));
 /* schedulers are async, so there's no fr_schedule_run() */
index 6ad2c1291a48605381d2b26ed05ff9dccb1b7fc3..e0fbd9dc5f78cadd88948254b71cda92edff08a2 100644 (file)
@@ -76,8 +76,6 @@ fr_log_t              debug_log = { .fd = -1, .dst = L_DST_NULL };
 static int reverse_lookups_parse(TALLOC_CTX *ctx, void *out, void *parent,CONF_ITEM *ci, CONF_PARSER const *rule);
 static int hostname_lookups_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
 
-static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
-static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
 static int lib_dir_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
 
 static int talloc_memory_limit_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
@@ -145,15 +143,6 @@ static const CONF_PARSER log_config[] = {
        CONF_PARSER_TERMINATOR
 };
 
-static const CONF_PARSER thread_config[] = {
-       { FR_CONF_OFFSET("num_networks", FR_TYPE_UINT32, main_config_t, num_networks), .dflt = STRINGIFY(1),
-         .func = num_networks_parse },
-       { FR_CONF_OFFSET("num_workers", FR_TYPE_UINT32, main_config_t, num_workers), .dflt = STRINGIFY(4),
-         .func = num_workers_parse },
-
-       CONF_PARSER_TERMINATOR
-};
-
 
 static const CONF_PARSER resources[] = {
        /*
@@ -193,8 +182,6 @@ static const CONF_PARSER server_config[] = {
 
        { FR_CONF_POINTER("resources", FR_TYPE_SUBSECTION, NULL), .subcs = (void const *) resources },
 
-       { FR_CONF_POINTER("thread", FR_TYPE_SUBSECTION, NULL), .subcs = (void const *) thread_config, .ident2 = CF_IDENT_ANY },
-
        /*
         *      People with old configs will have these.  They are listed
         *      AFTER the "log" section, so if they exist in radiusd.conf,
@@ -349,42 +336,6 @@ static int max_request_time_parse(TALLOC_CTX *ctx, void *out, void *parent,
        return 0;
 }
 
-
-static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent,
-                             CONF_ITEM *ci, CONF_PARSER const *rule)
-{
-       int             ret;
-       uint32_t        value;
-
-       if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
-
-       memcpy(&value, out, sizeof(value));
-
-       FR_INTEGER_BOUND_CHECK("thread.num_networks", value, ==, 1);
-
-       memcpy(out, &value, sizeof(value));
-
-       return 0;
-}
-
-static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent,
-                            CONF_ITEM *ci, CONF_PARSER const *rule)
-{
-       int             ret;
-       uint32_t        value;
-
-       if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
-
-       memcpy(&value, out, sizeof(value));
-
-       FR_INTEGER_BOUND_CHECK("thread.num_workers", value, >, 0);
-       FR_INTEGER_BOUND_CHECK("thread.num_workers", value, <, 64);
-
-       memcpy(out, &value, sizeof(value));
-
-       return 0;
-}
-
 static int lib_dir_parse(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *parent,
                         CONF_ITEM *ci, UNUSED CONF_PARSER const *rule)
 {
index 4a6eb98d6dc96bfb8c1801e4f589acf2f89fad62..defe6620b8ea798791202b301e6598c5f670a87a 100644 (file)
@@ -61,9 +61,6 @@ struct main_config_s {
        fr_time_delta_t max_request_time;               //!< How long a request can be processed for before
                                                        //!< timing out.
 
-       uint32_t        num_networks;                   //!< number of network threads
-       uint32_t        num_workers;                    //!< number of network threads
-
        bool            drop_requests;                  //!< Administratively disable request processing.
 
        char const      *log_dir;