Skip to content

Commit

Permalink
msys2-runtime: pipe: Fix a regression that raw_write() slows down
Browse files Browse the repository at this point in the history
This corresponds to msys2/msys2-runtime#227.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Sep 4, 2024
1 parent bf7f464 commit 4851f5d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 2bfb7739dadf6a27f9b4c006adfd69944f3df2f1 Mon Sep 17 00:00:00 2001
From: Takashi Yano <[email protected]>
Date: Sun, 1 Sep 2024 04:31:03 +0900
Subject: [PATCH 40/N] Cygwin: pipe: Fix a regression that raw_write() slows
down

After the commit 7f3c22532577, writing to pipe extremely slows down.
This is because cygwait(select_sem, 10, cw_cancel) is called even
when write operation is already completed. With this patch, the
cygwait() is called only if the write operation is not completed.

Backported-from: 37ab3e0d55 (Cygwin: pipe: Fix a regression that raw_write() slows down, 2024-09-01)
Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256398.html
Fixes: 7f3c22532577 ("Cygwin: pipe: handle signals explicitely in raw_write")
Reported-by: Jim Reisert AD1C <[email protected]>
Reviewed-by: Corinna Vinschen <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
---
winsup/cygwin/fhandler/pipe.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
index 5d2fe12..040176e 100644
--- a/winsup/cygwin/fhandler/pipe.cc
+++ b/winsup/cygwin/fhandler/pipe.cc
@@ -503,8 +503,9 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
raise (SIGPIPE);
goto out;
}
- else
- cygwait (select_sem, 10, cw_cancel);
+ /* Break out on completion */
+ if (waitret == WAIT_OBJECT_0)
+ break;
/* If we got a timeout in the blocking case, and we already
did a short write, we got a signal in the previous loop. */
if (waitret == WAIT_TIMEOUT && short_write_once)
@@ -512,6 +513,7 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
waitret = WAIT_SIGNALED;
break;
}
+ cygwait (select_sem, 10, cw_cancel);
}
/* Loop in case of blocking write or SA_RESTART */
while (waitret == WAIT_TIMEOUT || waitret == WAIT_SIGNALED);
11 changes: 7 additions & 4 deletions msys2-runtime/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pkgbase=msys2-runtime
pkgname=('msys2-runtime' 'msys2-runtime-devel')
pkgver=3.5.4
pkgrel=1
pkgrel=2
pkgdesc="Cygwin POSIX emulation engine"
arch=('x86_64')
url="https://www.cygwin.com/"
Expand Down Expand Up @@ -67,7 +67,8 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
0036-build_env-respect-the-MSYS-environment-variable.patch
0037-Revert-Cygwin-Enable-dynamicbase-on-the-Cygwin-DLL-b.patch
0038-Avoid-sharing-cygheaps-across-Cygwin-versions.patch
0039-uname-report-msys2-runtime-commit-hash-too.patch)
0039-uname-report-msys2-runtime-commit-hash-too.patch
0040-Cygwin-pipe-Fix-a-regression-that-raw_write-slows-do.patch)
sha256sums=('b8dce32fd9746506752d90ac3f30454fe1689100b08c41442016aaf244cc8584'
'9f9e1b6b05cbc9a715fe9443740b25171e9c1a276a058e6ba7e4f6eada6872c8'
'e5b2095e543a5d702cfce6da26cd17a78f40e17620315b1bcc434b94a007ae9b'
Expand Down Expand Up @@ -107,7 +108,8 @@ sha256sums=('b8dce32fd9746506752d90ac3f30454fe1689100b08c41442016aaf244cc8584'
'5990fbc34e4ac09229383e9a0f3326513a5a9482ebcca929302af0707d96a321'
'f74cb189aafc9f8bf04cdad02531d9eca524c2dd12672e4e118bfdbb48926110'
'344f108bc9e9ad597e07f1cc8e834e3d1a9fbd9972a1554c1c5de0fce0ae8506'
'f93578a1150d724a60a7e8eb8491342aeb13f809e2ddb5193d8d126465f665cb')
'f93578a1150d724a60a7e8eb8491342aeb13f809e2ddb5193d8d126465f665cb'
'41e896036ea67c5d12a712554f4d53949c2dc809bb3545ac6be1fe619848f8af')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
Expand Down Expand Up @@ -183,7 +185,8 @@ prepare() {
0036-build_env-respect-the-MSYS-environment-variable.patch \
0037-Revert-Cygwin-Enable-dynamicbase-on-the-Cygwin-DLL-b.patch \
0038-Avoid-sharing-cygheaps-across-Cygwin-versions.patch \
0039-uname-report-msys2-runtime-commit-hash-too.patch
0039-uname-report-msys2-runtime-commit-hash-too.patch \
0040-Cygwin-pipe-Fix-a-regression-that-raw_write-slows-do.patch
}

build() {
Expand Down

0 comments on commit 4851f5d

Please sign in to comment.