]>
Commit | Line | Data |
---|---|---|
a303686f LP |
1 | <?xml version='1.0'?> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" | |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
4 | <!-- SPDX-License-Identifier: LGPL-2.1-or-later --> | |
5 | ||
6 | <refentry id="sd_event_source_set_ratelimit" xmlns:xi="http://www.w3.org/2001/XInclude"> | |
7 | ||
8 | <refentryinfo> | |
9 | <title>sd_event_source_set_ratelimit</title> | |
10 | <productname>systemd</productname> | |
11 | </refentryinfo> | |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>sd_event_source_set_ratelimit</refentrytitle> | |
15 | <manvolnum>3</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>sd_event_source_set_ratelimit</refname> | |
20 | <refname>sd_event_source_get_ratelimit</refname> | |
21 | <refname>sd_event_source_is_ratelimited</refname> | |
fd69f224 | 22 | <refname>sd_event_source_set_ratelimit_expire_callback</refname> |
a303686f LP |
23 | |
24 | <refpurpose>Configure rate limiting on event sources</refpurpose> | |
25 | </refnamediv> | |
26 | ||
27 | <refsynopsisdiv> | |
28 | <funcsynopsis> | |
29 | <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> | |
30 | ||
31 | <funcprototype> | |
32 | <funcdef>int <function>sd_event_source_set_ratelimit</function></funcdef> | |
33 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
34 | <paramdef>uint64_t <parameter>interval_usec</parameter></paramdef> | |
35 | <paramdef>unsigned <parameter>burst</parameter></paramdef> | |
36 | </funcprototype> | |
37 | ||
38 | <funcprototype> | |
39 | <funcdef>int <function>sd_event_source_get_ratelimit</function></funcdef> | |
40 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
41 | <paramdef>uint64_t* <parameter>ret_interval_usec</parameter></paramdef> | |
42 | <paramdef>unsigned* <parameter>ret_burst</parameter></paramdef> | |
43 | </funcprototype> | |
44 | ||
45 | <funcprototype> | |
46 | <funcdef>int <function>sd_event_source_is_ratelimited</function></funcdef> | |
47 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
48 | </funcprototype> | |
49 | ||
fd69f224 MS |
50 | <funcprototype> |
51 | <funcdef>int <function>sd_event_source_set_ratelimit_expire_callback</function></funcdef> | |
52 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
53 | <paramdef>sd_event_handler_t<parameter>callback</parameter></paramdef> | |
54 | </funcprototype> | |
55 | ||
a303686f LP |
56 | </funcsynopsis> |
57 | </refsynopsisdiv> | |
58 | ||
59 | <refsect1> | |
60 | <title>Description</title> | |
61 | ||
62 | <para><function>sd_event_source_set_ratelimit()</function> may be used to enforce rate limiting on an | |
63 | event source. When used an event source will be temporarily turned off when it fires more often then a | |
64 | specified burst number within a specified time interval. This is useful as simple mechanism to avoid | |
65 | event source starvation if high priority event sources fire very frequently.</para> | |
66 | ||
67 | <para>Pass the event source to operate on as first argument, a time interval in microseconds as second | |
68 | argument and a maximum dispatch limit ("burst") as third parameter. Whenever the event source is | |
69 | dispatched more often than the specified burst within the specified interval it is placed in a mode | |
70 | similar to being disabled with | |
71 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
72 | and the <constant>SD_EVENT_OFF</constant> parameter. However it is disabled only temporarily – once the | |
73 | specified interval is over regular operation resumes. It is again disabled temporarily once the specified rate | |
74 | limiting is hit the next time. If either the interval or the burst value are specified as zero, rate | |
75 | limiting is turned off. By default event sources do not have rate limiting enabled. Note that rate | |
76 | limiting and disabling via <function>sd_event_source_set_enabled()</function> are independent of each | |
77 | other, and an event source will only effect event loop wake-ups and is dispatched while it both is | |
78 | enabled and rate limiting is not in effect.</para> | |
79 | ||
80 | <para><function>sd_event_source_get_ratelimit()</function> may be used to query the current rate limiting | |
81 | parameters set on the event source object <parameter>source</parameter>. The previously set interval and | |
82 | burst vales are returned in the second and third argument.</para> | |
83 | ||
84 | <para><function>sd_event_source_is_ratelimited()</function> may be used to query whether the event source | |
85 | is currently affected by rate limiting, i.e. it has recently hit the rate limit and is currently | |
86 | temporarily disabled due to that.</para> | |
87 | ||
fd69f224 MS |
88 | <para><function>sd_event_source_set_ratelimit_expire_callback</function> may be used to set a callback |
89 | function that is invoked every time the event source leaves rate limited state. Note that function is | |
90 | called in the same event loop iteration in which state transition occured.</para> | |
91 | ||
a303686f LP |
92 | <para>Rate limiting is currently implemented for I/O, timer, signal, defer and inotify event |
93 | sources.</para> | |
94 | </refsect1> | |
95 | ||
96 | <refsect1> | |
97 | <title>Return Value</title> | |
98 | ||
fd69f224 MS |
99 | <para>On success, <function>sd_event_source_set_ratelimit()</function>, |
100 | <function>sd_event_source_set_ratelimit_expire_callback</function> and | |
101 | <function>sd_event_source_get_ratelimit()</function> return a non-negative integer. On failure, they return | |
102 | a negative errno-style error code. <function>sd_event_source_is_ratelimited</function> returns zero if rate | |
103 | limiting is currently not in effect and greater than zero if it is in effect; it returns a negative | |
104 | errno-style error code on failure.</para> | |
a303686f LP |
105 | |
106 | <refsect2> | |
107 | <title>Errors</title> | |
108 | ||
109 | <para>Returned errors may indicate the following problems:</para> | |
110 | ||
111 | <variablelist> | |
112 | <varlistentry> | |
113 | <term><constant>-EINVAL</constant></term> | |
114 | ||
115 | <listitem><para><parameter>source</parameter> is not a valid pointer to an | |
116 | <structname>sd_event_source</structname> object. | |
117 | </para></listitem> | |
118 | </varlistentry> | |
119 | ||
120 | <varlistentry> | |
121 | <term><constant>-ECHILD</constant></term> | |
122 | ||
123 | <listitem><para>The event loop has been created in a different process.</para></listitem> | |
124 | </varlistentry> | |
125 | ||
126 | <varlistentry> | |
127 | <term><constant>-EDOM</constant></term> | |
128 | ||
129 | <listitem><para>It was attempted to use the rate limiting feature on an event source type that does | |
130 | not support rate limiting.</para></listitem> | |
131 | </varlistentry> | |
132 | ||
133 | <varlistentry> | |
134 | <term><constant>-ENOEXEC</constant></term> | |
135 | ||
387f6955 | 136 | <listitem><para><function>sd_event_source_get_ratelimit()</function> was called on an event source |
a303686f LP |
137 | that doesn't have rate limiting configured.</para></listitem> |
138 | </varlistentry> | |
139 | ||
140 | </variablelist> | |
141 | </refsect2> | |
142 | </refsect1> | |
143 | ||
144 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
145 | ||
146 | <refsect1> | |
147 | <title>See Also</title> | |
148 | ||
149 | <para> | |
150 | <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
151 | <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
152 | <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
153 | <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
154 | <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
155 | <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
156 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
157 | </para> | |
158 | </refsect1> | |
159 | ||
160 | </refentry> |