Blame view

Documentation/networking/net_dim.rst 7.81 KB
9b038086f   Jakub Kicinski   docs: networking:...
1
  ======================================================
faf4db008   Tal Gilboa   Documentation/net...
2
3
  Net DIM - Generic Network Dynamic Interrupt Moderation
  ======================================================
9b038086f   Jakub Kicinski   docs: networking:...
4
  :Author: Tal Gilboa <talgi@mellanox.com>
faf4db008   Tal Gilboa   Documentation/net...
5

9b038086f   Jakub Kicinski   docs: networking:...
6
  .. contents:: :depth: 2
faf4db008   Tal Gilboa   Documentation/net...
7

9b038086f   Jakub Kicinski   docs: networking:...
8
9
  Assumptions
  ===========
faf4db008   Tal Gilboa   Documentation/net...
10
11
12
  
  This document assumes the reader has basic knowledge in network drivers
  and in general interrupt moderation.
9b038086f   Jakub Kicinski   docs: networking:...
13
14
  Introduction
  ============
faf4db008   Tal Gilboa   Documentation/net...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  
  Dynamic Interrupt Moderation (DIM) (in networking) refers to changing the
  interrupt moderation configuration of a channel in order to optimize packet
  processing. The mechanism includes an algorithm which decides if and how to
  change moderation parameters for a channel, usually by performing an analysis on
  runtime data sampled from the system. Net DIM is such a mechanism. In each
  iteration of the algorithm, it analyses a given sample of the data, compares it
  to the previous sample and if required, it can decide to change some of the
  interrupt moderation configuration fields. The data sample is composed of data
  bandwidth, the number of packets and the number of events. The time between
  samples is also measured. Net DIM compares the current and the previous data and
  returns an adjusted interrupt moderation configuration object. In some cases,
  the algorithm might decide not to change anything. The configuration fields are
  the minimum duration (microseconds) allowed between events and the maximum
  number of wanted packets per event. The Net DIM algorithm ascribes importance to
  increase bandwidth over reducing interrupt rate.
9b038086f   Jakub Kicinski   docs: networking:...
31
32
  Net DIM Algorithm
  =================
faf4db008   Tal Gilboa   Documentation/net...
33
34
  
  Each iteration of the Net DIM algorithm follows these steps:
9b038086f   Jakub Kicinski   docs: networking:...
35
36
37
38
39
  
  #. Calculates new data sample.
  #. Compares it to previous sample.
  #. Makes a decision - suggests interrupt moderation configuration fields.
  #. Applies a schedule work function, which applies suggested configuration.
faf4db008   Tal Gilboa   Documentation/net...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  The first two steps are straightforward, both the new and the previous data are
  supplied by the driver registered to Net DIM. The previous data is the new data
  supplied to the previous iteration. The comparison step checks the difference
  between the new and previous data and decides on the result of the last step.
  A step would result as "better" if bandwidth increases and as "worse" if
  bandwidth reduces. If there is no change in bandwidth, the packet rate is
  compared in a similar fashion - increase == "better" and decrease == "worse".
  In case there is no change in the packet rate as well, the interrupt rate is
  compared. Here the algorithm tries to optimize for lower interrupt rate so an
  increase in the interrupt rate is considered "worse" and a decrease is
  considered "better". Step #2 has an optimization for avoiding false results: it
  only considers a difference between samples as valid if it is greater than a
  certain percentage. Also, since Net DIM does not measure anything by itself, it
  assumes the data provided by the driver is valid.
  
  Step #3 decides on the suggested configuration based on the result from step #2
  and the internal state of the algorithm. The states reflect the "direction" of
  the algorithm: is it going left (reducing moderation), right (increasing
  moderation) or standing still. Another optimization is that if a decision
  to stay still is made multiple times, the interval between iterations of the
  algorithm would increase in order to reduce calculation overhead. Also, after
  "parking" on one of the most left or most right decisions, the algorithm may
  decide to verify this decision by taking a step in the other direction. This is
  done in order to avoid getting stuck in a "deep sleep" scenario. Once a
  decision is made, an interrupt moderation configuration is selected from
  the predefined profiles.
  
  The last step is to notify the registered driver that it should apply the
  suggested configuration. This is done by scheduling a work function, defined by
  the Net DIM API and provided by the registered driver.
  
  As you can see, Net DIM itself does not actively interact with the system. It
  would have trouble making the correct decisions if the wrong data is supplied to
  it and it would be useless if the work function would not apply the suggested
  configuration. This does, however, allow the registered driver some room for
  manoeuvre as it may provide partial data or ignore the algorithm suggestion
  under some conditions.
9b038086f   Jakub Kicinski   docs: networking:...
78
79
  Registering a Network Device to DIM
  ===================================
faf4db008   Tal Gilboa   Documentation/net...
80

9b038086f   Jakub Kicinski   docs: networking:...
81
82
  Net DIM API exposes the main function net_dim().
  This function is the entry point to the Net
faf4db008   Tal Gilboa   Documentation/net...
83
84
  DIM algorithm and has to be called every time the driver would like to check if
  it should change interrupt moderation parameters. The driver should provide two
9b038086f   Jakub Kicinski   docs: networking:...
85
86
  data structures: :c:type:`struct dim <dim>` and
  :c:type:`struct dim_sample <dim_sample>`. :c:type:`struct dim <dim>`
