BNX2X: Spatch dev_addr->ea
[akaros.git] / kern / include / kthread.h
index dd92d6a..c5d90a4 100644 (file)
@@ -13,6 +13,7 @@
 #include <trap.h>
 #include <sys/queue.h>
 #include <atomic.h>
+#include <setjmp.h>
 
 struct proc;
 struct kthread;
@@ -26,7 +27,7 @@ TAILQ_HEAD(semaphore_tailq, semaphore);
  * a kthread is running, we make sure its stacktop is the default kernel stack,
  * meaning it will receive the interrupts from userspace. */
 struct kthread {
-       struct kernel_ctx                       context;
+       struct jmpbuf                           context;
        uintptr_t                                       stacktop;
        struct proc                                     *proc;
        struct syscall                          *sysc;
@@ -36,6 +37,7 @@ struct kthread {
        bool                                            is_ktask;       /* default is FALSE */
        char                                            *name;
        char                                            generic_buf[GENBUF_SZ];
+       struct systrace_record          *trace;
 };
 
 /* Semaphore for kthreads to sleep on.  0 or less means you need to sleep */
@@ -53,6 +55,23 @@ struct semaphore {
 #endif
 };
 
+/* omitted elements (the sem debug stuff) are initialized to 0 */
+#define SEMAPHORE_INITIALIZER(name, n)                                         \
+{                                                                              \
+    .waiters    = TAILQ_HEAD_INITIALIZER((name).waiters),                      \
+       .nr_signals = (n),                                                         \
+    .lock       = SPINLOCK_INITIALIZER,                                        \
+    .irq_okay   = FALSE,                                                       \
+}
+
+#define SEMAPHORE_INITIALIZER_IRQSAVE(name, n)                                 \
+{                                                                              \
+    .waiters    = TAILQ_HEAD_INITIALIZER((name).waiters),                      \
+       .nr_signals = (n),                                                         \
+    .lock       = SPINLOCK_INITIALIZER_IRQSAVE,                                \
+    .irq_okay   = TRUE,                                                        \
+}
+
 struct cond_var {
        struct semaphore                        sem;
        spinlock_t                                      *lock;          /* usually points to internal_ */
@@ -61,6 +80,17 @@ struct cond_var {
        bool                                            irq_okay;
 };
 
+struct cv_lookup_elm {
+       TAILQ_ENTRY(cv_lookup_elm)      link;
+       TAILQ_ENTRY(cv_lookup_elm)      abortall_link;          /* only used in abort_all */
+       struct cond_var                         *cv;
+       struct kthread                          *kthread;
+       struct syscall                          *sysc;
+       struct proc                                     *proc;
+       atomic_t                                        abort_in_progress;      /* 0 = no */
+};
+TAILQ_HEAD(cv_lookup_tailq, cv_lookup_elm);
+
 uintptr_t get_kstack(void);
 void put_kstack(uintptr_t stacktop);
 uintptr_t *kstack_bottom_addr(uintptr_t stacktop);
@@ -69,6 +99,7 @@ struct kthread *__kthread_zalloc(void);
 void restart_kthread(struct kthread *kthread);
 void kthread_runnable(struct kthread *kthread);
 void kthread_yield(void);
+void kthread_usleep(uint64_t usec);
 void ktask(char *name, void (*fn)(void*), void *arg);
 /* Debugging */
 void check_poison(char *msg);
@@ -101,4 +132,20 @@ void cv_broadcast(struct cond_var *cv);
 void cv_signal_irqsave(struct cond_var *cv, int8_t *irq_state);
 void cv_broadcast_irqsave(struct cond_var *cv, int8_t *irq_state);
 
+bool abort_sysc(struct proc *p, struct syscall *sysc);
+void abort_all_sysc(struct proc *p);
+int abort_all_sysc_fd(struct proc *p, int fd);
+void __reg_abortable_cv(struct cv_lookup_elm *cle, struct cond_var *cv);
+void dereg_abortable_cv(struct cv_lookup_elm *cle);
+bool should_abort(struct cv_lookup_elm *cle);
+
+/* qlocks are plan9's binary sempahore, which are wrappers around our sems.
+ * Not sure if they'll need irqsave or normal sems. */
+typedef struct semaphore qlock_t;
+#define qlock_init(x) sem_init((x), 1)
+#define qlock(x) sem_down(x)
+#define qunlock(x) sem_up(x)
+#define canqlock(x) sem_trydown(x)
+#define QLOCK_INITIALIZER(name) SEMAPHORE_INITIALIZER(name, 1)
+
 #endif /* ROS_KERN_KTHREAD_H */