kernel/power/qos.c

Source file repositories/reference/linux-study-clean/kernel/power/qos.c

File Facts

System
Linux kernel
Corpus path
kernel/power/qos.c
Extension
.c
Size
20844 bytes
Lines
795
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations cpu_latency_qos_fops = {
	.write = cpu_latency_qos_write,
	.read = cpu_latency_qos_read,
	.open = cpu_latency_qos_open,
	.release = cpu_latency_qos_release,
	.llseek = noop_llseek,
};

static struct miscdevice cpu_latency_qos_miscdev = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = "cpu_dma_latency",
	.fops = &cpu_latency_qos_fops,
};

#ifdef CONFIG_PM_QOS_CPU_SYSTEM_WAKEUP
/* The CPU system wakeup latency QoS. */
static struct pm_qos_constraints cpu_wakeup_latency_constraints = {
	.list = PLIST_HEAD_INIT(cpu_wakeup_latency_constraints.list),
	.target_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT,
	.default_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT,
	.no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT,
	.type = PM_QOS_MIN,
};

/**
 * cpu_wakeup_latency_qos_limit - Current CPU system wakeup latency QoS limit.
 *
 * Returns the current CPU system wakeup latency QoS limit that may have been
 * requested by user space.
 */
s32 cpu_wakeup_latency_qos_limit(void)
{
	return pm_qos_read_value(&cpu_wakeup_latency_constraints);
}

static int cpu_wakeup_latency_qos_open(struct inode *inode, struct file *filp)
{
	struct pm_qos_request *req;

	req = kzalloc_obj(*req);
	if (!req)
		return -ENOMEM;

	req->qos = &cpu_wakeup_latency_constraints;
	pm_qos_update_target(req->qos, &req->node, PM_QOS_ADD_REQ,
			     PM_QOS_RESUME_LATENCY_NO_CONSTRAINT);
	filp->private_data = req;

	return 0;
}

static int cpu_wakeup_latency_qos_release(struct inode *inode,
					  struct file *filp)
{
	struct pm_qos_request *req = filp->private_data;

	filp->private_data = NULL;
	pm_qos_update_target(req->qos, &req->node, PM_QOS_REMOVE_REQ,
			     PM_QOS_RESUME_LATENCY_NO_CONSTRAINT);
	kfree(req);

	return 0;
}

static ssize_t cpu_wakeup_latency_qos_read(struct file *filp, char __user *buf,
					   size_t count, loff_t *f_pos)
{
	s32 value = pm_qos_read_value(&cpu_wakeup_latency_constraints);

	return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32));
}

static ssize_t cpu_wakeup_latency_qos_write(struct file *filp,
					    const char __user *buf,
					    size_t count, loff_t *f_pos)
{
	struct pm_qos_request *req = filp->private_data;
	s32 value;

	if (count == sizeof(s32)) {
		if (copy_from_user(&value, buf, sizeof(s32)))
			return -EFAULT;
	} else {
		int ret;

		ret = kstrtos32_from_user(buf, count, 16, &value);
		if (ret)
			return ret;
	}

Annotation

Implementation Notes