tools/tracing/rtla/src/common.c

Source file repositories/reference/linux-study-clean/tools/tracing/rtla/src/common.c

File Facts

System
Linux kernel
Corpus path
tools/tracing/rtla/src/common.c
Extension
.c
Size
10326 bytes
Lines
457
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (retval == -1) {
			err_msg("Failed to set rtla to the house keeping CPUs\n");
			goto out_err;
		}
	} else if (params->cpus) {
		/*
		 * Even if the user do not set a house-keeping CPU, try to
		 * move rtla to a CPU set different to the one where the user
		 * set the workload to run.
		 *
		 * No need to check results as this is an automatic attempt.
		 */
		auto_house_keeping(&params->monitored_cpus);
	}

	/*
	 * Set workload according to type of thread if the kernel supports it.
	 * On kernels without support, user threads will have already failed
	 * on missing fd, and kernel threads do not need it.
	 */
	retval = osnoise_set_workload(tool->context, params->kernel_workload);
	if (retval < -1) {
		err_msg("Failed to set OSNOISE_WORKLOAD option\n");
		goto out_err;
	}

	return 0;

out_err:
	return -1;
}


/**
 * common_threshold_handler - handle latency threshold overflow
 * @tool: pointer to the osnoise_tool instance containing trace contexts
 *
 * Executes the configured threshold actions (e.g., saving trace, printing,
 * sending signals). If the continue flag is set (--on-threshold continue),
 * restarts the auxiliary trace instances to continue monitoring.
 *
 * Return: 0 for success, -1 for error.
 */
int
common_threshold_handler(const struct osnoise_tool *tool)
{
	actions_perform(&tool->params->threshold_actions);

	if (!should_continue_tracing(tool->params))
		/* continue flag not set, break */
		return 0;

	/* continue action reached, re-enable tracing */
	if (tool->record && trace_instance_start(&tool->record->trace))
		goto err;
	if (tool->aa && trace_instance_start(&tool->aa->trace))
		goto err;

	return 0;

err:
	err_msg("Error restarting trace\n");
	return -1;
}

int run_tool(struct tool_ops *ops, int argc, char *argv[])
{
	struct common_params *params;
	enum result return_value = ERROR;
	struct osnoise_tool *tool;
	bool stopped;
	int retval;

	nr_cpus = get_nprocs_conf();
	params = ops->parse_args(argc, argv);
	if (!params)
		exit(1);

	tool = ops->init_tool(params);
	if (!tool) {
		err_msg("Could not init osnoise tool\n");
		goto out_exit;
	}
	tool->ops = ops;
	tool->params = params;

	/*
	 * Expose the tool to signal handlers so they can stop the trace.
	 * Otherwise, rtla could loop indefinitely when overloaded.
	 */

Annotation

Implementation Notes