Whamcloud - gitweb
LU-9859 libcfs: remove wi_data from cfs_workitem
[fs/lustre-release.git] / lnet / selftest / selftest.h
index 4f883c9..ea1ee06 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- * copy of GPLv2].
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define LNET_ONLY
 
-#ifndef __KERNEL__
-
-/* XXX workaround XXX */
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#endif
 #include <libcfs/libcfs.h>
-#include <lnet/lnet.h>
+#include <lnet/api.h>
 #include <lnet/lib-lnet.h>
 #include <lnet/lib-types.h>
-#include <lnet/lnetst.h>
+#include <uapi/linux/lnet/lnetst.h>
 
 #include "rpc.h"
 #include "timer.h"
 #define SWI_STATE_DONE                     10
 
 /* forward refs */
-struct swi_workitem;
 struct srpc_service;
+struct srpc_service_cd;
 struct sfw_test_unit;
 struct sfw_test_instance;
 
-/*
- * A workitems is deferred work with these semantics:
- * - a workitem always runs in thread context.
- * - a workitem can be concurrent with other workitems but is strictly
- *   serialized with respect to itself.
- * - no CPU affinity, a workitem does not necessarily run on the same CPU
- *   that schedules it. However, this might change in the future.
- * - if a workitem is scheduled again before it has a chance to run, it
- *   runs only once.
- * - if a workitem is scheduled while it runs, it runs again after it
- *   completes; this ensures that events occurring while other events are
- *   being processed receive due attention. This behavior also allows a
- *   workitem to reschedule itself.
- *
- * Usage notes:
- * - a workitem can sleep but it should be aware of how that sleep might
- *   affect others.
- * - a workitem runs inside a kernel thread so there's no user space to access.
- * - do not use a workitem if the scheduling latency can't be tolerated.
- *
- * When wi_action returns non-zero, it means the workitem has either been
- * freed or reused and workitem scheduler won't touch it any more.
- */
-typedef int (*swi_action_t) (struct swi_workitem *);
-typedef struct swi_workitem {
-        cfs_list_t       wi_list;        /* chain on runq */
-        int              wi_state;
-        swi_action_t     wi_action;
-        void            *wi_data;
-        unsigned int     wi_running:1;
-        unsigned int     wi_scheduled:1;
-} swi_workitem_t;
-
-static inline void
-swi_init_workitem (swi_workitem_t *wi, void *data, swi_action_t action)
-{
-        CFS_INIT_LIST_HEAD(&wi->wi_list);
-
-        wi->wi_running   = 0;
-        wi->wi_scheduled = 0;
-        wi->wi_data      = data;
-        wi->wi_action    = action;
-        wi->wi_state     = SWI_STATE_NEWBORN;
-}
-
-#define SWI_RESCHED    128         /* # workitem scheduler loops before reschedule */
-
 /* services below SRPC_FRAMEWORK_SERVICE_MAX_ID are framework
  * services, e.g. create/modify session.
  */
@@ -149,7 +89,7 @@ swi_init_workitem (swi_workitem_t *wi, void *data, swi_action_t action)
 /* all reply/bulk RDMAs go to this portal */
 #define SRPC_RDMA_PORTAL                52
 
-static inline srpc_msg_type_t
+static inline enum srpc_msg_type
 srpc_service2request (int service)
 {
         switch (service) {
@@ -184,13 +124,13 @@ srpc_service2request (int service)
         }
 }
 
-static inline srpc_msg_type_t
+static inline enum srpc_msg_type
 srpc_service2reply (int service)
 {
         return srpc_service2request(service) + 1;
 }
 
