4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * libcfs/include/libcfs/libcfs_workitem.h
34 * Author: Isaac Huang <he.h.huang@oracle.com>
35 * Liang Zhen <zhen.liang@sun.com>
37 * A workitems is deferred work with these semantics:
38 * - a workitem always runs in thread context.
39 * - a workitem can be concurrent with other workitems but is strictly
40 * serialized with respect to itself.
41 * - no CPU affinity, a workitem does not necessarily run on the same CPU
42 * that schedules it. However, this might change in the future.
43 * - if a workitem is scheduled again before it has a chance to run, it
45 * - if a workitem is scheduled while it runs, it runs again after it
46 * completes; this ensures that events occurring while other events are
47 * being processed receive due attention. This behavior also allows a
48 * workitem to reschedule itself.
51 * - a workitem can sleep but it should be aware of how that sleep might
53 * - a workitem runs inside a kernel thread so there's no user space to access.
54 * - do not use a workitem if the scheduling latency can't be tolerated.
56 * When wi_action returns non-zero, it means the workitem has either been
57 * freed or reused and workitem scheduler won't touch it any more.
60 #ifndef __LIBCFS_WORKITEM_H__
61 #define __LIBCFS_WORKITEM_H__
65 void cfs_wi_sched_destroy(struct cfs_wi_sched *);
66 int cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, int cpt,
67 int nthrs, struct cfs_wi_sched **);
71 typedef int (*cfs_wi_action_t) (struct cfs_workitem *);
74 /** chain on runq or rerunq */
75 struct list_head wi_list;
76 /** working function */
77 cfs_wi_action_t wi_action;
78 /** arg for working function */
81 unsigned short wi_running:1;
83 unsigned short wi_scheduled:1;
87 cfs_wi_init(struct cfs_workitem *wi, void *data, cfs_wi_action_t action)
89 INIT_LIST_HEAD(&wi->wi_list);
94 wi->wi_action = action;
97 void cfs_wi_schedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
98 int cfs_wi_deschedule(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
99 void cfs_wi_exit(struct cfs_wi_sched *sched, struct cfs_workitem *wi);
101 int cfs_wi_startup(void);
102 void cfs_wi_shutdown(void);
104 /** # workitem scheduler loops before reschedule */
105 #define CFS_WI_RESCHED 128
107 #endif /* __LIBCFS_WORKITEM_H__ */