]>
Commit | Line | Data |
---|---|---|
354d119a | 1 | /* |
2 | * Quagga Work Queues. | |
3 | * | |
4 | * Copyright (C) 2005 Sun Microsystems, Inc. | |
5 | * | |
6 | * This file is part of Quagga. | |
7 | * | |
8 | * Quagga is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * Quagga is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Quagga; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | * 02111-1307, USA. | |
22 | */ | |
23 | ||
24 | #ifndef _QUAGGA_WORK_QUEUE_H | |
25 | #define _QUAGGA_WORK_QUEUE_H | |
26 | ||
27 | /* Work queue default hold and cycle times - millisec */ | |
190880dc | 28 | #define WORK_QUEUE_DEFAULT_HOLD 50 /* hold-time between runs of a queue */ |
29 | #define WORK_QUEUE_DEFAULT_DELAY 10 /* minimum delay for queue runs */ | |
30 | #define WORK_QUEUE_DEFAULT_FLOOD 40 /* flood factor, ~2s with prev values */ | |
354d119a | 31 | |
32 | /* action value, for use by item processor and item error handlers */ | |
33 | typedef enum | |
34 | { | |
35 | WQ_SUCCESS = 0, | |
36 | WQ_ERROR, /* Error, run error handler if provided */ | |
37 | WQ_RETRY_NOW, /* retry immediately */ | |
38 | WQ_RETRY_LATER, /* retry later, cease processing work queue */ | |
269d74fd | 39 | WQ_REQUEUE, /* requeue item, continue processing work queue */ |
40 | WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time. | |
41 | * Similar to WQ_RETRY_LATER, but doesn't penalise | |
42 | * the particular item.. */ | |
354d119a | 43 | } wq_item_status; |
44 | ||
45 | /* A single work queue item, unsurprisingly */ | |
46 | struct work_queue_item | |
47 | { | |
48 | void *data; /* opaque data */ | |
84369684 | 49 | unsigned short ran; /* # of times item has been run */ |
354d119a | 50 | }; |
51 | ||
269d74fd | 52 | enum work_queue_flags |
53 | { | |
54 | WQ_UNPLUGGED = 0, | |
55 | WQ_PLUGGED = 1, | |
56 | }; | |
57 | ||
354d119a | 58 | struct work_queue |
59 | { | |
190880dc | 60 | /* Everything but the specification struct is private */ |
354d119a | 61 | struct thread_master *master; /* thread master */ |
62 | struct thread *thread; /* thread, if one is active */ | |
63 | char *name; /* work queue name */ | |
190880dc | 64 | char status; /* status */ |
65 | #define WQ_STATE_FLOODED (1 << 0) | |
269d74fd | 66 | enum work_queue_flags flags; /* flags */ |
354d119a | 67 | |
190880dc | 68 | /* Specification for this work queue. |
69 | * Public, must be set before use by caller. May be modified at will. | |
70 | */ | |
354d119a | 71 | struct { |
72 | /* work function to process items with */ | |
8cc4198f | 73 | wq_item_status (*workfunc) (void *); |
354d119a | 74 | |
75 | /* error handling function, optional */ | |
76 | void (*errorfunc) (struct work_queue *, struct work_queue_item *); | |
77 | ||
78 | /* callback to delete user specific item data */ | |
8cc4198f | 79 | void (*del_item_data) (void *); |
354d119a | 80 | |
269d74fd | 81 | /* completion callback, called when queue is emptied, optional */ |
82 | void (*completion_func) (struct work_queue *); | |
83 | ||
354d119a | 84 | /* max number of retries to make for item that errors */ |
85 | unsigned int max_retries; | |
86 | ||
87 | unsigned int hold; /* hold time for first run, in ms */ | |
88 | unsigned int delay; /* min delay between queue runs, in ms */ | |
190880dc | 89 | |
90 | unsigned int flood; /* number of queue runs after which we consider | |
91 | * queue to be flooded, where the runs are | |
92 | * consecutive and each has used its full slot, | |
93 | * and the queue has still not been cleared. If | |
94 | * the queue is flooded, then we try harder to | |
95 | * clear it by ignoring the hold and delay | |
96 | * times. No point sparing CPU resources just | |
97 | * to use ever more memory resources. | |
98 | */ | |
354d119a | 99 | } spec; |
100 | ||
101 | /* remaining fields should be opaque to users */ | |
102 | struct list *items; /* queue item list */ | |
269d74fd | 103 | unsigned long runs; /* runs count */ |
190880dc | 104 | unsigned int runs_since_clear; /* number of runs since queue was |
105 | * last cleared | |
106 | */ | |
354d119a | 107 | |
108 | struct { | |
109 | unsigned int best; | |
110 | unsigned int granularity; | |
111 | unsigned long total; | |
112 | } cycles; /* cycle counts */ | |
113 | }; | |
114 | ||
115 | /* User API */ | |
269d74fd | 116 | |
117 | /* create a new work queue, of given name. | |
118 | * user must fill in the spec of the returned work queue before adding | |
119 | * anything to it | |
120 | */ | |
8cc4198f | 121 | extern struct work_queue *work_queue_new (struct thread_master *, |
122 | const char *); | |
269d74fd | 123 | /* destroy work queue */ |
8cc4198f | 124 | extern void work_queue_free (struct work_queue *); |
269d74fd | 125 | |
126 | /* Add the supplied data as an item onto the workqueue */ | |
8cc4198f | 127 | extern void work_queue_add (struct work_queue *, void *); |
354d119a | 128 | |
269d74fd | 129 | /* plug the queue, ie prevent it from being drained / processed */ |
130 | extern void work_queue_plug (struct work_queue *wq); | |
131 | /* unplug the queue, allow it to be drained again */ | |
132 | extern void work_queue_unplug (struct work_queue *wq); | |
133 | ||
354d119a | 134 | /* Helpers, exported for thread.c and command.c */ |
8cc4198f | 135 | extern int work_queue_run (struct thread *); |
354d119a | 136 | extern struct cmd_element show_work_queues_cmd; |
137 | #endif /* _QUAGGA_WORK_QUEUE_H */ |