-typedef enum {
+enum srpc_event_type {
         SRPC_BULK_REQ_RCVD   = 1, /* passive bulk request(PUT sink/GET source) received */
         SRPC_BULK_PUT_SENT   = 2, /* active bulk PUT sent (source) */
         SRPC_BULK_GET_RPLD   = 3, /* active bulk GET replied (sink) */
@@ -198,67 +138,75 @@ typedef enum {
         SRPC_REPLY_SENT      = 5, /* outgoing reply sent */
         SRPC_REQUEST_RCVD    = 6, /* incoming request received */
         SRPC_REQUEST_SENT    = 7, /* outgoing request sent */
-} srpc_event_type_t;
+};
 
 /* RPC event */
-typedef struct {
-        srpc_event_type_t ev_type;   /* what's up */
-        lnet_event_kind_t ev_lnet;   /* LNet event type */
+struct srpc_event {
+       enum srpc_event_type    ev_type;   /* what's up */
+       enum lnet_event_kind    ev_lnet;   /* LNet event type */
         int               ev_fired;  /* LNet event fired? */
         int               ev_status; /* LNet event status */
         void             *ev_data;   /* owning server/client RPC */
-} srpc_event_t;
+};
 
-typedef struct {
+/* bulk descriptor */
+struct srpc_bulk {
         int              bk_len;  /* len of bulk data */
-        lnet_handle_md_t bk_mdh;
+       struct lnet_handle_md bk_mdh;
         int              bk_sink; /* sink/source */
         int              bk_niov; /* # iov in bk_iovs */
-#ifdef __KERNEL__
         lnet_kiov_t      bk_iovs[0];
-#else
-        cfs_page_t     **bk_pages;
-        lnet_md_iovec_t  bk_iovs[0];
-#endif
-} srpc_bulk_t; /* bulk descriptor */
+};
 
 /* message buffer descriptor */
-typedef struct {
-        cfs_list_t           buf_list; /* chain on srpc_service::*_msgq */
-        srpc_msg_t           buf_msg;
-        lnet_handle_md_t     buf_mdh;
-        lnet_nid_t           buf_self;
-        lnet_process_id_t    buf_peer;
-} srpc_buffer_t;
+struct srpc_buffer {
+       struct list_head        buf_list; /* chain on srpc_service::*_msgq */
+       struct srpc_msg         buf_msg;
+       struct lnet_handle_md   buf_mdh;
+       lnet_nid_t              buf_self;
+       struct lnet_process_id  buf_peer;
+};
+
+struct swi_workitem;
+typedef int (*swi_action_t)(struct swi_workitem *);
+
+struct swi_workitem {
+       struct cfs_wi_sched     *swi_sched;
+       struct cfs_workitem     swi_workitem;
+        swi_action_t         swi_action;
+        int                  swi_state;
+};
 
 /* server-side state of a RPC */
-typedef struct srpc_server_rpc {
-        cfs_list_t           srpc_list;    /* chain on srpc_service::*_rpcq */
-        struct srpc_service *srpc_service;
-        swi_workitem_t       srpc_wi;
-        srpc_event_t         srpc_ev;      /* bulk/reply event */
-        lnet_nid_t           srpc_self;
-        lnet_process_id_t    srpc_peer;
-        srpc_msg_t           srpc_replymsg;
-        lnet_handle_md_t     srpc_replymdh;
-        srpc_buffer_t       *srpc_reqstbuf;
-        srpc_bulk_t         *srpc_bulk;
-
-        unsigned int         srpc_aborted; /* being given up */
-        int                  srpc_status;
-        void               (*srpc_done)(struct srpc_server_rpc *);
-} srpc_server_rpc_t;
+struct srpc_server_rpc {
+       /* chain on srpc_service::*_rpcq */
+       struct list_head        srpc_list;
+       struct srpc_service_cd *srpc_scd;
+       struct swi_workitem     srpc_wi;
+       struct srpc_event       srpc_ev;        /* bulk/reply event */
+       lnet_nid_t              srpc_self;
+       struct lnet_process_id  srpc_peer;
+       struct srpc_msg         srpc_replymsg;
+       struct lnet_handle_md   srpc_replymdh;
+       struct srpc_buffer     *srpc_reqstbuf;
+       struct srpc_bulk       *srpc_bulk;
+
+       unsigned int    srpc_aborted; /* being given up */
+       int             srpc_status;
+       void            (*srpc_done)(struct srpc_server_rpc *);
+};
 
 /* client-side state of a RPC */
-typedef struct srpc_client_rpc {
-        cfs_list_t           crpc_list;   /* chain on user's lists */
-        cfs_spinlock_t       crpc_lock;   /* serialize */
-        int                  crpc_service;
-        cfs_atomic_t         crpc_refcount;
-        int                  crpc_timeout; /* # seconds to wait for reply */
-        stt_timer_t          crpc_timer;
-        swi_workitem_t       crpc_wi;
-        lnet_process_id_t    crpc_dest;
+struct srpc_client_rpc {
+       struct list_head        crpc_list;      /* chain on user's lists */
+       spinlock_t              crpc_lock;      /* serialize */
+       int                     crpc_service;
+       atomic_t                crpc_refcount;
+       /* # seconds to wait for reply */
+       int                     crpc_timeout;
+       struct stt_timer        crpc_timer;
+       struct swi_workitem     crpc_wi;
+       struct lnet_process_id  crpc_dest;
 
         void               (*crpc_done)(struct srpc_client_rpc *);
         void               (*crpc_fini)(struct srpc_client_rpc *);
@@ -269,38 +217,38 @@ typedef struct srpc_client_rpc {
         unsigned int         crpc_aborted:1; /* being given up */
         unsigned int         crpc_closed:1;  /* completed */
 
-        /* RPC events */
-        srpc_event_t         crpc_bulkev;    /* bulk event */
-        srpc_event_t         crpc_reqstev;   /* request event */
-        srpc_event_t         crpc_replyev;   /* reply event */
+       /* RPC events */
+       struct srpc_event       crpc_bulkev;    /* bulk event */
+       struct srpc_event       crpc_reqstev;   /* request event */
+       struct srpc_event       crpc_replyev;   /* reply event */
 
-        /* bulk, request(reqst), and reply exchanged on wire */
-        srpc_msg_t           crpc_reqstmsg;
-        srpc_msg_t           crpc_replymsg;
-        lnet_handle_md_t     crpc_reqstmdh;
-        lnet_handle_md_t     crpc_replymdh;
-        srpc_bulk_t          crpc_bulk;
-} srpc_client_rpc_t;
+       /* bulk, request(reqst), and reply exchanged on wire */
+       struct srpc_msg         crpc_reqstmsg;
+       struct srpc_msg         crpc_replymsg;
+       struct lnet_handle_md   crpc_reqstmdh;
+       struct lnet_handle_md   crpc_replymdh;
+       struct srpc_bulk        crpc_bulk;
+};
 
 #define srpc_client_rpc_size(rpc)                                       \
-offsetof(srpc_client_rpc_t, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
+offsetof(struct srpc_client_rpc, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
 
 #define srpc_client_rpc_addref(rpc)                                     \
 do {                                                                    \
         CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-               cfs_atomic_read(&(rpc)->crpc_refcount));                 \
-        LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
-        cfs_atomic_inc(&(rpc)->crpc_refcount);                          \
+              atomic_read(&(rpc)->crpc_refcount));                 \
+       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
+       atomic_inc(&(rpc)->crpc_refcount);                          \
 } while (0)
 
 #define srpc_client_rpc_decref(rpc)                                     \
 do {                                                                    \
         CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-               cfs_atomic_read(&(rpc)->crpc_refcount));                 \
-        LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
-        if (cfs_atomic_dec_and_test(&(rpc)->crpc_refcount))             \
+              atomic_read(&(rpc)->crpc_refcount));                 \
+       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
+       if (atomic_dec_and_test(&(rpc)->crpc_refcount))             \
                 srpc_destroy_client_rpc(rpc);                           \
 } while (0)
 
