Date: Thu, 15 Jul 2010 21:49:28 +0000 (UTC) From: Jeff Roberson <jeff@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r210141 - projects/ofed/head/sys/ofed/include/linux Message-ID: <201007152149.o6FLnSwD010916@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jeff Date: Thu Jul 15 21:49:28 2010 New Revision: 210141 URL: http://svn.freebsd.org/changeset/base/210141 Log: - Add various missing trivial APIs. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/ofed/include/linux/mutex.h projects/ofed/head/sys/ofed/include/linux/semaphore.h projects/ofed/head/sys/ofed/include/linux/spinlock.h projects/ofed/head/sys/ofed/include/linux/timer.h projects/ofed/head/sys/ofed/include/linux/workqueue.h Modified: projects/ofed/head/sys/ofed/include/linux/mutex.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/mutex.h Thu Jul 15 21:47:30 2010 (r210140) +++ projects/ofed/head/sys/ofed/include/linux/mutex.h Thu Jul 15 21:49:28 2010 (r210141) @@ -43,6 +43,7 @@ typedef struct mutex { #define mutex_lock_nested(_m, _s) mutex_lock(_m) #define mutex_lock_interruptible(_m) ({ mutex_lock((_m)); 0; }) #define mutex_unlock(_m) sx_xunlock(&(_m)->sx) +#define mutex_trylock(_m) !!sx_try_xlock(&(_m)->sx) #define DEFINE_MUTEX(lock) \ mutex_t lock; \ Modified: projects/ofed/head/sys/ofed/include/linux/semaphore.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/semaphore.h Thu Jul 15 21:47:30 2010 (r210140) +++ projects/ofed/head/sys/ofed/include/linux/semaphore.h Thu Jul 15 21:49:28 2010 (r210141) @@ -42,4 +42,12 @@ struct semaphore { #define down_trylock(_rw) !sx_try_xlock(&(_rw)->sx) #define up(_rw) sx_xunlock(&(_rw)->sx) +static inline void +sema_init(struct semaphore *sem, int val) +{ + init_MUTEX(sem); + if (val == 0) + down(sem); +} + #endif /* _LINUX_SEMAPHORE_H_ */ Modified: projects/ofed/head/sys/ofed/include/linux/spinlock.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/spinlock.h Thu Jul 15 21:47:30 2010 (r210140) +++ projects/ofed/head/sys/ofed/include/linux/spinlock.h Thu Jul 15 21:49:28 2010 (r210141) @@ -45,6 +45,7 @@ typedef struct { #define spin_lock_init(_l) mtx_init(&(_l)->m, "ldev", NULL, MTX_DEF) #define spin_lock(_l) mtx_lock(&(_l)->m) #define spin_unlock(_l) mtx_unlock(&(_l)->m) +#define spin_lock_nested(_l, _n) mtx_lock_flags(&(_l)->m, MTX_DUPOK) #define spin_lock_irq(lock) spin_lock(lock) #define spin_unlock_irq(lock) spin_unlock(lock) #define spin_lock_irqsave(lock, flags) \ Modified: projects/ofed/head/sys/ofed/include/linux/timer.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/timer.h Thu Jul 15 21:47:30 2010 (r210140) +++ projects/ofed/head/sys/ofed/include/linux/timer.h Thu Jul 15 21:49:28 2010 (r210141) @@ -28,35 +28,57 @@ #ifndef _LINUX_TIMER_H_ #define _LINUX_TIMER_H_ -#include <sys/types.h> +#include <linux/types.h> + +#include <sys/param.h> +#include <sys/kernel.h> #include <sys/callout.h> struct timer_list { struct callout timer_callout; - void (*fn)(unsigned long); + void (*function)(unsigned long); unsigned long data; }; +#define expires timer_callout.c_time + static inline void _timer_fn(void *context) { struct timer_list *timer; timer = context; - timer->fn(timer->data); + timer->function(timer->data); } #define setup_timer(timer, func, dat) \ do { \ - (timer)->fn = (func); \ + (timer)->function = (func); \ (timer)->data = (dat); \ callout_init(&(timer)->timer_callout, CALLOUT_MPSAFE); \ } while (0) +#define init_timer(timer) \ +do { \ + (timer)->function = NULL; \ + (timer)->data = 0; \ + callout_init(&(timer)->timer_callout, CALLOUT_MPSAFE); \ +} while (0) + #define mod_timer(timer, expire) \ callout_reset(&(timer)->timer_callout, (expire), _timer_fn, (timer)) +#define add_timer(timer) \ + callout_reset(&(timer)->timer_callout, \ + (timer)->timer_callout.c_time, _timer_fn, (timer)) + #define del_timer(timer) callout_stop(&(timer)->timer_callout) #define del_timer_sync(timer) callout_drain(&(timer)->timer_callout) +static inline unsigned long +round_jiffies(unsigned long j) +{ + return roundup(j, hz); +} + #endif /* _LINUX_TIMER_H_ */ Modified: projects/ofed/head/sys/ofed/include/linux/workqueue.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/workqueue.h Thu Jul 15 21:47:30 2010 (r210140) +++ projects/ofed/head/sys/ofed/include/linux/workqueue.h Thu Jul 15 21:49:28 2010 (r210141) @@ -28,10 +28,13 @@ #ifndef _LINUX_WORKQUEUE_H_ #define _LINUX_WORKQUEUE_H_ -#include <sys/taskqueue.h> +#include <linux/types.h> +#include <linux/kernel.h> #include <linux/timer.h> #include <linux/slab.h> +#include <sys/taskqueue.h> + struct workqueue_struct { struct taskqueue *taskqueue; }; @@ -47,6 +50,14 @@ struct delayed_work { struct callout timer; }; +static inline struct delayed_work * +to_delayed_work(struct work_struct *work) +{ + + return container_of(work, struct delayed_work, work); +} + + static inline void _work_fn(void *context, int pending) { @@ -69,6 +80,8 @@ do { \ callout_init(&(_work)->timer, CALLOUT_MPSAFE); \ } while (0) +#define INIT_DELAYED_WORK_DEFERRABLE INIT_DELAYED_WORK + #define schedule_work(work) \ do { \ (work)->taskqueue = taskqueue_thread; \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007152149.o6FLnSwD010916>