View | Details | Raw Unified | Return to bug 210884 | Differences between
and this patch

Collapse All | Expand All

(-)share/man/man9/timeout.9 (-6 / +2 lines)
Lines 29-35 Link Here
29
.\"
29
.\"
30
.\" $FreeBSD$
30
.\" $FreeBSD$
31
.\"
31
.\"
32
.Dd July 4, 2016
32
.Dd September 14, 2015
33
.Dt TIMEOUT 9
33
.Dt TIMEOUT 9
34
.Os
34
.Os
35
.Sh NAME
35
.Sh NAME
Lines 247-256 Link Here
247
negative one is returned.
247
negative one is returned.
248
If the callout is currently being serviced and cannot be stopped,
248
If the callout is currently being serviced and cannot be stopped,
249
then zero will be returned.
249
then zero will be returned.
250
If the callout is currently being serviced and cannot be stopped, and at the
251
same time a next invocation of the same callout is also scheduled, then
252
.Fn callout_stop
253
unschedules the next run and returns zero.
254
If the callout has an associated lock,
250
If the callout has an associated lock,
255
then that lock must be held when this function is called.
251
then that lock must be held when this function is called.
256
.Pp
252
.Pp
Lines 818-824 Link Here
818
.Fn callout_drain
814
.Fn callout_drain
819
functions return a value of one if the callout was still pending when it was
815
functions return a value of one if the callout was still pending when it was
820
called, a zero if the callout could not be stopped and a negative one is it
816
called, a zero if the callout could not be stopped and a negative one is it
821
was either not running or has already completed.
817
was either not running or haas already completed.
822
The
818
The
823
.Fn timeout
819
.Fn timeout
824
function returns a
820
function returns a
(-)sys/kern/kern_timeout.c (-18 / +24 lines)
Lines 1166-1172 Link Here
1166
	struct callout_cpu *cc, *old_cc;
1166
	struct callout_cpu *cc, *old_cc;
1167
	struct lock_class *class;
1167
	struct lock_class *class;
1168
	int direct, sq_locked, use_lock;
1168
	int direct, sq_locked, use_lock;
1169
	int cancelled, not_on_a_list;
1169
	int not_on_a_list;
1170
1170
1171
	if ((flags & CS_DRAIN) != 0)
1171
	if ((flags & CS_DRAIN) != 0)
1172
		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, c->c_lock,
1172
		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, c->c_lock,
Lines 1236-1249 Link Here
1236
	}
1236
	}
1237
1237
1238
	/*
1238
	/*
1239
	 * If the callout is running, try to stop it or drain it.
1239
	 * If the callout isn't pending, it's not on the queue, so
1240
	 * don't attempt to remove it from the queue.  We can try to
1241
	 * stop it by other means however.
1240
	 */
1242
	 */
1241
	if (cc_exec_curr(cc, direct) == c) {
1243
	if (!(c->c_iflags & CALLOUT_PENDING)) {
1242
		/*
1244
		/*
1243
		 * Succeed we to stop it or not, we must clear the
1245
		 * If it wasn't on the queue and it isn't the current
1244
		 * active flag - this is what API users expect.
1246
		 * callout, then we can't stop it, so just bail.
1247
		 * It probably has already been run (if locking
1248
		 * is properly done). You could get here if the caller
1249
		 * calls stop twice in a row for example. The second
1250
		 * call would fall here without CALLOUT_ACTIVE set.
1245
		 */
1251
		 */
1246
		c->c_flags &= ~CALLOUT_ACTIVE;
1252
		c->c_flags &= ~CALLOUT_ACTIVE;
1253
		if (cc_exec_curr(cc, direct) != c) {
1254
			CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
1255
			    c, c->c_func, c->c_arg);
1256
			CC_UNLOCK(cc);
1257
			if (sq_locked)
1258
				sleepq_release(&cc_exec_waiting(cc, direct));
1259
			return (-1);
1260
		}
1247
1261
1248
		if ((flags & CS_DRAIN) != 0) {
1262
		if ((flags & CS_DRAIN) != 0) {
1249
			/*
1263
			/*
Lines 1362-1368 Link Here
1362
				cc_exec_drain(cc, direct) = drain;
1376
				cc_exec_drain(cc, direct) = drain;
1363
			}
1377
			}
1364
			CC_UNLOCK(cc);
1378
			CC_UNLOCK(cc);
1365
			return ((flags & CS_EXECUTING) != 0);
1379
			return ((flags & CS_MIGRBLOCK) != 0);
1366
		}
1380
		}
1367
		CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
1381
		CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
1368
		    c, c->c_func, c->c_arg);
1382
		    c, c->c_func, c->c_arg);
Lines 1369-1389 Link Here
1369
		if (drain) {
1383
		if (drain) {
1370
			cc_exec_drain(cc, direct) = drain;
1384
			cc_exec_drain(cc, direct) = drain;
1371
		}
1385
		}
1386
		CC_UNLOCK(cc);
1372
		KASSERT(!sq_locked, ("sleepqueue chain still locked"));
1387
		KASSERT(!sq_locked, ("sleepqueue chain still locked"));
1373
		cancelled = ((flags & CS_EXECUTING) != 0);
1388
		return (0);
1374
	} else
1389
	}
1375
		cancelled = 1;
1376
1377
	if (sq_locked)
1390
	if (sq_locked)
1378
		sleepq_release(&cc_exec_waiting(cc, direct));
1391
		sleepq_release(&cc_exec_waiting(cc, direct));
1379
1392
1380
	if ((c->c_iflags & CALLOUT_PENDING) == 0) {
1381
		CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
1382
		    c, c->c_func, c->c_arg);
1383
		CC_UNLOCK(cc);
1384
		return (cancelled);
1385
	}
1386
1387
	c->c_iflags &= ~CALLOUT_PENDING;
1393
	c->c_iflags &= ~CALLOUT_PENDING;
1388
	c->c_flags &= ~CALLOUT_ACTIVE;
1394
	c->c_flags &= ~CALLOUT_ACTIVE;
1389
1395
Lines 1400-1406 Link Here
1400
	}
1406
	}
1401
	callout_cc_del(c, cc);
1407
	callout_cc_del(c, cc);
1402
	CC_UNLOCK(cc);
1408
	CC_UNLOCK(cc);
1403
	return (cancelled);
1409
	return (1);
1404
}
1410
}
1405
1411
1406
void
1412
void
(-)sys/kern/subr_sleepqueue.c (-1 / +1 lines)
Lines 600-606 Link Here
600
	 * another CPU, so synchronize with it to avoid having it
600
	 * another CPU, so synchronize with it to avoid having it
601
	 * accidentally wake up a subsequent sleep.
601
	 * accidentally wake up a subsequent sleep.
602
	 */
602
	 */
603
	else if (_callout_stop_safe(&td->td_slpcallout, CS_EXECUTING, NULL)
603
	else if (_callout_stop_safe(&td->td_slpcallout, CS_MIGRBLOCK, NULL)
604
	    == 0) {
604
	    == 0) {
605
		td->td_flags |= TDF_TIMEOUT;
605
		td->td_flags |= TDF_TIMEOUT;
606
		TD_SET_SLEEPING(td);
606
		TD_SET_SLEEPING(td);
(-)sys/netinet6/in6.c (-8 / +2 lines)
Lines 2322-2337 Link Here
2322
			sdl = &ndpc.sdl;
2322
			sdl = &ndpc.sdl;
2323
			sdl->sdl_family = AF_LINK;
2323
			sdl->sdl_family = AF_LINK;
2324
			sdl->sdl_len = sizeof(*sdl);
2324
			sdl->sdl_len = sizeof(*sdl);
2325
			sdl->sdl_alen = ifp->if_addrlen;
2325
			sdl->sdl_index = ifp->if_index;
2326
			sdl->sdl_index = ifp->if_index;
2326
			sdl->sdl_type = ifp->if_type;
2327
			sdl->sdl_type = ifp->if_type;
2327
			if ((lle->la_flags & LLE_VALID) == LLE_VALID) {
2328
			bcopy(lle->ll_addr, LLADDR(sdl), ifp->if_addrlen);
2328
				sdl->sdl_alen = ifp->if_addrlen;
2329
				bcopy(lle->ll_addr, LLADDR(sdl),
2330
				    ifp->if_addrlen);
2331
			} else {
2332
				sdl->sdl_alen = 0;
2333
				bzero(LLADDR(sdl), ifp->if_addrlen);
2334
			}
2335
			if (lle->la_expire != 0)
2329
			if (lle->la_expire != 0)
2336
				ndpc.rtm.rtm_rmx.rmx_expire = lle->la_expire +
2330
				ndpc.rtm.rtm_rmx.rmx_expire = lle->la_expire +
2337
				    lle->lle_remtime / hz +
2331
				    lle->lle_remtime / hz +
(-)sys/sys/callout.h (-2 / +3 lines)
Lines 64-71 Link Here
64
64
65
/* Flags for callout_stop_safe() */
65
/* Flags for callout_stop_safe() */
66
#define	CS_DRAIN		0x0001 /* callout_drain(), wait allowed */
66
#define	CS_DRAIN		0x0001 /* callout_drain(), wait allowed */
67
#define	CS_EXECUTING		0x0002 /* Positive return value indicates that
67
#define	CS_MIGRBLOCK		0x0002 /* Block migration, return value
68
					  the callout was executing */
68
					  indicates that the callout was
69
				          executing */
69
70
70
#ifdef _KERNEL
71
#ifdef _KERNEL
71
/* 
72
/* 

Return to bug 210884