@@ -308,206 +256,292 @@ do {                                                                    \
                                    (rpc)->crpc_reqstev.ev_fired == 0 || \
                                    (rpc)->crpc_replyev.ev_fired == 0)
 
-typedef struct srpc_service {
-        int                sv_id;            /* service id */
-        const char        *sv_name;          /* human readable name */
-        int                sv_nprune;        /* # posted RPC to be pruned */
-        int                sv_concur;        /* max # concurrent RPCs */
-
-        cfs_spinlock_t     sv_lock;
-        int                sv_shuttingdown;
-        srpc_event_t       sv_ev;            /* LNet event */
-        int                sv_nposted_msg;   /* # posted message buffers */
-        cfs_list_t         sv_free_rpcq;     /* free RPC descriptors */
-        cfs_list_t         sv_active_rpcq;   /* in-flight RPCs */
-        cfs_list_t         sv_posted_msgq;   /* posted message buffers */
-        cfs_list_t         sv_blocked_msgq;  /* blocked for RPC descriptor */
-
+/* CPU partition data of srpc service */
+struct srpc_service_cd {
+       /** serialize */
+       spinlock_t              scd_lock;
+       /** backref to service */
+       struct srpc_service     *scd_svc;
+       /** event buffer */
+       struct srpc_event       scd_ev;
+       /** free RPC descriptors */
+       struct list_head        scd_rpc_free;
+       /** in-flight RPCs */
+       struct list_head        scd_rpc_active;
+       /** workitem for posting buffer */
+       struct swi_workitem     scd_buf_wi;
+       /** CPT id */
+       int                     scd_cpt;
+       /** error code for scd_buf_wi */
+       int                     scd_buf_err;
+       /** timestamp for scd_buf_err */
+       time64_t                scd_buf_err_stamp;
+       /** total # request buffers */
+       int                     scd_buf_total;
+       /** # posted request buffers */
+       int                     scd_buf_nposted;
+       /** in progress of buffer posting */
+       int                     scd_buf_posting;
+       /** allocate more buffers if scd_buf_nposted < scd_buf_low */
+       int                     scd_buf_low;
+       /** increase/decrease some buffers */
+       int                     scd_buf_adjust;
+       /** posted message buffers */
+       struct list_head        scd_buf_posted;
+       /** blocked for RPC descriptor */
+       struct list_head        scd_buf_blocked;
+};
+
+/* number of server workitems (mini-thread) for testing service */
+#define SFW_TEST_WI_MIN                256
+#define SFW_TEST_WI_MAX                2048
+/* extra buffers for tolerating buggy peers, or unbalanced number
+ * of peers between partitions  */
+#define SFW_TEST_WI_EXTRA      64
+
+/* number of server workitems (mini-thread) for framework service */
+#define SFW_FRWK_WI_MIN                16
+#define SFW_FRWK_WI_MAX                256
+
+struct srpc_service {
+       int                     sv_id;          /* service id */
+       const char              *sv_name;       /* human readable name */
+       int                     sv_wi_total;    /* total server workitems */
+       int                     sv_shuttingdown;
+       int                     sv_ncpts;
+       /* percpt data for srpc_service */
+       struct srpc_service_cd  **sv_cpt_data;
         /* Service callbacks:
          * - sv_handler: process incoming RPC request
          * - sv_bulk_ready: notify bulk data
          */
-        int              (*sv_handler) (srpc_server_rpc_t *);
-        int              (*sv_bulk_ready) (srpc_server_rpc_t *, int);
-} srpc_service_t;
-
-#define SFW_POST_BUFFERS         256
-#define SFW_SERVICE_CONCURRENCY  (SFW_POST_BUFFERS/2)
-
-typedef struct {
-        cfs_list_t        sn_list;    /* chain on fw_zombie_sessions */
-        lst_sid_t         sn_id;      /* unique identifier */
-        unsigned int      sn_timeout; /* # seconds' inactivity to expire */
-        int               sn_timer_active;
-        stt_timer_t       sn_timer;
-        cfs_list_t        sn_batches; /* list of batches */
-        char              sn_name[LST_NAME_SIZE];
-        cfs_atomic_t      sn_refcount;
-        cfs_atomic_t      sn_brw_errors;
-        cfs_atomic_t      sn_ping_errors;
-} sfw_session_t;
+       int              (*sv_handler)(struct srpc_server_rpc *);
+       int              (*sv_bulk_ready)(struct srpc_server_rpc *, int);
+};
+
+struct sfw_session {
+       /* chain on fw_zombie_sessions */
+       struct list_head        sn_list;
+       struct lst_sid          sn_id;          /* unique identifier */
+       /* # seconds' inactivity to expire */
+       unsigned int            sn_timeout;
+       int                     sn_timer_active;
+       unsigned int            sn_features;
+       struct stt_timer        sn_timer;
+       struct list_head        sn_batches;     /* list of batches */
+       char                    sn_name[LST_NAME_SIZE];
+       atomic_t                sn_refcount;
+       atomic_t                sn_brw_errors;
+       atomic_t                sn_ping_errors;
+       ktime_t                 sn_started;
+};
 
 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
                                        (sid0).ses_stamp == (sid1).ses_stamp)
 
