From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 29 16:03:45 2015 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5B7DFBB1 for ; Sun, 29 Mar 2015 16:03:45 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D8A4D3BC for ; Sun, 29 Mar 2015 16:03:44 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t2TG3dC7099724 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 29 Mar 2015 19:03:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t2TG3dC7099724 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t2TG3cUo099723; Sun, 29 Mar 2015 19:03:38 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 29 Mar 2015 19:03:38 +0300 From: Konstantin Belousov To: Jilles Tjoelker Subject: Re: kevent behavior Message-ID: <20150329160338.GZ2379@kib.kiev.ua> References: <550A6DA2.1070004@gmail.com> <20150324221541.GA67584@stack.nl> <20150325090041.GY2379@kib.kiev.ua> <20150325223530.GA79065@stack.nl> <20150326214551.GG2379@kib.kiev.ua> <20150326225826.GA97319@stack.nl> <20150327132654.GJ2379@kib.kiev.ua> <20150329150316.GB95224@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150329150316.GB95224@stack.nl> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: freebsd-hackers@FreeBSD.org, Ivan Radovanovic X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Mar 2015 16:03:45 -0000 On Sun, Mar 29, 2015 at 05:03:16PM +0200, Jilles Tjoelker wrote: > On Fri, Mar 27, 2015 at 03:26:54PM +0200, Konstantin Belousov wrote: > > +Otherwise, i.e. if > > +.Fa nevents > > +is zero, the call is not cancellable. > > > +Cancellation can only occur when the call was blocked and no changes > > +to the queue were requested. > > This is not how the code works, but I think the code is correct. The > code also allows cancellation before anything happens. As such, if > cancellation occurs at kevent(2), the kqueue's state is unchanged (from > that call). Below is only a new diff for the man pages changes. I found our list of the cancellation points in the pthread_testcancel(3), but did not checked it for correctness. > > A new error should be added to the man page: > > .It Bq Er EINTR > A cancellation request was delivered to the thread, but not yet handled. > > Both [EINTR] errors should have this sentence added to them: > > All changes in the > .Fa changelist > have been applied. > I formulated this after the error list. diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 93223f1..c5e8caf 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 18, 2014 +.Dd March 29, 2015 .Dt KQUEUE 2 .Os .Sh NAME @@ -41,7 +41,7 @@ .Fn kqueue "void" .Ft int .Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout" -.Fn EV_SET "&kev" ident filter flags fflags data udata +.Fn EV_SET "kev" ident filter flags fflags data udata .Sh DESCRIPTION The .Fn kqueue @@ -550,6 +550,16 @@ On return, .Va fflags contains the users defined flags in the lower 24 bits. .El +.Sh CANCELLATION BEHAVIOUR +If +.Fa nevents +is non-zero, i.e. the function is potentially blocking, the call +is a cancellation point. +Otherwise, i.e. if +.Fa nevents +is zero, the call is not cancellable. +Cancellation can only occur before any changes are made to the kqueue, +or when the call was blocked and no changes to the queue were requested. .Sh RETURN VALUES The .Fn kqueue @@ -620,6 +630,8 @@ The specified descriptor is invalid. .It Bq Er EINTR A signal was delivered before the timeout expired and before any events were placed on the kqueue for return. +.It Bq Er EINTR +A cancellation request was delivered to the thread, but not yet handled. .It Bq Er EINVAL The specified time limit or filter is invalid. .It Bq Er ENOENT @@ -634,6 +646,14 @@ sysctl. .It Bq Er ESRCH The specified process to attach to does not exist. .El +.Pp +When +.Fn kevent +call fails with +.Er EINTR +error, all changes in the +.Fa changelist +have been applied. .Sh SEE ALSO .Xr aio_error 2 , .Xr aio_read 2 , @@ -643,6 +663,7 @@ The specified process to attach to does not exist. .Xr select 2 , .Xr sigaction 2 , .Xr write 2 , +.Xr pthread_setcancelstate 3 , .Xr signal 3 .Sh HISTORY The diff --git a/share/man/man3/pthread_testcancel.3 b/share/man/man3/pthread_testcancel.3 index ef6a1c1..4390c92 100644 --- a/share/man/man3/pthread_testcancel.3 +++ b/share/man/man3/pthread_testcancel.3 @@ -1,5 +1,5 @@ .\" $FreeBSD$ -.Dd June 11, 2013 +.Dd March 29, 2015 .Dt PTHREAD_TESTCANCEL 3 .Os .Sh NAME @@ -107,6 +107,7 @@ functions: .Fn close , .Fn creat , .Fn fsync , +.Fn kevent , .Fn mq_receive , .Fn mq_send , .Fn mq_timedreceive ,