From owner-svn-src-projects@FreeBSD.ORG Sat Jun 9 16:10:59 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C180B1065670; Sat, 9 Jun 2012 16:10:59 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-bk0-f54.google.com (mail-bk0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9D2F18FC19; Sat, 9 Jun 2012 16:10:58 +0000 (UTC) Received: by bkvi18 with SMTP id i18so3163646bkv.13 for ; Sat, 09 Jun 2012 09:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=1jB80tkS80bLQmj/TAb7q6fRDZlk/KbBfhAQKdco4fk=; b=OBauBWB956Bs4pyiwzL7hC6Hx7+Mmm/TIDrpKsc+c9+YE41c0DBVG1gdD1gpbL63sB h6K9ASb5CB3Dn2zs8h/P0YFzhLZmJDz55kJdD/tjWJGHzT2MYKjV8Uy1ywB+WAIguUxl XhWET4u9V4gv6zhkt+U4m5xVjC6VphfIsBe87w6Kert/D2+3IeGSd8A5d9Tv7S8u1pZm FfAGncYkgYyoxQ0Mo/pGP5IvZoA2TEcgO9bCX1C6X3EZ63UG6vaHew0Z2Y2LfchTO0fG Yf0ul3ZxfdWxLbokKuj9j/ujrOEifaZHqblCEzRuFKEOc9kFcRXQfK6nOM/RC43oMnPj oitQ== Received: by 10.204.157.151 with SMTP id b23mr7740938bkx.44.1339258257281; Sat, 09 Jun 2012 09:10:57 -0700 (PDT) Received: from mavbook2.mavhome.dp.ua (pc.mavhome.dp.ua. [212.86.226.226]) by mx.google.com with ESMTPS id n17sm10786757bkw.5.2012.06.09.09.10.55 (version=SSLv3 cipher=OTHER); Sat, 09 Jun 2012 09:10:56 -0700 (PDT) Sender: Alexander Motin Message-ID: <4FD3758E.4030702@FreeBSD.org> Date: Sat, 09 Jun 2012 19:10:54 +0300 From: Alexander Motin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:12.0) Gecko/20120506 Thunderbird/12.0.1 MIME-Version: 1.0 To: Attilio Rao References: <201206081153.q58BrqG2056771@svn.freebsd.org> <4FD3707B.1050407@FreeBSD.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Davide Italiano , svn-src-projects@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r236744 - in projects/calloutng/sys: kern sys X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jun 2012 16:10:59 -0000 On 06/09/12 18:54, Attilio Rao wrote: > 2012/6/9 Alexander Motin: >> On 06/08/12 15:52, Attilio Rao wrote: >>> >>> 2012/6/8 Davide Italiano: >>>> >>>> Author: davide >>>> Date: Fri Jun 8 11:53:51 2012 >>>> New Revision: 236744 >>>> URL: http://svn.freebsd.org/changeset/base/236744 >>>> >>>> Log: >>>> Add (experimentally) a function to the sleepqueue(9) KPI >>>> sleepq_set_timeout_bt() in which the timeout may be specified in terms >>>> of bintime rather than ticks, and which takes advantage of the new >>>> precision capabilities of the callout subsystem. >>>> >>>> Modify the kern_nanosleep() function so that it may rely on >>>> sleepq_set_timeout_bt() rather than tsleep(). >>>> >>>> Modified: >>>> projects/calloutng/sys/kern/kern_time.c >>>> projects/calloutng/sys/kern/subr_sleepqueue.c >>>> projects/calloutng/sys/sys/sleepqueue.h >>>> >>>> Modified: projects/calloutng/sys/kern/kern_time.c >>>> >>>> ============================================================================== >>>> --- projects/calloutng/sys/kern/kern_time.c Fri Jun 8 11:40:30 2012 >>>> (r236743) >>>> +++ projects/calloutng/sys/kern/kern_time.c Fri Jun 8 11:53:51 2012 >>>> (r236744) >>>> @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); >>>> #include >>>> #include >>>> #include >>>> +#include >>>> #include >>>> #include >>>> #include >>>> @@ -352,37 +353,40 @@ static int nanowait; >>>> int >>>> kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec >>>> *rmt) >>>> { >>>> - struct timespec ts, ts2, ts3; >>>> - struct timeval tv; >>>> - int error; >>>> + struct timespec ts; >>>> + struct bintime bt, bt2, tmp; >>>> + int catch = 0, error; >>>> >>>> if (rqt->tv_nsec< 0 || rqt->tv_nsec>= 1000000000) >>>> return (EINVAL); >>>> if (rqt->tv_sec< 0 || (rqt->tv_sec == 0&& rqt->tv_nsec == 0)) >>>> >>>> return (0); >>>> - getnanouptime(&ts); >>>> - timespecadd(&ts, rqt); >>>> - TIMESPEC_TO_TIMEVAL(&tv, rqt); >>>> + binuptime(&bt); >>>> + timespec2bintime(rqt,&tmp); >>>> + bintime_add(&bt,&tmp); >>>> for (;;) { >>>> - error = tsleep(&nanowait, PWAIT | PCATCH, "nanslp", >>>> - tvtohz(&tv)); >>>> - getnanouptime(&ts2); >>>> - if (error != EWOULDBLOCK) { >>>> - if (error == ERESTART) >>>> - error = EINTR; >>>> - if (rmt != NULL) { >>>> - timespecsub(&ts,&ts2); >>>> - if (ts.tv_sec< 0) >>>> - timespecclear(&ts); >>>> - *rmt = ts; >>>> - } >>>> + sleepq_lock(&nanowait); >>>> + sleepq_add(&nanowait, NULL, "nanslp", PWAIT | PCATCH, 0); >>>> + sleepq_set_timeout_bt(&nanowait,bt); >>>> + error = sleepq_timedwait_sig(&nanowait,catch); >>>> + binuptime(&bt2); >>>> + if (catch) { >>>> + if (error != EWOULDBLOCK) { >>>> + if (error == ERESTART) >>>> + error = EINTR; >>>> + if (rmt != NULL) { >>>> + tmp = bt; >>>> + bintime_sub(&tmp,&bt2); >>>> + bintime2timespec(&tmp,&ts); >>>> + if (ts.tv_sec< 0) >>>> + timespecclear(&ts); >>>> + *rmt = ts; >>>> + } >>>> return (error); >>>> + } >>>> } >>>> - if (timespeccmp(&ts2,&ts,>=)) >>>> + if (bintime_cmp(&bt2,&bt,>=)) >>>> >>>> return (0); >>>> - ts3 = ts; >>>> - timespecsub(&ts3,&ts2); >>>> - TIMESPEC_TO_TIMEVAL(&tv,&ts3); >>>> } >>>> } >>>> >>>> >>>> Modified: projects/calloutng/sys/kern/subr_sleepqueue.c >>>> >>>> ============================================================================== >>>> --- projects/calloutng/sys/kern/subr_sleepqueue.c Fri Jun 8 >>>> 11:40:30 2012 (r236743) >>>> +++ projects/calloutng/sys/kern/subr_sleepqueue.c Fri Jun 8 >>>> 11:53:51 2012 (r236744) >>>> @@ -361,6 +361,22 @@ sleepq_add(void *wchan, struct lock_obje >>>> * Sets a timeout that will remove the current thread from the specified >>>> * sleep queue after timo ticks if the thread has not already been >>>> awakened. >>>> */ >>>> +void >>>> +sleepq_set_timeout_bt(void *wchan, struct bintime bt) >>>> +{ >>>> + >>>> + struct sleepqueue_chain *sc; >>>> + struct thread *td; >>>> + >>>> + td = curthread; >>>> + sc = SC_LOOKUP(wchan); >>>> + mtx_assert(&sc->sc_lock, MA_OWNED); >>>> + MPASS(TD_ON_SLEEPQ(td)); >>>> + MPASS(td->td_sleepqueue == NULL); >>>> + MPASS(wchan != NULL); >>>> + callout_reset_bt_on(&td->td_slpcallout, bt, sleepq_timeout, td, >>>> PCPU_GET(cpuid)); >>>> +} >>>> + >>> >>> >>> For this, I'd rather prefer that you patch sleepq_set_timeout() directly >>> to be: >>> void sleepq_set_timeout(void *wchan, int timo, struct bintime *bt); >>> >>> Then, if you pass a NULL ptr to bt the 'timo' is used, otherwise bt is >>> given preference in the logic. You will need to patch the current few >>> callers of sleepq_set_timo() to get NULL, but it is a small patch. >>> I would really like that you do the same also in the callout KPI, >>> possibly, because this avoids a lot of code duplication. >> >> >> As opposite opinion, I don't like an idea of functions with both kinds of >> time arguments. It will break existing API/ABI (yes, rarely used, but >> already existing and documented) without giving any real benefits. >> Duplication of few code lines IMHO is not an argument at all if we are >> speaking about choosing API. Speaking about such a popular API as >> callout(9), I believe API breakage is just not an option. > > I respectfully disagree. > We can break KPI between major version and this is not a problem. You > can consider to add some compatibility churn like this one for MFC, if > you need, but for HEAD we should really have cleaner code rather than > code duplication which brings to less mainteneability. For other > example of double-loaded arguments, please look at the interrupt > filter/interrupt threads interface. > I really think having a specific function just for passing timo/bt is > overkill. And you are really making a major change which is expected > to bring to changed KPI. That is a question of comparing prices. In my opinion, the fact that we can change KPI between major releases does not mean that we should do it without really strong reason. IMO open source world too often tends to change the rules and APIs. That may work for in-tree code, when person changing API will catch up all consequences. But each change of that kind can make sad some vendor you never heard about, when his code will no longer compile and he will have to either add some more #ifdef's or drop FreeBSD support. If keeping compatibility would cost us some performance or hundreds lines of extra code, I would agree, but IMHO this case with few lines of code is different. -- Alexander Motin