-typedef struct {
-        cfs_list_t        bat_list;      /* chain on sn_batches */
-        lst_bid_t         bat_id;        /* batch id */
-        int               bat_error;     /* error code of batch */
-        sfw_session_t    *bat_session;   /* batch's session */
-        cfs_atomic_t      bat_nactive;   /* # of active tests */
-        cfs_list_t        bat_tests;     /* test instances */
-} sfw_batch_t;
-
-typedef struct {
-        int  (*tso_init)(struct sfw_test_instance *tsi); /* intialize test client */
-        void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
-        int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
-                             lnet_process_id_t dest,
-                             srpc_client_rpc_t **rpc);   /* prep a tests rpc */
+struct sfw_batch {
+       struct list_head        bat_list;       /* chain on sn_batches */
+       struct lst_bid          bat_id;         /* batch id */
+       int                     bat_error;      /* error code of batch */
+       struct sfw_session      *bat_session;   /* batch's session */
+       atomic_t                bat_nactive;    /* # of active tests */
+       struct list_head        bat_tests;      /* test instances */
+};
+
+struct sfw_test_client_ops {
+       int  (*tso_init)(struct sfw_test_instance *tsi); /* intailize test client */
+       void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
+       int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
+                            struct lnet_process_id dest,
+                            struct srpc_client_rpc **rpc); /* prep a tests rpc */
         void (*tso_done_rpc)(struct sfw_test_unit *tsu,
-                             srpc_client_rpc_t *rpc);    /* done a test rpc */
-} sfw_test_client_ops_t;
-
-typedef struct sfw_test_instance {
-        cfs_list_t              tsi_list;         /* chain on batch */
-        int                     tsi_service;      /* test type */
-        sfw_batch_t            *tsi_batch;        /* batch */
-        sfw_test_client_ops_t  *tsi_ops;          /* test client operations */
-
-        /* public parameter for all test units */
-        int                     tsi_is_client:1;     /* is test client */
-        int                     tsi_stoptsu_onerr:1; /* stop tsu on error */
+                            struct srpc_client_rpc *rpc);  /* done a test rpc */
+};
+
+struct sfw_test_instance {
+       struct list_head        tsi_list;       /* chain on batch */
+       int                     tsi_service;    /* test type */
+       struct sfw_batch        *tsi_batch;     /* batch */
+       struct sfw_test_client_ops      *tsi_ops;       /* test client operations */
+
+       /* public parameter for all test units */
+       unsigned int            tsi_is_client:1;     /* is test client */
+       unsigned int            tsi_stoptsu_onerr:1; /* stop tsu on error */
         int                     tsi_concur;          /* concurrency */
         int                     tsi_loop;            /* loop count */
 
-        /* status of test instance */
-        cfs_spinlock_t          tsi_lock;         /* serialize */
-        int                     tsi_stopping:1;   /* test is stopping */
-        cfs_atomic_t            tsi_nactive;      /* # of active test unit */
-        cfs_list_t              tsi_units;        /* test units */
-        cfs_list_t              tsi_free_rpcs;    /* free rpcs */
-        cfs_list_t              tsi_active_rpcs;  /* active rpcs */
-
-        union {
-                test_bulk_req_t bulk;             /* bulk parameter */
-                test_ping_req_t ping;             /* ping parameter */
-        } tsi_u;
-} sfw_test_instance_t;
-
-/* XXX: trailing (CFS_PAGE_SIZE % sizeof(lnet_process_id_t)) bytes at
+       /* status of test instance */
+       spinlock_t              tsi_lock;       /* serialize */
+       unsigned int            tsi_stopping:1; /* test is stopping */
+       atomic_t                tsi_nactive;    /* # of active test unit */
+       struct list_head        tsi_units;      /* test units */
+       struct list_head        tsi_free_rpcs;  /* free rpcs */
+       struct list_head        tsi_active_rpcs;/* active rpcs */
+
+       union {
+               struct test_ping_req    ping;     /* ping parameter */
+               struct test_bulk_req    bulk_v0;  /* bulk parameter */
+               struct test_bulk_req_v1 bulk_v1;  /* bulk v1 parameter */
+       } tsi_u;
+};
+
+/* XXX: trailing (PAGE_SIZE % sizeof(struct lnet_process_id)) bytes at
  * the end of pages are not used */
 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