faf4db008   Tal Gilboa   Documentation/net...
87
88
89
  describes the state of DIM for a specific object (RX queue, TX queue,
  other queues, etc.). This includes the current selected profile, previous data
  samples, the callback function provided by the driver and more.
9b038086f   Jakub Kicinski   docs: networking:...
90
91
92
  :c:type:`struct dim_sample <dim_sample>` describes a data sample,
  which will be compared to the data sample stored in :c:type:`struct dim <dim>`
  in order to decide on the algorithm's next
faf4db008   Tal Gilboa   Documentation/net...
93
94
95
96
97
98
99
100
  step. The sample should include bytes, packets and interrupts, measured by
  the driver.
  
  In order to use Net DIM from a networking driver, the driver needs to call the
  main net_dim() function. The recommended method is to call net_dim() on each
  interrupt. Since Net DIM has a built-in moderation and it might decide to skip
  iterations under certain conditions, there is no need to moderate the net_dim()
  calls as well. As mentioned above, the driver needs to provide an object of type
9b038086f   Jakub Kicinski   docs: networking:...
101
102
103
104
  :c:type:`struct dim <dim>` to the net_dim() function call. It is advised for
  each entity using Net DIM to hold a :c:type:`struct dim <dim>` as part of its
  data structure and use it as the main Net DIM API object.
  The :c:type:`struct dim_sample <dim_sample>` should hold the latest
faf4db008   Tal Gilboa   Documentation/net...
105
106
107
108
109
110
111
112
113
  bytes, packets and interrupts count. No need to perform any calculations, just
  include the raw data.
  
  The net_dim() call itself does not return anything. Instead Net DIM relies on
  the driver to provide a callback function, which is called when the algorithm
  decides to make a change in the interrupt moderation parameters. This callback
  will be scheduled and run in a separate thread in order not to add overhead to
  the data flow. After the work is done, Net DIM algorithm needs to be set to
  the proper state in order to move to the next iteration.
9b038086f   Jakub Kicinski   docs: networking:...
114
115
  Example
  =======
faf4db008   Tal Gilboa   Documentation/net...
116
117
118
  
  The following code demonstrates how to register a driver to Net DIM. The actual
  usage is not complete but it should make the outline of the usage clear.
9b038086f   Jakub Kicinski   docs: networking:...
119
  .. code-block:: c
faf4db008   Tal Gilboa   Documentation/net...
120

9b038086f   Jakub Kicinski   docs: networking:...
121
    #include <linux/dim.h>
faf4db008   Tal Gilboa   Documentation/net...
122

9b038086f   Jakub Kicinski   docs: networking:...
123
124
125
    /* Callback for net DIM to schedule on a decision to change moderation */
    void my_driver_do_dim_work(struct work_struct *work)
    {
2168da459   Jacob Keller   net: update net_d...
126
127
128
  	/* Get struct dim from struct work_struct */
  	struct dim *dim = container_of(work, struct dim,
  				       work);
faf4db008   Tal Gilboa   Documentation/net...
129
130
131
132
  	/* Do interrupt moderation related stuff */
  	...
  
  	/* Signal net DIM work is done and it should move to next iteration */
2168da459   Jacob Keller   net: update net_d...
133
  	dim->state = DIM_START_MEASURE;
9b038086f   Jakub Kicinski   docs: networking:...
134
    }
faf4db008   Tal Gilboa   Documentation/net...
135

9b038086f   Jakub Kicinski   docs: networking:...
136
137
138
    /* My driver's interrupt handler */
    int my_driver_handle_interrupt(struct my_driver_entity *my_entity, ...)
    {
faf4db008   Tal Gilboa   Documentation/net...
139
140
  	...
  	/* A struct to hold current measured data */
2168da459   Jacob Keller   net: update net_d...
141
  	struct dim_sample dim_sample;
faf4db008   Tal Gilboa   Documentation/net...
142
143
  	...
  	/* Initiate data sample struct with current data */
2168da459   Jacob Keller   net: update net_d...
144
145
146
147
  	dim_update_sample(my_entity->events,
  		          my_entity->packets,
  		          my_entity->bytes,
  		          &dim_sample);
faf4db008   Tal Gilboa   Documentation/net...
148
149
150
  	/* Call net DIM */
  	net_dim(&my_entity->dim, dim_sample);
  	...
9b038086f   Jakub Kicinski   docs: networking:...
151
    }
faf4db008   Tal Gilboa   Documentation/net...
152

9b038086f   Jakub Kicinski   docs: networking:...
153
154
155
    /* My entity's initialization function (my_entity was already allocated) */
    int my_driver_init_my_entity(struct my_driver_entity *my_entity, ...)
    {
faf4db008   Tal Gilboa   Documentation/net...
156
157
158
159
  	...
  	/* Initiate struct work_struct with my driver's callback function */
  	INIT_WORK(&my_entity->dim.work, my_driver_do_dim_work);
  	...
9b038086f   Jakub Kicinski   docs: networking:...
160
    }
9d8592896   Randy Dunlap   docs: networking:...
161
162
163
164
165
166
  
  Dynamic Interrupt Moderation (DIM) library API
  ==============================================
  
  .. kernel-doc:: include/linux/dim.h
      :internal: