Hang detection additions.
This commit is contained in:
parent
8435ba6436
commit
8af1edae0e
@ -87,6 +87,11 @@ struct cpu {
|
||||
struct tlbshootdown c_shootdown[TLBSHOOTDOWN_MAX];
|
||||
unsigned c_numshootdown;
|
||||
struct spinlock c_ipi_lock;
|
||||
|
||||
/*
|
||||
* Accessed by other cpus. Protected inside hangman.c.
|
||||
*/
|
||||
HANGMAN_ACTOR(c_hangman);
|
||||
};
|
||||
|
||||
/*
|
||||
|
84
kern/include/hangman.h
Normal file
84
kern/include/hangman.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2015
|
||||
* The President and Fellows of Harvard College.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef HANGMAN_H
|
||||
#define HANGMAN_H
|
||||
|
||||
/*
|
||||
* Simple deadlock detector. Enable with "options hangman" in the
|
||||
* kernel config.
|
||||
*/
|
||||
|
||||
#include "opt-hangman.h"
|
||||
|
||||
#if OPT_HANGMAN
|
||||
|
||||
struct hangman_actor {
|
||||
const char *a_name;
|
||||
const struct hangman_lockable *a_waiting;
|
||||
};
|
||||
|
||||
struct hangman_lockable {
|
||||
const char *l_name;
|
||||
const struct hangman_actor *l_holding;
|
||||
};
|
||||
|
||||
void hangman_wait(struct hangman_actor *a, struct hangman_lockable *l);
|
||||
void hangman_acquire(struct hangman_actor *a, struct hangman_lockable *l);
|
||||
void hangman_release(struct hangman_actor *a, struct hangman_lockable *l);
|
||||
|
||||
#define HANGMAN_ACTOR(sym) struct hangman_actor sym
|
||||
#define HANGMAN_LOCKABLE(sym) struct hangman_lockable sym
|
||||
|
||||
#define HANGMAN_ACTORINIT(a, n) ((a)->a_name = (n), (a)->a_waiting = NULL)
|
||||
#define HANGMAN_LOCKABLEINIT(l, n) ((l)->l_name = (n), (l)->l_holding = NULL)
|
||||
|
||||
#define HANGMAN_LOCKABLE_INITIALIZER { "spinlock", NULL }
|
||||
|
||||
#define HANGMAN_WAIT(a, l) hangman_wait(a, l)
|
||||
#define HANGMAN_ACQUIRE(a, l) hangman_acquire(a, l)
|
||||
#define HANGMAN_RELEASE(a, l) hangman_release(a, l)
|
||||
|
||||
#else
|
||||
|
||||
#define HANGMAN_ACTOR(sym)
|
||||
#define HANGMAN_LOCKABLE(sym)
|
||||
|
||||
#define HANGMAN_ACTORINIT(a, name)
|
||||
#define HANGMAN_LOCKABLEINIT(a, name)
|
||||
|
||||
#define HANGMAN_LOCKABLE_INITIALIZER
|
||||
|
||||
#define HANGMAN_WAIT(a, l)
|
||||
#define HANGMAN_ACQUIRE(a, l)
|
||||
#define HANGMAN_RELEASE(a, l)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* HANGMAN_H */
|
@ -192,7 +192,7 @@ void kprintf_bootstrap(void);
|
||||
*/
|
||||
|
||||
#define DIVROUNDUP(a,b) (((a)+(b)-1)/(b))
|
||||
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*b)
|
||||
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*(b))
|
||||
|
||||
|
||||
#endif /* _LIB_H_ */
|
||||
|
@ -55,6 +55,9 @@ size_t mainbus_ramsize(void);
|
||||
/* Switch on an inter-processor interrupt. (Low-level.) */
|
||||
void mainbus_send_ipi(struct cpu *target);
|
||||
|
||||
/* Request breaking into the debugger, where available. */
|
||||
void mainbus_debugger(void);
|
||||
|
||||
/*
|
||||
* The various ways to shut down the system. (These are very low-level
|
||||
* and should generally not be called directly - md_poweroff, for
|
||||
|
@ -36,6 +36,7 @@
|
||||
*/
|
||||
|
||||
#include <cdefs.h>
|
||||
#include <hangman.h>
|
||||
|
||||
/* Inlining support - for making sure an out-of-line copy gets built */
|
||||
#ifndef SPINLOCK_INLINE
|
||||
@ -57,12 +58,18 @@
|
||||
struct spinlock {
|
||||
volatile spinlock_data_t splk_lock; /* Memory word where we spin. */
|
||||
struct cpu *splk_holder; /* CPU holding this lock. */
|
||||
HANGMAN_LOCKABLE(splk_hangman); /* Deadlock detector hook. */
|
||||
};
|
||||
|
||||
/*
|
||||
* Initializer for cases where a spinlock needs to be static or global.
|
||||
*/
|
||||
#ifdef OPT_HANGMAN
|
||||
#define SPINLOCK_INITIALIZER { SPINLOCK_DATA_INITIALIZER, NULL, \
|
||||
HANGMAN_LOCKABLE_INITIALIZER }
|
||||
#else
|
||||
#define SPINLOCK_INITIALIZER { SPINLOCK_DATA_INITIALIZER, NULL }
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Spinlock functions.
|
||||
|
@ -74,6 +74,7 @@ void V(struct semaphore *);
|
||||
*/
|
||||
struct lock {
|
||||
char *lk_name;
|
||||
HANGMAN_LOCKABLE(lk_hangman); /* Deadlock detector hook. */
|
||||
// add what you need here
|
||||
// (don't forget to mark things volatile as needed)
|
||||
};
|
||||
|
@ -83,6 +83,7 @@ struct thread {
|
||||
struct switchframe *t_context; /* Saved register context (on stack) */
|
||||
struct cpu *t_cpu; /* CPU thread runs on */
|
||||
struct proc *t_proc; /* Process thread belongs to */
|
||||
HANGMAN_ACTOR(t_hangman); /* Deadlock detector hook */
|
||||
|
||||
/*
|
||||
* Interrupt state fields.
|
||||
|
@ -34,7 +34,7 @@
|
||||
* Leave this alone, so we can tell what version of the OS/161 base
|
||||
* code we gave you.
|
||||
*/
|
||||
#define BASE_VERSION "2.0.2"
|
||||
#define BASE_VERSION "2.0.3"
|
||||
|
||||
/*
|
||||
* Change this as you see fit in the course of hacking the system.
|
||||
|
Loading…
x
Reference in New Issue
Block a user