-#define SFW_ID_PER_PAGE    (CFS_PAGE_SIZE / sizeof(lnet_process_id_packed_t))
+#define SFW_ID_PER_PAGE    (PAGE_SIZE / sizeof(struct lnet_process_id_packed))
 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
 
-typedef struct sfw_test_unit {
-        cfs_list_t            tsu_list;         /* chain on lst_test_instance */
-        lnet_process_id_t     tsu_dest;         /* id of dest node */
-        int                   tsu_loop;         /* loop count of the test */
-        sfw_test_instance_t  *tsu_instance;     /* pointer to test instance */
-        void                 *tsu_private;      /* private data */
-        swi_workitem_t        tsu_worker;       /* workitem of the test unit */
-} sfw_test_unit_t;
-
-typedef struct {
-        cfs_list_t              tsc_list;         /* chain on fw_tests */
-        srpc_service_t         *tsc_srv_service;  /* test service */
-        sfw_test_client_ops_t  *tsc_cli_ops;      /* ops of test client */
-} sfw_test_case_t;
-
-
-srpc_client_rpc_t *
-sfw_create_rpc(lnet_process_id_t peer, int service, int nbulkiov, int bulklen,
-               void (*done) (srpc_client_rpc_t *), void *priv);
-int sfw_create_test_rpc(sfw_test_unit_t *tsu, lnet_process_id_t peer,
-                        int nblk, int blklen, srpc_client_rpc_t **rpc);
-void sfw_abort_rpc(srpc_client_rpc_t *rpc);
-void sfw_post_rpc(srpc_client_rpc_t *rpc);
-void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
-void sfw_unpack_message(srpc_msg_t *msg);
-void sfw_free_pages(srpc_server_rpc_t *rpc);
-void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i);
-int sfw_alloc_pages(srpc_server_rpc_t *rpc, int npages, int sink);
-int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
-
-srpc_client_rpc_t *
-srpc_create_client_rpc(lnet_process_id_t peer, int service,
+struct sfw_test_unit {
+       struct list_head        tsu_list;       /* chain on lst_test_instance */
+       struct lnet_process_id  tsu_dest;       /* id of dest node */
+       int                     tsu_loop;       /* loop count of the test */
+       struct sfw_test_instance *tsu_instance; /* pointer to test instance */
+       void                    *tsu_private;   /* private data */
+       struct swi_workitem      tsu_worker;    /* workitem of the test unit */
+};
+
+struct sfw_test_case {
+       struct list_head                tsc_list;               /* chain on fw_tests */
+       struct srpc_service             *tsc_srv_service;       /* test service */
+       struct sfw_test_client_ops      *tsc_cli_ops;           /* ops of test client */
+};
+
+struct srpc_client_rpc *
+sfw_create_rpc(struct lnet_process_id peer, int service,
+              unsigned features, int nbulkiov, int bulklen,
+              void (*done)(struct srpc_client_rpc *), void *priv);
+int sfw_create_test_rpc(struct sfw_test_unit *tsu,
+                       struct lnet_process_id peer, unsigned int features,
+                       int nblk, int blklen, struct srpc_client_rpc **rpc);
+void sfw_abort_rpc(struct srpc_client_rpc *rpc);
+void sfw_post_rpc(struct srpc_client_rpc *rpc);
+void sfw_client_rpc_done(struct srpc_client_rpc *rpc);
+void sfw_unpack_message(struct srpc_msg *msg);
+void sfw_free_pages(struct srpc_server_rpc *rpc);
+void sfw_add_bulk_page(struct srpc_bulk *bk, struct page *pg, int i);
+int sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len,
+                   int sink);
+int sfw_make_session(struct srpc_mksn_reqst *request,
+                    struct srpc_mksn_reply *reply);
+
+struct srpc_client_rpc *
+srpc_create_client_rpc(struct lnet_process_id peer, int service,
                        int nbulkiov, int bulklen,
-                       void (*rpc_done)(srpc_client_rpc_t *),
-                       void (*rpc_fini)(srpc_client_rpc_t *), void *priv);
-void srpc_post_rpc(srpc_client_rpc_t *rpc);
-void srpc_abort_rpc(srpc_client_rpc_t *rpc, int why);
-void srpc_free_bulk(srpc_bulk_t *bk);
-srpc_bulk_t *srpc_alloc_bulk(int npages, int sink);
-int srpc_send_rpc(swi_workitem_t *wi);
-int srpc_send_reply(srpc_server_rpc_t *rpc);
-int srpc_add_service(srpc_service_t *sv);
-int srpc_remove_service(srpc_service_t *sv);
-void srpc_shutdown_service(srpc_service_t *sv);
-void srpc_abort_service(srpc_service_t *sv);
-int srpc_finish_service(srpc_service_t *sv);
-int srpc_service_add_buffers(srpc_service_t *sv, int nbuffer);
-void srpc_service_remove_buffers(srpc_service_t *sv, int nbuffer);
-void srpc_get_counters(srpc_counters_t *cnt);
-void srpc_set_counters(const srpc_counters_t *cnt);
-
-void swi_kill_workitem(swi_workitem_t *wi);
-void swi_schedule_workitem(swi_workitem_t *wi);
-void swi_schedule_serial_workitem(swi_workitem_t *wi);
-int swi_startup(void);
+                      void (*rpc_done)(struct srpc_client_rpc *),
+                      void (*rpc_fini)(struct srpc_client_rpc *), void *priv);
+void srpc_post_rpc(struct srpc_client_rpc *rpc);
+void srpc_abort_rpc(struct srpc_client_rpc *rpc, int why);
+void srpc_free_bulk(struct srpc_bulk *bk);
+struct srpc_bulk *srpc_alloc_bulk(int cpt, unsigned int off,
+                                 unsigned int bulk_npg, unsigned int bulk_len,
+                                 int sink);
+int srpc_send_rpc(struct swi_workitem *wi);
+int srpc_send_reply(struct srpc_server_rpc *rpc);
+int srpc_add_service(struct srpc_service *sv);
+int srpc_remove_service(struct srpc_service *sv);
+void srpc_shutdown_service(struct srpc_service *sv);
+void srpc_abort_service(struct srpc_service *sv);
+int srpc_finish_service(struct srpc_service *sv);
+int srpc_service_add_buffers(struct srpc_service *sv, int nbuffer);
+void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer);
+void srpc_get_counters(struct srpc_counters *cnt);
+void srpc_set_counters(const struct srpc_counters *cnt);
+
+extern struct cfs_wi_sched *lst_sched_serial;
+extern struct cfs_wi_sched **lst_sched_test;
+
+static inline int
+srpc_serv_is_framework(struct srpc_service *svc)
+{
+       return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID;
+}
+
+static inline int
+swi_wi_action(struct cfs_workitem *wi)
+{
+       struct swi_workitem *swi;
+
+       swi = container_of(wi, struct swi_workitem, swi_workitem);
+       return swi->swi_action(swi);
+}
+
+static inline void
+swi_init_workitem(struct swi_workitem *swi,
+                 swi_action_t action, struct cfs_wi_sched *sched)
+{
+       swi->swi_sched  = sched;
+       swi->swi_action = action;
+       swi->swi_state  = SWI_STATE_NEWBORN;
+       cfs_wi_init(&swi->swi_workitem, swi_wi_action);
+}
+
+static inline void
+swi_schedule_workitem(struct swi_workitem *wi)
+{
+       cfs_wi_schedule(wi->swi_sched, &wi->swi_workitem);
+}
+
+static inline void
+swi_exit_workitem(struct swi_workitem *swi)
+{
+       cfs_wi_exit(swi->swi_sched, &swi->swi_workitem);
+}
+
+static inline int
+swi_deschedule_workitem(struct swi_workitem *swi)
+{
+       return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem);
+}
+
 int sfw_startup(void);
 int srpc_startup(void);
