From owner-svn-src-head@freebsd.org Sat Jul 4 06:25:42 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 60E71363100; Sat, 4 Jul 2020 06:25:42 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49zMK21Hhvz4FG0; Sat, 4 Jul 2020 06:25:42 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1030418448; Sat, 4 Jul 2020 06:25:42 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0646Pflf026708; Sat, 4 Jul 2020 06:25:41 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0646Pf7H026707; Sat, 4 Jul 2020 06:25:41 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202007040625.0646Pf7H026707@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 4 Jul 2020 06:25:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362922 - head/sys/compat/linux X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/compat/linux X-SVN-Commit-Revision: 362922 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jul 2020 06:25:42 -0000 Author: mjg Date: Sat Jul 4 06:25:41 2020 New Revision: 362922 URL: https://svnweb.freebsd.org/changeset/base/362922 Log: linux: fix ioctl performance for termios TCGETS et al are frequently issued by Linux binaries while the previous code avoidably ping-pongs a global sx lock and serializes on Giant. Note that even with the fix the common case will serialize on a per-tty lock. Modified: head/sys/compat/linux/linux_ioctl.c Modified: head/sys/compat/linux/linux_ioctl.c ============================================================================== --- head/sys/compat/linux/linux_ioctl.c Sat Jul 4 06:22:05 2020 (r362921) +++ head/sys/compat/linux/linux_ioctl.c Sat Jul 4 06:25:41 2020 (r362922) @@ -132,8 +132,6 @@ static struct linux_ioctl_handler socket_handler = { linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX }; static struct linux_ioctl_handler sound_handler = { linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX }; -static struct linux_ioctl_handler termio_handler = -{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX }; static struct linux_ioctl_handler private_handler = { linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX }; static struct linux_ioctl_handler drm_handler = @@ -156,7 +154,6 @@ DATA_SET(linux_ioctl_handler_set, hdio_handler); DATA_SET(linux_ioctl_handler_set, disk_handler); DATA_SET(linux_ioctl_handler_set, socket_handler); DATA_SET(linux_ioctl_handler_set, sound_handler); -DATA_SET(linux_ioctl_handler_set, termio_handler); DATA_SET(linux_ioctl_handler_set, private_handler); DATA_SET(linux_ioctl_handler_set, drm_handler); DATA_SET(linux_ioctl_handler_set, sg_handler); @@ -165,6 +162,14 @@ DATA_SET(linux_ioctl_handler_set, video2_handler); DATA_SET(linux_ioctl_handler_set, fbsd_usb); DATA_SET(linux_ioctl_handler_set, evdev_handler); +/* + * Keep sorted by low. + */ +static struct linux_ioctl_handler linux_ioctls[] = { + { .func = linux_ioctl_termio, .low = LINUX_IOCTL_TERMIO_MIN, + .high = LINUX_IOCTL_TERMIO_MAX }, +}; + #ifdef __i386__ static TAILQ_HEAD(, linux_ioctl_handler_element) linux_ioctl_handlers = TAILQ_HEAD_INITIALIZER(linux_ioctl_handlers); @@ -3558,8 +3563,8 @@ linux_ioctl_evdev(struct thread *td, struct linux_ioct * main ioctl syscall function */ -int -linux_ioctl(struct thread *td, struct linux_ioctl_args *args) +static int +linux_ioctl_fallback(struct thread *td, struct linux_ioctl_args *args) { struct file *fp; struct linux_ioctl_handler_element *he; @@ -3618,6 +3623,35 @@ linux_ioctl(struct thread *td, struct linux_ioctl_args } return (EINVAL); +} + +int +linux_ioctl(struct thread *td, struct linux_ioctl_args *args) +{ + struct linux_ioctl_handler *handler; + int error, cmd, i; + + cmd = args->cmd & 0xffff; + + /* + * array of ioctls known at compilation time. Elides a lot of work on + * each call compared to the list variant. Everything frequently used + * should be moved here. + * + * Arguably the magic creating the list should create an array instead. + * + * For now just a linear scan. + */ + for (i = 0; i < nitems(linux_ioctls); i++) { + handler = &linux_ioctls[i]; + if (cmd >= handler->low && cmd <= handler->high) { + error = (*handler->func)(td, args); + if (error != ENOIOCTL) { + return (error); + } + } + } + return (linux_ioctl_fallback(td, args)); } int