xref: /dpdk/lib/eal/unix/eal_unix_thread.c (revision 8f1d23ece06adff5eae9f1b4365bdbbd3abee2b2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Red Hat, Inc.
3  */
4 
5 #include <errno.h>
6 #include <unistd.h>
7 
8 #include <rte_debug.h>
9 
10 #include "eal_private.h"
11 
12 void
13 eal_thread_wake_worker(unsigned int worker_id)
14 {
15 	int m2w = lcore_config[worker_id].pipe_main2worker[1];
16 	int w2m = lcore_config[worker_id].pipe_worker2main[0];
17 	char c = 0;
18 	int n;
19 
20 	do {
21 		n = write(m2w, &c, 1);
22 	} while (n == 0 || (n < 0 && errno == EINTR));
23 	if (n < 0)
24 		rte_panic("cannot write on configuration pipe\n");
25 
26 	do {
27 		n = read(w2m, &c, 1);
28 	} while (n < 0 && errno == EINTR);
29 	if (n <= 0)
30 		rte_panic("cannot read on configuration pipe\n");
31 }
32 
33 void
34 eal_thread_wait_command(void)
35 {
36 	unsigned int lcore_id = rte_lcore_id();
37 	int m2w;
38 	char c;
39 	int n;
40 
41 	m2w = lcore_config[lcore_id].pipe_main2worker[0];
42 	do {
43 		n = read(m2w, &c, 1);
44 	} while (n < 0 && errno == EINTR);
45 	if (n <= 0)
46 		rte_panic("cannot read on configuration pipe\n");
47 }
48 
49 void
50 eal_thread_ack_command(void)
51 {
52 	unsigned int lcore_id = rte_lcore_id();
53 	char c = 0;
54 	int w2m;
55 	int n;
56 
57 	w2m = lcore_config[lcore_id].pipe_worker2main[1];
58 	do {
59 		n = write(w2m, &c, 1);
60 	} while (n == 0 || (n < 0 && errno == EINTR));
61 	if (n < 0)
62 		rte_panic("cannot write on configuration pipe\n");
63 }
64