-void swi_shutdown(void);
 void sfw_shutdown(void);
 void srpc_shutdown(void);
 
 static inline void
-srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
+srpc_destroy_client_rpc(struct srpc_client_rpc *rpc)
 {
-        LASSERT (rpc != NULL);
-        LASSERT (!srpc_event_pending(rpc));
-        LASSERT (cfs_atomic_read(&rpc->crpc_refcount) == 0);
-#ifndef __KERNEL__
-        LASSERT (rpc->crpc_bulk.bk_pages == NULL);
-#endif
+       LASSERT (rpc != NULL);
+       LASSERT (!srpc_event_pending(rpc));
+       LASSERT (atomic_read(&rpc->crpc_refcount) == 0);
 
-        if (rpc->crpc_fini == NULL) {
-                LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
-        } else {
-                (*rpc->crpc_fini) (rpc);
-        }
+       if (rpc->crpc_fini == NULL) {
+               LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
+       } else {
+               (*rpc->crpc_fini) (rpc);
+       }
 
-        return;
+       return;
 }
 
 static inline void
-srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
-                      int service, int nbulkiov, int bulklen,
-                      void (*rpc_done)(srpc_client_rpc_t *),
-                      void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
+srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer,
+                    int service, int nbulkiov, int bulklen,
+                    void (*rpc_done)(struct srpc_client_rpc *),
+                    void (*rpc_fini)(struct srpc_client_rpc *), void *priv)
 {
-        LASSERT (nbulkiov <= LNET_MAX_IOV);
+       LASSERT(nbulkiov <= LNET_MAX_IOV);
 
-        memset(rpc, 0, offsetof(srpc_client_rpc_t,
-                                crpc_bulk.bk_iovs[nbulkiov]));
+       memset(rpc, 0, offsetof(struct srpc_client_rpc,
+                               crpc_bulk.bk_iovs[nbulkiov]));
 
-        CFS_INIT_LIST_HEAD(&rpc->crpc_list);
-        swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc);
-        cfs_spin_lock_init(&rpc->crpc_lock);
-        cfs_atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
+       INIT_LIST_HEAD(&rpc->crpc_list);
+       swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc,
+                         lst_sched_test[lnet_cpt_of_nid(peer.nid, NULL)]);
+       spin_lock_init(&rpc->crpc_lock);
+       atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
 
