]>
git.proxmox.com Git - mirror_frr.git/blob - lib/wheel.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2016 Cumulus Networks, Inc.
16 struct thread_master
*master
;
20 unsigned int nexttime
;
21 unsigned int slots_to_skip
;
23 struct list
**wheel_slot_lists
;
26 * Key to determine what slot the item belongs in
28 unsigned int (*slot_key
)(const void *);
30 void (*slot_run
)(void *);
34 * Creates a timer wheel
36 * master - Thread master structure for the process
37 * period - The Time in seconds that the timer wheel will
38 * take before it starts issuing commands again
39 * for items in each slot
40 * slots - The number of slots to have in this particular
42 * slot_key - A hashing function of some sort that will allow
43 * the timer wheel to put items into individual slots
44 * slot_run - The function to run over each item in a particular slot
46 * Creates a timer wheel that will wake up 'slots' times over the entire
47 * wheel. Each time the timer wheel wakes up it will iterate through
48 * and run the slot_run function for each item stored in that particular
51 * The timer code is 'intelligent' in that it notices if anything is
52 * in a particular slot and can schedule the next timer to skip
55 * The general purpose of a timer wheel is to reduce events in a system.
56 * A perfect example of usage for this is say hello packets that need
57 * to be sent out to all your neighbors. Suppose a large routing protocol
58 * has to send keepalive packets every Y seconds to each of it's peers.
59 * At scale we can have a very large number of peers, X.
60 * This means that we will have X timing events every Y seconds.
61 * If you replace these events with a timer wheel that has Z slots
62 * you will have at most Y/Z timer events if each slot has a work item
65 * When X is large the number of events in a system can quickly escalate
66 * and cause significant amount of time handling thread events instead
67 * of running your code.
69 struct timer_wheel
*wheel_init(struct thread_master
*master
, int period
,
71 unsigned int (*slot_key
)(const void *),
72 void (*slot_run
)(void *), const char *run_name
);
75 * Delete the specified timer wheel created
77 void wheel_delete(struct timer_wheel
*);
80 * wheel - The Timer wheel being modified
81 * item - The generic data structure that will be handed
82 * to the slot_run function.
84 * Add item to a slot setup by the slot_key,
85 * possibly change next time pop.
87 int wheel_add_item(struct timer_wheel
*wheel
, void *item
);
90 * wheel - The Timer wheel being modified.
91 * item - The item to remove from one of the slots in
94 * Remove a item to a slot setup by the slot_key,
95 * possibly change next time pop.
97 int wheel_remove_item(struct timer_wheel
*wheel
, void *item
);