Skip to content

Commit bf282d3

Browse files
committed
net: tc: allow to spread threads by more then 1 priority level
Allow to spread tc threads by more then one priority level and cleanup the computation of the priority. Signed-off-by: Cla Mattia Galliard <[email protected]>
1 parent 578a29f commit bf282d3

File tree

2 files changed

+26
-72
lines changed

2 files changed

+26
-72
lines changed

subsys/net/ip/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,20 @@ config NET_TC_THREAD_PRIO_CUSTOM
294294
Customise net threads priority by each.
295295

296296
if NET_TC_THREAD_PRIO_CUSTOM
297+
config NET_TC_TX_THREAD_PRIO_SPREAD
298+
int "Transmit traffic class thread priority spread"
299+
default 1
300+
help
301+
Transmit traffic class threads priority will increase/decrease
302+
byt this step. They will be separated by this many levels.
303+
304+
config NET_TC_RX_THREAD_PRIO_SPREAD
305+
int "Receive traffic class thread priority spread"
306+
default 1
307+
help
308+
Receive traffic class threads priority will increase/decrease
309+
byt this step. They will be separated by this many levels.
310+
297311
config NET_TC_TX_THREAD_BASE_PRIO
298312
int "Transmit traffic class base thread priority"
299313
default 0

subsys/net/ip/net_tc.c

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -151,88 +151,26 @@ int net_rx_priority2tc(enum net_priority prio)
151151

152152
#if defined(CONFIG_NET_TC_THREAD_PRIO_CUSTOM)
153153
#define BASE_PRIO_TX CONFIG_NET_TC_TX_THREAD_BASE_PRIO
154+
#define PRIO_SPREAD_TX CONFIG_NET_TC_TX_THREAD_PRIO_SPREAD
154155
#elif defined(CONFIG_NET_TC_THREAD_COOPERATIVE)
155156
#define BASE_PRIO_TX (CONFIG_NET_TC_NUM_PRIORITIES - 1)
157+
#define PRIO_SPREAD_TX 1
158+
BUILD_ASSERT(NET_TC_TX_COUNT <= CONFIG_NUM_COOP_PRIORITIES, "Too many traffic classes");
156159
#else
157160
#define BASE_PRIO_TX (CONFIG_NET_TC_TX_COUNT - 1)
161+
#define PRIO_SPREAD_TX 1
158162
#endif
159163

160-
#define PRIO_TX(i, _) (BASE_PRIO_TX - i)
161-
162164
#if defined(CONFIG_NET_TC_THREAD_PRIO_CUSTOM)
163165
#define BASE_PRIO_RX CONFIG_NET_TC_RX_THREAD_BASE_PRIO
166+
#define PRIO_SPREAD_RX CONFIG_NET_TC_RX_THREAD_PRIO_SPREAD
164167
#elif defined(CONFIG_NET_TC_THREAD_COOPERATIVE)
165168
#define BASE_PRIO_RX (CONFIG_NET_TC_NUM_PRIORITIES - 1)
169+
#define PRIO_SPREAD_RX 1
170+
BUILD_ASSERT(NET_TC_RX_COUNT <= CONFIG_NUM_COOP_PRIORITIES, "Too many traffic classes");
166171
#else
167172
#define BASE_PRIO_RX (CONFIG_NET_TC_RX_COUNT - 1)
168-
#endif
169-
170-
#define PRIO_RX(i, _) (BASE_PRIO_RX - i)
171-
172-
#if NET_TC_TX_COUNT > 0
173-
/* Convert traffic class to thread priority */
174-
static uint8_t tx_tc2thread(uint8_t tc)
175-
{
176-
/* Initial implementation just maps the traffic class to certain queue.
177-
* If there are less queues than classes, then map them into
178-
* some specific queue.
179-
*
180-
* Lower value in this table means higher thread priority. The
181-
* value is used as a parameter to K_PRIO_COOP() or K_PRIO_PREEMPT()
182-
* which converts it to actual thread priority.
183-
*
184-
* Higher traffic class value means higher priority queue. This means
185-
* that thread_priorities[7] value should contain the highest priority
186-
* for the TX queue handling thread.
187-
*
188-
* For example, if NET_TC_TX_COUNT = 8, which is the maximum number of
189-
* traffic classes, then this priority array will contain following
190-
* values if preemptive priorities are used:
191-
* 7, 6, 5, 4, 3, 2, 1, 0
192-
* and
193-
* 14, 13, 12, 11, 10, 9, 8, 7
194-
* if cooperative priorities are used.
195-
*
196-
* Then these will be converted to following thread priorities if
197-
* CONFIG_NET_TC_THREAD_COOPERATIVE is enabled:
198-
* -1, -2, -3, -4, -5, -6, -7, -8
199-
*
200-
* and if CONFIG_NET_TC_THREAD_PREEMPTIVE is enabled, following thread
201-
* priorities are used:
202-
* 7, 6, 5, 4, 3, 2, 1, 0
203-
*
204-
* This means that the lowest traffic class 1, will have the lowest
205-
* cooperative priority -1 for coop priorities and 7 for preemptive
206-
* priority.
207-
*/
208-
static const uint8_t thread_priorities[] = {
209-
LISTIFY(NET_TC_TX_COUNT, PRIO_TX, (,))
210-
};
211-
212-
BUILD_ASSERT(NET_TC_TX_COUNT <= CONFIG_NUM_COOP_PRIORITIES,
213-
"Too many traffic classes");
214-
215-
NET_ASSERT(tc < ARRAY_SIZE(thread_priorities));
216-
217-
return thread_priorities[tc];
218-
}
219-
#endif
220-
221-
#if NET_TC_RX_COUNT > 0
222-
/* Convert traffic class to thread priority */
223-
static uint8_t rx_tc2thread(uint8_t tc)
224-
{
225-
static const uint8_t thread_priorities[] = {
226-
LISTIFY(NET_TC_RX_COUNT, PRIO_RX, (,))
227-
};
228-
229-
BUILD_ASSERT(NET_TC_RX_COUNT <= CONFIG_NUM_COOP_PRIORITIES,
230-
"Too many traffic classes");
231-
232-
NET_ASSERT(tc < ARRAY_SIZE(thread_priorities));
233-
234-
return thread_priorities[tc];
235-
}
173+
#define PRIO_SPREAD_RX 1
236174
#endif
237175

238176
#if defined(CONFIG_NET_STATISTICS)
@@ -362,7 +300,8 @@ void net_tc_tx_init(void)
362300
int priority;
363301
k_tid_t tid;
364302

365-
thread_priority = tx_tc2thread(i);
303+
BUILD_ASSERT(BASE_PRIO_TX >= PRIO_SPREAD_TX * (NET_TC_TX_COUNT - 1));
304+
thread_priority = BASE_PRIO_TX - PRIO_SPREAD_TX * i;
366305

367306
priority = IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE) ?
368307
K_PRIO_COOP(thread_priority) :
@@ -430,7 +369,8 @@ void net_tc_rx_init(void)
430369
int priority;
431370
k_tid_t tid;
432371

433-
thread_priority = rx_tc2thread(i);
372+
BUILD_ASSERT(BASE_PRIO_RX >= PRIO_SPREAD_RX * (NET_TC_RX_COUNT - 1));
373+
thread_priority = BASE_PRIO_RX - PRIO_SPREAD_RX * i;
434374

435375
priority = IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE) ?
436376
K_PRIO_COOP(thread_priority) :

0 commit comments

Comments
 (0)