-        rpc->crpc_dest         = peer;
-        rpc->crpc_priv         = priv;
+       rpc->crpc_dest         = peer;
+       rpc->crpc_priv         = priv;
         rpc->crpc_service      = service;
         rpc->crpc_bulk.bk_len  = bulklen;
         rpc->crpc_bulk.bk_niov = nbulkiov;
         rpc->crpc_done         = rpc_done;
         rpc->crpc_fini         = rpc_fini;
-        LNetInvalidateHandle(&rpc->crpc_reqstmdh);
-        LNetInvalidateHandle(&rpc->crpc_replymdh);
-        LNetInvalidateHandle(&rpc->crpc_bulk.bk_mdh);
+       LNetInvalidateMDHandle(&rpc->crpc_reqstmdh);
+       LNetInvalidateMDHandle(&rpc->crpc_replymdh);
+       LNetInvalidateMDHandle(&rpc->crpc_bulk.bk_mdh);
 
         /* no event is expected at this point */
         rpc->crpc_bulkev.ev_fired  =
@@ -539,57 +573,46 @@ swi_state2str (int state)
 #undef STATE2STR
 }
 
-#define UNUSED(x)       ( (void)(x) )
-
-#ifndef __KERNEL__
-
-int stt_poll_interval(void);
-int sfw_session_removed(void);
-
-int stt_check_events(void);
-int swi_check_events(void);
-int srpc_check_event(int timeout);
-
-int lnet_selftest_init(void);
-void lnet_selftest_fini(void);
-int selftest_wait_events(void);
-
-#else
-
-#define selftest_wait_events()    cfs_pause(cfs_time_seconds(1))
-
-#endif
-
-#define lst_wait_until(cond, lock, fmt, ...)                            \
-do {                                                                    \
-        int __I = 2;                                                    \
-        while (!(cond)) {                                               \
-                CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET,               \
-                       fmt, ## __VA_ARGS__);                            \
-                cfs_spin_unlock(&(lock));                               \
-                                                                        \
-                selftest_wait_events();                                 \
-                                                                        \
-                cfs_spin_lock(&(lock));                                 \
-        }                                                               \
+#define lst_wait_until(cond, lock, fmt, ...)                           \
+do {                                                                   \
+       int __I = 2;                                                    \
+       while (!(cond)) {                                               \
+               CDEBUG(is_power_of_2(++__I) ? D_WARNING : D_NET,        \
+                      fmt, ## __VA_ARGS__);                            \
+               spin_unlock(&(lock));                                   \
+                                                                       \
+               set_current_state(TASK_UNINTERRUPTIBLE);                \
+               schedule_timeout(cfs_time_seconds(1) / 10);             \
+                                                                       \
+               spin_lock(&(lock));                                     \
+       }                                                               \
 } while (0)
 
 static inline void
-srpc_wait_service_shutdown (srpc_service_t *sv)
+srpc_wait_service_shutdown(struct srpc_service *sv)
 {
-        int i = 2;
-
-        cfs_spin_lock(&sv->sv_lock);
-        LASSERT (sv->sv_shuttingdown);
-        cfs_spin_unlock(&sv->sv_lock);
-
-        while (srpc_finish_service(sv) == 0) {
-                i++;
-                CDEBUG (((i & -i) == i) ? D_WARNING : D_NET,
-                        "Waiting for %s service to shutdown...\n",
-                        sv->sv_name);
-                selftest_wait_events();
-        }
+       int i = 2;
+
+       LASSERT(sv->sv_shuttingdown);
+
+       while (srpc_finish_service(sv) == 0) {
+               i++;
+               CDEBUG(((i & -i) == i) ? D_WARNING : D_NET,
+                      "Waiting for %s service to shutdown...\n",
+                      sv->sv_name);
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(cfs_time_seconds(1) / 10);
+       }
 }
 
+extern struct sfw_test_client_ops ping_test_client;
+extern struct srpc_service ping_test_service;
+void ping_init_test_client(void);
+void ping_init_test_service(void);
+
+extern struct sfw_test_client_ops brw_test_client;
+extern struct srpc_service brw_test_service;
+void brw_init_test_client(void);
+void brw_init_test_service(void);
+
 #endif /* __SELFTEST_SELFTEST_H__ */