From owner-svn-src-head@freebsd.org Mon Aug 7 14:34:07 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2BC70DD6D4F; Mon, 7 Aug 2017 14:34:07 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 07E516E9F4; Mon, 7 Aug 2017 14:34:06 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v77EY6Wf036369; Mon, 7 Aug 2017 14:34:06 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v77EY516036367; Mon, 7 Aug 2017 14:34:05 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201708071434.v77EY516036367@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 7 Aug 2017 14:34:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322169 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 322169 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.23 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: Mon, 07 Aug 2017 14:34:07 -0000 Author: mav Date: Mon Aug 7 14:34:05 2017 New Revision: 322169 URL: https://svnweb.freebsd.org/changeset/base/322169 Log: Fix hrtimer_active() in case of cancellation. While there, switch to FreeBSD internal callout active status. Reviewed by: markj, hselasky Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D11900 Modified: head/sys/compat/linuxkpi/common/include/linux/hrtimer.h head/sys/compat/linuxkpi/common/src/linux_hrtimer.c Modified: head/sys/compat/linuxkpi/common/include/linux/hrtimer.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/hrtimer.h Mon Aug 7 14:09:57 2017 (r322168) +++ head/sys/compat/linuxkpi/common/include/linux/hrtimer.h Mon Aug 7 14:34:05 2017 (r322169) @@ -48,7 +48,6 @@ struct hrtimer { enum hrtimer_restart (*function)(struct hrtimer *); struct mtx mtx; struct callout callout; - uint32_t flags; }; #define hrtimer_active(hrtimer) linux_hrtimer_active(hrtimer) Modified: head/sys/compat/linuxkpi/common/src/linux_hrtimer.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_hrtimer.c Mon Aug 7 14:09:57 2017 (r322168) +++ head/sys/compat/linuxkpi/common/src/linux_hrtimer.c Mon Aug 7 14:34:05 2017 (r322169) @@ -37,9 +37,6 @@ __FBSDID("$FreeBSD$"); #include -/* hrtimer flags */ -#define HRTIMER_ACTIVE 0x01 - static void hrtimer_call_handler(void *arg) { @@ -49,7 +46,7 @@ hrtimer_call_handler(void *arg) hrtimer = arg; ret = hrtimer->function(hrtimer); MPASS(ret == HRTIMER_NORESTART); - hrtimer->flags &= ~HRTIMER_ACTIVE; + callout_deactivate(&hrtimer->callout); } bool @@ -58,19 +55,20 @@ linux_hrtimer_active(struct hrtimer *hrtimer) bool ret; mtx_lock(&hrtimer->mtx); - ret = (hrtimer->flags & HRTIMER_ACTIVE) != 0; + ret = callout_active(&hrtimer->callout); mtx_unlock(&hrtimer->mtx); return (ret); } +/* + * Cancel active hrtimer. + * Return 1 if timer was active and cancellation succeeded, or 0 otherwise. + */ int linux_hrtimer_cancel(struct hrtimer *hrtimer) { - if (!hrtimer_active(hrtimer)) - return (0); - (void)callout_drain(&hrtimer->callout); - return (1); + return (callout_drain(&hrtimer->callout) > 0); } void @@ -78,7 +76,6 @@ linux_hrtimer_init(struct hrtimer *hrtimer) { hrtimer->function = NULL; - hrtimer->flags = 0; mtx_init(&hrtimer->mtx, "hrtimer", NULL, MTX_DEF | MTX_RECURSE); callout_init_mtx(&hrtimer->callout, &hrtimer->mtx, 0); } @@ -103,6 +100,5 @@ linux_hrtimer_start_range_ns(struct hrtimer *hrtimer, mtx_lock(&hrtimer->mtx); callout_reset_sbt(&hrtimer->callout, nstosbt(time.tv64), nstosbt(nsec), hrtimer_call_handler, hrtimer, 0); - hrtimer->flags |= HRTIMER_ACTIVE; mtx_unlock(&hrtimer->mtx); }