[dpdk-dev,v4,1/5] vhost: eventfd_link: moving ioctl to a function
Commit Message
Move ioctl `EVENTFD_COPY' handler code to an inline function.
---
lib/librte_vhost/eventfd_link/eventfd_link.c | 171 ++++++++++++++-------------
1 file changed, 89 insertions(+), 82 deletions(-)
Comments
On 4/3/2015 1:02 AM, Pavel Boldin wrote:
> Move ioctl `EVENTFD_COPY' handler code to an inline function.
Pavel:
There is no necessity to inline this function.
/huawei
On Thu, May 7, 2015 at 10:57 AM, Xie, Huawei <huawei.xie@intel.com> wrote:
> On 4/3/2015 1:02 AM, Pavel Boldin wrote:
> > Move ioctl `EVENTFD_COPY' handler code to an inline function.
> Pavel:
> There is no necessity to inline this function.
>
Xie, there is even no necessity to split this in a five piece patchseries.
I did that solely for the purpose of clean reading.
There is no necessity to inline any single-used functions as long the
compiler is decent. But I prefer to instruct compiler to do this explictly
so there is no call/ret path in the generated code.
Pavel
> /huawei
>
On 5/7/2015 9:17 PM, Pavel Boldin wrote:
On Thu, May 7, 2015 at 10:57 AM, Xie, Huawei <huawei.xie@intel.com<mailto:huawei.xie@intel.com>> wrote:
On 4/3/2015 1:02 AM, Pavel Boldin wrote:
> Move ioctl `EVENTFD_COPY' handler code to an inline function.
Pavel:
There is no necessity to inline this function.
Xie, there is even no necessity to split this in a five piece patchseries. I did that solely for the purpose of clean reading.
There is no necessity to inline any single-used functions as long the compiler is decent. But I prefer to instruct compiler to do this explictly so there is no call/ret path in the generated code.
The purpose of inline or not is not for friendly reading. inline is for performance only.
Pavel
/huawei
On Mon, May 18, 2015 at 9:06 AM, Xie, Huawei <huawei.xie@intel.com> wrote:
> On 5/7/2015 9:17 PM, Pavel Boldin wrote:
>
>
> On Thu, May 7, 2015 at 10:57 AM, Xie, Huawei <huawei.xie@intel.com<mailto:
> huawei.xie@intel.com>> wrote:
> On 4/3/2015 1:02 AM, Pavel Boldin wrote:
> > Move ioctl `EVENTFD_COPY' handler code to an inline function.
> Pavel:
> There is no necessity to inline this function.
> Xie, there is even no necessity to split this in a five piece patchseries.
> I did that solely for the purpose of clean reading.
>
> There is no necessity to inline any single-used functions as long the
> compiler is decent. But I prefer to instruct compiler to do this explictly
> so there is no call/ret path in the generated code.
>
> The purpose of inline or not is not for friendly reading. inline is for
> performance only.
>
Well, an optimizing compiler `inline's all the `static' functions that are
called only once in the file. So, this `inline' is purely for readability
of the code. This makes user aware that the function will be `inline'd
anyway.
Pavel
>
>
>
> /huawei
>
>
>
Two opens here, the trivial one is i think it is not good practice to
explicitly inline non performance critical functions in c file, even if
it will be done by compiler anyway.
The critical one i have concern is whether it will introduce
inconsistency if we call fd_install on a fd that is just closed by
sys_close, because that fd will be set to next-to-be-allocated fd. I
prefer to keep the original logic in patch 4/5 if we are not clear.
As we actually don't need to use the eventfd that is allocated in user
space at all, future patch would be: directly allocate a new fd in the
kernel and call fd_install on it.
@@ -65,9 +65,8 @@ put_files_struct(struct files_struct *files)
BUG();
}
-
-static long
-eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
+static inline long
+eventfd_link_ioctl_copy(unsigned long arg)
{
void __user *argp = (void __user *) arg;
struct task_struct *task_target = NULL;
@@ -76,90 +75,98 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
struct fdtable *fdt;
struct eventfd_copy eventfd_copy;
- switch (ioctl) {
- case EVENTFD_COPY:
- if (copy_from_user(&eventfd_copy, argp,
- sizeof(struct eventfd_copy)))
- return -EFAULT;
-
- /*
- * Find the task struct for the target pid
- */
- task_target =
- pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID);
- if (task_target == NULL) {
- pr_debug("Failed to get mem ctx for target pid\n");
- return -EFAULT;
- }
-
- files = get_files_struct(current);
- if (files == NULL) {
- pr_debug("Failed to get files struct\n");
- return -EFAULT;
- }
-
- rcu_read_lock();
- file = fcheck_files(files, eventfd_copy.source_fd);
- if (file) {
- if (file->f_mode & FMODE_PATH ||
- !atomic_long_inc_not_zero(&file->f_count))
+ if (copy_from_user(&eventfd_copy, argp,
+ sizeof(struct eventfd_copy)))
+ return -EFAULT;
+
+ /*
+ * Find the task struct for the target pid
+ */
+ task_target =
+ pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID);
+ if (task_target == NULL) {
+ pr_debug("Failed to get mem ctx for target pid\n");
+ return -EFAULT;
+ }
+
+ files = get_files_struct(current);
+ if (files == NULL) {
+ pr_debug("Failed to get files struct\n");
+ return -EFAULT;
+ }
+
+ rcu_read_lock();
+ file = fcheck_files(files, eventfd_copy.source_fd);
+ if (file) {
+ if (file->f_mode & FMODE_PATH ||
+ !atomic_long_inc_not_zero(&file->f_count))
+ file = NULL;
+ }
+ rcu_read_unlock();
+ put_files_struct(files);
+
+ if (file == NULL) {
+ pr_debug("Failed to get file from source pid\n");
+ return 0;
+ }
+
+ /*
+ * Release the existing eventfd in the source process
+ */
+ spin_lock(&files->file_lock);
+ fput(file);
+ filp_close(file, files);
+ fdt = files_fdtable(files);
+ fdt->fd[eventfd_copy.source_fd] = NULL;
+ spin_unlock(&files->file_lock);
+
+ /*
+ * Find the file struct associated with the target fd.
+ */
+
+ files = get_files_struct(task_target);
+ if (files == NULL) {
+ pr_debug("Failed to get files struct\n");
+ return -EFAULT;
+ }
+
+ rcu_read_lock();
+ file = fcheck_files(files, eventfd_copy.target_fd);
+ if (file) {
+ if (file->f_mode & FMODE_PATH ||
+ !atomic_long_inc_not_zero(&file->f_count))
file = NULL;
- }
- rcu_read_unlock();
- put_files_struct(files);
-
- if (file == NULL) {
- pr_debug("Failed to get file from source pid\n");
- return 0;
- }
-
- /*
- * Release the existing eventfd in the source process
- */
- spin_lock(&files->file_lock);
- fput(file);
- filp_close(file, files);
- fdt = files_fdtable(files);
- fdt->fd[eventfd_copy.source_fd] = NULL;
- spin_unlock(&files->file_lock);
-
- /*
- * Find the file struct associated with the target fd.
- */
-
- files = get_files_struct(task_target);
- if (files == NULL) {
- pr_debug("Failed to get files struct\n");
- return -EFAULT;
- }
-
- rcu_read_lock();
- file = fcheck_files(files, eventfd_copy.target_fd);
- if (file) {
- if (file->f_mode & FMODE_PATH ||
- !atomic_long_inc_not_zero(&file->f_count))
- file = NULL;
- }
- rcu_read_unlock();
- put_files_struct(files);
-
- if (file == NULL) {
- pr_debug("Failed to get file from target pid\n");
- return 0;
- }
-
- /*
- * Install the file struct from the target process into the
- * file desciptor of the source process,
- */
-
- fd_install(eventfd_copy.source_fd, file);
+ }
+ rcu_read_unlock();
+ put_files_struct(files);
+ if (file == NULL) {
+ pr_debug("Failed to get file from target pid\n");
return 0;
+ }
+
+ /*
+ * Install the file struct from the target process into the
+ * file desciptor of the source process,
+ */
+
+ fd_install(eventfd_copy.source_fd, file);
+
+ return 0;
+}
- default:
- return -ENOIOCTLCMD;
+static long
+eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
+{
+ long ret = -ENOIOCTLCMD;
+
+ switch (ioctl) {
+ case EVENTFD_COPY:
+ ret = eventfd_link_ioctl_copy(arg);
+ break;
}
+
+ return ret;
}
static const struct file_operations eventfd_link_fops = {