arch/x86/kernel/itmt.c

Source file repositories/reference/linux-study-clean/arch/x86/kernel/itmt.c

File Facts

System
Linux kernel
Corpus path
arch/x86/kernel/itmt.c
Extension
.c
Size
5081 bytes
Lines
191
Domain
Architecture Layer
Bucket
arch/x86
Inferred role
Architecture Layer: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations dfs_sched_itmt_fops = {
	.read =         debugfs_read_file_bool,
	.write =        sched_itmt_enabled_write,
	.open =         simple_open,
	.llseek =       default_llseek,
};

static struct dentry *dfs_sched_itmt;
static struct dentry *dfs_sched_core_prio;

/**
 * sched_set_itmt_support() - Indicate platform supports ITMT
 *
 * This function is used by the OS to indicate to scheduler that the platform
 * is capable of supporting the ITMT feature.
 *
 * The current scheme has the pstate driver detects if the system
 * is ITMT capable and call sched_set_itmt_support.
 *
 * This must be done only after sched_set_itmt_core_prio
 * has been called to set the cpus' priorities.
 * It must not be called with cpu hot plug lock
 * held as we need to acquire the lock to rebuild sched domains
 * later.
 *
 * Return: 0 on success
 */
int sched_set_itmt_support(void)
{
	guard(mutex)(&itmt_update_mutex);

	if (sched_itmt_capable)
		return 0;

	dfs_sched_itmt = debugfs_create_file_unsafe("sched_itmt_enabled",
						    0644,
						    arch_debugfs_dir,
						    &sysctl_sched_itmt_enabled,
						    &dfs_sched_itmt_fops);
	if (IS_ERR_OR_NULL(dfs_sched_itmt)) {
		dfs_sched_itmt = NULL;
		return -ENOMEM;
	}

	dfs_sched_core_prio = debugfs_create_file("sched_core_priority", 0644,
						  arch_debugfs_dir, NULL,
						  &sched_core_priority_fops);
	if (IS_ERR_OR_NULL(dfs_sched_core_prio)) {
		dfs_sched_core_prio = NULL;
		return -ENOMEM;
	}

	sched_itmt_capable = true;

	sysctl_sched_itmt_enabled = 1;

	x86_topology_update = true;
	rebuild_sched_domains();

	return 0;
}

/**
 * sched_clear_itmt_support() - Revoke platform's support of ITMT
 *
 * This function is used by the OS to indicate that it has
 * revoked the platform's support of ITMT feature.
 *
 * It must not be called with cpu hot plug lock
 * held as we need to acquire the lock to rebuild sched domains
 * later.
 */
void sched_clear_itmt_support(void)
{
	guard(mutex)(&itmt_update_mutex);

	if (!sched_itmt_capable)
		return;

	sched_itmt_capable = false;

	debugfs_remove(dfs_sched_itmt);
	dfs_sched_itmt = NULL;
	debugfs_remove(dfs_sched_core_prio);
	dfs_sched_core_prio = NULL;

	if (sysctl_sched_itmt_enabled) {
		/* disable sched_itmt if we are no longer ITMT capable */
		sysctl_sched_itmt_enabled = 0;
		x86_topology_update = true;

Annotation

Implementation Notes