]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_event_source_set_ratelimit.xml
tree-wide: "a" -> "an"
[thirdparty/systemd.git] / man / sd_event_source_set_ratelimit.xml
CommitLineData
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>
22
23 <refpurpose>Configure rate limiting on event sources</refpurpose>
24 </refnamediv>
25
26 <refsynopsisdiv>
27 <funcsynopsis>
28 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
29
30 <funcprototype>
31 <funcdef>int <function>sd_event_source_set_ratelimit</function></funcdef>
32 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
33 <paramdef>uint64_t <parameter>interval_usec</parameter></paramdef>
34 <paramdef>unsigned <parameter>burst</parameter></paramdef>
35 </funcprototype>
36
37 <funcprototype>
38 <funcdef>int <function>sd_event_source_get_ratelimit</function></funcdef>
39 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
40 <paramdef>uint64_t* <parameter>ret_interval_usec</parameter></paramdef>
41 <paramdef>unsigned* <parameter>ret_burst</parameter></paramdef>
42 </funcprototype>
43
44 <funcprototype>
45 <funcdef>int <function>sd_event_source_is_ratelimited</function></funcdef>
46 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
47 </funcprototype>
48
49 </funcsynopsis>
50 </refsynopsisdiv>
51
52 <refsect1>
53 <title>Description</title>
54
55 <para><function>sd_event_source_set_ratelimit()</function> may be used to enforce rate limiting on an
56 event source. When used an event source will be temporarily turned off when it fires more often then a
57 specified burst number within a specified time interval. This is useful as simple mechanism to avoid
58 event source starvation if high priority event sources fire very frequently.</para>
59
60 <para>Pass the event source to operate on as first argument, a time interval in microseconds as second
61 argument and a maximum dispatch limit ("burst") as third parameter. Whenever the event source is
62 dispatched more often than the specified burst within the specified interval it is placed in a mode
63 similar to being disabled with
64 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
65 and the <constant>SD_EVENT_OFF</constant> parameter. However it is disabled only temporarily – once the
66 specified interval is over regular operation resumes. It is again disabled temporarily once the specified rate
67 limiting is hit the next time. If either the interval or the burst value are specified as zero, rate
68 limiting is turned off. By default event sources do not have rate limiting enabled. Note that rate
69 limiting and disabling via <function>sd_event_source_set_enabled()</function> are independent of each
70 other, and an event source will only effect event loop wake-ups and is dispatched while it both is
71 enabled and rate limiting is not in effect.</para>
72
73 <para><function>sd_event_source_get_ratelimit()</function> may be used to query the current rate limiting
74 parameters set on the event source object <parameter>source</parameter>. The previously set interval and
75 burst vales are returned in the second and third argument.</para>
76
77 <para><function>sd_event_source_is_ratelimited()</function> may be used to query whether the event source
78 is currently affected by rate limiting, i.e. it has recently hit the rate limit and is currently
79 temporarily disabled due to that.</para>
80
81 <para>Rate limiting is currently implemented for I/O, timer, signal, defer and inotify event
82 sources.</para>
83 </refsect1>
84
85 <refsect1>
86 <title>Return Value</title>
87
88 <para>On success, <function>sd_event_source_set_ratelimit()</function> and
89 <function>sd_event_source_get_ratelimit()</function> return a non-negative integer. On failure, they
90 return a negative errno-style error code. <function>sd_event_source_is_ratelimited</function> returns
91 zero if rate limiting is currently not in effect and greater than zero if it is in effect; it returns a
92 negative errno-style error code on failure.</para>
93
94 <refsect2>
95 <title>Errors</title>
96
97 <para>Returned errors may indicate the following problems:</para>
98
99 <variablelist>
100 <varlistentry>
101 <term><constant>-EINVAL</constant></term>
102
103 <listitem><para><parameter>source</parameter> is not a valid pointer to an
104 <structname>sd_event_source</structname> object.
105 </para></listitem>
106 </varlistentry>
107
108 <varlistentry>
109 <term><constant>-ECHILD</constant></term>
110
111 <listitem><para>The event loop has been created in a different process.</para></listitem>
112 </varlistentry>
113
114 <varlistentry>
115 <term><constant>-EDOM</constant></term>
116
117 <listitem><para>It was attempted to use the rate limiting feature on an event source type that does
118 not support rate limiting.</para></listitem>
119 </varlistentry>
120
121 <varlistentry>
122 <term><constant>-ENOEXEC</constant></term>
123
387f6955 124 <listitem><para><function>sd_event_source_get_ratelimit()</function> was called on an event source
a303686f
LP
125 that doesn't have rate limiting configured.</para></listitem>
126 </varlistentry>
127
128 </variablelist>
129 </refsect2>
130 </refsect1>
131
132 <xi:include href="libsystemd-pkgconfig.xml" />
133
134 <refsect1>
135 <title>See Also</title>
136
137 <para>
138 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
139 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
140 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
141 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
142 <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
143 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
144 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
145 </para>
146 </refsect1>
147
148</refentry>