aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2023-08-23 11:02:20 +0200
committerMikael Olsson <mikael.olsson@arm.com>2023-09-07 10:42:34 +0200
commit18257600f30afb78f4f82cd921073cef98f5ce81 (patch)
tree5461227e18d6f4cf413b41939ea097d561ef5c42
parent27fe8e06f3ceb6bcd606daeca5fb572c1ccdb9e7 (diff)
downloadethos-u-linux-driver-stack-18257600f30afb78f4f82cd921073cef98f5ce81.tar.gz
Reduce mutex scope for NPU device IOCTL calls
Instead of locking the device mutex for all IOCTL calls to the NPU device, the mutex will now only be locked for the calls that have resources that must be protected from concurrent access. IOCTL calls that only copy static data do not need to lock the mutex. The same device mutex is used for all concurrent access protection in the driver, including the mailbox handling, so removing unnecessary locking decreases the need to wait for the mutex. Change-Id: Ic606fe0e1db4aa2e3d4e579ada74418491546468 Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
-rw-r--r--kernel/ethosu_device.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/kernel/ethosu_device.c b/kernel/ethosu_device.c
index b63d068..6866857 100644
--- a/kernel/ethosu_device.c
+++ b/kernel/ethosu_device.c
@@ -244,10 +244,6 @@ static long ethosu_ioctl(struct file *file,
void __user *udata = (void __user *)arg;
int ret;
- ret = device_lock_interruptible(dev);
- if (ret)
- return ret;
-
dev_info(dev, "Device ioctl. file=0x%pK, cmd=0x%x, arg=0x%lx",
file, cmd, arg);
@@ -271,8 +267,16 @@ static long ethosu_ioctl(struct file *file,
break;
}
case ETHOSU_IOCTL_PING: {
+ ret = device_lock_interruptible(dev);
+ if (ret)
+ return ret;
+
dev_info(dev, "Device ioctl: Send ping");
+
ret = ethosu_mailbox_ping(&edev->mailbox);
+
+ device_unlock(dev);
+
break;
}
case ETHOSU_IOCTL_BUFFER_CREATE: {
@@ -283,11 +287,18 @@ static long ethosu_ioctl(struct file *file,
break;
}
+ ret = device_lock_interruptible(dev);
+ if (ret)
+ return ret;
+
dev_info(dev,
"Device ioctl: Buffer create. capacity=%u",
uapi.capacity);
ret = ethosu_buffer_create(dev, uapi.capacity);
+
+ device_unlock(dev);
+
break;
}
case ETHOSU_IOCTL_NETWORK_CREATE: {
@@ -298,11 +309,18 @@ static long ethosu_ioctl(struct file *file,
break;
}
+ ret = device_lock_interruptible(dev);
+ if (ret)
+ return ret;
+
dev_info(dev,
"Device ioctl: Network create. type=%u, fd/index=%u",
uapi.type, uapi.fd);
ret = ethosu_network_create(dev, &edev->mailbox, &uapi);
+
+ device_unlock(dev);
+
break;
}
default: {
@@ -313,8 +331,6 @@ static long ethosu_ioctl(struct file *file,
}
}
- device_unlock(dev);
-
return ret;
}