fr_schedule_network_t *sn; //!< pointer to the (one) network thread
};
+static _Thread_local int worker_id; //!< Internal ID of the current worker thread.
+
+/** Return the worker id for the current thread
+ *
+ * @return worker ID
+ */
+int fr_schedule_worker_id(void)
+{
+ return worker_id;
+}
/** Initialize and run the worker thread.
*
fr_schedule_child_status_t status = FR_CHILD_FAIL;
char buffer[32];
+ worker_id = sw->id; /* Store the current worker ID */
+
sw->ctx = ctx = talloc_init("worker %d", sw->id);
if (!ctx) {
fr_log(sc->log, L_ERR, "Worker %d - Failed allocating memory", sw->id);
static void *fr_schedule_network_thread(void *arg)
{
TALLOC_CTX *ctx;
- fr_schedule_network_t *sn = arg;
+ fr_schedule_network_t *sn = talloc_get_type_abort(arg, fr_schedule_network_t);
fr_schedule_t *sc = sn->sc;
fr_schedule_child_status_t status = FR_CHILD_FAIL;
fr_event_list_t *el;
typedef struct fr_schedule_t fr_schedule_t;
typedef int (*fr_schedule_thread_instantiate_t)(void *ctx, fr_event_list_t *el);
+int fr_schedule_worker_id(void);
+
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,
#include <freeradius-devel/io/channel.h>
#include <freeradius-devel/io/message.h>
#include <freeradius-devel/io/listen.h>
+#include <freeradius-devel/io/schedule.h>
/**
* Track things by priority and time.
worker->next_cleanup = cleanup;
fr_time_to_timeval(&when, cleanup);
- DEBUG2("Resetting worker cleanup timer to +%ds", worker->max_request_time);
+ DEBUG2("Resetting worker %i cleanup timer to +%ds", worker->max_request_time, fr_schedule_worker_id());
if (fr_event_timer_insert(worker, worker->el, &worker->ev_cleanup,
&when, fr_worker_max_request_time, worker) < 0) {
ERROR("Failed inserting max_request_time timer.");
*/
request = fr_heap_pop(worker->runnable);
if (request) {
- DEBUG3("Worker found runnable request.");
+ DEBUG3("Worker %i found runnable request", fr_schedule_worker_id());
REQUEST_VERIFY(request);
rad_assert(request->runnable_id < 0);
fr_time_tracking_resume(&request->async->tracking, now);
WORKER_HEAP_POP(to_decode, cd, request.list);
}
if (!cd) {
- DEBUG3("Worker localized and decode lists are empty.");
+ DEBUG3("Worker %i localized and decode lists are empty", fr_schedule_worker_id());
return NULL;
}
- DEBUG3("Worker found request to decode.");
+ DEBUG3("Worker %i found request to decode", fr_schedule_worker_id());
worker->num_decoded++;
} while (!cd);
* are still sleeping.
*/
if (worker->was_sleeping) {
- DEBUG3("\tworker was sleeping, not re-signaling");
+ DEBUG3("Worker %i was sleeping, not re-signaling", fr_schedule_worker_id());
return 0;
}
*/
wait_for_event = (fr_heap_num_elements(worker->runnable) == 0);
if (wait_for_event) {
- DEBUG("Ready to process requests.");
+ INFO("Worker %i ready to process requests", fr_schedule_worker_id());
}
/*
{
module_thread_instance_t *ti = talloc_get_type_abort(to_free, module_thread_instance_t);
- DEBUG3("Worker cleaning up %s thread instance data (%p/%p)", ti->module->name, ti, ti->data);
+ DEBUG4("Worker %i cleaning up %s thread instance data (%p/%p)",
+ fr_schedule_worker_id(), ti->module->name, ti, ti->data);
if (ti->module->thread_detach) (void) ti->module->thread_detach(ti->el, ti->data);
talloc_free(ti);
{
rbtree_t *thread_inst_tree = talloc_get_type_abort(to_free , rbtree_t);
- DEBUG3("Worker cleaning up thread instance tree");
+ DEBUG4("Worker %i cleaning up thread instance tree", fr_schedule_worker_id());
talloc_free(thread_inst_tree);
}
talloc_free(type_name);
}
- DEBUG3("Worker alloced %s thread instance data (%p/%p)", ti->module->name, ti, ti->data);
+ DEBUG4("Worker %i alloced %s thread instance data (%p/%p)",
+ fr_schedule_worker_id(), ti->module->name, ti, ti->data);
if (mi->module->thread_instantiate) {
ret = mi->module->thread_instantiate(mi->dl_inst->conf, mi->dl_inst->data,
thread_inst_ctx->el, ti->data);
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
+#include <freeradius-devel/io/schedule.h>
#include <ctype.h>
static void _xlat_thread_inst_free(void *to_free)
{
xlat_thread_inst_t *thread_inst = talloc_get_type_abort(to_free, xlat_thread_inst_t);
+
+ DEBUG4("Worker %i cleaning up xlat thread instance (%p/%p)", fr_schedule_worker_id(),
+ thread_inst, thread_inst->data);
+
talloc_free(thread_inst);
}
{
rbtree_t *thread_inst_tree = talloc_get_type_abort(to_free , rbtree_t);
- DEBUG3("Worker cleaning up xlat thread instance tree");
+ DEBUG4("Worker %i cleaning up xlat thread instance tree", fr_schedule_worker_id());
talloc_free(thread_inst_tree);
}
#endif
}
+ DEBUG4("Worker %i alloced xlat thread instance (%p/%p)", fr_schedule_worker_id(),
+ thread_inst, thread_inst->data);
+
return thread_inst;
}