From 7efe3414b73d759692751aeddd4e5c662994e57e Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Sun, 17 Oct 2021 23:50:38 -0700 Subject: [PATCH] qos: Change cpus_affine to not be atomic There isn't a need for cpus_affine to be atomic, and reading/writing to it outside of the global pm_qos lock is racy anyway. As such, we can simply turn it into a primitive integer type. Signed-off-by: Sultan Alsawaf --- drivers/gpu/drm/drm_atomic.c | 2 +- drivers/gpu/msm/kgsl_ioctl.c | 2 +- include/linux/pm_qos.h | 2 +- kernel/power/qos.c | 19 ++++++++++--------- techpack/audio/asoc/kona.c | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 1132a675e266..207614897a1e 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -2726,7 +2726,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, void *data, */ struct pm_qos_request req = { .type = PM_QOS_REQ_AFFINE_CORES, - .cpus_affine = ATOMIC_INIT(BIT(raw_smp_processor_id())) + .cpus_affine = BIT(raw_smp_processor_id()) }; int ret; diff --git a/drivers/gpu/msm/kgsl_ioctl.c b/drivers/gpu/msm/kgsl_ioctl.c index 7c17b19fe3a9..c123b6a73710 100644 --- a/drivers/gpu/msm/kgsl_ioctl.c +++ b/drivers/gpu/msm/kgsl_ioctl.c @@ -203,7 +203,7 @@ long kgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) */ struct pm_qos_request req = { .type = PM_QOS_REQ_AFFINE_CORES, - .cpus_affine = ATOMIC_INIT(BIT(raw_smp_processor_id())) + .cpus_affine = BIT(raw_smp_processor_id()) }; long ret; diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h index 13a9e912840a..a855d0073689 100644 --- a/include/linux/pm_qos.h +++ b/include/linux/pm_qos.h @@ -54,8 +54,8 @@ enum pm_qos_req_type { }; struct pm_qos_request { + unsigned long cpus_affine; enum pm_qos_req_type type; - atomic_t cpus_affine; #ifdef CONFIG_SMP uint32_t irq; /* Internal structure members */ diff --git a/kernel/power/qos.c b/kernel/power/qos.c index 3d3b6170b404..e0b662acc2d0 100644 --- a/kernel/power/qos.c +++ b/kernel/power/qos.c @@ -287,10 +287,10 @@ static inline int pm_qos_set_value_for_cpus(struct pm_qos_request *new_req, if (new_cpus) { /* cpus_affine changed, so the old CPUs need to be refreshed */ - new_req_cpus = atomic_read(&new_req->cpus_affine) | new_cpus; - atomic_set(&new_req->cpus_affine, new_cpus); + new_req_cpus = new_req->cpus_affine | new_cpus; + new_req->cpus_affine = new_cpus; } else { - new_req_cpus = atomic_read(&new_req->cpus_affine); + new_req_cpus = new_req->cpus_affine; } if (new_action != PM_QOS_REMOVE_REQ) { @@ -310,7 +310,7 @@ static inline int pm_qos_set_value_for_cpus(struct pm_qos_request *new_req, plist_for_each_entry(req, &c->list, node) { unsigned long affected_cpus; - affected_cpus = atomic_read(&req->cpus_affine) & new_req_cpus; + affected_cpus = req->cpus_affine & new_req_cpus; if (!affected_cpus) continue; @@ -601,7 +601,8 @@ void pm_qos_add_request(struct pm_qos_request *req, switch (req->type) { case PM_QOS_REQ_AFFINE_CORES: - if (!atomic_cmpxchg_relaxed(&req->cpus_affine, 0, CPUMASK_ALL)) { + if (!req->cpus_affine) { + req->cpus_affine = CPUMASK_ALL; req->type = PM_QOS_REQ_ALL_CORES; WARN(1, "Affine cores not set for request with affinity flag\n"); } @@ -618,14 +619,14 @@ void pm_qos_add_request(struct pm_qos_request *req, mask = desc->irq_data.common->affinity; /* Get the current affinity */ - atomic_set(&req->cpus_affine, *cpumask_bits(mask)); + req->cpus_affine = *cpumask_bits(mask); req->irq_notify.irq = req->irq; req->irq_notify.notify = pm_qos_irq_notify; req->irq_notify.release = pm_qos_irq_release; } else { req->type = PM_QOS_REQ_ALL_CORES; - atomic_set(&req->cpus_affine, CPUMASK_ALL); + req->cpus_affine = CPUMASK_ALL; WARN(1, "IRQ-%d not set for request with affinity flag\n", req->irq); } @@ -635,7 +636,7 @@ void pm_qos_add_request(struct pm_qos_request *req, WARN(1, "Unknown request type %d\n", req->type); /* fall through */ case PM_QOS_REQ_ALL_CORES: - atomic_set(&req->cpus_affine, CPUMASK_ALL); + req->cpus_affine = CPUMASK_ALL; break; } @@ -654,7 +655,7 @@ void pm_qos_add_request(struct pm_qos_request *req, if (ret) { WARN(1, "IRQ affinity notify set failed\n"); req->type = PM_QOS_REQ_ALL_CORES; - atomic_set(&req->cpus_affine, CPUMASK_ALL); + req->cpus_affine = CPUMASK_ALL; pm_qos_update_target( pm_qos_array[pm_qos_class]->constraints, &req->node, PM_QOS_UPDATE_REQ, value); diff --git a/techpack/audio/asoc/kona.c b/techpack/audio/asoc/kona.c index e9089df8f8fe..2fe8d07db9ce 100755 --- a/techpack/audio/asoc/kona.c +++ b/techpack/audio/asoc/kona.c @@ -5189,7 +5189,7 @@ static int msm_fe_qos_prepare(struct snd_pcm_substream *substream) if (pm_qos_request_active(&substream->latency_pm_qos_req)) pm_qos_remove_request(&substream->latency_pm_qos_req); - atomic_set(&substream->latency_pm_qos_req.cpus_affine, BIT(1) | BIT(2)); + substream->latency_pm_qos_req.cpus_affine = BIT(1) | BIT(2); substream->latency_pm_qos_req.type = PM_QOS_REQ_AFFINE_CORES;