Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/meters/tswtcl.c
+++ new/usr/src/uts/common/ipp/meters/tswtcl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/types.h>
30 28 #include <sys/kmem.h>
31 29 #include <sys/random.h>
32 30 #include <netinet/in.h>
33 31 #include <netinet/in_systm.h>
34 32 #include <netinet/ip6.h>
35 33 #include <inet/common.h>
36 34 #include <inet/ip.h>
37 35 #include <inet/ip6.h>
38 36 #include <ipp/meters/meter_impl.h>
39 37
40 38 /*
41 39 * Module : Time Sliding Window meter - tswtclmtr
42 40 * Description
43 41 * This module implements the metering part of RFC 2859. It accepts the
44 42 * committed rate, peak rate and the window for a flow and determines
45 43 * if the flow is within the committed/peak rate and assigns the appropriate
46 44 * next action.
47 45 * The meter provides an estimate of the running average bandwidth for the
48 46 * flow over the specified window. It uses probability to benefit TCP flows
49 47 * as it reduces the likelihood of dropping multiple packets within a TCP
50 48 * window without adversely effecting UDP flows.
51 49 */
52 50
53 51 int tswtcl_debug = 0;
54 52
55 53 /*
56 54 * Given a packet and the tswtcl_data it belongs to, this routine meters the
57 55 * ToS or DSCP for IPv4 and IPv6 resp. with the values configured for
58 56 * the tswtcl_data.
59 57 */
60 58 /* ARGSUSED */
61 59 int
62 60 tswtcl_process(mblk_t **mpp, tswtcl_data_t *tswtcl_data,
63 61 ipp_action_id_t *next_action)
64 62 {
65 63 ipha_t *ipha;
66 64 hrtime_t now;
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
67 65 ip6_t *ip6_hdr;
68 66 uint32_t pkt_len;
69 67 mblk_t *mp = *mpp;
70 68 hrtime_t deltaT;
71 69 uint64_t bitsinwin;
72 70 uint32_t min = 0, additive, rnd;
73 71 tswtcl_cfg_t *cfg_parms = tswtcl_data->cfg_parms;
74 72
75 73 if (mp == NULL) {
76 74 tswtcl0dbg(("tswtcl_process: null mp!\n"));
77 - atomic_add_64(&tswtcl_data->epackets, 1);
75 + atomic_inc_64(&tswtcl_data->epackets);
78 76 return (EINVAL);
79 77 }
80 78
81 79 if (mp->b_datap->db_type != M_DATA) {
82 80 if ((mp->b_cont != NULL) &&
83 81 (mp->b_cont->b_datap->db_type == M_DATA)) {
84 82 mp = mp->b_cont;
85 83 } else {
86 84 tswtcl0dbg(("tswtcl_process: no data\n"));
87 - atomic_add_64(&tswtcl_data->epackets, 1);
85 + atomic_inc_64(&tswtcl_data->epackets);
88 86 return (EINVAL);
89 87 }
90 88 }
91 89
92 90 /* Figure out the ToS/Traffic Class and length from the message */
93 91 if ((mp->b_wptr - mp->b_rptr) < IP_SIMPLE_HDR_LENGTH) {
94 92 if (!pullupmsg(mp, IP_SIMPLE_HDR_LENGTH)) {
95 93 tswtcl0dbg(("tswtcl_process: pullup error\n"));
96 - atomic_add_64(&tswtcl_data->epackets, 1);
94 + atomic_inc_64(&tswtcl_data->epackets);
97 95 return (EINVAL);
98 96 }
99 97 }
100 98 ipha = (ipha_t *)mp->b_rptr;
101 99 if (IPH_HDR_VERSION(ipha) == IPV4_VERSION) {
102 100 pkt_len = ntohs(ipha->ipha_length);
103 101 } else {
104 102 ip6_hdr = (ip6_t *)mp->b_rptr;
105 103 pkt_len = ntohs(ip6_hdr->ip6_plen) +
106 104 ip_hdr_length_v6(mp, ip6_hdr);
107 105 }
108 106
109 107 /* Convert into bits */
110 108 pkt_len <<= 3;
111 109
112 110 /* Get current time */
113 111 now = gethrtime();
114 112
115 113 /* Update the avg_rate and win_front tswtcl_data */
116 114 mutex_enter(&tswtcl_data->tswtcl_lock);
117 115
118 116 /* avg_rate = bits/sec and window in msec */
119 117 bitsinwin = ((uint64_t)tswtcl_data->avg_rate * cfg_parms->window /
120 118 1000) + pkt_len;
121 119
122 120 deltaT = now - tswtcl_data->win_front + cfg_parms->nsecwindow;
123 121
124 122 tswtcl_data->avg_rate = (uint64_t)bitsinwin * METER_SEC_TO_NSEC /
125 123 deltaT;
126 124 tswtcl_data->win_front = now;
127 125
128 126 if (tswtcl_data->avg_rate <= cfg_parms->committed_rate) {
129 127 *next_action = cfg_parms->green_action;
130 128 } else if (tswtcl_data->avg_rate <= cfg_parms->peak_rate) {
131 129 /*
132 130 * Compute the probability:
133 131 *
134 132 * p0 = (avg_rate - committed_rate) / avg_rate
135 133 *
136 134 * Yellow with probability p0
137 135 * Green with probability (1 - p0)
138 136 *
139 137 */
140 138 uint32_t aminusc;
141 139
142 140 /* Get a random no. betweeen 0 and avg_rate */
143 141 (void) random_get_pseudo_bytes((uint8_t *)&additive,
144 142 sizeof (additive));
145 143 rnd = min + (additive % (tswtcl_data->avg_rate - min + 1));
146 144
147 145 aminusc = tswtcl_data->avg_rate - cfg_parms->committed_rate;
148 146 if (aminusc >= rnd) {
149 147 *next_action = cfg_parms->yellow_action;
150 148 } else {
151 149 *next_action = cfg_parms->green_action;
152 150 }
153 151 } else {
154 152 /*
155 153 * Compute the probability:
156 154 *
157 155 * p1 = (avg_rate - peak_rate) / avg_rate
158 156 * p2 = (peak_rate - committed_rate) / avg_rate
159 157 *
160 158 * Red with probability p1
161 159 * Yellow with probability p2
162 160 * Green with probability (1 - (p1 + p2))
163 161 *
164 162 */
165 163 uint32_t aminusp;
166 164
167 165 /* Get a random no. betweeen 0 and avg_rate */
168 166 (void) random_get_pseudo_bytes((uint8_t *)&additive,
169 167 sizeof (additive));
170 168 rnd = min + (additive % (tswtcl_data->avg_rate - min + 1));
171 169
172 170 aminusp = tswtcl_data->avg_rate - cfg_parms->peak_rate;
173 171
174 172 if (aminusp >= rnd) {
175 173 *next_action = cfg_parms->red_action;
176 174 } else if ((cfg_parms->pminusc + aminusp) >= rnd) {
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
177 175 *next_action = cfg_parms->yellow_action;
178 176 } else {
179 177 *next_action = cfg_parms->green_action;
180 178 }
181 179
182 180 }
183 181 mutex_exit(&tswtcl_data->tswtcl_lock);
184 182
185 183 /* Update Stats */
186 184 if (*next_action == cfg_parms->green_action) {
187 - atomic_add_64(&tswtcl_data->green_packets, 1);
185 + atomic_inc_64(&tswtcl_data->green_packets);
188 186 atomic_add_64(&tswtcl_data->green_bits, pkt_len);
189 187 } else if (*next_action == cfg_parms->yellow_action) {
190 - atomic_add_64(&tswtcl_data->yellow_packets, 1);
188 + atomic_inc_64(&tswtcl_data->yellow_packets);
191 189 atomic_add_64(&tswtcl_data->yellow_bits, pkt_len);
192 190 } else {
193 191 ASSERT(*next_action == cfg_parms->red_action);
194 - atomic_add_64(&tswtcl_data->red_packets, 1);
192 + atomic_inc_64(&tswtcl_data->red_packets);
195 193 atomic_add_64(&tswtcl_data->red_bits, pkt_len);
196 194 }
197 195 return (0);
198 196 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX