Deleted Added
full compact
kern_sx.c (278693) kern_sx.c (278694)
1/*-
2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 28 unchanged lines hidden (view full) ---

37 */
38
39#include "opt_ddb.h"
40#include "opt_hwpmc_hooks.h"
41#include "opt_kdtrace.h"
42#include "opt_no_adaptive_sx.h"
43
44#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 28 unchanged lines hidden (view full) ---

37 */
38
39#include "opt_ddb.h"
40#include "opt_hwpmc_hooks.h"
41#include "opt_kdtrace.h"
42#include "opt_no_adaptive_sx.h"
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: stable/10/sys/kern/kern_sx.c 278693 2015-02-13 18:45:44Z sbruno $");
45__FBSDID("$FreeBSD: stable/10/sys/kern/kern_sx.c 278694 2015-02-13 19:06:22Z sbruno $");
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kdb.h>
50#include <sys/ktr.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53#include <sys/proc.h>
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kdb.h>
50#include <sys/ktr.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53#include <sys/proc.h>
54#include <sys/sched.h>
54#include <sys/sleepqueue.h>
55#include <sys/sx.h>
56#include <sys/sysctl.h>
57
58#if defined(SMP) && !defined(NO_ADAPTIVE_SX)
59#include <machine/cpu.h>
60#endif
61

--- 493 unchanged lines hidden (view full) ---

555 if ((x & SX_LOCK_SHARED) == 0) {
556 x = SX_OWNER(x);
557 owner = (struct thread *)x;
558 if (TD_IS_RUNNING(owner)) {
559 if (LOCK_LOG_TEST(&sx->lock_object, 0))
560 CTR3(KTR_LOCK,
561 "%s: spinning on %p held by %p",
562 __func__, sx, owner);
55#include <sys/sleepqueue.h>
56#include <sys/sx.h>
57#include <sys/sysctl.h>
58
59#if defined(SMP) && !defined(NO_ADAPTIVE_SX)
60#include <machine/cpu.h>
61#endif
62

--- 493 unchanged lines hidden (view full) ---

556 if ((x & SX_LOCK_SHARED) == 0) {
557 x = SX_OWNER(x);
558 owner = (struct thread *)x;
559 if (TD_IS_RUNNING(owner)) {
560 if (LOCK_LOG_TEST(&sx->lock_object, 0))
561 CTR3(KTR_LOCK,
562 "%s: spinning on %p held by %p",
563 __func__, sx, owner);
564 KTR_STATE1(KTR_SCHED, "thread",
565 sched_tdname(curthread), "spinning",
566 "lockname:\"%s\"",
567 sx->lock_object.lo_name);
563 GIANT_SAVE();
564 while (SX_OWNER(sx->sx_lock) == x &&
565 TD_IS_RUNNING(owner)) {
566 cpu_spinwait();
567#ifdef KDTRACE_HOOKS
568 spin_cnt++;
569#endif
570 }
568 GIANT_SAVE();
569 while (SX_OWNER(sx->sx_lock) == x &&
570 TD_IS_RUNNING(owner)) {
571 cpu_spinwait();
572#ifdef KDTRACE_HOOKS
573 spin_cnt++;
574#endif
575 }
576 KTR_STATE0(KTR_SCHED, "thread",
577 sched_tdname(curthread), "running");
571 continue;
572 }
573 } else if (SX_SHARERS(x) && spintries < asx_retries) {
578 continue;
579 }
580 } else if (SX_SHARERS(x) && spintries < asx_retries) {
581 KTR_STATE1(KTR_SCHED, "thread",
582 sched_tdname(curthread), "spinning",
583 "lockname:\"%s\"", sx->lock_object.lo_name);
574 GIANT_SAVE();
575 spintries++;
576 for (i = 0; i < asx_loops; i++) {
577 if (LOCK_LOG_TEST(&sx->lock_object, 0))
578 CTR4(KTR_LOCK,
579 "%s: shared spinning on %p with %u and %u",
580 __func__, sx, spintries, i);
581 x = sx->sx_lock;
582 if ((x & SX_LOCK_SHARED) == 0 ||
583 SX_SHARERS(x) == 0)
584 break;
585 cpu_spinwait();
586#ifdef KDTRACE_HOOKS
587 spin_cnt++;
588#endif
589 }
584 GIANT_SAVE();
585 spintries++;
586 for (i = 0; i < asx_loops; i++) {
587 if (LOCK_LOG_TEST(&sx->lock_object, 0))
588 CTR4(KTR_LOCK,
589 "%s: shared spinning on %p with %u and %u",
590 __func__, sx, spintries, i);
591 x = sx->sx_lock;
592 if ((x & SX_LOCK_SHARED) == 0 ||
593 SX_SHARERS(x) == 0)
594 break;
595 cpu_spinwait();
596#ifdef KDTRACE_HOOKS
597 spin_cnt++;
598#endif
599 }
600 KTR_STATE0(KTR_SCHED, "thread",
601 sched_tdname(curthread), "running");
590 if (i != asx_loops)
591 continue;
592 }
593 }
594#endif
595
596 sleepq_lock(&sx->lock_object);
597 x = sx->sx_lock;

--- 246 unchanged lines hidden (view full) ---

844 if ((sx->lock_object.lo_flags & SX_NOADAPTIVE) == 0) {
845 x = SX_OWNER(x);
846 owner = (struct thread *)x;
847 if (TD_IS_RUNNING(owner)) {
848 if (LOCK_LOG_TEST(&sx->lock_object, 0))
849 CTR3(KTR_LOCK,
850 "%s: spinning on %p held by %p",
851 __func__, sx, owner);
602 if (i != asx_loops)
603 continue;
604 }
605 }
606#endif
607
608 sleepq_lock(&sx->lock_object);
609 x = sx->sx_lock;

--- 246 unchanged lines hidden (view full) ---

856 if ((sx->lock_object.lo_flags & SX_NOADAPTIVE) == 0) {
857 x = SX_OWNER(x);
858 owner = (struct thread *)x;
859 if (TD_IS_RUNNING(owner)) {
860 if (LOCK_LOG_TEST(&sx->lock_object, 0))
861 CTR3(KTR_LOCK,
862 "%s: spinning on %p held by %p",
863 __func__, sx, owner);
864 KTR_STATE1(KTR_SCHED, "thread",
865 sched_tdname(curthread), "spinning",
866 "lockname:\"%s\"", sx->lock_object.lo_name);
852 GIANT_SAVE();
853 while (SX_OWNER(sx->sx_lock) == x &&
854 TD_IS_RUNNING(owner)) {
855#ifdef KDTRACE_HOOKS
856 spin_cnt++;
857#endif
858 cpu_spinwait();
859 }
867 GIANT_SAVE();
868 while (SX_OWNER(sx->sx_lock) == x &&
869 TD_IS_RUNNING(owner)) {
870#ifdef KDTRACE_HOOKS
871 spin_cnt++;
872#endif
873 cpu_spinwait();
874 }
875 KTR_STATE0(KTR_SCHED, "thread",
876 sched_tdname(curthread), "running");
860 continue;
861 }
862 }
863#endif
864
865 /*
866 * Some other thread already has an exclusive lock, so
867 * start the process of blocking.

--- 347 unchanged lines hidden ---
877 continue;
878 }
879 }
880#endif
881
882 /*
883 * Some other thread already has an exclusive lock, so
884 * start the process of blocking.

--- 347 unchanged lines hidden ---