1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/libcfs_workitem.h
38 * Author: Isaac Huang <he.h.huang@oracle.com>
39 * Liang Zhen <zhen.liang@sun.com>
41 * A workitems is deferred work with these semantics:
42 * - a workitem always runs in thread context.
43 * - a workitem can be concurrent with other workitems but is strictly
44 * serialized with respect to itself.
45 * - no CPU affinity, a workitem does not necessarily run on the same CPU
46 * that schedules it. However, this might change in the future.
47 * - if a workitem is scheduled again before it has a chance to run, it
49 * - if a workitem is scheduled while it runs, it runs again after it
50 * completes; this ensures that events occurring while other events are
51 * being processed receive due attention. This behavior also allows a
52 * workitem to reschedule itself.
55 * - a workitem can sleep but it should be aware of how that sleep might
57 * - a workitem runs inside a kernel thread so there's no user space to access.
58 * - do not use a workitem if the scheduling latency can't be tolerated.
60 * When wi_action returns non-zero, it means the workitem has either been
61 * freed or reused and workitem scheduler won't touch it any more.
64 #ifndef __LIBCFS_WORKITEM_H__
65 #define __LIBCFS_WORKITEM_H__
69 typedef int (*cfs_wi_action_t) (struct cfs_workitem *);
70 typedef struct cfs_workitem {
71 /** chain on runq or rerunq */
73 /** working function */
74 cfs_wi_action_t wi_action;
75 /** arg for working function */
77 /** scheduler id, can be negative */
80 unsigned short wi_running:1;
82 unsigned short wi_scheduled:1;
86 * positive values are reserved as CPU id of future implementation of
87 * per-cpu scheduler, so user can "bind" workitem on specific CPU.
89 #define CFS_WI_SCHED_ANY (-1)
90 #define CFS_WI_SCHED_SERIAL (-2)
93 cfs_wi_init(cfs_workitem_t *wi, void *data,
94 cfs_wi_action_t action, short sched_id)
96 CFS_INIT_LIST_HEAD(&wi->wi_list);
98 wi->wi_sched_id = sched_id;
100 wi->wi_scheduled = 0;
102 wi->wi_action = action;
105 void cfs_wi_exit(cfs_workitem_t *wi);
106 int cfs_wi_cancel(cfs_workitem_t *wi);
107 void cfs_wi_schedule(cfs_workitem_t *wi);
108 int cfs_wi_startup(void);
109 void cfs_wi_shutdown(void);
112 /** # workitem scheduler loops before reschedule */
113 #define CFS_WI_RESCHED 128
115 int cfs_wi_check_events(void);
118 #endif /* __LIBCFS_WORKITEM_H__ */