David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 1 | /* Worker thread pool for slow items, such as filesystem lookups or mkdirs |
| 2 | * |
| 3 | * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
David Howells | 8f0aa2f | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 10 | * |
| 11 | * See Documentation/slow-work.txt |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #ifndef _LINUX_SLOW_WORK_H |
| 15 | #define _LINUX_SLOW_WORK_H |
| 16 | |
| 17 | #ifdef CONFIG_SLOW_WORK |
| 18 | |
David Howells | 12e22c5 | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 19 | #include <linux/sysctl.h> |
Jens Axboe | 6b8268b | 2009-11-19 18:10:47 +0000 | [diff] [blame^] | 20 | #include <linux/timer.h> |
David Howells | 12e22c5 | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 21 | |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 22 | struct slow_work; |
| 23 | |
| 24 | /* |
| 25 | * The operations used to support slow work items |
| 26 | */ |
| 27 | struct slow_work_ops { |
David Howells | 3d7a641 | 2009-11-19 18:10:23 +0000 | [diff] [blame] | 28 | /* owner */ |
| 29 | struct module *owner; |
| 30 | |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 31 | /* get a ref on a work item |
| 32 | * - return 0 if successful, -ve if not |
| 33 | */ |
| 34 | int (*get_ref)(struct slow_work *work); |
| 35 | |
| 36 | /* discard a ref to a work item */ |
| 37 | void (*put_ref)(struct slow_work *work); |
| 38 | |
| 39 | /* execute a work item */ |
| 40 | void (*execute)(struct slow_work *work); |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * A slow work item |
| 45 | * - A reference is held on the parent object by the thread pool when it is |
| 46 | * queued |
| 47 | */ |
| 48 | struct slow_work { |
David Howells | 3d7a641 | 2009-11-19 18:10:23 +0000 | [diff] [blame] | 49 | struct module *owner; /* the owning module */ |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 50 | unsigned long flags; |
| 51 | #define SLOW_WORK_PENDING 0 /* item pending (further) execution */ |
| 52 | #define SLOW_WORK_EXECUTING 1 /* item currently executing */ |
| 53 | #define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */ |
| 54 | #define SLOW_WORK_VERY_SLOW 3 /* item is very slow */ |
Jens Axboe | 0160950 | 2009-11-19 18:10:43 +0000 | [diff] [blame] | 55 | #define SLOW_WORK_CANCELLING 4 /* item is being cancelled, don't enqueue */ |
Jens Axboe | 6b8268b | 2009-11-19 18:10:47 +0000 | [diff] [blame^] | 56 | #define SLOW_WORK_DELAYED 5 /* item is struct delayed_slow_work with active timer */ |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 57 | const struct slow_work_ops *ops; /* operations table for this item */ |
| 58 | struct list_head link; /* link in queue */ |
| 59 | }; |
| 60 | |
Jens Axboe | 6b8268b | 2009-11-19 18:10:47 +0000 | [diff] [blame^] | 61 | struct delayed_slow_work { |
| 62 | struct slow_work work; |
| 63 | struct timer_list timer; |
| 64 | }; |
| 65 | |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 66 | /** |
| 67 | * slow_work_init - Initialise a slow work item |
| 68 | * @work: The work item to initialise |
| 69 | * @ops: The operations to use to handle the slow work item |
| 70 | * |
| 71 | * Initialise a slow work item. |
| 72 | */ |
| 73 | static inline void slow_work_init(struct slow_work *work, |
| 74 | const struct slow_work_ops *ops) |
| 75 | { |
| 76 | work->flags = 0; |
| 77 | work->ops = ops; |
| 78 | INIT_LIST_HEAD(&work->link); |
| 79 | } |
| 80 | |
| 81 | /** |
Jens Axboe | 6b8268b | 2009-11-19 18:10:47 +0000 | [diff] [blame^] | 82 | * slow_work_init - Initialise a delayed slow work item |
| 83 | * @work: The work item to initialise |
| 84 | * @ops: The operations to use to handle the slow work item |
| 85 | * |
| 86 | * Initialise a delayed slow work item. |
| 87 | */ |
| 88 | static inline void delayed_slow_work_init(struct delayed_slow_work *dwork, |
| 89 | const struct slow_work_ops *ops) |
| 90 | { |
| 91 | init_timer(&dwork->timer); |
| 92 | slow_work_init(&dwork->work, ops); |
| 93 | } |
| 94 | |
| 95 | /** |
Jonathan Corbet | 5dd559f | 2009-04-21 16:30:32 -0600 | [diff] [blame] | 96 | * vslow_work_init - Initialise a very slow work item |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 97 | * @work: The work item to initialise |
| 98 | * @ops: The operations to use to handle the slow work item |
| 99 | * |
| 100 | * Initialise a very slow work item. This item will be restricted such that |
| 101 | * only a certain number of the pool threads will be able to execute items of |
| 102 | * this type. |
| 103 | */ |
| 104 | static inline void vslow_work_init(struct slow_work *work, |
| 105 | const struct slow_work_ops *ops) |
| 106 | { |
| 107 | work->flags = 1 << SLOW_WORK_VERY_SLOW; |
| 108 | work->ops = ops; |
| 109 | INIT_LIST_HEAD(&work->link); |
| 110 | } |
| 111 | |
| 112 | extern int slow_work_enqueue(struct slow_work *work); |
Jens Axboe | 0160950 | 2009-11-19 18:10:43 +0000 | [diff] [blame] | 113 | extern void slow_work_cancel(struct slow_work *work); |
David Howells | 3d7a641 | 2009-11-19 18:10:23 +0000 | [diff] [blame] | 114 | extern int slow_work_register_user(struct module *owner); |
| 115 | extern void slow_work_unregister_user(struct module *owner); |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 116 | |
Jens Axboe | 6b8268b | 2009-11-19 18:10:47 +0000 | [diff] [blame^] | 117 | extern int delayed_slow_work_enqueue(struct delayed_slow_work *dwork, |
| 118 | unsigned long delay); |
| 119 | |
| 120 | static inline void delayed_slow_work_cancel(struct delayed_slow_work *dwork) |
| 121 | { |
| 122 | slow_work_cancel(&dwork->work); |
| 123 | } |
| 124 | |
David Howells | 12e22c5 | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 125 | #ifdef CONFIG_SYSCTL |
| 126 | extern ctl_table slow_work_sysctls[]; |
| 127 | #endif |
David Howells | 07fe7cb | 2009-04-03 16:42:35 +0100 | [diff] [blame] | 128 | |
| 129 | #endif /* CONFIG_SLOW_WORK */ |
| 130 | #endif /* _LINUX_SLOW_WORK_H */ |