From owner-svn-src-projects@FreeBSD.ORG Thu Jul 15 21:49:28 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C5D45106567F; Thu, 15 Jul 2010 21:49:28 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B44588FC14; Thu, 15 Jul 2010 21:49:28 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6FLnSvW010922; Thu, 15 Jul 2010 21:49:28 GMT (envelope-from jeff@svn.freebsd.org) Received: (from jeff@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6FLnSwD010916; Thu, 15 Jul 2010 21:49:28 GMT (envelope-from jeff@svn.freebsd.org) Message-Id: <201007152149.o6FLnSwD010916@svn.freebsd.org> From: Jeff Roberson Date: Thu, 15 Jul 2010 21:49:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210141 - projects/ofed/head/sys/ofed/include/linux X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2010 21:49:28 -0000 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 +#include + +#include +#include #include 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 +#include +#include #include #include +#include + 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; \