From owner-svn-src-all@FreeBSD.ORG Thu May 3 21:31:50 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D21E8106566B; Thu, 3 May 2012 21:31:50 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id D231C8FC14; Thu, 3 May 2012 21:31:49 +0000 (UTC) Received: by lagv3 with SMTP id v3so2166477lag.13 for ; Thu, 03 May 2012 14:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=emo8DhR5jaLJrOmpkKGNH0Y2TY78tgpKafzBsigjwFU=; b=OWjLZrqhBthWnltUCQq/yOSH4h7seddkE7qwhBxTZwgldSo+7Q7ato+AmXOd+rceLr oYGIlE98yWfv2Y9eiGJAavkJDVzrR+oybarbWn8prxIwKvY6TYiAV0AXOSphvzzPR4hY wrMd9yzvYCp0Dz3nfKMpqhW7yPa9ob8t2lxB0txlRNVr10UxSFN2Q/nJWHKecchNBdbr ZzduoES7WDu0Ohb/40T7XlLZO17wUou47CKCwJcPGL5zxvMIF9r/gT+dTWqk3/XWUEqw P7SUIqG/Uc1qOt3x/92SFPXHXvSbVe1XIT/NiORX60b+7EurGNofmbMo1bbFtrT+5LZZ mgEg== MIME-Version: 1.0 Received: by 10.152.132.166 with SMTP id ov6mr3801938lab.35.1336080708695; Thu, 03 May 2012 14:31:48 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.112.27.65 with HTTP; Thu, 3 May 2012 14:31:48 -0700 (PDT) In-Reply-To: <20120503212834.GP2358@deviant.kiev.zoral.com.ua> References: <201205031038.q43Ac2eZ032779@svn.freebsd.org> <20120503114913.GJ2358@deviant.kiev.zoral.com.ua> <20120503132715.GN2358@deviant.kiev.zoral.com.ua> <20120503212834.GP2358@deviant.kiev.zoral.com.ua> Date: Thu, 3 May 2012 22:31:48 +0100 X-Google-Sender-Auth: TH52gjxYDjpMyh00j1TxztT-UIU Message-ID: From: Attilio Rao To: Konstantin Belousov Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, christian.esken@trivago.com Subject: Re: svn commit: r234952 - in head/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2012 21:31:50 -0000 2012/5/3 Konstantin Belousov : > On Thu, May 03, 2012 at 10:06:53PM +0100, Attilio Rao wrote: >> 2012/5/3 Konstantin Belousov : >> > On Thu, May 03, 2012 at 02:14:20PM +0100, Attilio Rao wrote: >> >> 2012/5/3, Konstantin Belousov : >> >> > On Thu, May 03, 2012 at 12:02:08PM +0100, Attilio Rao wrote: >> >> >> 2012/5/3, Konstantin Belousov : >> >> >> > Author: kib >> >> >> > Date: Thu May =C2=A03 10:38:02 2012 >> >> >> > New Revision: 234952 >> >> >> > URL: http://svn.freebsd.org/changeset/base/234952 >> >> >> > >> >> >> > Log: >> >> >> > =C2=A0 When callout_reset_on() cannot immediately migrate a call= out since it >> >> >> > =C2=A0 is running on other cpu, the CALLOUT_PENDING flag is temp= orarily >> >> >> > =C2=A0 cleared. Then, callout_stop() on this, in fact active, ca= llout fails >> >> >> > =C2=A0 because CALLOUT_PENDING is not set, and callout_stop() re= turns 0. >> >> >> > >> >> >> > =C2=A0 Now, in sleepq_check_timeout(), the failed callout_stop()= causes the >> >> >> > =C2=A0 sleepq code to execute mi_switch() without even setting t= he wmesg, >> >> >> > =C2=A0 since the switch-out is supposed to be transient. In fact= , the thread >> >> >> > =C2=A0 is put off the CPU for full timeout interval, instead of = being put on >> >> >> > =C2=A0 runq immediately. =C2=A0Until timeout fires, the process = is unkillable for >> >> >> > =C2=A0 obvious reasons. >> >> >> > >> >> >> > =C2=A0 Fix this by marking the migrating callouts with CALLOUT_D= FRMIGRATION >> >> >> > =C2=A0 flag. The flag is cleared by callout_stop_safe() when the= function >> >> >> > =C2=A0 detects a migration, besides returning the success. The s= oftclock() >> >> >> > =C2=A0 rechecks the flag for migrating callout and cancels its e= xecution if >> >> >> > =C2=A0 the flag was cleared meantime. >> >> >> >> >> >> Can you please clarify why you cannot simply drop the deferred >> >> >> migration in the case !CALLOUT_PENDING in callout_stop_safe()? >> >> > >> >> > I probably can, I think I went with the route of committed patch >> >> > because it is slightly less work. Also, the comment in the while() >> >> > loop suggested me to rely on softclock. >> >> >> >> I don't think this is more work at all, the attached patch >> >> (pre-r234952, untested) should address it properly in few than 10 >> >> lines: >> >> http://www.freebsd.org/~attilio/callout_cancel_mig_stop.patch >> >> >> >> without the need to add further flags and re-using existing mechanism= s. >> > >> > (cc->cc_curr !=3D c) is not the case which caused the issue. It might = be >> > needed to treatened this way, but the reported case is opposite. >> >> Yes, of course, because the migration handover happens in the same >> critical context of cc->cc_curr =3D=3D c, but now I wonder if this fix i= s >> really right. >> >> It seems to me that in the case you describe callout_stop() must >> return 0 and the migration must not be cancelled because the callout >> is not stopped. It is not stopped not because of the deferred >> migration but because cc->cc_curr =3D=3D c. It seems a perfectly valid >> situation to me. > Yes, and my patch makes the callout to be indeed stopped right after > migration is finished. Did you looked at the patch itself ? > > What is the valid situation ? callout_stop returning 0 but not stopping > a pending callout ? I have to disagree. The function callout_stop() cancels a callout if it is currently pending. If the callout is pending, then callout_stop() will return a non-zero value. If the callout is not set, has already been serviced or is cur= =E2=80=90 rently being serviced, then zero will be returned. If the callout has= an associated mutex, then that mutex must be held when this function is called. [ From the callout manpage ] If the "callout is currently being serviced" means cc->cc_curr =3D=3D c and it must return 0. I still fail in seeing what are you trying to fix here. Attilio --=20 Peace can only be achieved by understanding - A. Einstein