Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 554479d4 authored by Akhil P Oommen's avatar Akhil P Oommen Committed by Harshit Jain
Browse files

msm: kgsl: Improve locking of process list



Use a light weight lock for process list to avoid lock contention.

Change-Id: I8d751c5aa3f61066af097a0c67abbed8c399b913
Signed-off-by: default avatarAkhil P Oommen <akhilpo@codeaurora.org>
Signed-off-by: default avatarPuranam V G Tejaswi <pvgtejas@codeaurora.org>
parent f946add8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
/* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -745,7 +745,7 @@ static void setup_fault_process(struct kgsl_device *device,
	if (kgsl_mmu_is_perprocess(&device->mmu)) {
		struct kgsl_process_private *tmp;

		mutex_lock(&kgsl_driver.process_mutex);
		spin_lock(&kgsl_driver.proclist_lock);
		list_for_each_entry(tmp, &kgsl_driver.process_list, list) {
			u64 pt_ttbr0;

@@ -756,7 +756,7 @@ static void setup_fault_process(struct kgsl_device *device,
				break;
			}
		}
		mutex_unlock(&kgsl_driver.process_mutex);
		spin_unlock(&kgsl_driver.proclist_lock);
	}
done:
	snapshot->process = process;
+7 −2
Original line number Diff line number Diff line
@@ -1002,7 +1002,7 @@ struct kgsl_process_private *kgsl_process_private_find(pid_t pid)
{
	struct kgsl_process_private *p, *private = NULL;

	mutex_lock(&kgsl_driver.process_mutex);
	spin_lock(&kgsl_driver.proclist_lock);
	list_for_each_entry(p, &kgsl_driver.process_list, list) {
		if (pid_nr(p->pid) == pid) {
			if (kgsl_process_private_get(p))
@@ -1010,7 +1010,7 @@ struct kgsl_process_private *kgsl_process_private_find(pid_t pid)
			break;
		}
	}
	mutex_unlock(&kgsl_driver.process_mutex);
	spin_unlock(&kgsl_driver.proclist_lock);
	return private;
}

@@ -1127,7 +1127,9 @@ static void kgsl_process_private_close(struct kgsl_device_private *dev_priv,
		kgsl_mmu_detach_pagetable(private->pagetable);

	/* Remove the process struct from the master list */
	spin_lock(&kgsl_driver.proclist_lock);
	list_del(&private->list);
	spin_unlock(&kgsl_driver.proclist_lock);

	/*
	 * Unlock the mutex before releasing the memory and the debugfs
@@ -1163,7 +1165,9 @@ static struct kgsl_process_private *kgsl_process_private_open(
		kgsl_process_init_sysfs(device, private);
		kgsl_process_init_debugfs(private);

		spin_lock(&kgsl_driver.proclist_lock);
		list_add(&private->list, &kgsl_driver.process_list);
		spin_unlock(&kgsl_driver.proclist_lock);
	}

done:
@@ -4877,6 +4881,7 @@ static const struct file_operations kgsl_fops = {

struct kgsl_driver kgsl_driver  = {
	.process_mutex = __MUTEX_INITIALIZER(kgsl_driver.process_mutex),
	.proclist_lock = __SPIN_LOCK_UNLOCKED(kgsl_driver.proclist_lock),
	.ptlock = __SPIN_LOCK_UNLOCKED(kgsl_driver.ptlock),
	.devlock = __MUTEX_INITIALIZER(kgsl_driver.devlock),
	/*
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ struct kgsl_context;
 * @pagetable_list: LIst of open pagetables
 * @ptlock: Lock for accessing the pagetable list
 * @process_mutex: Mutex for accessing the process list
 * @proclist_lock: Lock for accessing the process list
 * @devlock: Mutex protecting the device list
 * @stats: Struct containing atomic memory statistics
 * @full_cache_threshold: the threshold that triggers a full cache flush
@@ -143,6 +144,7 @@ struct kgsl_driver {
	struct list_head pagetable_list;
	spinlock_t ptlock;
	struct mutex process_mutex;
	spinlock_t proclist_lock;
	struct mutex devlock;
	struct {
		atomic_long_t vmalloc;
+3 −3
Original line number Diff line number Diff line
@@ -781,16 +781,16 @@ static struct kgsl_process_private *kgsl_iommu_identify_process(u64 ptbase)
	struct kgsl_process_private *p = NULL;
	struct kgsl_iommu_pt *iommu_pt;

	mutex_lock(&kgsl_driver.process_mutex);
	spin_lock(&kgsl_driver.proclist_lock);
	list_for_each_entry(p, &kgsl_driver.process_list, list) {
		iommu_pt = p->pagetable->priv;
		if (iommu_pt->ttbr0 == ptbase) {
			mutex_unlock(&kgsl_driver.process_mutex);
			spin_unlock(&kgsl_driver.proclist_lock);
			return p;
		}
	}

	mutex_unlock(&kgsl_driver.process_mutex);
	spin_unlock(&kgsl_driver.proclist_lock);
	return p;
}